Skip to content

PDF tiling patterns: colour-through-base fix, BBox clip, registry dedup#575

Merged
andiwand merged 1 commit into
mainfrom
pdf-tiling-pattern-fixes
Jun 28, 2026
Merged

PDF tiling patterns: colour-through-base fix, BBox clip, registry dedup#575
andiwand merged 1 commit into
mainfrom
pdf-tiling-pattern-fixes

Conversation

@andiwand

@andiwand andiwand commented Jun 28, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Follow-ups on the stage-4.10 tiling-pattern work (#574), addressing the Codex review comments plus some cleanup.

Correctness

  • Uncoloured-pattern colour through the base space. ColorSpaceDef::to_rgb returned black for ColorSpaceKind::pattern, ignoring its base. When a /PaintType 2 pattern is selected through a named Pattern colour space (/CS1 [/Pattern /DeviceRGB]), set_color feeds the leading components into to_rgb, so /CS1 cs 1 0 0 /P scn painted black instead of red. to_rgb now defers the pattern case to its underlying base. Adds a regression test (the existing test used the inline /Pattern cs form, where color.def stays null and the device-by-count path masks the bug).
  • Clip each tiling-pattern cell to its /BBox (ISO 32000-1 8.7.3.1). When /XStep//YStep differ from /BBox, marks drawn outside the cell — or in the gap when a step exceeds the BBox — leaked into the repeated tile. The tile content is now wrapped in a <clipPath> rect sized by the BBox. (An overlapping lattice, a step smaller than the BBox, can't be expressed as a single SVG <pattern> and is left unreproduced.)

Cleanup / dedup

  • Extract a shared DefsRegistry base for the three per-page <defs> registries (clip/gradient/pattern), which carried identical m_page/m_count/m_id_by_signature/m_defs members, an identical defs(), and the same intern-and-mint-id idiom.
  • Extract an svg_matrix helper for the repeated matrix(a,b,c,d,round2(e),round2(f)) serialization (gradient/pattern transforms and the image fragment).
  • Use has_value for the pattern /Resources lookup, matching the /BBox check.

Tests

All 200 PDF tests pass locally (199 + the new scn_uncoloured_tiling_pattern_colour_through_base).

Follow-ups on the stage-4.10 tiling-pattern work (#574):

- Fix uncoloured-pattern colour resolution: `ColorSpaceDef::to_rgb` now
  defers `ColorSpaceKind::pattern` to its underlying base, so a `/PaintType 2`
  pattern selected through a named Pattern space (`[/Pattern /DeviceRGB]`)
  paints in its tint instead of black. Adds a regression test.
- Clip each tiling-pattern cell to its `/BBox` so marks outside the cell, or
  in the gap when a step exceeds the BBox, don't leak into the tile.
- Deduplicate the per-page `<defs>` registries (clip/gradient/pattern) behind
  a shared `DefsRegistry` base, and extract an `svg_matrix` helper for the
  repeated `matrix(...)` serialization.
- Use `has_value` for the pattern `/Resources` lookup, matching `/BBox`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Negfa31h7p7vRYJzGUhjdE
@andiwand andiwand enabled auto-merge (squash) June 28, 2026 18:27
@andiwand andiwand merged commit 39cf457 into main Jun 28, 2026
11 checks passed
@andiwand andiwand deleted the pdf-tiling-pattern-fixes branch June 28, 2026 18:57
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