diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c024c985..8669e8b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ follow semantic versioning; release dates are ISO 8601. ### Public API +- **A panel bled to the paper's edge stands where the page puts it in Word.** A panel's + table indent places its text, and an indent of 0 was not written. A panel whose negative + margin takes its fill to the paper's edge and whose padding takes its text back to the + margin has exactly that indent, and with none Word puts the table's edge on the margin: + `IndigoProposal`'s about band, fill and text, stood 27.6pt right of the page's. The indent is + now written in the body even when it is 0. LibreOffice already set the band where the page + does. - **A drawing over text in a row nested through a one-layer stack takes its room in DOCX.** A row cannot sit in a row cell, so templates wrap one in a layer stack of one layer; the row is written in the flow, and a drawing in it is drawn where the page puts it. Its room diff --git a/docs/recipes/docx-export.md b/docs/recipes/docx-export.md index 79fefcc3b..a4044238e 100644 --- a/docs/recipes/docx-export.md +++ b/docs/recipes/docx-export.md @@ -387,6 +387,10 @@ How it lands: by the other half, so the text and the border land where the page draws them. Measured in LibreOffice against the engine's render at 96 dpi, the band, a 3pt accent bar and the text of a card land within a pixel of the page's. +- **Indent.** In the body the table's `w:tblInd` places its cell's text, less half its left + border, and is written even when it is 0 — a panel bled to the paper's edge by a negative + margin its padding takes back. Unwritten, Word 16 puts the table's edge on the margin and the + text a padding further in (measured). - **Nesting.** A panel inside a panel is a table inside its cell. So is a row, with no fill of its own, so the panel shows through it. A table keeps its own cell fills, and a cell no style fills is written white, as the page draws it on the card. Word draws a table's 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 718d055b9..d78f41955 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 @@ -3278,7 +3278,11 @@ private void writePanelPiece(XWPFDocument document, DocumentNode node, Container holdRowAtLeast(table.getRow(0), shape.outline().height() - bordersOutside); } - if (indent != 0) { + // In the body it is written even when it is 0. The indent places the cell's text, less + // half its left border, and with none Word 16 places the table's edge on the margin + // instead, its text a padding further in (measured): IndigoProposal's about band, bled to the paper's edge by a negative margin its + // padding takes back, stood 27.6pt right of the page's, fill and text. + if (indent != 0 || currentCell == null) { CTTblPr tableProperties = table.getCTTbl().getTblPr(); CTTblWidth tableIndent = tableProperties.isSetTblInd() ? tableProperties.getTblInd() diff --git a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxPanelInsetTest.java b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxPanelInsetTest.java index 41518b910..b55f17a93 100644 --- a/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxPanelInsetTest.java +++ b/render-docx/src/test/java/com/demcha/compose/document/backend/semantic/docx/DocxPanelInsetTest.java @@ -45,6 +45,26 @@ void aPaddedPanelsTextIsHeldInByTheCellNotByAnIndent() throws Exception { } } + @Test + void aPanelBledToThePaperEdgeWritesItsIndentOfNothing() throws Exception { + // A negative margin takes the fill to the paper's edge and the padding takes the text + // back to the page margin: the indent placing the text is 0. Unwritten, Word puts the + // table's edge on the margin and the text a padding further in (measured, 27.6pt). + try (XWPFDocument document = DocxExports.withLayout(400, 300, 30, page -> page + .addSection(s -> s.fillColor(SURFACE) + .margin(new DocumentInsets(0, -30, 0, -30)) + .padding(new DocumentInsets(0, 0, 0, 30)) + .addParagraph(p -> p.text("Band"))))) { + var properties = document.getTables().get(0).getCTTbl().getTblPr(); + + assertThat(properties.isSetTblInd()).as("written, though it is nothing").isTrue(); + assertThat(DocxTwips.of(properties.getTblInd().getW())).isZero(); + assertThat(DocxTwips.of(document.getTables().get(0).getRow(0).getCell(0).getCTTc().getTcPr() + .getTcMar().getLeft().getW())) + .as("the text at the margin, the fill from the paper's edge").isEqualTo(30 * 20L); + } + } + @Test void anUnpaintedContainerStillHoldsItsTextIn() throws Exception { try (XWPFDocument document = DocxExports.withLayout(400, 300, 30, page -> page