Conversation
|
Looks good to me. I believe the SVG parser should be rewritten entirely, but in the meantime this suffices. Nitpick: you don't need to set x and y to zero explicitly, they already are! |
Thanks. I was just doing a one-to-one conversion of what was there before, but I removed it now. Would it be bad to include the attributes of the tag in the returned I pushed a change demonstrating it. If you're good with this, it is ready to be pulled I think. |
|
I would love to see like this feature implemented as well. What is the current status? |
|
In the meanwhile you could use https://pkg.go.dev/encoding/xml#Token to parse an SVG and find the |
I ran into a use case that wasn't yet covered by the library, in that I need to be able to pull only certain paths/shapes from one SVG file, and draw them to another canvas with a custom styling applied. It sounds like there were plans to implement something of the sort already, according to the wiki:
This only accounts for SVGs, and it only returns paths/shapes to the user, not text (so far). So it's not a full solution yet.
My approach essentially took the original
ParseSVGfunction, made it a private function, made it set aside the paths/shapes it finds while parsing the rest of the SVG as usual, and then returns them at the end. And the actualParseSVGfunction is now just a small helper function which calls the modified original function, but discards the paths it found, to maintain backwards compatibility.The new
ParseSVGWithPathsfunction returns the paths/shapes that were parsed, to the user. This is the function I ended up needing for my use. It actually returns a new type calledSVGPathwhich includes the tag of each path, along with the*Pathitself. This allows the user to distinguish paths/shapes, and only use the relevant ones. This is useful to me personally.Am I on the right track here? How would you suggest going about this? Ultimately my goal is creating a rasterized mask file from a vector outline. Example (first turns into second):