swhitty / SwiftDraw

Swift library and command line tool to convert SVGs into SFSymbol, PNG, PDF and Swift source code.
zlib License
326 stars 41 forks source link

Internal stylesheet support? #6

Closed samizdatco closed 1 year ago

samizdatco commented 1 year ago

At the moment SwiftDraw only seems to support style attributes that are set directly on SVG elements. Many tools create SVG files with an embedded stylesheet and rely on the style cascade to apply them to the elements. I can imagine this would be a significant undertaking, but it would be a great compatibility improvement if both types of files could be rendered.

For instance, here are two 'identical' SVGs that differ only in terms of where their styles live:

inline styles

inline

internal stylesheet

internal

SwiftDraw produces very different output when rendering them though:

image
swhitty commented 1 year ago

While SwiftDraw probably can't full support all selectors (e.g. descendents) within stylesheets, would it be useful if a small subset were supported? Simple class and element matching (stylesheet.svg) is probably simple enough to implement.

samizdatco commented 1 year ago

The use case I have in mind is being able to work with SVG produced by Illustrator, Figma, and the like. As far as I can tell, the embedded stylesheets they produce don't get any fancier than using class- and id-based selectors. So the subset you're considering seems like it would be a huge compatibility boost.

swhitty commented 1 year ago

Great, I will look to implement this in the next version.

swhitty commented 1 year ago

Release 0.12.0 adds basic support for stylesheets.