From 6c671ab6ca697459d2c35f30677916065c546420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 12 Mar 2021 09:04:13 +0100 Subject: [PATCH] #1122 SVG import - relative coordinates - test pservers-grad-10-b --- CHANGELOG.md | 3 +- .../flash/importers/svg/SvgImporter.java | 33 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94d5577eb..e8074a89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ All notable changes to this project will be documented in this file. - AS3 P-code - hilight and edit traits outside classes - [#1585] SVG import - support for style tag (CSS) - [#1585] SVG import - support for switch tag -- [#1122] SVG import - relative coordinates (tests coords-units-01-b, coords-units-02-b, pservers-grad-12-b) +- [#1122] SVG import - relative coordinates +(tests coords-units-01-b, coords-units-02-b, pservers-grad-10-b, pservers-grad-12-b) - Preview in image file selection dialogs ### Changed 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 58a38dc15..195252a12 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 @@ -1456,10 +1456,11 @@ public class SvgImporter { double x2 = parseCoordinate(lgfill.x2, 1); double y2 = parseCoordinate(lgfill.y2, 1); - x1 = x1 * SWF.unitDivisor; - y1 = y1 * SWF.unitDivisor; - x2 = x2 * SWF.unitDivisor; - y2 = y2 * SWF.unitDivisor; + Matrix xyMatrix = new Matrix(); + xyMatrix.scaleX = (x2 - x1) * SWF.unitDivisor; + xyMatrix.rotateSkew0 = (y2 - y1) * SWF.unitDivisor; + xyMatrix.rotateSkew1 = -xyMatrix.rotateSkew0; + xyMatrix.scaleY = xyMatrix.scaleX; Matrix gmatrix = new Matrix(); if (lgfill.gradientUnits == SvgGradientUnits.OBJECT_BOUNDING_BOX) { @@ -1469,29 +1470,25 @@ public class SvgImporter { gmatrix.scaleY = (bounds.Ymax - bounds.Ymin) / SWF.unitDivisor; gmatrix.translateX = bounds.Xmin; gmatrix.translateY = bounds.Ymin; + x1 *= bounds.getWidth(); + y1 *= bounds.getHeight(); } else { gmatrix = new Matrix(fillStyle.gradientMatrix); + x1 *= SWF.unitDivisor; + y1 *= SWF.unitDivisor; } - Matrix xyMatrix = new Matrix(); - xyMatrix.scaleX = x2 - x1; - xyMatrix.rotateSkew0 = y2 - y1; - xyMatrix.rotateSkew1 = -xyMatrix.rotateSkew0; - xyMatrix.scaleY = xyMatrix.scaleX; - - xyMatrix = xyMatrix.preConcatenate(gmatrix); - Matrix zeroStartMatrix = Matrix.getTranslateInstance(0.5, 0); - Matrix scaleMatrix = Matrix.getScaleInstance(1 / 16384.0 / 2); Matrix transMatrix = Matrix.getTranslateInstance(x1, y1); Matrix tMatrix = new Matrix(); - tMatrix = tMatrix.preConcatenate(scaleMatrix); - tMatrix = tMatrix.preConcatenate(zeroStartMatrix); - tMatrix = tMatrix.preConcatenate(xyMatrix); - - tMatrix = tMatrix.preConcatenate(transMatrix); + tMatrix = tMatrix + .concatenate(transMatrix) + .concatenate(gmatrix) + .concatenate(xyMatrix) + .concatenate(zeroStartMatrix) + .concatenate(scaleMatrix); fillStyle.gradientMatrix = tMatrix.toMATRIX(); } else if (fill instanceof SvgRadialGradient) { SvgRadialGradient rgfill = (SvgRadialGradient) fill;