sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
866 stars 124 forks source link

Images don't render correctly when exceeding canvas size #117

Closed leonstyhre closed 1 year ago

leonstyhre commented 1 year ago

Hi!

I have encountered a number of images that don't render correctly in LunaSVG but that render correctly in NanoSVG, Firefox and Chromium. At least they're rendering fine in the web browsers if opened directly. If using the GitHub SVG viewer for instance, then they render incorrectly in the same manner as with LunaSVG.

This issue is quite confusing as I would guess that LunaSVG renders the files as they should as I thought the canvas size was always the restriction for what to actually display. But since these files render fine in the web browsers as well as in NanoSVG I'm not sure what is going on. Is there perhaps some special SVG option to ignore the canvas size or similar that LunaSVG is not respecting?

Here are two example screenshots: https://es-de.org/temp/NanoSVG_canvas_issues.png https://es-de.org/temp/LunaSVG_canvas_issues.png

And here's the problematic file, that will render fine if opened directly in a web browser: https://es-de.org/temp/logo_canvas_issues.svg

However the GitHub preview tool renders it as LunaSVG does: https://github.com/AmadhiX/es-theme-eudora/blob/master/custom-collections/logo.svg

Thanks!

sammycage commented 1 year ago

This is an SVG image file with no width, height, or view box. Viewbox is an attribute that defines the dimension and position of an SVG file in the user’s space. When there are no dimensions, LunaSVG, Chrome and most other browsers will automatically set the image to a default size of 300×150.

sammycage commented 1 year ago

Fixed in commit 0562a5dcc8c25e59c060ee73d6d4d538f172d642

leonstyhre commented 1 year ago

Thanks a lot for the explanation and for the really quick fix! I can confirm that it solved the problem and I'll include your change in the upcoming 2.0.0-alpha release that I'm currently working on!