Browse Source

Handle linear and radial gradient stop offsets (other than 0.0 and 1.0) in SVG.

tags/v2.6.0
Andrew Belt 5 months ago
parent
commit
e5a067398d
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      src/window/Svg.cpp

+ 6
- 2
src/window/Svg.cpp View File

@@ -246,18 +246,22 @@ void svgDraw(NVGcontext* vg, NSVGimage* svg) {
assert(g->nstops >= 1); assert(g->nstops >= 1);
NVGcolor icol = getNVGColor(g->stops[0].color); NVGcolor icol = getNVGColor(g->stops[0].color);
NVGcolor ocol = getNVGColor(g->stops[g->nstops - 1].color); NVGcolor ocol = getNVGColor(g->stops[g->nstops - 1].color);
float iOffset = g->stops[0].offset;
float oOffset = g->stops[g->nstops - 1].offset;


float t[6]; float t[6];
nvgTransformInverse(t, g->xform); nvgTransformInverse(t, g->xform);
DEBUG_ONLY(printf(" inverse: %f %f %f %f %f %f\n", t[0], t[1], t[2], t[3], t[4], t[5]);) DEBUG_ONLY(printf(" inverse: %f %f %f %f %f %f\n", t[0], t[1], t[2], t[3], t[4], t[5]);)
nvgTransform(vg, t[0], t[1], t[2], t[3], t[4], t[5]); nvgTransform(vg, t[0], t[1], t[2], t[3], t[4], t[5]);
// Because nvgLinearGradient() and nvgRadialGradient() arbitrarily limit a minimum of 1.0 feather, rescale and use (0, 100) coordinates.
nvgScale(vg, 1/100.0, 1/100.0);


NVGpaint paint; NVGpaint paint;
if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT) { if (shape->fill.type == NSVG_PAINT_LINEAR_GRADIENT) {
paint = nvgLinearGradient(vg, 0.0, 0.0, 0.0, 1.0, icol, ocol);
paint = nvgLinearGradient(vg, 0.0, 100 * iOffset, 0.0, 100 * oOffset, icol, ocol);
} }
else if (shape->fill.type == NSVG_PAINT_RADIAL_GRADIENT) { else if (shape->fill.type == NSVG_PAINT_RADIAL_GRADIENT) {
paint = nvgRadialGradient(vg, 0.0, 0.0, 0.0, 1.0, icol, ocol);
paint = nvgRadialGradient(vg, 0.0, 0.0, 100 * iOffset, 100 * oOffset, icol, ocol);
} }
nvgFillPaint(vg, paint); nvgFillPaint(vg, paint);
nvgFill(vg); nvgFill(vg);


Loading…
Cancel
Save