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

Path elements with transparent fills removed #27

Closed tinder-darraghburke closed 8 months ago

tinder-darraghburke commented 8 months ago

Hi, hope you're doing well! Thanks for all your work on SwiftDraw!

Just reaching out again about another issue we're running into - we noticed that elements with transparent fills are removed from the final output. For example, we have the following SVG:

verified-true

Here are the relevant elements:

  <path fill="transparent"
    d="m1.055 8.448.657-.37c.552-.317.84-.95.683-1.532l-.131-.74A1.493 1.493 0 0 1 3.63 4.062l.762-.052a1.461 1.461 0 0 0 1.34-1.084l.21-.74a1.45 1.45 0 0 1 1.97-.977l.71.29c.578.238 1.235.08 1.655-.396l.5-.581a1.449 1.449 0 0 1 2.18-.053l.5.581c.42.476 1.103.608 1.68.37l.789-.29c.814-.344 1.76.105 1.997.95l.21.74c.158.608.71 1.031 1.34 1.057l.762.027a1.46 1.46 0 0 1 1.392 1.717l-.131.74c-.105.608.21 1.242.762 1.532l.657.37c.762.397.998 1.427.499 2.14l-.447.634a1.474 1.474 0 0 0 0 1.718l.447.607a1.49 1.49 0 0 1-.473 2.167l-.657.37c-.552.317-.84.925-.735 1.559l.13.74a1.491 1.491 0 0 1-1.365 1.743l-.762.053a1.461 1.461 0 0 0-1.34 1.083l-.21.74a1.45 1.45 0 0 1-1.97.977l-.71-.29a1.459 1.459 0 0 0-1.655.396l-.5.581a1.458 1.458 0 0 1-2.207.027l-.499-.581c-.42-.476-1.103-.608-1.681-.37l-.71.29c-.814.344-1.76-.105-1.997-.95l-.21-.74c-.157-.608-.71-1.031-1.34-1.057l-.762-.027a1.461 1.461 0 0 1-1.392-1.717l.131-.74a1.475 1.475 0 0 0-.762-1.532l-.656-.37c-.762-.396-.999-1.427-.5-2.14l.447-.634a1.474 1.474 0 0 0 0-1.718l-.447-.607a1.49 1.49 0 0 1 .473-2.167Z"
    class="multicolor-0:custom hierarchical-0:secondary SFSymbolsPreviewtransparent" data-fill="secondary" />
  <path fill="currentColor" fill-rule="evenodd"
    d="m1.712 8.078-.657.37a1.49 1.49 0 0 0-.473 2.167l.447.607a1.474 1.474 0 0 1 0 1.718l-.447.634c-.499.713-.262 1.744.5 2.14l.656.37c.552.29.867.924.762 1.532l-.131.74c-.158.872.5 1.69 1.392 1.717l.762.027c.63.026 1.183.449 1.34 1.056l.21.74c.237.846 1.183 1.295 1.997.951l.71-.29c.578-.238 1.26-.106 1.681.37l.5.58a1.456 1.456 0 0 0 2.206-.026l.5-.58a1.459 1.459 0 0 1 1.655-.397l.71.29a1.45 1.45 0 0 0 1.97-.977l.21-.74a1.461 1.461 0 0 1 1.34-1.083l.762-.053a1.493 1.493 0 0 0 1.366-1.744l-.131-.74a1.495 1.495 0 0 1 .735-1.558l.657-.37a1.49 1.49 0 0 0 .473-2.167l-.447-.607a1.474 1.474 0 0 1 0-1.718l.447-.634c.5-.713.263-1.743-.5-2.14l-.656-.37a1.475 1.475 0 0 1-.762-1.532l.131-.74a1.46 1.46 0 0 0-1.392-1.717l-.762-.027a1.437 1.437 0 0 1-1.34-1.056l-.21-.74c-.237-.846-1.183-1.295-1.997-.951l-.788.29c-.578.238-1.261.106-1.682-.37l-.499-.58a1.449 1.449 0 0 0-2.18.052l-.5.581a1.459 1.459 0 0 1-1.655.397l-.71-.291a1.45 1.45 0 0 0-1.97.978l-.21.74a1.461 1.461 0 0 1-1.34 1.083l-.762.052a1.493 1.493 0 0 0-1.366 1.744l.131.74c.158.581-.131 1.215-.683 1.532Zm14.891-1.105c.437 0 .822.158 1.13.474.308.29.462.712.462 1.134 0 .422-.18.843-.488 1.16l-6.136 6.812a1.474 1.474 0 0 1-1.104.474c-.41 0-.796-.158-1.104-.474l-3.08-3.675c-.309-.29-.463-.712-.463-1.133 0-.422.154-.818.462-1.134a1.572 1.572 0 0 1 1.13-.475c.41 0 .796.159 1.104.475l1.951 1.748L15.5 7.447a1.474 1.474 0 0 1 1.104-.474Z"
    clip-rule="evenodd" data-fill="primary" />

The first element is removed from the final output. I'm guessing this is an optimization with the idea that transparent elements wouldn't be visible in the final symbol, but we'd actually like to retain the layer since we want it to be dynamically recolorable. Is it possible to support this? Perhaps elements with classnames indicating they support recoloring should be preserved, even when their fill is transparent?

swhitty commented 8 months ago

Thanks @tinder-darraghburke for reporting this 🙏🏼. This issue was part bug and part optimisation and I believe it is now fixed on develop. Please try it out and let me know if it fulfils your purpose.

The named color transparent was previously not parsed correctly and has been fixed.

Your suggestion of including all layers with SFSymbol annotations is smart and I think it works well. The intention of the optimisation was to hide invisible layers in SVGs from unknown sources. Layers that include the supported SFSymbol class annotations will not be from unknown sources and can safely be included 👍🏻.

tinder-darraghburke commented 8 months ago

Amazing! Thanks so much for the quick resolution @swhitty!

Would love to test this out - would you be able to release another version of the CLI with these changes?

swhitty commented 8 months ago

Sure, try this notarized build from develop SwiftDraw.dmg.zip

swhitty commented 8 months ago

Included within 0.15.0 release

tinder-darraghburke commented 8 months ago

This is fantastic, thank you so much!