Skip to content

fix(usvg): use the viewport as the bbox of a sliced <image>#1059

Open
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/image-slice-objectboundingbox-clip
Open

fix(usvg): use the viewport as the bbox of a sliced <image>#1059
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/image-slice-objectboundingbox-clip

Conversation

@StefanoD

@StefanoD StefanoD commented Jun 13, 2026

Copy link
Copy Markdown

An <image> with preserveAspectRatio="… slice" is scaled to cover its viewport and the overflow is cut away by a rectangular clip. Its bounding box is therefore the image's x/y/width/height rect (the viewport), but usvg derived it from the children, i.e. the oversized scaled-to-cover image.

As a result, an objectBoundingBox clip-path (or mask/filter) applied to a sliced image was resolved against the wrong, much larger box. With a non-square viewport this scaled the clip shape anisotropically and made it collapse — e.g. a decorative arched window clipped to a tall image rendered as a flat top instead of the intended curve, differing from Chrome/Firefox.

Set the slice wrapper group's bounding box to the image rect so downstream bbox-relative units are resolved correctly.

Adds a regression test asserting the clip transform is built from the viewport rect and not the scaled image.

Closes #1034

Generated by Claude

An `<image>` with `preserveAspectRatio="… slice"` is scaled to *cover* its
viewport and the overflow is cut away by a rectangular clip. Its bounding box
is therefore the image's `x/y/width/height` rect (the viewport), but usvg
derived it from the children, i.e. the oversized scaled-to-cover image.

As a result, an `objectBoundingBox` clip-path (or mask/filter) applied to a
sliced image was resolved against the wrong, much larger box. With a non-square
viewport this scaled the clip shape anisotropically and made it collapse — e.g.
a decorative arched window clipped to a tall image rendered as a flat top
instead of the intended curve, differing from Chrome/Firefox.

Set the slice wrapper group's bounding box to the image rect so downstream
bbox-relative units are resolved correctly.

Adds a regression test asserting the clip transform is built from the viewport
rect and not the scaled image.

Closes linebender#1034

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@RazrFalcon

Copy link
Copy Markdown
Collaborator

I would have to investigate this one first. objectBoundingBox is a very tricky thing to change blindly.

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.

Bug: clip-path rendering gives different result compared to chrome/firefox

2 participants