Skip to content

Apply root SVG transform after the viewBox mapping - #1085

Merged
LaurenzV merged 2 commits into
linebender:mainfrom
StefanoD:fix/899-root-svg-transform
Oct 8, 2026
Merged

LaurenzV merged 2 commits into
linebender:mainfrom
StefanoD:fix/899-root-svg-transform

Conversation

@StefanoD

Copy link
Copy Markdown
Contributor

Fixes #899.

Problem

A transform on the outermost <svg> combined with a viewBox rendered
differently from Chromium/Firefox/Inkscape. resvg applied the transform inside
the viewBox space, clipping content into the corner.

Fix

The transform on the outermost <svg> is a CSS transform in the SVG viewport
coordinate system, i.e. applied after the viewBox-to-viewport mapping. Combine
it with the viewBox transform in convert_doc so it wraps the viewBox mapping,
and skip it in convert_group for the root <svg> to avoid applying it twice.

Testing

  • New tests root_svg_transform_with_viewbox and nested_svg_transform_still_applies.
  • All 1724 resvg render tests pass.

Generated by Claude


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

StefanoD and others added 2 commits October 8, 2026 19:20
A `transform` on the outermost `svg` element is applied in the SVG viewport
coordinate system, i.e. after the viewBox-to-viewport mapping, matching
Chromium, Firefox and Inkscape. Combine it with the viewBox transform in
`convert_doc` (wrapping it) and skip it in `convert_group` for the root `svg`.

Fixes linebender#899

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LaurenzV
LaurenzV force-pushed the fix/899-root-svg-transform branch from 19c6799 to a3446a2 Compare October 8, 2026 17:59
@LaurenzV LaurenzV changed the title Apply root svg transform after the viewBox mapping Apply root SVG transform after the viewBox mapping Oct 8, 2026
@LaurenzV

LaurenzV commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@LaurenzV
LaurenzV merged commit f6d4f7a into linebender:main Oct 8, 2026
5 checks passed
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.

Root svg transform inconsistent with Chromium/Firefox/Inkscape

2 participants