Skip to content

Draw an SVG's clipped picture where the author put it - #99

Merged
marcosqlbi merged 1 commit into
mainfrom
fix/svg-image-clip
Sep 3, 2026
Merged

Draw an SVG's clipped picture where the author put it#99
marcosqlbi merged 1 commit into
mainfrom
fix/svg-image-clip

Conversation

@marcosqlbi

Copy link
Copy Markdown
Collaborator

Why

Fixes #98. An SVG that embeds a bitmap and clips it, as the attached illustration frames a screenshot, drew the bitmap shifted and partly blank.

Cause

SharpVectors builds a drawing group for an <image> that carries the scale and offset for the image's width, height, and preserveAspectRatio, and puts the image's own clip-path on that same group. WPF applies a group's clip in the group's local space, so a clip written in page coordinates (140,310 in the report) is scaled and shifted along with the bitmap and lands at 254,564. The blank band above and to the left of the picture is exactly that displacement. It happens without preserveAspectRatio too, since the size alone produces the transform. 1.8.5 is the latest SharpVectors release and has the same code.

Fix

SvgMarkup.HoistImageClips in Core moves an image's clip-path, and its transform with it so the clip keeps the space the author meant, onto a <g> around the image before the markup is decoded. SharpVectors handles a clipped group correctly, as the rendering of the attached SVG now shows. The stored asset is untouched; only what is handed to the renderer changes, with formatting disabled so no whitespace is added between the runs of a <text>. Markup that does not parse is passed through for the renderer to reject in its own words.

Smoke tests cover the hoist, the pass-through of markup with nothing to hoist, and unparsable input. The 1.3.0 release notes and decision 21 record it.

🤖 Generated with Claude Code

SharpVectors puts an image's own clip-path on the same drawing group as
the scale and offset it builds for the image's width, height, and aspect
ratio, so a clip written in page coordinates is transformed along with
the bitmap and lands elsewhere: the picture came out shifted and partly
blank. The clip, and the image's transform with it, is now hoisted onto
a group around the image before decoding, which is what the markup
means and what the renderer handles correctly. The stored asset is
untouched; only what is handed to the renderer changes.

Fixes #98.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@marcosqlbi
marcosqlbi merged commit 705fec3 into main Sep 3, 2026
5 checks passed
@marcosqlbi
marcosqlbi deleted the fix/svg-image-clip branch September 3, 2026 22:35
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.

SVG not properly rendered when bitmaps are embedded

1 participant