From 7c1906adcd5f7a56b8ce15fa307381f21d21227f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 28 Oct 2023 13:28:19 +0200 Subject: [PATCH] Fixed Morphshape SVG export - closing the stroke Propagate noClose flag to morphshape linestyles on replace --- CHANGELOG.md | 1 + .../morphshape/CanvasMorphShapeExporter.java | 9 +++++++-- .../DefaultSVGMorphShapeExporter.java | 10 +++++++--- .../morphshape/IMorphShapeExporter.java | 4 ++-- .../morphshape/MorphShapeExporterBase.java | 18 +++++++++++++++--- .../morphshape/SVGMorphShapeExporter.java | 2 +- .../flash/exporters/shape/BitmapExporter.java | 2 +- .../exporters/shape/CanvasShapeExporter.java | 2 +- .../shape/DefaultSVGShapeExporter.java | 2 +- .../flash/exporters/shape/IShapeExporter.java | 2 +- .../flash/exporters/shape/PathExporter.java | 2 +- .../exporters/shape/SVGShapeExporter.java | 2 +- .../exporters/shape/ShapeExporterBase.java | 6 ++++-- .../morphshape/ShapeForMorphExporter.java | 3 ++- 14 files changed, 45 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcbaf2bae..beed50d72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ All notable changes to this project will be documented in this file. - Not updating Morphshape end bounds - SVG import - linear gradients - SVG import - Do not use fill winding nonzero when only stroking +- Morphshape SVG export - closing the stroke ### Changed - Basic tag info panel always visible even when nothing to display (to avoid flickering) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/CanvasMorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/CanvasMorphShapeExporter.java index 45ffd4fc1..343523e0e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/CanvasMorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/CanvasMorphShapeExporter.java @@ -45,6 +45,8 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase { protected static final String DRAW_COMMAND_L = "L"; protected static final String DRAW_COMMAND_Q = "Q"; + + protected static final String DRAW_COMMAND_Z = "Z"; protected String currentDrawCommand = ""; @@ -151,7 +153,10 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase { } @Override - public void endLines() { + public void endLines(boolean close) { + if (close) { + pathData.append(DRAW_COMMAND_Z).append(" "); + } finalizePath(); } @@ -248,7 +253,7 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase { } @Override - public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); thickness /= SWF.unitDivisor; thicknessEnd /= SWF.unitDivisor; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/DefaultSVGMorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/DefaultSVGMorphShapeExporter.java index 4fe125348..b76b87953 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/DefaultSVGMorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/DefaultSVGMorphShapeExporter.java @@ -67,8 +67,12 @@ public abstract class DefaultSVGMorphShapeExporter extends MorphShapeExporterBas } @Override - public void endLines() { - finalizePath(); + public void endLines(boolean close) { + if (close) { + pathData.append("Z"); + pathDataEnd.append("Z"); + } + finalizePath(); } @Override @@ -92,7 +96,7 @@ public abstract class DefaultSVGMorphShapeExporter extends MorphShapeExporterBas } @Override - public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/IMorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/IMorphShapeExporter.java index 110bcb996..e5f5ec384 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/IMorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/IMorphShapeExporter.java @@ -37,7 +37,7 @@ public interface IMorphShapeExporter { public void beginLines(); - public void endLines(); + public void endLines(boolean close); public void beginFill(RGB color, RGB colorEnd); @@ -47,7 +47,7 @@ public interface IMorphShapeExporter { public void endFill(); - public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit); + public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose); public void lineGradientStyle(int type, GRADRECORD[] gradientRecords, GRADRECORD[] gradientRecordsEnd, Matrix matrix, Matrix matrixEnd, int spreadMethod, int interpolationMethod, float focalPointRatio, float focalPointRatioEnd); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java index 38b706f1a..67c6037d1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java @@ -395,7 +395,10 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { List path = createPathFromEdgeMap(_lineEdgeMaps.get(groupIndex)); int posX = Integer.MAX_VALUE; int posY = Integer.MAX_VALUE; + int lastMoveToX = posX; + int lastMoveToY = posY; int lineStyleIdx = Integer.MAX_VALUE; + boolean autoClose = true; if (path.size() > 0) { beginLines(); for (int i = 0; i < path.size(); i++) { @@ -420,8 +423,13 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { int joinStyle = LINESTYLE2.ROUND_JOIN; float miterLimitFactor = 3f; boolean hasFillFlag = false; + autoClose = true; if (lineStyle instanceof LINESTYLE2) { LINESTYLE2 lineStyle2 = (LINESTYLE2) lineStyle; + + if (lineStyle2.noClose) { + autoClose = false; + } if (lineStyle2.noHScaleFlag && lineStyle2.noVScaleFlag) { scaleMode = "NONE"; } else if (lineStyle2.noHScaleFlag) { @@ -446,7 +454,9 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { startCapStyle, endCapStyle, joinStyle, - miterLimitFactor); + miterLimitFactor, + !autoClose + ); if (hasFillFlag) { LINESTYLE2 lineStyle2 = (LINESTYLE2) lineStyle; @@ -489,11 +499,13 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { } } else { // We should never get here - lineStyle(1, 1, new RGB(Color.black), new RGB(Color.BLACK), false, "NORMAL", 0, 0, 0, 3); + lineStyle(1, 1, new RGB(Color.black), new RGB(Color.BLACK), false, "NORMAL", 0, 0, 0, 3, false); } } if (posX != e.getFromX() || posY != e.getFromY()) { moveTo(e.getFromX(), e.getFromY(), e.getFromEndX(), e.getFromEndY()); + lastMoveToX = e.getFromX(); + lastMoveToY = e.getFromY(); } if (e instanceof CurvedMorphEdge) { CurvedMorphEdge c = (CurvedMorphEdge) e; @@ -504,7 +516,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { posX = e.getToX(); posY = e.getToY(); } - endLines(); + endLines(autoClose && lastMoveToX == posX && lastMoveToY == posY); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java index 5d82e9df8..5116c4de8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java @@ -165,7 +165,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter { } @Override - public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, double thicknessEnd, RGB color, RGB colorEnd, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); thickness *= zoom / SWF.unitDivisor; thicknessEnd *= zoom / SWF.unitDivisor; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java index edb88f404..145b47f88 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java @@ -403,7 +403,7 @@ public class BitmapExporter extends ShapeExporterBase { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); linePaint = null; lineTransform = null; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java index 13fa0b8b5..cdd1a24b2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java @@ -289,7 +289,7 @@ public class CanvasShapeExporter extends ShapeExporterBase { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); thickness /= SWF.unitDivisor; strokeData.append("\tvar scaleMode = \"").append(scaleMode).append("\";\r\n"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/DefaultSVGShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/DefaultSVGShapeExporter.java index d6b2ba8d7..ab3c8783b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/DefaultSVGShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/DefaultSVGShapeExporter.java @@ -109,7 +109,7 @@ public abstract class DefaultSVGShapeExporter extends ShapeExporterBase { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/IShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/IShapeExporter.java index 845194bea..0176e231f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/IShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/IShapeExporter.java @@ -49,7 +49,7 @@ public interface IShapeExporter { public void endFill(); - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit); + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose); public void lineGradientStyle(int type, GRADRECORD[] gradientRecords, Matrix matrix, int spreadMethod, int interpolationMethod, float focalPointRatio); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/PathExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/PathExporter.java index b31c5f6a7..4284dce18 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/PathExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/PathExporter.java @@ -114,7 +114,7 @@ public class PathExporter extends ShapeExporterBase { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); this.thickness = thickness; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java index 7666183a4..81b82473e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java @@ -163,7 +163,7 @@ public class SVGShapeExporter extends DefaultSVGShapeExporter { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { finalizePath(); thickness *= zoom / SWF.unitDivisor; path.setAttribute("fill", "none"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java index cb48b1158..de535ee67 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java @@ -453,7 +453,9 @@ public abstract class ShapeExporterBase implements IShapeExporter { startCapStyle, endCapStyle, joinStyle, - miterLimitFactor); + miterLimitFactor, + !autoClose + ); if (hasFillFlag) { FillStyle fillStyle = lineStyle.fillType; @@ -485,7 +487,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { } } else { // We should never get here - lineStyle(1, new RGB(Color.black), false, "NORMAL", 0, 0, 0, 3); + lineStyle(1, new RGB(Color.black), false, "NORMAL", 0, 0, 0, 3, false); } } if (posX != e.getFromX() || posY != e.getFromY()) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/morphshape/ShapeForMorphExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/morphshape/ShapeForMorphExporter.java index 5d67c8f1e..6de322fc8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/morphshape/ShapeForMorphExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/morphshape/ShapeForMorphExporter.java @@ -304,7 +304,7 @@ public class ShapeForMorphExporter extends ShapeExporterBase { } @Override - public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit) { + public void lineStyle(double thickness, RGB color, boolean pixelHinting, String scaleMode, int startCaps, int endCaps, int joints, float miterLimit, boolean noClose) { endCurrent(); currentLineStyle = lineStyles.size(); LINESTYLE2 lineStyle = new LINESTYLE2(); @@ -327,6 +327,7 @@ public class ShapeForMorphExporter extends ShapeExporterBase { lineStyle.endCapStyle = endCaps; lineStyle.joinStyle = joints; lineStyle.miterLimitFactor = miterLimit; + lineStyle.noClose = noClose; lineStyles.add(lineStyle); }