Skip to content

PDF: draw horizontal and vertical lines inside groups - #1474

Merged
echelon merged 4 commits into
storytold:mainfrom
cyril265:fix/pdf-zero-height-lines
Oct 14, 2026
Merged

echelon merged 4 commits into
storytold:mainfrom
cyril265:fix/pdf-zero-height-lines

Conversation

@cyril265

@cyril265 cyril265 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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_path in crates/pdf/src/lib.rs returned None for every shape with w <= 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, because float_rect gives it a 1 pt frame; connector presets (straightConnector1 and the others) were not affected either, because they are drawn as paths. The affected shape is prst="line", which Word also writes for its straight connectors (with wps: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), then wordcraft-cli convert lines.docx out.pdf: the red divider inside the grey group is missing on main.

Before: the grey group without its divider. After: the red divider is drawn

Both images: wordcraft-cli convert lines.docx out.pdf, then pdftoppm -r 100. lines.docx is a hand-written fixture: a group (wpg:wgp) holding a rounded rectangle and a prst="line" shape with a:ext cy="0".

Note: the 1 pt minimum in float_rect still draws a standalone horizontal line as a 1 pt diagonal; left alone here.

docs/file-format-parity.md and the ROADMAP.md progress 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:

thread 'tests::flat_lines_in_a_group_are_drawn' panicked at crates/pdf/src/tests.rs:607:5:
assertion `left == right` failed: the horizontal and the vertical line, not the one without length
  left: 0
 right: 2

After: cargo test -p wordcraft-pdf: 26 passed.

cargo fmt --check and cargo clippy -p wordcraft-pdf --all-targets -- -D warnings are clean. I didn't run the wasm build.

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.
cyril265 and others added 2 commits October 13, 2026 22:59
# Conflicts:
#	ROADMAP.md
#	docs/file-format-parity.md
@echelon
echelon merged commit 5ff69b8 into storytold:main Oct 14, 2026
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants