Skip to content

Apply root svg transform after the viewBox mapping#1068

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

Apply root svg transform after the viewBox mapping#1068
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/899-root-svg-transform

Conversation

@StefanoD

Copy link
Copy Markdown

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

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>
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

1 participant