memononen / nanosvg

Simple stupid SVG parser
zlib License
1.68k stars 355 forks source link

Support for referenced gradients #121

Open SergeySlice opened 6 years ago

SergeySlice commented 6 years ago

Hi, The SVG file contains the follow

    <linearGradient id="linear-gradient" x1="49.93" y1="124.6" x2="49.93" y2="39.4" gradientTransform="matrix(1, 0, 0, -1, 0, 162)" gradientUnits="userSpaceOnUse">
        <stop offset="0" stop-color="#ff0"/>
        <stop offset="1" stop-color="#dd4814"/>
    </linearGradient>
    <linearGradient id="linear-gradient-2" x1="98.9" y1="133.54" x2="98.9" y2="85.29" xlink:href="#linear-gradient"/>
    <linearGradient id="linear-gradient-3" x1="99.1" y1="79.2" x2="99.1" y2="31.03" xlink:href="#linear-gradient"/>

And "linear-gradient" used as well as "linear-gradient-2" and "linear-gradient-3". Existing codes will not fully work. I propose follow patch (i don't know how to create pull request) createGradient.patch.zip

  1. matrix multiplication data and ref
  2. because of this ref should not be same as data.

Thanks for the good project! Regards

SergeySlice commented 6 years ago

To illustrate Ubuntu2.zip

SergeySlice commented 6 years ago

More correct it should be

nsvg__xformPremultiply(data->xform, ref->xform);

because of data->xform should be applied over referenced gradient.