Fixed: #2566 Export bounds of sprites and buttons not containg filter offsets

This commit is contained in:
Jindra Petřík
2025-12-06 20:09:30 +01:00
parent 363b1e5322
commit 44a475987d
3 changed files with 51 additions and 2 deletions

View File

@@ -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);

View File

@@ -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<FILTER> 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);