adobe / svg-native-viewer

SVG Native viewer is a library that parses and renders SVG Native documents
Apache License 2.0
155 stars 37 forks source link

Stop colors via `style` attribute without the `;` delimiter #155

Closed moazin closed 2 years ago

moazin commented 3 years ago

Specifying stop attributes like stop-color and stop-opacity is possible by using the style attribute. However, if there is only one property set in the style attribute and a semi-colon is missing, it's not parsed and interpreted properly. I'm not sure about whether this is correct according to the CSS standard or not, but a lot of glyphs in NotoColorEmoji are like this. They do not have a ; at the end of the style attribute's value.

Example document (this doesn't work):

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 1000" width="2000" height="1000">
  <defs>
    <linearGradient id="grad" gradientUnits="userSpaceOnUse" x1="100" y1="100" x2="200" y2="200">
      <stop offset="0" style="stop-color: #FF0000" />
      <stop offset="1" style="stop-color: #00FF00" />
    </linearGradient>
  </defs>
  <rect x="100" y="100" width="100" height="100" fill="url(#grad)"/>
</svg>

This does work:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 1000" width="2000" height="1000">
  <defs>
    <linearGradient id="grad" gradientUnits="userSpaceOnUse" x1="100" y1="100" x2="200" y2="200">
      <stop offset="0" style="stop-color: #FF0000;" />
      <stop offset="1" style="stop-color: #00FF00;" />
    </linearGradient>
  </defs>
  <rect x="100" y="100" width="100" height="100" fill="url(#grad)"/>
</svg>
moazin commented 3 years ago

It seems that this comes from the stylesheet submodule which comes from adobe/stylesheet which is a fork of adozenlines/stylesheet. It parses by reading the string until the ; and the code doesn't do anything if no ; is found in the string. Very simple addition of few lines can fix it. I'm not sure how to get it fixed though. Should I submit a PR to the Adobe fork? @dirkschulze

tjindal commented 2 years ago

style attribute is deprecated in latest version of SVG 2.0.