meerk40t / svgelements

SVG Parsing for Elements, Paths, and other SVG Objects.
MIT License
127 stars 28 forks source link

Cannot parse Gradient #159

Open faye1225 opened 2 years ago

faye1225 commented 2 years ago
<linearGradient id="hair_1_" gradientUnits="userSpaceOnUse" x1="489.9507" y1="138.5193" x2="509.7526" y2="306.5162">
    <stop  offset="0" style="stop-color:#333333"/>
    <stop  offset="0.4113" style="stop-color:#5F5E5D"/>
    <stop  offset="0.804" style="stop-color:#898888"/>
    <stop  offset="1" style="stop-color:#9A9A9A"/>
</linearGradient>

Like the snippet above, only the SVGelement can be returned, not the full linearGradient I'm not sure how to write to the file using svgwrite for this element Any other solutions?

tatarize commented 2 years ago

76 -- Svgelements is mostly to actually get the the geometry out of the svg file. While linearGradients are nice they are sort of a higher level paint object. There's not any actual geometric/rendering done for them. The fills and strokes are Colors since that was the easiest and most properly useful thing for geometric data. Following the IRI link to the linearGradient for rendering just wasn't going to result in rendered data. It certainly is an SVGElement there's just not much the project renders with it.

I'm not quite sure what your trying to solve here. But, I think it's one of those many projects that needs something like #87 for better svg file reading and writing from within python.

While svgelements loads svgs and does so in a robust way it loads the data and gives the geometry approximating a rendered result. The lack of saving is largely because the data is loaded but the core structure of the svg is destroyed in the process. You can write something that will look the same geometrically speaking but it will lose node data and somethings that don't get processed can't just be correctly passed through as unknowns.

faye1225 commented 2 years ago

The original purpose was that a single svg could be programmatically automated to split the svg of n parts.

For example: man.svg -> head.svg, upper-limbs.svg, lower-limbs.svg

So svgelements can't get Gradient. I will consider what you said meerk40t/svgelements#87 this method, thank you very much for your reply