memononen / nanosvg

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

Attributes of NSVGparser #150

Open alisa-patotskaya opened 5 years ago

alisa-patotskaya commented 5 years ago

Hello, I have a question regarding attributes of NSVGparser: why after parsing an element (e.g. "path" or "rect") we first push its' value and than pop it back? This way all saved values in the attributes are going to be lost (such as opacity / strokes / gradients). Is there a mapping between attributes and corresponding shapes?

Thanks.

memononen commented 5 years ago

If you look the difference how g (group) and rect are handled in nsvg__startElement(), it should give you a hint. Groups can be nested, but rects cannot. That is, you cannot have:

<rect>
   <rect/>
</rect>

Since push/pop attrib is used for both group and elements, elements have the push/parse/pop pattern.