Repository navigation
fix(docx): keep the space above a paragraph or spacer the layout moves to a new page - #825
Merged
Merged
Conversation
…ge above, and take the Linux LibreOffice baseline from CI
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When a page break moves a block down, the layout keeps three kinds of space above it on the new page:
CompilerState.advanceSpacemoves to a new page before spending it).Word drops a paragraph's space above at the top of a page, and keeps its line's height. #821 handled tables and rows. Body paragraphs and spacers still lost the space:
ModernProfessional. The second page opens with a heading its section pads 8pt down. In Word the heading and everything under it stood 7.7pt high.Executive. The second page opens with the 3pt spacer between two entries, 3pt below the margin, because the 3pt gap before it did not fit on the first page. In Word the page stood 3.2pt high.What changed
holdAParagraphsTopEdgeOnItsPage. A body paragraph the layout starts on a new page gets an empty line before it, kept with it (keepNext, a 1pt mark).spaceAboveOnItsPage) plus its own padding. So it includes a gap the layout carried there, and it does not include edges the layout spent on the page above.ClassicSerif's second page's first line fit on its first page in Word.holdTheGapAboveInTheLine. A bodySpacerNodethe layout starts on a new page moves the space the layout leaves above it there out of its hairline paragraph's space above and into its exact height. That is the gap the layout carried there, and the edges of any containers opening with it (theExecutivecase).takeFromTheLineHoldingItsEdge.applyLineGaptakes one line gap out of a paragraph's space above. For a paragraph whose edge a line holds, it now takes that gap from the line, then from the line's space above. Without this the gap was shared out over the lines:MinimalUnderlined's page-2 description set its two lines 0.7pt closer than the page.holdInALineKeptWithTheNext. The table path (fix(docx): keep a table's top edge on the page the layout moves it to #821) and the paragraph path now build the holding line with this one helper.word-windows,libreoffice-windowsand their-linesfiles are rewritten.MinimalUnderlined, "ADDITIONAL INFORMATION" goes from −0.03 to +0.57, past the gate's 0.5pt. In Word, mean |dy| on that page goes from 0.35 to 0.27pt.BoxedSections, mean |dy| on page 2 gets worse in Word (0.28 → 0.33pt) and better in LibreOffice (0.34 → 0.29pt).libreoffice-linuxand its-linesfile are taken from this PR's CI run (docx-fidelity-37107445748, on the code before the review fixes; those leave both Windows corpora unchanged).EditorialBlue's page 2 also moves, 2.0pt lower on all 9 lines (−1.8 → +0.2pt). Its lines past 2pt go 2 → 0, p90 1.78 → 0.45pt.CHANGELOG.md, and the Paragraphs, Spacers and Tables rows ofdocs/recipes/docx-export.md.Verification
Template corpus, re-measured in full in both editors. Rows that change:
Across the corpus, Word's lines past 2pt fall from 48 to 28, and LibreOffice's (Windows) from 644 to 624. Page counts are unchanged everywhere.
New test class,
DocxSpaceAboveOnANewPageTest, eleven tests. Spacers:Paragraphs:
Line gap:
Each mechanism fails the tests when taken out or replaced:
DocxSpaceOnANewPageTest(fix(docx): keep a table's top edge on the page the layout moves it to #821, table path): its 4 tests stay green.Full reactor gate:
./mvnw -B -ntp clean verify -pl :graph-compose-core,:graph-compose-render-pdf,:graph-compose-render-docx,:graph-compose-render-pptx,:graph-compose-templates,:graph-compose-testing,:graph-compose-qa,:graph-compose-coverage -amgives BUILD SUCCESS. render-docx runs 833 tests, qa 1814.Known limits
Lane: shared-engine (render-docx). No public API change.