Repository navigation
Draw an SVG referenced by an <image> in the image's viewport - #547
Merged
Merged
Conversation
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.
Fixes #237.
An
<image>that references an SVG document draws that document at its own size and ignores thewidth,heightandpreserveAspectRatioof the<image>. With the files attached to #237,circle.svg(199.5mm square) is drawn about 560 units wide instead of filling the 68.8 x 69.9 rectangle drawn under it, where Inkscape and browsers place it.SVG 1.1 §5.7 says the referenced document is rendered into the viewport of the
<image>: the image's width and height replace the document's, and the image'spreserveAspectRatioreplaces the document's own.renderSvg()already fits a nested<svg>to its viewport withpreserveAspectRatio, so the new_render_svg_in_image()sets these three attributes on the referenced root<svg>while it is rendered, and restores them afterwards, because the same document can be referenced again at another size (ExternalSVGcaches it). An<image>withoutwidth/heightkeeps the document's size, as before (tests/samples/others/svg_in_svg.svgis unchanged), and a reference to a fragment (file.svg#id) is not affected.With the #237 files, the circles now fill the rectangle exactly (bounds 50.6, 49.8 to 119.5, 119.7, the rectangle's box).
Added
test_svg_in_image_fills_the_image_viewport, which compares an<image>of an SVG file with the same content as an inline nested<svg>, forpreserveAspectRatio="none", the default andxMinYMax slice, plus a second reference to the same file at another size; it fails on main. Updatedtests/public_api.jsonwith--updatefor the new private name, and added a### Fixedentry inCHANGELOG.md(I used #546, I'll fix it if the PR gets another number).pytest(without the network-dependent sample downloads),ruff format --check,ruff checkandmypy src testspass.AI-assisted (Claude Code); I reviewed and tested the change