Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Added support for multiple svg paths & groups #177

Closed Amiicli closed 1 year ago

Amiicli commented 1 year ago

Hi, I added support for multiple paths and groups in SVGs. It searches recursively so any amount of groups within groups should be fine. I’ve tested support for SVGs with: -One path -Multiple paths, no groups -Groups within groups -Empty groups

A positive side effect that I hadn’t expected is that this seems to have fixed support for SVGs exported directly from Adobe Illustrator

I was initially concerned that feeding paths into &shape through buildShapeFromSvgPath() multiple times might not have been the most elegant solution but in all of my tests I found that this works quite well.

Thank you for the great program!

Edit: My apologies, looking through past pull requests it seems like choosing paths by index was an important consideration that I had overlooked. I'm wondering if a compromise could be having a path index of -1 to select all paths and groups could be an option. This way people looking for select specific paths can have their functionality in place and people who want to select all paths in an svg can also have it their way.

Chlumsky commented 1 year ago

Do you think this wasn't implemented because I didn't know how to iterate all paths in the SVG? The reason only one path is taken is that the algorithm is only able to generate an SDF from a single non-intersecting shape. If no paths ever intersect and have consistent windings, this will work, but that is a pretty rare case. On the other hand, many SVG editors have the functionality to merge the paths properly, so if the user knows that they need to provide a single path, they have a chance to do this conversion correctly.

However, since the project now links Skia, I could use that to merge the paths, so I might implement that when I have time.

Chlumsky commented 1 year ago

Also, another reason is that each path or group in the SVG may have the transform attribute which changes its positioning in relation to other paths.

Chlumsky commented 1 year ago

Alright, I implemented it today in 0286aeb6eb452ec1cd9636b43cf303d33f61eb31.