From 58222f286980fbf947226cee87fbdd9362d90d06 Mon Sep 17 00:00:00 2001 From: DemchaAV Date: Sun, 18 Oct 2026 16:08:42 +0100 Subject: [PATCH 1/2] fix(docx): name a table whose columns are left to the editor A table with an auto column whose widths the layout does not show was written with its columns left to Word, and the report said nothing: one composed in another table's cell, which the layout lays out among that table's own rows, and one with a column edge no row of it shows, which leaves the grid read off the rows short of a column. Measured in Word and LibreOffice on Windows, a two-column table in a cell came out half the cell a column in both, its first column 121pt where the page sets it 45, and a fixed column of 120pt beside an auto one 146pt: a grid is every column's width or none, so the fixed one is not written either, and the same holds beside a position past the columns a table declares, which the layout sizes as an auto one. The report names such a table (TableNode), saying which of the two it is and, where it has one, that its fixed columns are not written. A chart's data table, which the page does not draw, is not named. With no layout behind the export, the section's note now says that a fixed column beside an auto one is written with no width. --- CHANGELOG.md | 10 ++ .../architecture/backend-capability-matrix.md | 2 +- docs/recipes/docx-export.md | 7 +- .../semantic/docx/DocxSemanticBackend.java | 60 ++++++- .../semantic/docx/DocxWithoutLayout.java | 14 +- .../docx/DocxNodeFieldLedgerTest.java | 6 +- .../DocxTableColumnsLeftToTheEditorTest.java | 158 ++++++++++++++++++ .../semantic/docx/DocxWithoutLayoutTest.java | 21 +++ 8 files changed, 266 insertions(+), 12 deletions(-) create mode 100644 render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd4b024a..901fe0d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ follow semantic versioning; release dates are ISO 8601. ### Public API +- **A DOCX export names a table whose columns it leaves to the editor.** A table with an auto + column whose widths the layout does not show — one composed in another table's cell, which the + layout lays out among that table's own rows, or one with a column edge no row of it shows — + was written with its columns left to Word, and nothing said. Measured in Word and LibreOffice on + Windows, + a two-column table in a cell came out half the cell a column in both, its first column 121pt + where the page sets it 45, and a fixed column of 120pt beside an auto one 146pt, its width not + written either. The report now names such a table (`TableNode`), and with no layout behind the + export the section's note says that a fixed column beside an auto one is written with no width. + A chart's data table, which the page does not draw, is not named. - **A DOCX export names a border Word draws at another width than the page, and writes a text header's or footer's separator of no width.** A Word border is no thinner than a quarter of a point and no wider than twelve, and the export held a border to that without a word: a panel's diff --git a/docs/architecture/backend-capability-matrix.md b/docs/architecture/backend-capability-matrix.md index 803ddafbb..7d595f48f 100644 --- a/docs/architecture/backend-capability-matrix.md +++ b/docs/architecture/backend-capability-matrix.md @@ -80,7 +80,7 @@ Payload records live in `core` under | Gradient strokes | ✅ `PdfPathPainter` (pattern stroking colour) | ✅ `PptxGradientFill` (native `ln`/`gradFill`) | ❌ | | Image — STRETCH / CONTAIN / COVER fit (`ImageFragmentPayload`) | ✅ `PdfImageFragmentRenderHandler` | ✅ `PptxImageFragmentRenderHandler` (COVER via the picture source crop) | ✅ `DocxSemanticBackend.writeImage` (the box comes from `NodeDefinitionSupport.resolveImageDimensions`, the same rule layout applies to `width` / `height` / `scale` and the content-width clamp; CONTAIN is embedded at its fitted size, COVER via the picture source crop as in PPTX, and the picture type is read from the bytes; its left margin and padding are not written, and a picture drawn beside its text is fitted to its box with its padding in it — each named in the report) | | Barcode / QR (`BarcodeFragmentPayload`) | ✅ `PdfBarcodeFragmentRenderHandler` (vector: the ZXing bit matrix filled as merged rectangles) | ✅ `PptxBarcodeFragmentRenderHandler` (native freeforms: the same ZXing bit matrix as merged rectangles) | ⚠️ `DocxSemanticBackend.writeBarcode` (a PNG picture of the same ZXing bit matrix through `BarcodeMatrices`, one pixel a cell, in the symbol's two colours with their alpha and at the node's size, its data as the picture's description; it scans, but its data is part of the picture rather than editable, reported `APPROXIMATED`, which also names a link, a transform or its left margin and padding as not carried; an `anchor` is a bookmark on its paragraph; in a page zone it is skipped) | -| Table rows — resolved cells, row/col spans, two-pass fill/border paint (`TableRowFragmentPayload`) | ✅ `PdfTableRowFragmentRenderHandler` + row grouping in `PdfFixedLayoutBackend` | ✅ `PptxTableRowFragmentRenderHandler` + row grouping in `PptxFixedLayoutBackend` (positioned rectangles, edge lines, and text frames — never native PPTX tables, which re-lay-out content) | ⚠️ `DocxSemanticBackend.writeTable` (a real Word table on the grid `TableGrid` resolves: `colSpan` maps to `w:gridSpan`, `rowSpan` to `w:vMerge`, and the cascaded `DocumentTableStyle` text style reaches the cell's runs; the cell's fill maps to `w:shd` and its stroke to `w:tcBorders` — the engine's default 1pt black rule where the table states none, not Word's thinner grid — its padding to `w:tcMar`, less above and below the room Word makes for the horizontal rules (half of a rule between two rows, the lower row's, to each; the rules above and below the table whole to their row), each as wide as Word draws it, in eighths of a point (one outside Word's range reported, `border width`), and counted as both editors count it, two and a half twips an eighth rounded down (a rule between two rows shared in whole twips, the row above it taking half rounded down; a cell's top and bottom margins rounded to the twip together), a row held at the page's height less the most any of its cells takes, its margins and the rules it holds — between two others, the rest of its own above and half that of the cell under it; LibreOffice makes room at the edge between two rows for the heavier of their rules, where Word makes it for the lower row's, and under a row ruled heavier than it a row stands the difference lower there; a row of text cells moved by its top and bottom margins together, from Word's seat four fifths of the way down an exact line onto the page's baselines, by the least its cells' lines call for and no further than the margins hold — not a row holding a composed cell, one the layout did not measure, one in a vertical merge or whose cells call for opposite ways, nor a least call under a tenth of a point — and what the margins leave of a cell's call, half a point and more, moved by its text's position, and less, from a tenth of a point, by the height of its lines, each written shorter and the space after it taller, or the other way as far as that space holds, which keeps the cell's content as tall — where every paragraph of the cell is one line, in a face whose letters the export reads, and its letters stay clear of the line's top and foot; a row's cells at the row's smallest top and bottom margins, since both editors give every cell the row's largest, the rest of each cell's padding as space above its first paragraph and below its last, down to the largest margin a cell opening with a table or in a vertical merge keeps; the cascaded `textAnchor` maps to `w:vAlign` on every cell and to `w:jc` on a text cell's paragraph, with the engine's default — the vertical middle, on the left, or on the right for a right-to-left cell — and `DEFAULT` at the bottom left, as the renderer draws it; a composed cell is written by the same writers that write its node anywhere, so one built from an image, a list or a table carries it — a nested table is a real `w:tbl` taking the width of the column it sits in, less its own margins and padding, which is the column's rather than the one the page gives it, since the layout reports a composed cell's content under the owner's path; the paragraph Word requires after a nested table is hidden where it ends its cell holding nothing and no space; a translucent fill is flattened against the colour the page paints under the cell, and a translucent rule against the cell's fill where it has one, since `w:shd` and `w:tcBorders` are opaque, and the table's report note names it (`translucency`); Word re-paginates, so the export states where the layout breaks: every row the layout placed is `w:cantSplit`, `repeatHeader(n)` rows are `w:tblHeader` and keep with the row under them, and a row of blocks is kept whole the same way; the paragraph Word requires after a document's closing table is an ordinary one where the last page has room for two lines below it, so a reader can type below the table, and otherwise a point tall with its mark hidden, so it opens no blank page, reported `APPROXIMATED` since text typed at the end then goes into the table's last cell) | +| Table rows — resolved cells, row/col spans, two-pass fill/border paint (`TableRowFragmentPayload`) | ✅ `PdfTableRowFragmentRenderHandler` + row grouping in `PdfFixedLayoutBackend` | ✅ `PptxTableRowFragmentRenderHandler` + row grouping in `PptxFixedLayoutBackend` (positioned rectangles, edge lines, and text frames — never native PPTX tables, which re-lay-out content) | ⚠️ `DocxSemanticBackend.writeTable` (a real Word table on the grid `TableGrid` resolves, its columns the layout's widths — where one is `auto` and the layout does not show them, composed in a table cell or with a column edge no row shows, the editor's, and reported (`TableNode`): `colSpan` maps to `w:gridSpan`, `rowSpan` to `w:vMerge`, and the cascaded `DocumentTableStyle` text style reaches the cell's runs; the cell's fill maps to `w:shd` and its stroke to `w:tcBorders` — the engine's default 1pt black rule where the table states none, not Word's thinner grid — its padding to `w:tcMar`, less above and below the room Word makes for the horizontal rules (half of a rule between two rows, the lower row's, to each; the rules above and below the table whole to their row), each as wide as Word draws it, in eighths of a point (one outside Word's range reported, `border width`), and counted as both editors count it, two and a half twips an eighth rounded down (a rule between two rows shared in whole twips, the row above it taking half rounded down; a cell's top and bottom margins rounded to the twip together), a row held at the page's height less the most any of its cells takes, its margins and the rules it holds — between two others, the rest of its own above and half that of the cell under it; LibreOffice makes room at the edge between two rows for the heavier of their rules, where Word makes it for the lower row's, and under a row ruled heavier than it a row stands the difference lower there; a row of text cells moved by its top and bottom margins together, from Word's seat four fifths of the way down an exact line onto the page's baselines, by the least its cells' lines call for and no further than the margins hold — not a row holding a composed cell, one the layout did not measure, one in a vertical merge or whose cells call for opposite ways, nor a least call under a tenth of a point — and what the margins leave of a cell's call, half a point and more, moved by its text's position, and less, from a tenth of a point, by the height of its lines, each written shorter and the space after it taller, or the other way as far as that space holds, which keeps the cell's content as tall — where every paragraph of the cell is one line, in a face whose letters the export reads, and its letters stay clear of the line's top and foot; a row's cells at the row's smallest top and bottom margins, since both editors give every cell the row's largest, the rest of each cell's padding as space above its first paragraph and below its last, down to the largest margin a cell opening with a table or in a vertical merge keeps; the cascaded `textAnchor` maps to `w:vAlign` on every cell and to `w:jc` on a text cell's paragraph, with the engine's default — the vertical middle, on the left, or on the right for a right-to-left cell — and `DEFAULT` at the bottom left, as the renderer draws it; a composed cell is written by the same writers that write its node anywhere, so one built from an image, a list or a table carries it — a nested table is a real `w:tbl` taking the width of the column it sits in, less its own margins and padding, which is the column's rather than the one the page gives it, since the layout reports a composed cell's content under the owner's path; the paragraph Word requires after a nested table is hidden where it ends its cell holding nothing and no space; a translucent fill is flattened against the colour the page paints under the cell, and a translucent rule against the cell's fill where it has one, since `w:shd` and `w:tcBorders` are opaque, and the table's report note names it (`translucency`); Word re-paginates, so the export states where the layout breaks: every row the layout placed is `w:cantSplit`, `repeatHeader(n)` rows are `w:tblHeader` and keep with the row under them, and a row of blocks is kept whole the same way; the paragraph Word requires after a document's closing table is an ordinary one where the last page has room for two lines below it, so a reader can type below the table, and otherwise a point tall with its mark hidden, so it opens no blank page, reported `APPROXIMATED` since text typed at the end then goes into the table's last cell) | | Clip region open/close (`ShapeClipBegin/EndPayload`) | ✅ `PdfShapeClipBegin/EndRenderHandler` (CLIP_BOUNDS + CLIP_PATH) | ✅ `PptxClipSafety` + raster fallback in `PptxFixedLayoutBackend` — a provably no-op clip (padded content that cannot be cut) skips the fallback entirely and stays native, editable shapes; a clip that can cut ink renders through the PDF backend into one transparent picture on the clip bounds (pixel-exact, not editable as shapes; run-level link hotspots are not emitted and custom fragment handlers do not apply inside the picture; `Builder.clipRasterFallback(false)` restores unclipped vectors + warning; the raster targets a 2048px long edge, clamped to between native size and 4x, so a region larger than that is rendered at native resolution rather than downscaled — which also means its transient memory grows with the clip instead of stopping at the target (a 3370pt A0-landscape region costs ~45MB while rendering, against ~17MB for anything up to 2048pt); a true vector clip is tracked in [#413](https://github.com/DemchaAV/GraphCompose/issues/413)) | ⚠️ inline fallback + one-time capability warning; the report names a clip that cuts what its layers paint, measured from the layout's fragments by `DocxClipInk` — a clip that cuts nothing (an icon inside its box, a disc's initials, a photo filling its circle) is not named; a picture that fills a container clipped to an ellipse takes the ellipse as its geometry, which both editors crop it to; a badge's glyph — a smaller picture in a painted container that clips it to its outline (`CLIP_PATH`) and holds nothing else but drawing — is drawn by `DocxDrawings` as a floating picture over the outline, where the layout places it, reported `APPROXIMATED` — inside a filled panel the badge and its glyph are drawn in front of the shading; an icon picture beside its text in an unpainted container or a layer stack is drawn the same way; a filled or outlined rectangle or rounded rectangle holding text, composed in a table cell, which has no place in the layout to be drawn at, is written as a panel — a one-cell table in its fill and outline, its corners squared and reported, its row held at least the outline's height less its borders and margins, which keep inside it, and a one-line label the shape centres top to bottom on a line taller than the room Word leaves its content cut alike on both sides to that room, no closer to its letters than three quarters of a point, and seated where the page sets it, from the shape's top where the line is taller than its outline and Word sets it on the shape's middle, and a label it holds whole written at the line height that stands its text on the page's baseline, as far as its letters and the room allow, by a tenth of a point or more and not in a standard face the export does not embed — its row held and its label cut in whole twips rounded down, as the row the cell is in holds the page's height rounded once, and what its letters keep the label past that room taken out of the margins of the cell it is in, where it is all that cell holds and the cell all its row holds; the rest of what a composed cell draws (an icon, a tile, a disc) is the table's own drawing and is drawn by `drawCellDrawing` where the layout puts it, anchored as a rectangle is | | Timeline rail — one logical connector line resolved from marker and entry anchors after layout (`ShapeFragmentPayload` per page) | ✅ `PdfShapeFragmentRenderHandler` — one fragment per page, spliced beneath the markers | ✅ `PptxShapeFragmentRenderHandler` — same payload, same per-page fragments | ⚠️ `DocxDrawings` — the rail is read from the resolved layout's pass fragments and drawn per page as a `line` shape, and the markers as the shapes they are, anchored as a rectangle is: beside an entry's text they move with it when the text above is edited | | Transform open/close — rotate/scale about fragment centre (`TransformBegin/EndPayload`) | ✅ `PdfTransformBegin/EndRenderHandler` | ✅ `PptxTransformBegin/EndRenderHandler` (group shape; rotation and centre-pivot scaling via the exterior/interior frame ratio) | ⚠️ inline fallback + one-time capability warning; a turned shape container is written upright, and the report names its transform — in its drawn outline's note, or on its own where the outline draws nothing | diff --git a/docs/recipes/docx-export.md b/docs/recipes/docx-export.md index 3994a2349..64bdb883f 100644 --- a/docs/recipes/docx-export.md +++ b/docs/recipes/docx-export.md @@ -70,7 +70,7 @@ creation date is real metadata. | Paragraphs | Word paragraphs with alignment, font, size, colour (a translucent one with its transparency, as Word's text fill — see "Translucent colours"), bold/italic/underline; inline runs preserved; a `\n` in the text is a line break (`w:br`), which Word would otherwise read as a space; a table cell's `text("a\nb")` stays one line, as the page sets it; a character the page draws nothing for — a control such as a tab or a bell, a soft hyphen, a zero-width space, one of private use — is not written either, where the file held a question mark for most controls, the direction marks and joiners kept; a margin below zero on a paragraph, a list or a block round them sets its text out past that side in the flow as far as the page does — in a table cell, a panel's included, as far as the cell's text and no further, and the report names what is held back; a row's first child the page sets out past the row's left edge starts at it, named; a `bulletOffset` of spaces is an indent — the wrapped lines (`FROM_SECOND_LINE`), the first (`FIRST_LINE`) or all of them start that far in, measured in the paragraph's style as the page measures it; a prefix with letters in it is not written, but the wrapped lines still start after the spaces the page covers it with; no prefix is applied to a paragraph written over the flow, as one of an overlay's left-and-right pair, as a badge's initials, or in a header or footer; the report names a prefix's letters, and the room a prefix sets lines in by where a path that writes none leaves it out and it moves a line — on the paragraph, or in a header or footer on the zone's note. A session reads markdown unless told not to (`markdown(false)`): it sets a paragraph of plain text's emphasis marks as the style of the text they mark, a heading line bold (the first three levels larger), and drops its marks; the export writes the text as the page sets it — read line by line through the page's own parser, one run a piece in the face, family, colour, tracking and size the page sets it in, `**Java**` a bold run reading `Java`, a linked paragraph's pieces in one link, Word's outline listing a heading by the text written — wherever it writes a paragraph, a page zone's and a badge's included (a badge's initials counted as the page sets them, and written in the flow where they stand in two faces or as a heading, as initials in two runs' faces are). The page's laid-out lines decide it: the pieces are written where those lines hold their letters in their faces, families, colours and tracking, at their sizes — an auto-sized paragraph's read at the size the page fits it to, a heading at its multiple of it; a session that reads no markdown has its marks written as they stand, and text the parser changes nothing of, an underscore inside a word, is written as it stands too. A paragraph composed in a table cell takes only lines that set its pieces so. The page sets a markdown heading in a line as tall as the paragraph's own and draws its letters past it; written in that exact line, Word cuts their tops on screen, and the report names a heading written taller than its line. The faces are the page's: where the session reads markdown its parser sets every piece in a face of its own, the paragraph's left aside, so a bold paragraph's `Senior_Engineer` is written regular, as the page sets it. A paragraph whose lines are not read — with no layout, composed in a table cell whose text, as authored or as the page reads it, no line of its table carries, or a page zone's the layout shows none of — or that the page sets in other letters than its text, as Arabic, which the page shapes before it reads the marks, or that the parser reads into nothing — a lone `*`, an empty list item; `***`, a rule; a line set four spaces in, a block of code — which the page sets as nothing, is written as authored, marks and all, and the report names it, saying where the lines are not read that whether the page reads its marks is not measured, where the page's parser drops one. An auto-sized paragraph (`autoSize`) is written at the size the page fits its text to, read off the layout's lines, on every path that writes a paragraph: a run with a style of its own keeps it, as on the page, and a prefix is measured at the fitted size. Where the lines do not tell it — none are read, they are in sizes that do not say which is the paragraph's, or the paragraph is added at more than one place, which the page fits at each apart — the text is written at its style's size, and the report says the fitted size is not measured, on the paragraph or, in a header or footer, on the zone's note. LibreOffice breaks a badge's initials wider than the square inscribed in its disc, at any size, and hides what wraps; an auto-sized badge, which fills its disc, meets this too. A body paragraph the layout moves to a new page keeps the space the layout leaves above its text there — its own top edge, the edges of the containers opening with it, and the gap before it where the gap did not fit at the foot of the page above — as an empty line that tall before it, kept with it, since Word drops a paragraph's space above at the top of a page and keeps a line's height; the rest of the space owed stays above that line, so Word breaks the page where it did, and the gap between the paragraph's lines comes off the line as it would off its space above. A paragraph in a table cell, an overlay or a list is left to its container | | Lists | Real Word lists: a `numbering.xml` definition per list, `w:numPr` on each item, and the authored marker as the level's text. Nesting is a list level, so Enter continues the list and Tab demotes an item. An item the page reads as markdown is written as the page sets it, as a paragraph is. See "What a list becomes" below for the kinds that stay plain paragraphs | | Tables | Word tables, one cell per cell. Each cell states its own padding, on all four sides, so a row is as tall as the page draws it: as `w:tcMar`, and above and below partly in its paragraphs. Word and LibreOffice give every cell of a row the largest top and bottom margin of any cell in it, so a row's cells are written with its smallest, and the rest of a cell's padding above and below is space above its first paragraph and below its last (measured: a row whose day cells were padded 5.5pt above and 10.25pt below beside a label padded 0.75pt stood 60.3pt tall in both editors, where its tallest cell came to 46). A cell opening with a table has no paragraph above it to hold its padding, and a cell in a vertical merge has its bottom edge in another row: these keep their margins, and the row's comes down no lower than the largest of them. Its padding above and below gives up the room Word makes for the table's horizontal rules — half of a rule between two rows to each, the lower row's rule where the two differ, the rule above the table and the one below it whole to their row — which the page does not (measured: a 0.75pt rule made each row 0.75pt taller). Each rule comes off as wide as Word draws it, in eighths of a point: a 0.7pt hairline is drawn 0.75pt wide (measured: taken off at 0.7, `EditorialProposal`'s tables and all under them stood a step of Word's grid lower). A cell's rule is written from two to ninety-six eighths of a point, the range of a line border's width. A rule is counted as both editors count it, two and a half twips an eighth rounded down (measured: one of 12.5 twips takes 12, one of 17.5 takes 17), and a rule between two rows is shared in whole twips, the row above it taking half rounded down and the row under it the rest; a cell's top and bottom margins are rounded to the twip together. Tables of one, two, three and six rows ruled at five, six, seven and nine eighths then take the page's height to within a step of Word's grid and to the twip in LibreOffice (measured). A row held at the page's height is written less its margins and those rules too — a rule and a half in the first row and the last, two in a table of one row — since both editors read a row's written height as its cells' content (measured: held less one rule, a table ruled at 0.75pt stood 0.46pt taller in its first row and 0.36pt in its last). A row between two others is written less the rest of its own rule above it and half that of the cell under it, one rule where the two are ruled alike, and any row less the most one of its cells takes, its margins and those rules together (measured: held less its own rule alone, a row ruled at 0.5pt over one ruled at 1.5pt stood half a point taller in Word, and all under it half a point lower). LibreOffice makes room at the edge between two rows for the heavier of their rules, where Word makes it for the lower row's: under a row ruled heavier than it, a row and all under it stand the difference lower there (measured: under a 1.5pt row, 0.5pt rows stood 1pt lower in LibreOffice on Windows and LibreOffice 24.2, and where the page sets them in Word). A cell that holds nothing but an empty line — a row that is only a rule, its thickness the empty cell's font — has that line cut to the room its row leaves it, the page's row less the cell's own margins and border: the page draws the rule's borders across the line, and Word and LibreOffice keep them outside it and grow the row (measured: `CobaltRota`'s two rules under a 0.9pt border stood 0.9pt taller each). A line with letters, a picture or a paragraph border of its own keeps its height. A table that states no rule is written with the engine's default 1pt black rule, as the page draws it, not left on Word's thinner grid. Its `textAnchor` becomes `w:vAlign` and the paragraph's `w:jc`, with the engine's default — the vertical middle, on the left — where Word's is the top, so a line beside a taller neighbour sits where the page puts it and an amount column stays right-aligned. A row of text cells is moved by its margins to stand its text where the page sets it: the page sets a cell's line its face's ascent below the line's top, Word an exact line's baseline four fifths of the way down it, so every cell's top margin is made smaller and its bottom one as much larger — or the other way — by the least any of its cells calls for, no further than the margin holds, and each cell's text moves with its room, set at the top, the middle or the bottom, while the row keeps its height (measured: a line of 8pt Poppins stood 0.58pt low in Word and 0.55pt in LibreOffice, of Lato 0.24 and 0.25pt high; moved, within 0.04pt and 0.09pt). Not a row holding a composed cell, whose paragraphs their own writers seat where they can, nor a row the layout did not measure, nor one in a vertical merge or whose cells call for opposite ways; a least call under a tenth of a point is left. What the margins leave of a cell's call is moved by its text's position where that is half a point or more, as a paragraph's is: LibreOffice moves raised text further than it is raised, by up to half as much again, which from half a point up is less than what is left. Less, from a tenth of a point, is moved by the height of the cell's lines: each written shorter and the space after it taller by as much, or the other way as far as that space holds, which keeps the cell's content as tall and each line's top where it was, and moves the text four fifths of the difference in both editors — where every paragraph of the cell is one line, in a face whose letters the export reads (not a standard face it does not embed), and its letters stay clear of the line's top and foot, where Word cuts them on screen (measured: `CobaltRota`'s staff names, beside the day cells its chips are composed in, stood 0.25pt low in Word, 0.2pt in LibreOffice on Windows and 0.19pt in LibreOffice 24.2; so, within 0.08pt in all three, every row its height; the line alone written shorter shortened a row whose tallest content it was by as much in LibreOffice 24.2, which holds a row to its cells' content). LibreOffice sets a vertically centred cell's content as if its first paragraph had no space above it, so a cell padded more above than its row's smallest stands its text up to half that difference higher there (measured: 3pt above it stood the line 1.5pt high). A cell with no style of its own is set in the engine's default cell face rather than the document's Normal. A cell's lines are one paragraph with line breaks; when its style's `lineSpacing(...)` is above zero and it has more than one line, they are a paragraph each, with the spacing after every line but the last, since Word has no space between the lines of one paragraph but a taller line. A column sized to its content gets a point more than the page gives it, so the editor's font substitute cannot wrap its widest cell. The width is written when the document states one or every column is fixed; otherwise Word sizes the table — see "What falls back". A table breaks across pages where the layout breaks it: every row the layout placed is kept whole (`w:cantSplit`) — but the row of a one-row table of paragraphs kept with what follows (see Sections / containers) — `repeatHeader(n)` rows repeat on each page (`w:tblHeader`) and stay with the row under them. Two tables in a row — rows included, since a row is carried as a table — are kept apart by a paragraph a tenth of a point tall, holding the rest of the gap between them: an editor joins two tables with nothing between them into one. A table or a row the layout moves to a new page keeps its own top edge there, as the page does — written as a line that tall, kept with it, since Word drops a paragraph's space above at the top of a page — while the gap between it and the block before stays at the foot of the page above, where it fits there; a gap the layout carries onto the new page, because it did not fit at the foot of the page above, is not yet held above a table (body paragraphs and spacers: see their rows). A table's margin is its indent and the space round it, and its padding on the sides holds its rows in as the page draws them: its left side is in the indent too, and both are out of the room its columns are given | -| Composed cells (`DocumentTableCell.node(...)`) | Written by the same writers that write that node anywhere else, so a cell built from an image, a list or a table carries it. A nested table is a real `w:tbl` followed by the paragraph Word requires a cell to end with — a hairline, which the paragraph written next in the cell takes over, so no empty line opens under the table, and whose mark is hidden where it is left at the cell's end holding nothing and no space, since LibreOffice lays it out — and takes the width of the column it sits in, less its own margins and padding — the column's, not the one the page gives it, because the layout reports a composed cell's content under the owner's path | +| Composed cells (`DocumentTableCell.node(...)`) | Written by the same writers that write that node anywhere else, so a cell built from an image, a list or a table carries it. A nested table is a real `w:tbl` followed by the paragraph Word requires a cell to end with — a hairline, which the paragraph written next in the cell takes over, so no empty line opens under the table, and whose mark is hidden where it is left at the cell's end holding nothing and no space, since LibreOffice lays it out — and takes the width of the column it sits in, less its own margins and padding — the column's, not the one the page gives it, because the layout reports a composed cell's content under the owner's path. Its fixed columns are written where every column is fixed; where one is `auto`, the editor divides the width among them (measured: Word and LibreOffice on Windows alike, half the cell each for two), and the report names it (`TableNode`) | | Inline chips (`inlineCode(...)`, `inlineChip(...)`, `highlight(...)`) | The chip's fill becomes the run's own `w:shd`, in a paragraph and in a list item alike. Its shape does not travel — see "What a chip keeps and loses" below | | Images | Embedded pictures at the node's declared size. In the flow, the margin and padding above and below are the space round the picture's paragraph; on the left they are not written, and the report names them, as it does a barcode's and a page reference's sides. A picture drawn beside its text is fitted to its box with its padding in it, which the report names too | | Links and anchors | A `linkTarget` becomes a `w:hyperlink` — a relationship for an address, `w:anchor` for one of the document's own anchors — and a run's own link wins over the paragraph's — in a list item as much as in a paragraph. An `anchor(...)` becomes a bookmark wrapping that paragraph's text, named as Word requires; on a section, container, table or image it wraps everything the block wrote, from the start of its first paragraph to the end of its last, so a link to a block lands on its first line. Two anchors that clean to one name, or to a name a suffix gave another, stay two bookmarks; one anchor two nodes declare is one bookmark, the last the file writes one for — the node the page sends a link to and reads a page reference's page from, where that node writes a paragraph to mark — and the report names the anchor, the nodes counted off the document, two cells of one table two of them, and a node of a kind of the caller's own counted where the layout registers it. An anchor in a table's header row the page repeats is drawn again on each page it repeats on, and the page sends a link to the last of them; the file holds the row once, where the table starts, which a link goes to and a page reference reads once Word updates it (measured: the bookmark on page 1, a reference written as 5 reading 1), and the report names it. A `bookmark(...)` outline level becomes Word's own `HeadingN` style, which is what puts the paragraph in the Navigation Pane, the outline view and a generated table of contents. The style states the outline level and nothing else, so the paragraph keeps its own formatting. The role comes from what the document declared, never from how big the text is | @@ -191,7 +191,7 @@ it cannot work out for itself: | What | Where it lands | |---|---| | Line height | `w:spacing w:lineRule="exact"` on every paragraph, cells and list items included — the height the engine measured, not a multiple Word would measure again against a substituted font. Word has one height for a paragraph's lines: it is the tallest line's text, or, where the page sets lines of different heights further apart than that, the page's mean distance between their baselines, with what a paragraph on one page then falls short of the page owed below it, and what it passes the page by — written at its tallest line, a wrapped line after a large first one, which the page sets at its own height — hung below it, as a line held to its icon is: the space below takes it, and what it cannot take is named (`space above`) (not yet text set over the flow; measured: `CompactMono`'s sidebar, whose skills are two lines a paragraph and each written 0.12pt taller than the page, ended a point low in Word). Lines rounded up to the twip, over enough of them, hang the same way; what rounding takes from a paragraph written at its tallest line is owed below it as well (measured: `ModernInvoice`'s address blocks, six lines of 11.475pt written at 11.45, stood the table under them 0.15pt high in Word and LibreOffice). A tenth of a point or less is not owed or hung below its paragraph, as Word sets lines on a grid of its own, 0.12pt apart (measured), but carried on to the next paragraph's and settled with it once the two come to more; what is carried stays on its page, starts again where the space owed is set anew — a band's or a column's layer, below a band — and in each cell, whose end settles what its own lines carry there, however little — what they fall short of the page owed below its last block, what they pass it by hung below the cell as a line hanging there is — and a paragraph that owed for its lines and whose pictures then grow them takes that back and carries on what the lines above it carried (measured: `Panel`'s card lines, each written a fiftieth of a point taller than the page's, stood a median 0.46pt low in Word and 0.39pt in LibreOffice on Windows; carried, 0.35 and 0.34pt). A list's item is settled with the page as a paragraph is, its lines carried with the paragraphs' around it (measured: `Panel`'s skills and projects, items of two lines and more, each line a fiftieth of a point taller than the page's, ran 0.21 and 0.35pt taller in Word and grew their cards by as much; items and cells' ends settled, `Panel` stood a median 0.21pt from the page in Word and in LibreOffice on Windows). In a paragraph of more than one line on one page, the spaces a `bulletOffset` sets before a line, written as an indent, do not count towards that line's text. A paragraph of lines as tall as their text, on one page, opening a table cell takes the gap above its first line from the cell's top padding, no more than steps its lines the page's distance apart — not in a row beside a merged cell or a cell that may open with a table — anything but text, a paragraph, a list, a picture or a spacer: a table, a row of columns, a painted container, a shape — whose margin Word would set the whole row at, nor in a panel. One opening a column of a row of columns or of a stack's columns takes it from the space above the row, which the row is lifted out of, its other cells starting as much lower inside (one opening with a table below a hairline paragraph holding the lift) and a row held to a height held as much taller — only where the lift raises the first line half a point or more above where sharing the gaps out sets it, a smaller rise leaving a cell's last paragraph high with nothing under it to lower it into; not on a page's first row or in an overlay (measured: `EditorialProposal`'s goal cells, three lines each, 1.46 and 0.56pt off the page in Word, stand within 0.16pt; `OrangeOps`' degree, two lines 0.45pt low and 0.45pt high, within 0.27pt). One with no room above it for the gap otherwise (a cell padded less, a gap too small) shares the gaps out over all its lines, so its lines stand a little closer than on the page. A paragraph the layout did not measure — one an export without a layout writes — is left to the editor, and a line holding a picture above its text is written "at least" that height — except a paragraph of one line of text with room above for its pictures' reach, held exact at the page's height (see "Inline pictures"); in both the paragraph mark is set in the text's size and face, since the mark counts towards the last line's height. A line holding pictures and no text, where they fill the page's line, has its mark and its pictures' runs set at a point instead, so Word makes the line as tall as the pictures and no taller: in the paragraph's own size the mark's depth went under the picture (measured: `SlateOrange`'s skills, a 12.4pt icon beside each label, stood 0.2pt taller each in Word). A smaller picture in a line the page sets at its font's height keeps its mark, and so does a line holding a letter, a break, a tab, a field or a link's text. A paragraph's own line of drawn shapes and no text written at least their reach, which Word grows to the pictures and the transparent frame each keeps around its ink, has that frame taken from the space above the line and above what follows, where it passes the height written: the ink stands where the page draws it, and what follows where the page sets it. Both editors stand the baseline of an exact line four fifths of the way down it whatever the face (measured in Word and LibreOffice on the fifteen faces the templates use and JetBrains Mono, 8 to 36pt), and the page sets it the face's ascent below the line's top, matched at a paragraph's middle line. A line Word sets lower than the page by a tenth of a point or more is moved up into the space written above it, written to the twip, and that space is owed below it, so what follows stays where it was; both editors keep a paragraph's space above as written (by its position alone, Helvetica's lines, which the page seats 0.78 of the way down, stood 0.12 to 0.38pt low in Word). A column's later layer, which measures the space to itself from the page, takes back the raise of the line above it, and so do a band's later layer and the space below the band — a stack laying one layer over another, a shape container — which measure what follows them from the page too (measured: `ConsultingInvoice`'s contact lines, in a band, half a point low in Word and both LibreOffice builds and its address 0.3pt, within 0.03pt raised; a band's first paragraph or list item, where a band in the flow opens its page, is not raised, as a paragraph's there is not; a band in a stack of one layer the layout moves to a new page is not yet told apart). A line pair's shared line moves up into the space written above it, not a cell's padding, for both its halves, by the lesser of what they call for, where neither is moved by its position — moved for one alone, it would move the other too — and not where a half is cut to its own measure or the layout opens a page with the pair (measured: `ConsultingInvoice`'s bank details, a label and its value to a line, 0.7 to 0.8pt low in Word and both LibreOffice builds, stand 0.2 to 0.33pt low raised, the rest a drift all under its line-item table shares; `LumaStudioInvoice`'s, in Carlito, which both editors set higher than the export reckons, rise too far: in its short invoice the bank details stand 0.27pt high in Word and 0.34pt in LibreOffice, where they stood 0.03 and 0.14pt high). Not a line in another overlay — a canvas, a text box — whose writers measure what follows them from the page and pay nothing, though a stack of one layer is the flow, its lines raised and its rows lifted as there (measured: `SlateOrange`'s experience timeline, set in one, its employers' lines and their items 0.12 to 0.36pt nearer the page in Word and 0.2pt in LibreOffice, `SubscriptionInvoice`'s contact rows 0.12 to 0.24pt and 0.25pt); not a line cut to fit, a container's stacked lines or one held to its pictures; not a paragraph the layout moves to a new page, the first of a stack of one layer it moves there whole among them or the first of a band in the flow that opens its page, whose space above Word drops there, or breaks over one; and not into the space above a panel's first line that its top border takes. A line opening a cell has no space above it of its own: a panel's padding and a table cell's are the cell's margin, and a row's columns have their space above written above the row's table. One Word sets less than half a point low takes what its space above cannot give from the top padding of the cell it opens: a table's composed cell's, in a row whose margins all even, as the gap above a first line does, the cells beside it taking the margin back above their first lines; and a panel's, which the gap does not take, less what its top border takes, the panel's row then held as much taller, as Word adds the margin left to the height a row is held at. A row of columns' first row is lifted out of the space above its table by the most its cells' first lines call for, each line rising by its own and the space under it taking that back, so what follows stays (measured: `ModernProfessional`'s entries, a title beside its dates in a row of their own, moved up 0.24pt in Word and 0.2pt in LibreOffice, `ConsultingInvoice`'s line items, composed cells, 0.24 to 0.36pt and 0.35pt, everything under them where it was). Not a row the layout moves to a new page, whose space above stays on the page above, a row held to a height, or one whose column opens with a panel or a table — a column with a fill or a border is a panel in its cell — which would rise whole; LibreOffice 24.2 counts a row's margins inside the height it is held at, so a panel or a table row held taller than its text — a drawing set where the page puts it — comes out taller there by the raise. A paragraph in a table's composed cell, in a row the layout placed, is raised into the space above it as anywhere else: the cell has no placement of its own, but its row is kept on one page; one in a table nested in that cell is not yet. A line of its own Word sets higher than the page by a tenth of a point or more, and under half a point, is lowered by the space between it and what follows: its space above grows by what is left of that space once the block under it has taken its own of it — the gap between its lines, its own raise, the room its pictures reach into, a row's lift out of the space above its table — above that block, or below the line where a table or a cell's end follows, and the block under it stands where it did. What nothing gives — a block on a later page, whose space above Word drops, a block in an overlay, a page break, a block the layout moves to the next page, a column's later layer — it is not lowered by, and where the section's end leaves the space below a cell's last line out, the lowering that space gave is taken back with it. Not a list's item, which its own list lowers, nor a line in an overlay (a stack of one layer is the flow), one opening its page or a panel, cut to fit or not on one page (measured, with the rules below a heading hung as below: `LetterSidebarPortrait`'s lines, 0.41pt high by median in Word, stand within 0.07pt, `TimelineMinimal`'s within 0.05pt in Word and LibreOffice). What the space above cannot give of a raise, and a line Word sets half a point or more high, is raised or lowered to the page's baseline by `w:position` where the whole difference is half a point or more, a face with a deep descent, as Spectral's is. A list's item is seated as a paragraph is: raised into the gap above it, the item under it rising into what it owes, under half a point into its cell's padding or out of the space above its row of columns where it opens one, and what is left moved by its position where the whole difference is half a point or more. Not raised into the gap, though still moved by its position where it takes one: an item the layout opens a page with, the first of a list it starts on a new page in the flow or one it sets on a later page than the item before it, whose space above Word drops there, nor one of a list the layout sets over two pages in a cell, where what an item owed would be the space above the next page's first, inside the cell. An item whose marker Word draws, a Word list's, is not moved by its position: Word sets that marker from the paragraph's mark, which LibreOffice does not move by the mark's position (measured: `MidnightNavy`'s duties, lowered a point by both, stood 1.15pt under their bullets there), so its line set low keeps what the space above does not take of it; set high by half a point or more, it is lowered by the space above it instead, marker and text together, the items under it giving that back from the space above them — one that cannot, and stands less high itself, has it taken back as far — and what the list's last items still owe hung below the list as a line hanging below a block is — taken out of the space above what follows, or at a cell's end out of what the cell owes under the list, the room under it in its row or under its layer stack's column, or a card's padding — and taken back, the items as high as before, where that hang is let go: below a table's composed cell, under a column's later layer, at a block the layout sets on a later page, which takes nothing of the hang left on the page above, or at a section's end, among others (measured: `MidnightNavy`'s duties, 0.70 to 1.06pt high in Word and 0.82 to 1.04pt in LibreOffice, stand within 0.2pt); not where the layout opens a page with the item, sets its list over two pages in a cell, opens a card with it, or sets it in an overlay — a stack laying one layer over another, a band, a shape container — though a stack of one layer is the flow. A list composed in a table cell has its lines among its table's, and is matched to the run of them that holds its items in turn, opening at a line no paragraph or list before it in the table's order took — each a line of the item's text as the page lays it out, the marker and indent the page sets in that text before it, and, in a `hangingIndent` list, the line of the item's visible marker set level before it in a column of its own, a paragraph before it that the page reads as markdown matched first; its items take their height, the list's lineSpacing, a `hangingIndent` list's marker column and their seat from those lines as a list's in the flow do, and an item in a row Word keeps whole on its page rises into the gap above it, as a paragraph composed there does (measured: `SlateOrange`'s certifications, written at no height at all, stood 0.3pt lower with every item, 1.18pt low by the fourth in Word; matched, 0.26pt low at most). Having no place of its own, a Word list composed so whose marker the page sets in its text keeps its stated column. An item the layout's lines are not matched to is not seated — among them every item of a list in a table's composed cell holding an item of runs, whose text is not read there, one the page reads as markdown, its marks dropped, or a blank item of a `hangingIndent` list, which the page draws as a marker alone. A table text cell's lines are seated by its row's margins where its row allows (see "Tables"). LibreOffice moves text by `w:position` further than it is raised, by the face's height over its em — Spectral's 1.53 times, Poppins' 1.49, Volkhov's 1.31 (measured) — so a line raised by its position stands where the page sets it in Word only: Spectral's 24pt line, raised 4pt, stood 2.4pt high in LibreOffice. A picture among such text moves with it in Word; LibreOffice keeps a picture on its own baseline, where it stood before. Lines a container stacks tighter than their face — a title's lines a pitch apart — each end halfway between their letters and the next line's, since Word draws an exact line's text on screen only inside the line, and the last layer of a shape container, where its line runs past the foot, ends at the foot or below its letters | -| Table columns | the resolved cell widths as `w:gridCol`, with `w:tblLayout` fixed so Word does not re-fit them | +| Table columns | the resolved cell widths as `w:gridCol`, with `w:tblLayout` fixed so Word does not re-fit them; read off the table's rows, so a table with an `auto` column and a column edge no row of it shows has none, and its columns are the editor's (measured on one such table: Word set them as the page did, LibreOffice on Windows otherwise), and the report names it (`TableNode`) | | Row columns | where the layout placed each child, with the row's gap and padding folded into the neighbouring column and taken back out as that cell's margin — in a painted row's panel the padding is the panel cell's margins instead, and the columns are without it. A column sized to its content (`DocumentRowColumn.auto()`) gets a point more, taken from the row's weight columns so the row keeps its width, for the reason a table's does: the editor's substitute font would wrap it — a table of contents' labels broke mid-word ("Intr" / "o") in LibreOffice without it. A row with no auto column, no weight column, or no stated columns (weights, an even split) is written as placed | The space a block holds above and below itself needs no measuring and is written from the @@ -778,7 +778,8 @@ recolour what is under it in Word and it keeps the colour it was flattened to. columns only when they are weights, an even split or fixed, and no line height is written at all. An `auto` column and the flex path are measurements, and a guess in their place would be right for a table whose text fills the line and wrong for one - holding three short values. A row its arrangement or a growing spacer divides has columns + holding three short values. A table's fixed column beside an `auto` one is written with no + width either, the grid being every column's or none. A row its arrangement or a growing spacer divides has columns Word sizes; what an alignment or a stack's layer is set at across the width is written from the left; and the keeps the page makes — a block kept together or with the next, a table's row in one piece, a row of columns — are written only where the layout shows the page held them on diff --git a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java index 543f44ee6..8cb36466c 100644 --- a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java +++ b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java @@ -224,6 +224,8 @@ public final class DocxSemanticBackend implements SemanticBackend { // each session sees the warning at least once. private final AtomicBoolean shapeContainerWarned = new AtomicBoolean(false); private final AtomicBoolean chartWarned = new AtomicBoolean(false); + // Whether the table being written is a chart's data table, which the page does not draw. + private boolean writingAChartsTable; // Geometry-only node kinds already warned about this export pass. private final java.util.Set warnedNodeKinds = java.util.concurrent.ConcurrentHashMap.newKeySet(); @@ -6353,7 +6355,13 @@ private void writeChartFallback(XWPFDocument document, ChartNode node) throws Ex } table.row(row); } - writeTable(document, table.build()); + boolean outer = writingAChartsTable; + writingAChartsTable = true; + try { + writeTable(document, table.build()); + } finally { + writingAChartsTable = outer; + } } /** @@ -17197,6 +17205,51 @@ private static void setCellMargin(CTTblWidth margin, double points) { margin.setW(BigInteger.valueOf(Math.round(Math.max(0.0, points) * POINT_TO_TWIP))); } + /** + * Names a table whose columns are left to the editor where the page sizes them: one with an + * auto column whose widths the layout does not show. Composed in a table cell, a table is laid + * out among its table's own rows, under that table's path, which do not tell its columns apart; + * a table in the flow shows its widths only where its rows show every column's edge between + * them. Its fixed columns are written with no width either, the grid being all of them or none: + * beside an auto column, or beside a position past the columns it declares, which is sized as + * one. + * + *

Measured in Word and LibreOffice on Windows: in a table of two auto columns composed in a + * cell, the first, which the page sets 45pt wide to its content, came out 121pt wide in both, + * half the cell's 242pt; with a fixed column of 120pt beside an auto one, the fixed column came + * out 146pt wide in both, half the cell's 292pt. A table of three auto columns whose two rows + * both span the first two, Word set as the page did, and LibreOffice set its last column 83pt + * further right. A chart's data table, which the page + * does not draw, is not named: the chart's own note says what is written for it. Without a + * layout nothing is measured, which the section's note says once.

+ */ + private void nameTheColumnsLeftToTheEditor(TableNode node) { + if (layout.isEmpty() || writingAChartsTable) { + return; + } + String why = composedInACell(node) + ? "composed in a table cell, it is laid out among its table's own rows, which do not tell " + + "its columns apart" + : "the layout's rows of it do not show every one of its column edges"; + report.add(DocxExportReport.Severity.APPROXIMATED, node.nodeKind(), layout.pathOf(node), + "its columns are the editor's to size, where the page sizes an auto column to its content: " + + why + (fixedBesideAuto(node) ? "; its fixed columns' widths are not written either" : "")); + } + + /** Whether a table sets a fixed column beside one sized otherwise, which a grid of fixed widths cannot hold. */ + static boolean fixedBesideAuto(TableNode node) { + boolean fixed = false; + // A position past the columns the table declares is sized as an auto one. + boolean other = TableGrid.columnCount(node) > node.columns().size(); + // A fixed column always states its width (DocumentTableColumn). + for (com.demcha.compose.document.table.DocumentTableColumn column : node.columns()) { + boolean stated = column.type() == com.demcha.compose.document.table.DocumentTableColumn.Type.FIXED; + fixed |= stated; + other |= !stated; + } + return fixed && other; + } + /** * Gives a table the width the fixed-layout render gives it, in the cases where that * width can be known without measuring anything. @@ -17244,6 +17297,7 @@ private void applyTableWidth(XWPFTable table, TableNode node, int columnCount) { } else if (Double.isFinite(nestedTableWidth())) { setTableWidth(table, nestedTableWidth()); } + nameTheColumnsLeftToTheEditor(node); return; } @@ -17605,8 +17659,8 @@ private XWPFTable newTable(XWPFDocument document, int rows, int columns) { /** * Gives a table the grid a Word table cannot be without, empty: POI makes a table with none, * the columns written later fill it, and a table whose columns are left to Word — a chart's - * data table, a table or a row with no layout, a row the layout does not place in a cell — - * keeps it empty. Word and LibreOffice lay out a table with an empty grid as one without + * data table, a table or a row with no layout, a row the layout does not place in a cell, a + * table with an auto column the layout does not show the widths of — keeps it empty. Word and LibreOffice lay out a table with an empty grid as one without * (measured: every word where it stood, in both, in a row of columns in the flow and in a cell, * a table of auto columns with and without a width, and {@code WordExportCompanion}'s chart). */ diff --git a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java index fc54b1adc..56a08f635 100644 --- a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java +++ b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java @@ -25,10 +25,11 @@ *

Without the layout nothing is measured or placed, and the export writes what the document * states. Line heights, the space between lines and auto columns are the editor's then, and so is * more, which the note named none of: a row its arrangement or a growing spacer divides is written - * as columns Word sizes; what an alignment or a stack's layer is set at across the width stands at - * the left; and the keeps the page makes — a block kept together or with the next, a table's row - * in one piece, a row of columns — are written only where the layout shows the page held them on - * one page, which is nowhere. (A table's repeated header row is still kept with the row under it: + * as columns Word sizes; a table's fixed column beside an auto one is written with no width, the + * table's columns all left to Word; what an alignment or a stack's layer is set at across the + * width stands at the left; and the keeps the page makes — a block kept together or with the + * next, a table's row in one piece, a row of columns — are written only where the layout shows the + * page held them on one page, which is nowhere. (A table's repeated header row is still kept with the row under it: * that needs no layout.) Each of those is named where the section holds one.

* * @author Artem Demchyshyn @@ -57,6 +58,9 @@ static String note(DocumentGraph graph, String what) { } StringBuilder note = new StringBuilder(what).append(" could not be laid out, so ") .append(listed(editors)).append(" are the editor's rather than the engine's"); + if (found.fixedBesideAuto) { + note.append("; a table's fixed column beside an auto one is written with no width either"); + } if (found.placedAcross) { note.append("; what an alignment or a stack's layer is set at across the width is written from the left"); } @@ -85,6 +89,7 @@ private static String listed(List items) { private static final class Found { private boolean dividedRows; + private boolean fixedBesideAuto; private boolean placedAcross; private boolean keptBlocks; private boolean tableRows; @@ -114,6 +119,7 @@ private void look(DocumentNode node, boolean inACell) { } if (node instanceof TableNode table && !table.rows().isEmpty()) { tableRows = true; + fixedBesideAuto |= DocxSemanticBackend.fixedBesideAuto(table); } keptBlocks |= !inACell && (node.keepTogether() || node.keepWithNext()); Set cells = cellContentOf(node); diff --git a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxNodeFieldLedgerTest.java b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxNodeFieldLedgerTest.java index 597aeb836..85393cd15 100644 --- a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxNodeFieldLedgerTest.java +++ b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxNodeFieldLedgerTest.java @@ -303,7 +303,11 @@ private record Entry(Fate fate, String note) { "padding:REPORTED:above and below; below a block a band or a column measures from, written", "margin:REPORTED:above and below; below a block a band or a column measures from, written", "grow:WRITTEN"); - node(TableNode.class, "name:INERT", "columns:WRITTEN", "rows:REPORTED:" + CELL_TRANSLUCENCY, + node(TableNode.class, "name:INERT", + "columns:REPORTED:where one is auto and the layout does not show their widths — composed in a " + + "table cell, or with a column edge no row shows — the editor's, a fixed one beside it with " + + "them; with no layout, in the section's note; any other is written", + "rows:REPORTED:" + CELL_TRANSLUCENCY, "defaultCellStyle:REPORTED:" + CELL_TRANSLUCENCY, "rowStyles:REPORTED:" + CELL_TRANSLUCENCY, "columnStyles:REPORTED:" + CELL_TRANSLUCENCY, "width:WRITTEN", "linkTarget:REPORTED", "bookmarkOptions:REPORTED", diff --git a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java new file mode 100644 index 000000000..ce643e06f --- /dev/null +++ b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java @@ -0,0 +1,158 @@ +package com.demcha.compose.document.backend.semantic.docx; + +import com.demcha.compose.document.chart.ChartData; +import com.demcha.compose.document.chart.ChartSpec; +import com.demcha.compose.document.dsl.PageFlowBuilder; +import com.demcha.compose.document.dsl.TableBuilder; +import com.demcha.compose.document.node.ChartNode; +import com.demcha.compose.document.node.TableNode; +import com.demcha.compose.document.table.DocumentTableCell; +import com.demcha.compose.document.table.DocumentTableColumn; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * A table whose columns the layout does not show the widths of — composed in a table cell, or + * one with a column edge no row of it shows — is written with its columns left to the editor, + * and the report says so where the page sizes an auto column to its content. + */ +class DocxTableColumnsLeftToTheEditorTest { + + /** The report addresses a table by its node kind, as it does a row whose columns are Word's. */ + private static final String SUBJECT = "TableNode"; + private static final String LEFT ="its columns are the editor's to size, where the page sizes an auto column " + + "to its content: "; + private static final String COMPOSED = LEFT + "composed in a table cell, it is laid out among its table's own " + + "rows, which do not tell its columns apart"; + private static final String HIDDEN = LEFT + "the layout's rows of it do not show every one of its column edges"; + private static final String FIXED = "; its fixed columns' widths are not written either"; + + @Test + void aTableOfAutoColumnsComposedInACellIsNamed() throws Exception { + List notes = tableNotes(page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(250)) + .rowCells(DocumentTableCell.text("Breakdown"), + DocumentTableCell.node(inner(DocumentTableColumn.auto(), DocumentTableColumn.auto()))))); + assertThat(notes).singleElement().satisfies(note -> { + assertThat(note.severity()).isEqualTo(DocxExportReport.Severity.APPROXIMATED); + assertThat(note.detail()).isEqualTo(COMPOSED); + assertThat(note.path()).as("composed content has no path of its own").isNull(); + }); + } + + @Test + void aFixedColumnBesideAnAutoOneComposedInACellIsNamedWithIt() throws Exception { + assertThat(tableNotes(page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(300)) + .rowCells(DocumentTableCell.text("Breakdown"), + DocumentTableCell.node(inner(DocumentTableColumn.fixed(120), DocumentTableColumn.auto())))))) + .extracting(DocxExportReport.Note::detail).containsExactly(COMPOSED + FIXED); + } + + @Test + void aFixedColumnBesideAPositionPastTheDeclaredColumnsIsNamedWithIt() throws Exception { + // The row's second cell stands in a column the table does not declare, which is sized as + // an auto one; a named table composed in a cell is still composed in it. + assertThat(tableNotes(page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(300)) + .rowCells(DocumentTableCell.text("Breakdown"), DocumentTableCell.node(new TableBuilder() + .name("Hours").columns(DocumentTableColumn.fixed(120)).row("Hours", "12").build()))))) + .extracting(DocxExportReport.Note::detail).containsExactly(COMPOSED + FIXED); + } + + @Test + void aTableOfFixedColumnsComposedInACellIsWrittenAtThemAndNotNamed() throws Exception { + List notes; + try (org.apache.poi.xwpf.usermodel.XWPFDocument document = DocxExports.withLayout(500, 400, 30, page -> page + .addTable(t -> t.columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(300)) + .rowCells(DocumentTableCell.text("Breakdown"), DocumentTableCell.node( + inner(DocumentTableColumn.fixed(120), DocumentTableColumn.fixed(110))))))) { + var grid = document.getTables().get(0).getRow(0).getCell(1).getTables().get(0).getCTTbl().getTblGrid(); + assertThat(grid.getGridColList()).extracting(column -> DocxTwips.of(column.getW())) + .containsExactly(2400L, 2200L); + } + assertThat(tableNotes(page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(300)) + .rowCells(DocumentTableCell.text("Breakdown"), + DocumentTableCell.node(inner(DocumentTableColumn.fixed(120), DocumentTableColumn.fixed(110))))))) + .isEmpty(); + } + + @Test + void aTableWithAColumnEdgeNoRowShowsIsNamedWithItsFixedColumns() throws Exception { + assertThat(tableNotes(page -> page.addTable(t -> t + .columns(DocumentTableColumn.fixed(120), DocumentTableColumn.auto(), DocumentTableColumn.auto()) + .rowCells(DocumentTableCell.text("A wide heading here").colSpan(2), DocumentTableCell.text("c")) + .rowCells(DocumentTableCell.text("Another one").colSpan(2), DocumentTableCell.text("dd"))))) + .extracting(DocxExportReport.Note::detail).containsExactly(HIDDEN + FIXED); + } + + @Test + void aTableWithAColumnEdgeNoRowShowsIsNamed() throws Exception { + List notes = tableNotes(page -> page.addTable(t -> t.name("Spans") + .columns(DocumentTableColumn.auto(), DocumentTableColumn.auto(), DocumentTableColumn.auto()) + .rowCells(DocumentTableCell.text("A wide heading here").colSpan(2), DocumentTableCell.text("c")) + .rowCells(DocumentTableCell.text("Another one").colSpan(2), DocumentTableCell.text("dd")))); + assertThat(notes).singleElement().satisfies(note -> { + assertThat(note.detail()).isEqualTo(HIDDEN); + assertThat(note.path()).as("a table in the flow is found by its path").contains("Spans"); + }); + } + + @Test + void aTableTheLayoutMeasuresIsNotNamed() throws Exception { + assertThat(tableNotes(page -> page + .addTable(t -> t.columns(DocumentTableColumn.auto(), DocumentTableColumn.auto()) + .row("Hours", "12").row("Rate", "95.00 per hour")) + .addTable(t -> t.columns(DocumentTableColumn.auto(), DocumentTableColumn.auto(), DocumentTableColumn.auto()) + .rowCells(DocumentTableCell.text("A wide heading here").colSpan(2), DocumentTableCell.text("c")) + .rowCells(DocumentTableCell.text("a"), DocumentTableCell.text("b"), DocumentTableCell.text("d"))) + .addTable(t -> t.columns(DocumentTableColumn.auto(), DocumentTableColumn.auto(), DocumentTableColumn.auto()) + .rowCells(DocumentTableCell.text("A wide heading here").colSpan(2), DocumentTableCell.text("c")) + .rowCells(DocumentTableCell.text("a"), DocumentTableCell.text("Another one").colSpan(2))))) + .as("a row that shows every edge measures the table, and so do rows that show them between them") + .isEmpty(); + } + + @Test + void aChartsDataTableIsTheChartsNoteAndNotNamed() throws Exception { + ChartSpec spec = ChartSpec.bar() + .data(ChartData.builder().categories("Q1", "Q2").series("Sales", 3.0, 5.0).build()).build(); + DocxExportReport report = DocxExports.report(400, 400, 20, page -> page.add(new ChartNode(spec))); + assertThat(report.bySubject()).containsKey("chart").doesNotContainKey(SUBJECT) + .as("laid out").doesNotContainKey("measured geometry"); + DocxExportReport composed = DocxExports.report(400, 400, 20, page -> page.addTable(t -> t + .columns(DocumentTableColumn.fixed(300)).rowCells(DocumentTableCell.node(new ChartNode(spec))))); + assertThat(composed.bySubject()).as("composed in a cell").doesNotContainKey(SUBJECT) + .as("laid out").doesNotContainKey("measured geometry"); + assertThat(tableNotes(page -> page.add(new ChartNode(spec)).addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(250)) + .rowCells(DocumentTableCell.text("Breakdown"), + DocumentTableCell.node(inner(DocumentTableColumn.auto(), DocumentTableColumn.auto())))))) + .as("a table after a chart's").extracting(DocxExportReport.Note::detail).containsExactly(COMPOSED); + } + + @Test + void withNoLayoutTheSectionsNoteSaysItAndATableIsNotNamed() throws Exception { + DocxExportReport report = DocxExports.reportWithoutLayout(400, 400, 20, page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(250)) + .rowCells(DocumentTableCell.text("Breakdown"), + DocumentTableCell.node(inner(DocumentTableColumn.auto(), DocumentTableColumn.auto()))))); + assertThat(report.bySubject()).doesNotContainKey(SUBJECT).containsKey("measured geometry"); + } + + private static TableNode inner(DocumentTableColumn first, DocumentTableColumn second) { + return new TableBuilder().columns(first, second).row("Hours", "12").row("Rate", "95.00 per hour").build(); + } + + /** The table notes of an export the layout stands behind: a document it refuses is another case. */ + private static List tableNotes(Consumer content) throws Exception { + DocxExportReport report = DocxExports.report(500, 400, 30, content); + assertThat(report.bySubject()).as("laid out").doesNotContainKey("measured geometry"); + return report.bySubject().getOrDefault(SUBJECT, List.of()); + } +} diff --git a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayoutTest.java b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayoutTest.java index ee86ae08c..4fed4a764 100644 --- a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayoutTest.java +++ b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayoutTest.java @@ -69,6 +69,27 @@ void anAlignmentOrAStacksLayerIsNamedAsWrittenFromTheLeftAndALeftOneIsNot() thro .isEqualTo(BASE); } + @Test + void aTablesFixedColumnBesideAnAutoOneIsNamedAndAllFixedOrAllAutoAreNot() throws Exception { + String fixed = BASE + "; a table's fixed column beside an auto one is written with no width either"; + assertThat(sectionNote(page -> page.addTable(t -> t + .columns(DocumentTableColumn.fixed(120), DocumentTableColumn.auto()).row("Hours", "12")))) + .startsWith(fixed); + assertThat(sectionNote(page -> page.addTable(t -> t + .columns(DocumentTableColumn.fixed(120), DocumentTableColumn.fixed(60)).row("Hours", "12")))) + .as("a grid of fixed widths is written").doesNotContain("fixed column"); + assertThat(sectionNote(page -> page.addTable(t -> t + .columns(DocumentTableColumn.auto(), DocumentTableColumn.auto()).row("Hours", "12")))) + .as("auto columns are the base note's").doesNotContain("fixed column"); + assertThat(sectionNote(page -> page.addTable(t -> t.columns(DocumentTableColumn.auto()) + .rowCells(DocumentTableCell.node(new com.demcha.compose.document.dsl.TableBuilder() + .columns(DocumentTableColumn.fixed(80), DocumentTableColumn.auto()).row("A", "B").build()))))) + .as("composed in a cell").startsWith(fixed); + assertThat(sectionNote(page -> page.addTable(t -> t + .columns(DocumentTableColumn.fixed(120)).row("Hours", "12")))) + .as("beside a position past the columns it declares, sized as an auto one").startsWith(fixed); + } + @Test void whatThePageKeepsFromAPageBreakIsNamedKindByKind() throws Exception { String keep = "; Word is not told to keep what the page keeps from a page break: "; From f6621a018ed10d897c437c6f46c156a6e8aa8c51 Mon Sep 17 00:00:00 2001 From: DemchaAV Date: Sun, 18 Oct 2026 17:07:27 +0100 Subject: [PATCH 2/2] test(docx): drop an unread variable from the table-columns test The case for a table of fixed columns composed in a cell declared a list of notes it never read. The Javadoc of the table's note, of withAGrid and of the no-layout note is wrapped at the file's width again. --- .../backend/semantic/docx/DocxSemanticBackend.java | 9 +++++---- .../backend/semantic/docx/DocxWithoutLayout.java | 4 ++-- .../docx/DocxTableColumnsLeftToTheEditorTest.java | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java index 8cb36466c..b415a3f66 100644 --- a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java +++ b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxSemanticBackend.java @@ -17219,9 +17219,9 @@ private static void setCellMargin(CTTblWidth margin, double points) { * half the cell's 242pt; with a fixed column of 120pt beside an auto one, the fixed column came * out 146pt wide in both, half the cell's 292pt. A table of three auto columns whose two rows * both span the first two, Word set as the page did, and LibreOffice set its last column 83pt - * further right. A chart's data table, which the page - * does not draw, is not named: the chart's own note says what is written for it. Without a - * layout nothing is measured, which the section's note says once.

+ * further right. A chart's data table, which the page does not draw, is not named: the chart's + * own note says what is written for it. Without a layout nothing is measured, which the + * section's note says once.

*/ private void nameTheColumnsLeftToTheEditor(TableNode node) { if (layout.isEmpty() || writingAChartsTable) { @@ -17660,7 +17660,8 @@ private XWPFTable newTable(XWPFDocument document, int rows, int columns) { * Gives a table the grid a Word table cannot be without, empty: POI makes a table with none, * the columns written later fill it, and a table whose columns are left to Word — a chart's * data table, a table or a row with no layout, a row the layout does not place in a cell, a - * table with an auto column the layout does not show the widths of — keeps it empty. Word and LibreOffice lay out a table with an empty grid as one without + * table with an auto column the layout does not show the widths of — keeps it empty. Word and + * LibreOffice lay out a table with an empty grid as one without * (measured: every word where it stood, in both, in a row of columns in the flow and in a cell, * a table of auto columns with and without a width, and {@code WordExportCompanion}'s chart). */ diff --git a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java index 56a08f635..507f8e1a6 100644 --- a/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java +++ b/render-docx/src/main/java/com/demcha/compose/document/backend/semantic/docx/DocxWithoutLayout.java @@ -29,8 +29,8 @@ * table's columns all left to Word; what an alignment or a stack's layer is set at across the * width stands at the left; and the keeps the page makes — a block kept together or with the * next, a table's row in one piece, a row of columns — are written only where the layout shows the - * page held them on one page, which is nowhere. (A table's repeated header row is still kept with the row under it: - * that needs no layout.) Each of those is named where the section holds one.

+ * page held them on one page, which is nowhere. (A table's repeated header row is still kept with + * the row under it: that needs no layout.) Each of those is named where the section holds one.

* * @author Artem Demchyshyn */ diff --git a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java index ce643e06f..4c22f92ad 100644 --- a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java +++ b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxTableColumnsLeftToTheEditorTest.java @@ -66,7 +66,6 @@ void aFixedColumnBesideAPositionPastTheDeclaredColumnsIsNamedWithIt() throws Exc @Test void aTableOfFixedColumnsComposedInACellIsWrittenAtThemAndNotNamed() throws Exception { - List notes; try (org.apache.poi.xwpf.usermodel.XWPFDocument document = DocxExports.withLayout(500, 400, 30, page -> page .addTable(t -> t.columns(DocumentTableColumn.auto(), DocumentTableColumn.fixed(300)) .rowCells(DocumentTableCell.text("Breakdown"), DocumentTableCell.node(