Fixed #1915 SVG import - gradient when it has two final stops

This commit is contained in:
Jindra Petřík
2022-12-28 10:48:23 +01:00
parent 46195989c8
commit ad3cfc9e3c
2 changed files with 30 additions and 6 deletions

View File

@@ -1553,21 +1553,42 @@ public class SvgImporter {
break;
}
fillStyle.gradient.gradientRecords = new GRADRECORD[gfill.stops.size()];
int prevRatio = -1;
int prevRatio = -1;
int recCount = 0;
for (int i = 0; i < gfill.stops.size(); i++) {
SvgStop stop = gfill.stops.get(i);
int ratio = Math.max((int) Math.round(stop.offset * 255), prevRatio + 1);
recCount++;
//two finish stops
if (ratio == 255 && i + 1 < gfill.stops.size()) {
if (prevRatio == 254) {
break;
}
ratio = 254;
}
prevRatio = ratio;
if (prevRatio == 255) {
break;
}
}
prevRatio = -1;
fillStyle.gradient.gradientRecords = new GRADRECORD[recCount];
for (int i = 0; i < recCount; i++) {
SvgStop stop = gfill.stops.get(i);
Color color = stop.color;
color = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) Math.round(color.getAlpha() * style.getOpacity()));
fillStyle.gradient.gradientRecords[i] = new GRADRECORD();
fillStyle.gradient.gradientRecords[i].inShape3 = shapeNum >= 3;
fillStyle.gradient.gradientRecords[i].color = getRGB(shapeNum, color);
int ratio = Math.max((int) Math.round(stop.offset * 255), prevRatio + 1);
fillStyle.gradient.gradientRecords[i].ratio = ratio;
prevRatio = ratio;
if (prevRatio == 255) {
break;
if (ratio == 255 && i + 1 < recCount) {
ratio = 254;
}
fillStyle.gradient.gradientRecords[i].ratio = ratio;
prevRatio = ratio;
}
} else if (fill instanceof SvgBitmapFill) {
SvgBitmapFill bfill = (SvgBitmapFill) fill;