Skip to content

fix(plot): correct hatch rendering in PDF / plot export#1

Closed
sLuCHaa wants to merge 1 commit into
mainfrom
fix/block-internal-hatch-pdf-export
Closed

fix(plot): correct hatch rendering in PDF / plot export#1
sLuCHaa wants to merge 1 commit into
mainfrom
fix/block-internal-hatch-pdf-export

Conversation

@sLuCHaa

@sLuCHaa sLuCHaa commented Jul 6, 2026

Copy link
Copy Markdown
Owner

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 shared exploded_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_dxf re-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. imperial 0.125 vs the catalog's metric 3.175 for 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_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 (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:

  • block-internal hatch reaches the export set,
  • stored-line spacing is honoured (not re-scaled from the catalog),
  • far-from-origin fills are not dropped,
  • TEXTBOX paths are not filled.

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.

@sLuCHaa sLuCHaa changed the title fix(plot): export block-internal hatch fills to PDF/print fix(hatch): block-internal fills + correct pattern spacing in viewport/PDF Jul 6, 2026
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.
@sLuCHaa sLuCHaa force-pushed the fix/block-internal-hatch-pdf-export branch from dd74b1e to 1a45f6b Compare July 6, 2026 10:24
@sLuCHaa sLuCHaa changed the title fix(hatch): block-internal fills + correct pattern spacing in viewport/PDF fix(plot): correct hatch rendering in PDF / plot export Jul 6, 2026
@sLuCHaa

sLuCHaa commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR HakanSeven12#292 (same branch, opened against the main project).

@sLuCHaa sLuCHaa closed this Jul 6, 2026
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.

1 participant