diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b01dd0f1..ac316f4ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed +- [#1915] SVG import - gradient when it has two final stops ## [18.2.1] - 2022-12-28 ### Fixed @@ -2809,6 +2811,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1915]: https://www.free-decompiler.com/flash/issues/1915 [#1922]: https://www.free-decompiler.com/flash/issues/1922 [#1921]: https://www.free-decompiler.com/flash/issues/1921 [#1917]: https://www.free-decompiler.com/flash/issues/1917 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java index dde1f866a..9a48d51b3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java @@ -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;