sammycage / lunasvg

SVG rendering and manipulation library in C++
MIT License
866 stars 124 forks source link

Gradient URL references with single quotes appear as black #86

Closed fdwr closed 2 years ago

fdwr commented 2 years ago

URL references with single quotes appear as blackness because Parser::parseUrl treats the entire string as a name including the single quotes too. This is low priority, as single quotes are rare (except if the URL includes parentheses, whitespace, or quotes), and the necessary SVG edit is trivial - just remove the single quotes from the url, and escape any parens/ws/quotes. I'll likely create a PR this week, along with a few other accumulated tiny fixes for issues I've encountered.

image

<!-- from https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient -->
<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  width="64"
  height="64"
  >
  <defs>
    <linearGradient id="myGradient" gradientTransform="rotate(90)">
      <stop offset="5%"  stop-color="gold" />
      <stop offset="95%" stop-color="red" />
    </linearGradient>
  </defs>

  <circle cx="32" cy="32" r="25.5" fill="url('#myGradient')" /> <!-- ◀◀◀ single quote here -->
</svg>

References:

Note this was also a bug in GNOME librsvg, fixed in rsvg-convert version 2.44.10. So, you're not alone :b.

sammycage commented 2 years ago

Fixed : 984ddfd9c5e9cc56b96dc52e4ab9821281547674

fdwr commented 2 years ago

@sammycage : Nice. I tried fixing it last night (with a change that looked fairly similar to yours in Parser::parseUrl), but I wasn't sure what other parts might be impacted or need updating too. I see that you found Parser::parsePaint also needed the fix. TY, closing.

sammycage commented 2 years ago

@sammycage : Nice. I tried fixing it last night (with a change that looked fairly similar to yours in Parser::parseUrl), but I wasn't sure what other parts might be impacted or need updating too. I see that you found Parser::parsePaint also needed the fix. TY, closing.

You're right... "Code sharing" is a quality of good software. https://github.com/sammycage/lunasvg/blob/7417baa0aff477f361e44e2aa793fdb0c7aae352/source/parser.cpp#L922-L957