Repository navigation
fix(docx): keep the space above a stack of one layer opening a page - #929
Merged
Merged
Conversation
A stack of one layer is written in the flow, and Word drops its first paragraph's space above at the top of a page as any other's, but the line holding that space was written only outside every stack. Measured in Word and LibreOffice, a paragraph or a picture with a 20pt margin opening such a stack on a new page stood 20pt high, and one in a stack with a 14pt margin 14pt high. A paragraph or a picture opening one is now held as in the flow, with the stack's own edges. A layer's offset in its stack, which is named and not written, is not held either.
DemchaAV
marked this pull request as draft
October 20, 2026 10:08
A plain paragraph opening a stack of one layer on a new page now leaves a pull out of the block above on that block's page, as one in the flow does: the report no longer names it as standing lower there. The test pins both sides: named on the paragraph's page, not on the next.
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
Word drops a paragraph's space above at the top of a page. The export holds that space for a
paragraph or a picture the layout moves to a new page in an empty line kept with it
(
holdAParagraphsTopEdgeOnItsPage), but only whenoverlayDepth == 0: in the flow, outside everylayer stack. A stack of one layer is written in the flow too. It raises
overlayDepthandoneLayerDepthtogether, so the first block opening one on a new page lost everything above it.Measured in Word 16 and LibreOffice on Windows, the first line (or a picture's top) on page 2:
Nothing was named. A paragraph's baseline stands 0.9–1.0pt higher than the page's in each
case, as under the plain control. In every case the page broke where it did before.
What changed
writeParagraphandwriteImagehold the top edge whereoverlayDepth == oneLayerDepth:in the flow, a stack of one layer's included. A band, or anything else laid over the flow, is
left as it was.
reportTheLayerMovednames it: "Word writes it where the stack starts".layerOffsetDownholds the offset arithmetic the report used inline.writeContainerBodyadds the offset to
layerOffsetNotWrittenwhile it writes the stack's layer, and restoresit after.
holdAParagraphsTopEdgeOnItsPagetakes the offset off the page's space above. Withoutthat, the line would hold the offset wherever space is owed above the layer, against the
layer's own note.
owed above it, as named.
for a stack's first paragraph or picture opening the next page, as in the flow.
was named as standing 5pt lower ("space above").
Verification
are identical.
word-export-companion.docxwas regenerated. It differs from the committed one onlyin
docProps/core.xml, the export's time.DocxStackOfOneLayerOnANewPageTest(new, 11 tests), each with the premise that the stackopens the second page where it matters:
./mvnw -B -ntp clean verify: BUILD SUCCESS on the first commit.do the knowledge checks.
javadoc passes with no warnings.
Two cases this leaves as they were, not measured:
writeSpacerstill holds the gapabove in its line only outside every stack.
writeOverlayBandstill marks the page it opensonly outside every stack.
Lane: render-docx (semantic backend). DOCX output changes only for a paragraph or a picture
opening a stack of one layer that the layout moves to a new page. One with space above it gains
the line holding it. Without such space, a pull, border or hanging line left by the block above
no longer reaches it.