fix(docx): let the list's own block carry its spacing#471
Merged
Conversation
A list was wrapped in two blocks: an outer one holding the Word line box, and an inner one holding the list's `w:spacing` edge gaps. Typst does not apply block spacing at a container's edges, so the inner gaps never reached the boundary and the outer wrapper - which set neither `above` nor `below` - fell back to Typst's own 1.2em `block.spacing`. Every numbered item in the technical manual opened 10.19pt too far from the shaded code line after it, accumulating to +30pt by section 3. Emit one block instead, carrying both the line box and the gaps. `generate_list` now takes the line-height settings rather than a bool and builds the wrapper itself, so there is nowhere for a default to leak in. On page 1 of `05_technical_manual_en` the item-to-code pitch goes from 25.83pt to Word's 15.64pt, mean absolute vertical drift falls from 12.67pt to 1.43pt, and the 5% fuzz pixel difference against the Word export drops from 88,314 to 57,544. `02_contract_ko` moves the other way, from 4.20pt to 9.11pt, because the leaked default had been masking a deficit rather than helping: Word's gap there really is the 4pt `w:spacing w:after` this change now emits, and the ~8pt the document is short by accumulates earlier, in the title paragraph that #402 tracks. Fixes #463 Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
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.
Summary
w:spacingedge gapsgenerate_listtakes the line-height settings instead of a bool and builds the wrapper itselfRelated issue
Fixes #463
Details
A list was wrapped in two blocks: an outer one holding the Word line box, and an inner one holding the edge gaps. Typst does not apply block spacing at a container's edges, so the inner gaps never reached the boundary and the outer wrapper — which set neither
abovenorbelow— fell back to Typst's own 1.2emblock.spacing.Baseline-to-baseline pitch from a numbered item to the shaded code line after it, page 1:
$ office2pdf report.docx$ office2pdf slides.pptx …$ office2pdf *.xlsx …Mean absolute vertical drift on that file falls from 12.67pt to 1.43pt, and across the business corpus from 13.52pt to 12.88pt.
02_contract_komoves the other way, 4.20pt to 9.11pt. That is the leaked default having masked a deficit rather than helped: itsw:spacing w:afterthere really is 4pt, matching Word's 22.32pt pitch against an 18pt line box, and the ~8pt the document is short by accumulates earlier — its first three paragraphs are already 2.79pt, 7.52pt, and 7.76pt high before any list appears, which is the title-paragraph defect #402 tracks.Testing
cargo fmt --all -- --checkcargo test --workspacecargo clippy --workspace --all-targets --all-featurespython3 scripts/validate_business_golden_mocks.pypdftotext -bboxpitch comparison against all 10 Word-produced DOCX golden PDFspdftoppm -r 150rendering, matched region crops, andmagick compare -metric AE -fuzz 5%Visual impact
Visual audit
tests/golden_mocks/business/sources/docx/05_technical_manual_en.docxpdftoppm, 150 DPIfixassets/bugfixes/issue-463/gt.jpgassets/bugfixes/issue-463/before.jpgassets/bugfixes/issue-463/after.jpgVisual comparison
Required inspection
The 5% fuzz sweep against the size-normalized GT falls from 88,314 to 57,544 differing pixels. The residual clusters are the 12pt code-paragraph indent tracked in #464 plus font antialiasing. The page's only hairline is the header rule, which matches GT in position, width, and weight on the full-resolution crop; there are no dashed or dotted borders. Bold headings, the monospace runs, and the italic disclaimer all keep the same emphasis as GT.
Deviation audit
w:ind w:left; the page box and text column match GTF4F4F4code shading is the same color, though its left edge inherits #464Checklist
Signed-off-byline