Skip to content

Fix symbol instance viewports and preserve drawing state - #145

Open
middlegrey wants to merge 1 commit into
dompdf:masterfrom
middlegrey:codex/fix-symbol-use-viewports
Open

middlegrey wants to merge 1 commit into
dompdf:masterfrom
middlegrey:codex/fix-symbol-use-viewports

Conversation

@middlegrey

Copy link
Copy Markdown

Fix symbol instance viewports and preserve drawing state

SVGs containing reusable symbols can render at the root document's size instead of the width and height requested by each use element. A symbol declared outside defs also triggers an unmatched graphics-state restore when its definition closes. When embedded through Dompdf, this can discard the image transform, making CSS width changes appear ineffective.

Apply use width and height to the referenced symbol's instance attributes, with length conversion, while preserving the shared definition. Do not end-render a symbol definition that was never rendered. Correct viewport alignment to read the normalized preserveaspectratio attribute, honor meet/slice, and apply YMid/YMax offsets on the vertical axis.

The new tests cover repeated instances, omitted dimensions, px lengths, negative viewBox origins, meet/slice/none alignment, and balanced graphics state for symbols declared outside defs. tests/fixtures/symbol-use.svg is a minimal standalone reproduction without application assets.

Validation: PHPUnit on PHP 8.2: 10 tests, 91 assertions pass. The repository's existing PHPUnit XML schema produces a deprecation notice.

@middlegrey middlegrey closed this Oct 26, 2026
@middlegrey
middlegrey deleted the codex/fix-symbol-use-viewports branch October 26, 2026 09:40
@middlegrey
middlegrey restored the codex/fix-symbol-use-viewports branch October 26, 2026 09:49
@middlegrey middlegrey reopened this Oct 26, 2026
@bsweeney bsweeney added this to the 1.0.3 milestone Oct 26, 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.

2 participants