Skip to content

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

Merged
LaurenzV merged 2 commits into
linebender:mainfrom
StefanoD:fix/image-slice-objectboundingbox-clip
Aug 16, 2026
Merged

fix(usvg): use the viewport as the bbox of a sliced <image>#1077
LaurenzV merged 2 commits into
linebender:mainfrom
StefanoD:fix/image-slice-objectboundingbox-clip

Conversation

@StefanoD

Copy link
Copy Markdown
Contributor

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


Note: I accidentally closed the original PR (#1059) 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 June 13, 2026 15:14
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>
@LaurenzV

Copy link
Copy Markdown
Collaborator

Thanks!

@LaurenzV
LaurenzV merged commit 021d44b into linebender:main Aug 16, 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.

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

2 participants