Repository navigation
fix(docx): keep the space above a picture moved to a new page - #927
Merged
Merged
Conversation
Word drops a paragraph's space above at the top of a page, a picture's paragraph's too. Measured in Word and LibreOffice, a 100pt picture the layout moves to a new page stood at the page's top: 20pt high with a 20pt margin, 15pt with a 15pt padding, 25pt contained in a box with 25pt of room above it, 10pt in a section padded 10pt. In the flow, that space is now held in an empty line that tall before the picture, kept with it, as a text paragraph's top edge already is.
DemchaAV
marked this pull request as draft
October 19, 2026 21:14
A picture the layout moves to a new page now leaves a pull out of the block above on that block's page, as a paragraph does. Before, a plain picture opening a page after a paragraph pulling 5pt up was named as standing 5pt lower, which on the new page it does not. 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
The page starts a block the layout moves to a new page at its own top edge. Word drops a
paragraph's space above at the top of a page, and a picture's paragraph is no exception, so
everything above a picture opening its page was lost.
Measured in Word 16 and LibreOffice on Windows, a 100pt picture opening page 2 (picture top, y):
Nothing was named. In every case, the page broke where it did before, with the same lines on
page 1. Below each picture nothing moved: in both editors, the distance from its foot to the
baseline of the paragraph under it is what it was before the change, within 0.1pt.
What changed
writeImage: a picture in the flow (not in a cell, not in an overlay) that the layoutstarts on a later page than the block before it has its top edge held on that page by
holdAParagraphsTopEdgeOnItsPage, before its paragraph is created. This is the mechanism atext paragraph opening its page already goes through.
holdAParagraphsTopEdgeOnItsPagetakes any block and the room it has above its contentinside its box. For a contained picture that is the room
roomRoundgives above it. The lineholds:
The paragraph's own space above loses as much (
applyVerticalSpacing). A text paragraphpasses no room, so it is written as before, and the two-argument form it called is gone.
A pull, a border or a hanging line left by the block above now stays on the page above
for a picture opening the next page too, as it does for a paragraph and a spacer.
standing 5pt lower ("space above").
Docs:
{@link}in theapplyVerticalSpacingJavadoc now namesroomRound.Verification
are identical.
word-export-companion.docxwas regenerated. It differs from the committed one onlyin
docProps/core.xml, the export's time.DocxPictureOnANewPageTest(new, 10 tests):line kept with the picture, which keeps no space above of its own;
./mvnw -B -ntp clean verify: BUILD SUCCESS. The knowledge pack's--checkpasses.Two things this leaves as they were, each a separate step, for text and pictures alike:
its top edge. A paragraph or picture with a 20pt margin stands 20pt high in both editors.
above, while the page sets the whole stack on the next.
Lane: render-docx (semantic backend). DOCX output changes only for a picture 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.