Draw an SVG's clipped picture where the author put it - #99
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andpreserveAspectRatio, and puts the image's ownclip-pathon 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 withoutpreserveAspectRatiotoo, since the size alone produces the transform. 1.8.5 is the latest SharpVectors release and has the same code.Fix
SvgMarkup.HoistImageClipsin Core moves an image'sclip-path, and itstransformwith 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