Parse Paths Separately From Full SVG #326
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ParseSVG
function, 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 actualParseSVG
function 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
ParseSVGWithPaths
function 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 calledSVGPath
which includes the tag of each path, along with the*Path
itself. 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):