Skip to content

Fix nested svg transform being applied twice#1084

Open
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/nested-svg-double-transform
Open

Fix nested svg transform being applied twice#1084
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/nested-svg-double-transform

Conversation

@StefanoD

Copy link
Copy Markdown

Fixes #1066.

Problem

A transform on a nested <svg> element was applied twice. The same happens to
other group properties (e.g. opacity). For example, a rect under
<svg transform="translate(50,50)"> was rendered at (100,100) instead of (50,50).

Cause

In convert_element, a nested <svg> was wrapped in a convert_group (which
reads the element's transform), and then convert_svg created its own group as
well — so the transform was applied in both. <use> does not have this problem
because it is routed to its handler and returns before the convert_group wrapper.

Fix

Route a nested <svg> directly to convert_svg and return early, exactly like
<use>. The outermost <svg> (no parent element) is unaffected.

Testing

  • New regression test nested_svg_transform_applied_once (fails on main with
    translate(20,40), passes with the fix as translate(10,20)).
  • The full usvg test suite and all 1724 resvg render tests pass.

Generated by Claude


Note: I accidentally closed the original PR (#1067) by deleting my fork, which auto-closed it. This reopens the same change — the branch and commits are unchanged.

A nested `svg` element was wrapped in a redundant group in `convert_element`,
while `convert_svg` already creates its own group, so its `transform` (and
other group properties) were applied twice. Route nested `svg` directly to
`convert_svg` and return early, like `use` does.

Fixes linebender#1066

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Nested <svg> transform is applied twice (inconsistent with <use> and browsers)

1 participant