Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewbox values get rounded to nearest int #810

Open
RiedleroD opened this issue Aug 30, 2024 · 4 comments
Open

viewbox values get rounded to nearest int #810

RiedleroD opened this issue Aug 30, 2024 · 4 comments

Comments

@RiedleroD
Copy link

RiedleroD commented Aug 30, 2024

Not much to explain here, the issue is quite simple. I hope the fix will be simple too 🤞🏻 I've attached some renders of a test image. I tested in resvg 0.41 and 0.43

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1.5 1.5">
	<rect fill="green" width="1.7" height="1.7"/>
	<rect fill="blue" width="1.5" height="1.5"/>
	<rect fill="red" width="1.2" height="1.2"/>
</svg>
Impl Image viewbox size command
Your Browser test - -
rsvg test_rsvg 1.5x1.5 rsvg-convert test.svg -w 100 -o test_rsvg.png
inkscape test_inkscape 1.5x1.5 inkscape "/home/riedler/Downloads/test.svg" --export-filename="test_inkscape.png" -w 100
resvg test_resvg 2x2 resvg test.svg -w 100 test_resvg.png

note that this is less of an issue when rounded up, but quite a big issue when rounded down, since some SVGs are perfectly cut to their contents. I feel that a suitable hotfix would be always rounding up, and cutting the resulting bitmap image to the proper size afterwards.

I didn't test whether aspect ratio is preserved e.g. when viewBox="0 0 1.5 2", but I assume that's also an issue.

@RazrFalcon
Copy link
Collaborator

Not sure if the SVG spec specifies this behavior to begin with. Will see what we can do about it.

@RiedleroD
Copy link
Author

RiedleroD commented Sep 3, 2024

I would say so, considering what they say here: https://www.w3.org/TR/SVG11/types.html#Precision

edit: equivalent SVG 2 spec: https://www.w3.org/TR/SVG2/types.html#Precision

@RazrFalcon
Copy link
Collaborator

Yes, I'm familiar with it, but it doesn't describe that case in particular.
Once again, I will look into it eventually.

@jermy
Copy link

jermy commented Nov 15, 2024

Just to quickly comment - this is a specific issue with the resvg binary, and shouldn't be an issue if you use the the C or Rust API directly.

It's easy enough to change to support floating point sizes returned for the SVG, but for consistent behaviour will require a small modification to tiny-skia to support scale_by, scale_to_width and scale_to_height against the Size type (which currently only exist on it uses IntSize).

I've got those patches - let me know if it's worth doing a couple of respective PRs for this.

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

No branches or pull requests

3 participants