Repository navigation
PDF: draw horizontal and vertical lines inside groups - #1474
Merged
Merged
Conversation
A line or connector inside a group keeps its zero height or width (a:ext cy="0"), and the PDF export skipped every shape without area, so dividers drawn in Word groups were missing from exported PDFs while the screen showed them.
# Conflicts: # ROADMAP.md # docs/file-format-parity.md
Member
|
Thanks for the contribution, @cyril265! This has landed in main. If you haven't already, come join us on Discord: https://discord.gg/artcraft |
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.
Problem: a horizontal or vertical line inside a group is missing from the exported PDF, although the screen shows it. Word's documents use this for dividers inside grouped boxes (for example a line between two text blocks in an info box), so the PDF loses them.
Cause: such a line keeps a zero height or width in the group (
a:ext cy="0").shape_pathincrates/pdf/src/lib.rsreturnedNonefor every shape withw <= 0 || h <= 0, so the PDF export skipped it. The raster renderer has no such check, so the screen drew it. A floating line on its own was not affected, becausefloat_rectgives it a 1 pt frame; connector presets (straightConnector1and the others) were not affected either, because they are drawn as paths. The affected shape isprst="line", which Word also writes for its straight connectors (withwps:cNvCnPr).Fix: lines (and connectors, for the frame-based fallback) may now be flat on one axis. Closed shapes still need an area, and a line without length is still skipped.
Found while converting generated letters to PDF with
wordcraft-cli convert.Reproduction:
lines.docx(hand-written from the spec, no Word output), thenwordcraft-cli convert lines.docx out.pdf: the red divider inside the grey group is missing onmain.Both images:
wordcraft-cli convert lines.docx out.pdf, thenpdftoppm -r 100.lines.docxis a hand-written fixture: a group (wpg:wgp) holding a rounded rectangle and aprst="line"shape witha:ext cy="0".Note: the 1 pt minimum in
float_rectstill draws a standalone horizontal line as a 1 pt diagonal; left alone here.docs/file-format-parity.mdand theROADMAP.mdprogress log are updated.Tests
New and changed tests in
crates/pdf/src/tests.rs:flat_lines_in_a_group_are_drawn: a group with a horizontal, a vertical and a zero-length line exports exactly two more paths than the empty group.shapes_have_paths: horizontal and vertical lines and connectors get a path; a flat rectangle, a line without length, and NaN, infinite or negative sizes don't.Before the fix:
After:
cargo test -p wordcraft-pdf: 26 passed.cargo fmt --checkandcargo clippy -p wordcraft-pdf --all-targets -- -D warningsare clean. I didn't run the wasm build.