memononen / nanosvg

Simple stupid SVG parser
zlib License
1.71k stars 363 forks source link

fix handling of <defs> after <g> #123

Closed poke1024 closed 5 years ago

poke1024 commented 6 years ago

Some SVGs (like the ones exported from Affinity Designer) have their <defs> tags after their <g> tags. Example file:

gradient-circles.svg.zip

Currently, NanoSVG will miss those tags as they're not yet available at the time <g> is parsed (i.e. the shapes needing those gradient will not be painted). This PR fixes this by relaying the resolution of gradient names to a point when the whole XML has been parsed.

Rendering without PR (background not part of NanoSVG rendering):

without-pr

Rendering with PR (background not part of NanoSVG rendering):

with-pr
SergeySlice commented 6 years ago

All is good now.

diimdeep commented 5 years ago

Please merge!

poke1024 commented 5 years ago

I'm closing this in favour of https://github.com/memononen/nanosvg/pull/157, which I think is the cleaner and better solution.