Repository navigation
fix(svg): export svg files without the #508 layout zoom (#552) - #553
Merged
Merged
Conversation
Member
|
Great thank you and welcome !! |
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 #552.
Follows the approach from the issue thread: the layout zoom only pays off when the browser itself rasterizes the SVG, so SVG output that leaves as a file is serialized without the zoom wrapper, the same wrapper Safari and 1x screens already get. Raster exports keep it. No new option, and
dpris not involved.Cause
On a real hi-DPI screen in Chromium and Firefox,
composeAndSerializelays the clone out on the device grid (#508):zoom: <dpr>on the foreignObject's container,scale(1/dpr)on a<g>around it, and foreignObject geometry multiplied by the zoom. Browsers cancel the two out. macOS Preview and Quick Look do not: inline<svg>children of the foreignObject draw at about 2x while the HTML text around them stays the right size. The zoom came only fromliveLayoutZoom(view), so there was no way to get a downloadable SVG that Preview displays correctly.Fix
src/engines/svg.js: whenlayoutZoom !== 1,composeAndSerializealso records the 1x wrapper next to the zoomed one inoptions.__fileSvg: the svg header with the foreignObject open tag, the container open tag, and the footer. Only the wrapper differs between the two (positions inside are the same CSS pixels), so the clone markup is not serialized twice. The 1x wrapper keeps the cliptranslate()and dropsscale(), the containerzoomand the zoomed fo geometry. At zoom 1 the field is reset tonull, so a reused options bag never carries a previous capture's tags.src/utils/helpers.js:fileSvgText(svgText, fileSvg)swaps the zoomed wrapper for the flat one. If the markup does not have the expected shape (no zoom, or a plugin rewrote it after render), it returns the input unchanged.toBlob({ format: 'svg' })(and sodownload({ format: 'svg' })) insrc/exporters/toBlob.js, andsvgString()for plugins insrc/api/snapdom.js.result.url,toImg,toCanvasand every raster export keep the zoomed SVG, so the Layout becomes misaligned on mobile browsers #508 match with the page stays.Cost: nothing at zoom 1. At zoom ≠ 1, two shallow-clone tag serializations per capture, and one string splice per file export.
Tests
New
describe('svg files drop the layout zoom (#552)')in__tests__/engine.svg.layoutZoom.test.js, usingstubHiDPI:toBlobsvg has nozoomand noscale(, its foreignObject is in CSS pixels, andurlstill haszoom: 2.625.snapdom.toBlobshortcut gets the same file.svgString()seen by a plugin is the 1x wrapper.url.Results:
main, the new zoomed cases fail:npm test(chromium):npm run test:full:This PR was prepared with AI assistance.