openfl / svg

Provides SVG parsing and rendering for OpenFL and Haxe
MIT License
68 stars 30 forks source link

Respect `viewBox` attribute #73

Open player-03 opened 1 year ago

player-03 commented 1 year ago

Inkscape, the foremost open source SVG editor, always inserts a viewBox attribute when it creates a new SVG. This library ignores viewBox, causing it to scale these images incorrectly.


To demonstrate, I made a new Inkscape file, resized the canvas to 128x128px, and filled it with a circle:

With viewBox

Which looks like this in the XML:

<svg
   width="128px"
   height="128px"
   viewBox="0 0 210 297"
   version="1.1">
  <!-- ... -->
</svg>

And looks like this when rendered in a browser:

drawing.svg


But that's taking viewBox into account, which openfl/svg doesn't. Here's what you get when you use this library:

rendered.png

Note that you get the exact same result if you delete the viewBox attribute in Inkscape:

Without viewBox


I may look into this further at some other point, but I'm hoping someone who already knows this library already knows where to go to fix this. I think you should scale based on the minimum of width and height, but don't quote me on it.