From b2961e21e3363f25e20e5d9b02120d1fbb32abc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 27 May 2025 09:36:27 +0200 Subject: [PATCH] Fixed: #2461 SVG export - incorrect clipping / missing shapes --- CHANGELOG.md | 2 ++ .../exporters/commonshape/SVGExporter.java | 16 +++++++++----- .../decompiler/flash/timeline/Timeline.java | 21 ++++++++++--------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 945ff1e9e..9fea5a5d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. - AS2 Class names not showing in Folder list view - AS1/2 - Incorrect DefineFunction2 parameter names when parameter name is empty - [#2460] SVG export - incorrect caching colorTransform and ratio for the same tag +- [#2461] SVG export - incorrect clipping / missing shapes ## [23.0.1] - 2025-05-16 ### Fixed @@ -3833,6 +3834,7 @@ Major version of SWF to XML export changed to 2. [#2456]: https://www.free-decompiler.com/flash/issues/2456 [#2459]: https://www.free-decompiler.com/flash/issues/2459 [#2460]: https://www.free-decompiler.com/flash/issues/2460 +[#2461]: https://www.free-decompiler.com/flash/issues/2461 [#2427]: https://www.free-decompiler.com/flash/issues/2427 [#1826]: https://www.free-decompiler.com/flash/issues/1826 [#2448]: https://www.free-decompiler.com/flash/issues/2448 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java index 57efead9c..80bd75bbc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java @@ -95,19 +95,22 @@ public class SVGExporter { private final Tag tag; public final ColorTransform colorTransform; public final int ratio; + public final boolean clipped; - public ExportKey(Tag tag, ColorTransform colorTransform, int ratio) { + public ExportKey(Tag tag, ColorTransform colorTransform, int ratio, boolean clipped) { this.tag = tag; this.colorTransform = colorTransform; this.ratio = ratio; + this.clipped = clipped; } @Override public int hashCode() { int hash = 7; - hash = 43 * hash + Objects.hashCode(this.tag); - hash = 43 * hash + Objects.hashCode(this.colorTransform); - hash = 43 * hash + this.ratio; + hash = 79 * hash + Objects.hashCode(this.tag); + hash = 79 * hash + Objects.hashCode(this.colorTransform); + hash = 79 * hash + this.ratio; + hash = 79 * hash + (this.clipped ? 1 : 0); return hash; } @@ -126,11 +129,14 @@ public class SVGExporter { if (this.ratio != other.ratio) { return false; } + if (this.clipped != other.clipped) { + return false; + } if (!Objects.equals(this.tag, other.tag)) { return false; } return Objects.equals(this.colorTransform, other.colorTransform); - } + } } public SVGExporter(ExportRectangle bounds, double zoom, String objectType) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java index 8f5a23776..799a27264 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -1623,7 +1623,7 @@ public class Timeline { clipGroup = null; } - if (clips.size() > 0) { + if (!clips.isEmpty()) { String clip = clips.get(clips.size() - 1).shape; // todo: merge clip areas clipGroup = exporter.createSubGroup(null, null); clipGroup.setAttribute("clip-path", "url(#" + clip + ")"); @@ -1656,16 +1656,7 @@ public class Timeline { String assetName; Tag drawableTag = (Tag) drawable; RECT boundRect = drawable.getRect(); - boolean createNew = false; - SVGExporter.ExportKey exportKey = new SVGExporter.ExportKey(drawableTag, clrTrans, layer.ratio); - if (exporter.exportedTags.containsKey(exportKey)) { - assetName = exporter.exportedTags.get(exportKey); - } else { - assetName = getTagIdPrefix(drawableTag, exporter); - exporter.exportedTags.put(exportKey, assetName); - createNew = true; - } ExportRectangle rect = new ExportRectangle(boundRect); DefineScalingGridTag scalingGrid = character.getScalingGridTag(); @@ -1681,6 +1672,16 @@ public class Timeline { drawable.toSVG(exporter, layer.ratio, clrTrans, level + 1); exporter.endGroup(); } else { + boolean createNew = false; + + SVGExporter.ExportKey exportKey = new SVGExporter.ExportKey(drawableTag, clrTrans, layer.ratio, layer.clipDepth > -1); + if (exporter.exportedTags.containsKey(exportKey)) { + assetName = exporter.exportedTags.get(exportKey); + } else { + assetName = getTagIdPrefix(drawableTag, exporter); + exporter.exportedTags.put(exportKey, assetName); + createNew = true; + } if (createNew) { exporter.createDefGroup(new ExportRectangle(boundRect), assetName); drawable.toSVG(exporter, layer.ratio, clrTrans, level + 1);