From 44a475987d6f9bb7cb8ea848c5dfa9d9b7ad4922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 6 Dec 2025 20:09:30 +0100 Subject: [PATCH] Fixed: #2566 Export bounds of sprites and buttons not containg filter offsets --- CHANGELOG.md | 2 ++ .../flash/tags/DefineButton2Tag.java | 20 ++++++++++++ .../flash/tags/DefineSpriteTag.java | 31 +++++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76288351d..ef0523fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - [#2575] dumpSWF CLI command displayed import assets GUI dialog - [#2573] AS3 - Incorrect uint/int/Number coercion - AS3 local registers type propagation +- [#2566] Export bounds of sprites and buttons not containg filter offsets ### Changed - [#2575] dumpSWF CLI command only allows single SWF dump (no imports, etc.) @@ -4063,6 +4064,7 @@ Major version of SWF to XML export changed to 2. [#2571]: https://www.free-decompiler.com/flash/issues/2571 [#2575]: https://www.free-decompiler.com/flash/issues/2575 [#2573]: https://www.free-decompiler.com/flash/issues/2573 +[#2566]: https://www.free-decompiler.com/flash/issues/2566 [#2556]: https://www.free-decompiler.com/flash/issues/2556 [#2536]: https://www.free-decompiler.com/flash/issues/2536 [#2537]: https://www.free-decompiler.com/flash/issues/2537 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java index a85e568a1..87b1976ca 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.annotations.Reserved; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.SWFVersion; +import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; import java.io.ByteArrayOutputStream; @@ -238,6 +239,25 @@ public class DefineButton2Tag extends ButtonTag implements ASMSourceContainer { if (mat != null) { r2 = mat.apply(r2); } + double deltaXMax = 0; + double deltaYMax = 0; + if (r.buttonHasFilterList && r.filterList != null && !r.filterList.isEmpty()) { + for (FILTER filter : r.filterList) { + if (!filter.enabled) { + continue; + } + double x = filter.getDeltaX(); + double y = filter.getDeltaY(); + deltaXMax += x * SWF.unitDivisor; + deltaYMax += y * SWF.unitDivisor; + } + } + + r2.Xmin -= deltaXMax; + r2.Ymin -= deltaYMax; + r2.Xmax += deltaXMax; + r2.Ymax += deltaYMax; + rect.Xmin = Math.min(r2.Xmin, rect.Xmin); rect.Ymin = Math.min(r2.Ymin, rect.Ymin); rect.Xmax = Math.max(r2.Xmax, rect.Xmax); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index e0d84d112..5f73c0999 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -40,6 +40,7 @@ import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.decompiler.flash.types.annotations.SWFField; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.annotations.SWFVersion; +import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; import com.jpexs.helpers.SerializableImage; @@ -249,12 +250,13 @@ public class DefineSpriteTag extends DrawableTag implements Timelined { for (Tag t : getTags()) { MATRIX m = null; int characterId = -1; + double deltaXMax = 0; + double deltaYMax = 0; if (t instanceof RemoveTag) { RemoveTag rt = (RemoveTag) t; depthMap.remove(rt.getDepth()); depthMatrixMap.remove(rt.getDepth()); - } - if (t instanceof PlaceObjectTypeTag) { + } else if (t instanceof PlaceObjectTypeTag) { PlaceObjectTypeTag pot = (PlaceObjectTypeTag) t; m = pot.getMatrix(); @@ -284,6 +286,26 @@ public class DefineSpriteTag extends DrawableTag implements Timelined { characterId = chi; } } + + List filters = pot.getFilters(); + + deltaXMax = 0; + deltaYMax = 0; + + if (filters != null && !filters.isEmpty()) { + // calculate size after applying the filters + for (FILTER filter : filters) { + if (!filter.enabled) { + continue; + } + double x = filter.getDeltaX(); + double y = filter.getDeltaY(); + deltaXMax += x * SWF.unitDivisor; + deltaYMax += y * SWF.unitDivisor; + } + } + } else { + continue; } if (characterId != -1 && swf != null) { //Do not handle Fonts as characters. TODO: make this better @@ -315,6 +337,11 @@ public class DefineSpriteTag extends DrawableTag implements Timelined { r.Xmax = (int) Math.max(Math.max(Math.max(topleft.x, topright.x), bottomleft.x), bottomright.x); r.Ymax = (int) Math.max(Math.max(Math.max(topleft.y, topright.y), bottomleft.y), bottomright.y); } + + r.Xmin -= deltaXMax; + r.Ymin -= deltaYMax; + r.Xmax += deltaXMax; + r.Ymax += deltaYMax; ret.Xmin = Math.min(r.Xmin, ret.Xmin); ret.Ymin = Math.min(r.Ymin, ret.Ymin);