fix(plot): correct hatch rendering in PDF / plot export#292
Open
sLuCHaa wants to merge 1 commit into
Open
Conversation
Hatched content — especially fills nested inside a block INSERT, such as a title-block logo — plotted incorrectly: missing, mis-spaced, or with phantom bars. Five related fixes make the PDF/plot output match AutoCAD. 1. Export block-internal hatch fills. The export collected only hatches owned directly by the layout block, so a hatch nested in a block INSERT was dropped and printed as bare monochrome outlines. The insert-explosion the viewport already does is extracted into a shared `exploded_insert_hatch_models()` and called from both the viewport (`synced_hatch_models`) and the export (`paper_canvas_hatches`), so a plot draws block-internal hatches identically to the screen. 2. Honour the hatch's own stored pattern-line spacing. `hatch_model_from_dxf` re-derived pattern spacing from the name-matched catalog entry x pattern_scale, ignoring the resolved line geometry the DWG stores on the hatch. When a drawing was authored against a different base spacing (imperial 0.125 vs the catalog's metric 3.175 for ANSI31), lines came out up to ~25x too coarse and a dense fill collapsed to a few stray lines. When the hatch carries its own line geometry it is now used directly (identity scale/angle); the catalog path remains the fallback. 3. Fill far-from-origin pattern hatches. `pattern_segments` clamped the ABSOLUTE scan-line index to +/-MAX_LINES_PER_FAMILY. A fine-spaced hatch far from the pattern origin has large-magnitude indices at both ends but a small span, so the clamp inverted the range and emitted nothing — silently dropping the fill. Cap the line count (span) instead of the absolute index. 4. Skip TEXTBOX boundary paths. TEXTBOX boundary paths (flag bit 3) are text bounding-boxes AutoCAD derives for island detection; they are never drawn or filled. Treating one as a fill boundary painted its rectangle solid — a phantom bar. It is now skipped when building the fill boundary. 5. Print white/ACI-7 hatch fills black on paper. Hatch fills arrive adapted to the dark screen background, so a white/ACI-7 fill would vanish white-on-white on the sheet. Mirror the wire pass: near-white/near-yellow -> black, near-cyan -> dark blue, matching AutoCAD's colour-7-on-white plotting. Wipeouts keep their paper-white mask. Adds `tests/block_hatch_export.rs` covering: block-internal hatch reaches the export set, stored-line spacing is honoured, far-from-origin fills are not dropped, and TEXTBOX paths are not filled.
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
Hatched content plotted incorrectly in the PDF / plot export — especially fills nested inside a block INSERT (a title-block logo, for example): they were missing, mis-spaced, or drew phantom bars. This PR makes the PDF/plot output match AutoCAD.
Fixes
1. Export block-internal hatch fills
The export path (
paper_canvas_hatches) collected only hatches owned directly by the layout block, so a hatch nested in a block INSERT was dropped and the block printed as bare monochrome outlines. The insert-explosion the viewport already performs is extracted into a sharedexploded_insert_hatch_models(), now called from both the viewport (synced_hatch_models) and the export — so a plot draws block-internal hatches identically to the screen.2. Honour the hatch's own stored pattern-line spacing
hatch_model_from_dxfre-derived pattern spacing from the name-matched catalog entry ×pattern_scale, ignoring the resolved line geometry the DWG stores on the hatch itself. When a drawing was authored against a different base spacing (e.g. imperial0.125vs the catalog's metric3.175for ANSI31), lines came out up to ~25× (inch→mm) too coarse and a dense fill collapsed to a few stray lines. When the hatch carries its own line geometry it is now used directly (identity scale/angle); the catalog lookup remains the fallback.3. Fill far-from-origin pattern hatches
pattern_segmentsclamped the absolute scan-line index to±MAX_LINES_PER_FAMILY. A fine-spaced hatch far from the pattern origin has large-magnitude indices at both ends but a small span, so the clamp inverted the range (k_lo > k_hi) and emitted nothing — silently dropping the fill. It now caps the line count (span) instead of the absolute index.4. Skip TEXTBOX boundary paths
TEXTBOX boundary paths (flag bit 3) are text bounding-boxes AutoCAD derives for island detection; they are never drawn or filled. Treating one as a fill boundary painted its rectangle solid — a phantom bar. Such paths are now skipped when building the fill boundary.
5. Print white/ACI-7 hatch fills black on paper
Hatch fills arrive adapted to the dark screen background, so a white/ACI-7 fill would vanish white-on-white on the sheet. The export now mirrors the wire pass (near-white/near-yellow → black, near-cyan → dark blue), matching AutoCAD's colour-7-on-white plotting. Wipeouts keep their paper-white mask.
Tests
Adds
tests/block_hatch_export.rs:All self-contained (no external drawing required).
Scope
Export/plot path only. An unrelated on-screen GPU hatch-clipping nuance (dense pattern fills rendering over their bounding box in the viewport) is not part of this PR — it does not affect the plotted output.