fix(docx): give a table the space it holds above and below itself - #712
Merged
Merged
Conversation
Word has no space above a table and none below one, so a table's margin and padding were dropped. A row is exported as a one-row table, so a row's padding went the same way: measured on the probe corpus through LibreOffice, a row lost 14pt at each edge and a billing table the 6pt it holds above itself. Neither edge needs an element of its own. The space above a table is the space below the paragraph before it, and the space below one is the space above the paragraph after, so both go through the same gap every other block goes through — a table between two paragraphs now reads as two paragraphs with a gap between them. What Word genuinely cannot hold is the top edge of a table with nothing above it: there is no paragraph to carry it, and an empty one would be a line the document never asked for. That edge is still dropped, and a test says so. With this and the two changes before it, the probe corpus's first page renders within 1.2pt of the reference PDF everywhere, against 87pt of accumulated drift before.
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 has no space above a table and none below one, so a table's own
marginandpaddingwere dropped on the way out. A
RowNodeis exported as a one-row table, so a row's paddingwent the same way.
Measured on the probe corpus through LibreOffice against the reference PDF, that was three
of the four gaps still missing from page 1 — a row's 14pt lost at each edge, and the 6pt a
billing table holds above itself:
They looked like two defects (a row's padding, a header row) and were one.
What changed
A table-shaped node's own box goes through the same gap as everything else.
writeTableWithItsOwnSpacingowes its top edge before the table is written — the flush thatalready runs before a table pays it onto the paragraph above — and owes its bottom edge
after, which the next paragraph writes above itself. So a table between two paragraphs now
reads as two paragraphs with a gap between them, and nothing needs an element of its own.
The one edge Word cannot hold is still dropped. A table with no paragraph above it loses
its top edge rather than getting an empty paragraph to carry it, which would be a line the
document never asked for. A test pins that, and pins that the bottom edge still arrives.
Verification
./mvnw -B -ntp clean verifyover the eight-module gate → BUILD SUCCESS (core 815,render-pdf 337, render-docx 225, testing 5, render-pptx 140, templates 127, qa 1784).
./mvnw -B -ntp test -f examples/pom.xml→ 93 tests, BUILD SUCCESS; no committed previewdrifted.
Measured again on the same corpus and the same editor, page 1 end to end:
Every block is within 1.2pt of the page, against 87pt of accumulated drift three changes
ago. The residue is the 1.1pt the first paragraph starts with and never grows.
render-docx goes from 222 to 225 tests.
DocxVerticalSpacingTestgains a table's twoedges landing on the paragraphs around it, a row's padding doing the same, and a table with
nothing above it keeping the bottom edge while losing the top.
Lane: canonical —
document.backend.semantic.docxonly. No public API change.Page 2 is not touched by this and still drifts:
Checklistsits 23.8pt high and the Latoparagraph 37.4pt. That page opens with an image, so the next thing to measure is what an
image block reserves.