diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index b5adf5e01..d2f956688 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -226,7 +226,7 @@ public final class SWF implements TreeItem, Timelined { public String fileTitle; public boolean readOnly; public boolean isAS3; - public HashMap characters; + public Map characters = new HashMap<>(); public List abcList; public JPEGTablesTag jtt; public Map sourceFontsMap = new HashMap<>(); @@ -234,6 +234,47 @@ public final class SWF implements TreeItem, Timelined { private Timeline timeline; + private void parseCharacters(List list) { + for (ContainerItem t : list) { + if (t instanceof CharacterTag) { + characters.put(((CharacterTag) t).getCharacterId(), (CharacterTag) t); + } + if (t instanceof Container) { + parseCharacters(((Container) t).getSubItems()); + } + } + } + + /** + * Unresolve recursive sprites + */ + private void checkInvalidSprites() { + for (int i = 0; i < tags.size(); i++) { + Tag t = tags.get(i); + if (t instanceof DefineSpriteTag) { + if (!isSpriteValid((DefineSpriteTag) t, new ArrayList())) { + tags.set(i, new Tag(this, t.getId(), "InvalidSprite", t.getData(), t.getPos())); + } + } + } + } + + private boolean isSpriteValid(DefineSpriteTag sprite, List path) { + if (path.contains(sprite.spriteId)) { + return false; + } + path.add(sprite.spriteId); + for (Tag t : sprite.subTags) { + if (t instanceof DefineSpriteTag) { + if (!isSpriteValid((DefineSpriteTag) t, path)) { + return false; + } + } + } + path.remove((Integer) sprite.spriteId); + return true; + } + @Override public Timeline getTimeline() { if (timeline == null) { @@ -509,6 +550,7 @@ public final class SWF implements TreeItem, Timelined { tagMap.put(tag.getPos(), tag); } + checkInvalidSprites(); for (Tag tag : tags) { if (tag instanceof ShowFrameTag) { ShowFrameTag showFrameTag = (ShowFrameTag) tag; @@ -520,7 +562,7 @@ public final class SWF implements TreeItem, Timelined { showFrameTag.innerTags = innerTags; } } - + parseCharacters(new ArrayList(tags)); assignExportNamesToSymbols(); assignClassesToSymbols(); findFileAttributes(); @@ -2236,7 +2278,7 @@ public final class SWF implements TreeItem, Timelined { image.fillTransparent(); Matrix m = new Matrix(); m.translate(-rect.Xmin, -rect.Ymin); - frameToImage(timeline, frame, displayRect, visited, image, m, colorTransform); + frameToImage(timeline, frame, image, m, colorTransform); putToCache(key, image); return image; } @@ -2249,7 +2291,7 @@ public final class SWF implements TreeItem, Timelined { image.fillTransparent(); Matrix m = new Matrix(); m.translate(-rect.Xmin, -rect.Ymin); - frameToImage(timeline, f, displayRect, visited, image, m, colorTransform); + frameToImage(timeline, f, image, m, colorTransform); ret.add(image); } } @@ -2266,7 +2308,7 @@ public final class SWF implements TreeItem, Timelined { } - public static void frameToImage(Timeline timeline, int frame, RECT displayRect, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public static void frameToImage(Timeline timeline, int frame, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { float unzoom = (float) SWF.unitDivisor; Frame frameObj = timeline.frames.get(frame); Graphics2D g = (Graphics2D) image.getGraphics(); @@ -2315,7 +2357,7 @@ public final class SWF implements TreeItem, Timelined { int dframe = 0 + layer.time % drawable.getNumFrames(); if (drawable instanceof BoundedTag) { BoundedTag bounded = (BoundedTag) drawable; - RECT boundRect = bounded.getRect(timeline.characters, new Stack()); + RECT boundRect = bounded.getRect(); ExportRectangle rect = new ExportRectangle(boundRect); rect = mat.transform(rect); Matrix m = mat.clone(); @@ -2355,11 +2397,11 @@ public final class SWF implements TreeItem, Timelined { m.translate(-rect.xMin, -rect.yMin); drawMatrix.translate(rect.xMin, rect.yMin); - drawable.toImage(dframe, layer.ratio, timeline.swf.tags, timeline.characters, visited, img, m, clrTrans); + drawable.toImage(dframe, layer.ratio, img, m, clrTrans); } else if (drawable instanceof FontTag) { // only DefineFont tags FontTag fontTag = (FontTag) drawable; - img = fontTag.toImage(dframe, layer.ratio, timeline.swf.tags, timeline.characters, visited, transformation, clrTrans); + img = fontTag.toImage(dframe, layer.ratio, transformation, clrTrans); } else { throw new Error("Unsupported drawable."); } @@ -2459,7 +2501,7 @@ public final class SWF implements TreeItem, Timelined { BoundedTag b = (BoundedTag) character; g.setPaint(new Color(255, 255, 255, 128)); g.setComposite(BlendComposite.Invert); - RECT r = b.getRect(timeline.characters, visited); + RECT r = b.getRect(); int div = (int) unzoom; g.drawString(character.toString(), r.Xmin / div + 3, r.Ymin / div + 15); g.draw(new Rectangle(r.Xmin / div, r.Ymin / div, r.getWidth() / div, r.getHeight() / div)); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 8d23dd996..1724426d3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -60,7 +60,6 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis private Timer timer; private int frame = -1; private SWF swf; - private HashMap characters; private boolean loaded; @Override @@ -119,11 +118,10 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis label.setIcon(icon); } - public void setDrawable(final DrawableTag drawable, final SWF swf, final HashMap characters, int frameRate) { + public void setDrawable(final DrawableTag drawable, final SWF swf, int frameRate) { pause(); this.drawable = drawable; this.swf = swf; - this.characters = characters; loaded = true; if (drawable.getNumFrames() == 0) { @@ -140,18 +138,18 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis if (img == null) { if (drawable instanceof BoundedTag) { BoundedTag bounded = (BoundedTag) drawable; - RECT rect = bounded.getRect(characters, new Stack()); + RECT rect = bounded.getRect(); SerializableImage image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1, (int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB); image.fillTransparent(); Matrix m = new Matrix(); m.translate(-rect.Xmin, -rect.Ymin); - drawable.toImage(0, 0, swf.tags, characters, new Stack(), image, m, new ColorTransform()); + drawable.toImage(0, 0, image, m, new ColorTransform()); img = image; } else if (drawable instanceof FontTag) { // only DefineFont tags FontTag fontTag = (FontTag) drawable; - img = fontTag.toImage(0, 0, swf.tags, characters, new Stack(), Matrix.getScaleInstance(1 / SWF.unitDivisor), new ColorTransform()); + img = fontTag.toImage(0, 0, Matrix.getScaleInstance(1 / SWF.unitDivisor), new ColorTransform()); } SWF.putToCache(key, img); } @@ -209,13 +207,13 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis } } - private static SerializableImage getFrame(SWF swf, int frame, DrawableTag drawable, Map characters) { + private static SerializableImage getFrame(SWF swf, int frame, DrawableTag drawable) { String key = "drawable_" + frame + "_" + drawable.hashCode(); SerializableImage img = SWF.getFromCache(key); if (img == null) { if (drawable instanceof BoundedTag) { BoundedTag bounded = (BoundedTag) drawable; - RECT rect = bounded.getRect(characters, new Stack()); + RECT rect = bounded.getRect(); if (rect == null) { //??? Why? rect = new RECT(0, 0, 1, 1); } @@ -232,12 +230,12 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis Matrix m = new Matrix(); m.translate(-rect.Xmin, -rect.Ymin); m.scale(scale); - drawable.toImage(frame, frame, swf.tags, characters, new Stack(), image, m, new ColorTransform()); + drawable.toImage(frame, frame, image, m, new ColorTransform()); img = image; } else if (drawable instanceof FontTag) { // only DefineFont tags FontTag fontTag = (FontTag) drawable; - img = fontTag.toImage(frame, frame, swf.tags, characters, new Stack(), Matrix.getScaleInstance(1 / SWF.unitDivisor), new ColorTransform()); + img = fontTag.toImage(frame, frame, Matrix.getScaleInstance(1 / SWF.unitDivisor), new ColorTransform()); } SWF.putToCache(key, img); } @@ -251,7 +249,7 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis Matrix mat = new Matrix(); mat.translateX = swf.displayRect.Xmin; mat.translateY = swf.displayRect.Ymin; - ImageIcon icon = new ImageIcon(getFrame(swf, frame, drawable, characters).getBufferedImage()); + ImageIcon icon = new ImageIcon(getFrame(swf, frame, drawable).getBufferedImage()); label.setIcon(icon); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 5560f5227..efc7bb74d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -949,11 +949,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } - List list2 = new ArrayList<>(); - list2.addAll(swf.tags); - swf.characters = new HashMap<>(); - parseCharacters(swf, list2); - if (Configuration.autoRenameIdentifiers.get()) { try { swf.deobfuscateIdentifiers(RenameType.TYPENUMBER); @@ -1146,17 +1141,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } - private void parseCharacters(SWF swf, List list) { - for (ContainerItem t : list) { - if (t instanceof CharacterTag) { - swf.characters.put(((CharacterTag) t).getCharacterId(), (CharacterTag) t); - } - if (t instanceof Container) { - parseCharacters(swf, ((Container) t).getSubItems()); - } - } - } - public static void getShapes(List list, List shapes) { for (ContainerItem t : list) { if (t instanceof Container) { @@ -2470,7 +2454,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } else if ((tagObj instanceof DrawableTag) && (!(tagObj instanceof TextTag)) && (!(tagObj instanceof FontTag)) && (mainMenu.isInternalFlashViewerSelected())) { Tag tag = (Tag) tagObj; showCard(CARDDRAWPREVIEWPANEL); - previewImagePanel.setDrawable((DrawableTag) tag, tag.getSwf(), tag.getSwf().characters, 50/*FIXME*/); + previewImagePanel.setDrawable((DrawableTag) tag, tag.getSwf(), 50/*FIXME*/); } else if ((tagObj instanceof FontTag) && (mainMenu.isInternalFlashViewerSelected())) { FontTag fontTag = (FontTag) tagObj; showCard(CARDFLASHPANEL); @@ -2491,7 +2475,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (fn.getParent() instanceof DefineSpriteTag) { controlTags = ((DefineSpriteTag) fn.getParent()).subTags; containerId = ((DefineSpriteTag) fn.getParent()).spriteId; - rect = ((DefineSpriteTag) fn.getParent()).getRect(swf.characters, new Stack()); + rect = ((DefineSpriteTag) fn.getParent()).getRect(); totalFrameCount = ((DefineSpriteTag) fn.getParent()).frameCount; timeline = ((DefineSpriteTag) fn.getParent()).getTimeline(); } @@ -2613,7 +2597,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec break; } Tag t = (Tag) item; - Set needed = t.getDeepNeededCharacters(swf.characters, new ArrayList()); + Set needed = t.getDeepNeededCharacters(swf.characters); for (int n : needed) { if (!doneCharacters.contains(n)) { sos2.writeTag(classicTag(swf.characters.get(n))); @@ -2639,7 +2623,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } mat = Helper.deepCopy(mat); if (parent instanceof BoundedTag) { - RECT r = ((BoundedTag) parent).getRect(swf.characters, new Stack()); + RECT r = ((BoundedTag) parent).getRect(); mat.translateX = mat.translateX + width / 2 - r.getWidth() / 2; mat.translateY = mat.translateY + height / 2 - r.getHeight() / 2; } else { @@ -2661,7 +2645,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } else if (tagObj instanceof AloneTag) { } else { - Set needed = ((Tag) tagObj).getDeepNeededCharacters(swf.characters, new ArrayList()); + Set needed = ((Tag) tagObj).getDeepNeededCharacters(swf.characters); for (int n : needed) { sos2.writeTag(classicTag(swf.characters.get(n))); } @@ -2680,7 +2664,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec mat.translateX = 0; mat.translateY = 0; if (tagObj instanceof BoundedTag) { - RECT r = ((BoundedTag) tagObj).getRect(swf.characters, new Stack()); + RECT r = ((BoundedTag) tagObj).getRect(); mat.translateX = -r.Xmin; mat.translateY = -r.Ymin; mat.translateX = mat.translateX + width / 2 - r.getWidth() / 2; @@ -2900,7 +2884,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private void showFontTag(FontTag ft) { if (mainMenu.isInternalFlashViewerSelected() /*|| ft instanceof GFxDefineCompactedFont*/) { ((CardLayout) viewerCards.getLayout()).show(viewerCards, INTERNAL_VIEWER_CARD); - internelViewerPanel.setDrawable(ft, ft.getSwf(), ft.getSwf().characters, 1); + internelViewerPanel.setDrawable(ft, ft.getSwf(), 1); } else { ((CardLayout) viewerCards.getLayout()).show(viewerCards, FLASH_VIEWER_CARD); } @@ -2914,7 +2898,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private void showTextTag(TextTag textTag) { if (mainMenu.isInternalFlashViewerSelected() /*|| ft instanceof GFxDefineCompactedFont*/) { ((CardLayout) viewerCards.getLayout()).show(viewerCards, INTERNAL_VIEWER_CARD); - internelViewerPanel.setDrawable(textTag, textTag.getSwf(), textTag.getSwf().characters, 1); + internelViewerPanel.setDrawable(textTag, textTag.getSwf(), 1); } else { ((CardLayout) viewerCards.getLayout()).show(viewerCards, FLASH_VIEWER_CARD); } @@ -2974,35 +2958,35 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } break; /*case TagTreeModel.FOLDER_FONTS: - for (Tag tag : swf.tags) { - if (tag instanceof FontTag) { - Component c = PreviewImage.createFolderPreviewImage(tag); - if (c != null) { - panel.add(c); - } - } - } - break;*/ + for (Tag tag : swf.tags) { + if (tag instanceof FontTag) { + Component c = PreviewImage.createFolderPreviewImage(tag); + if (c != null) { + panel.add(c); + } + } + } + break;*/ /*case TagTreeModel.FOLDER_FRAMES: - for (Tag tag : swf.tags) { - if (tag instanceof FrameTag) { - Component c = PreviewImage.createFolderPreviewImage(tag); - if (c != null) { - panel.add(c); - } - } - } - break;*/ + for (Tag tag : swf.tags) { + if (tag instanceof FrameTag) { + Component c = PreviewImage.createFolderPreviewImage(tag); + if (c != null) { + panel.add(c); + } + } + } + break;*/ /*case TagTreeModel.FOLDER_IMAGES: - for (Tag tag : swf.tags) { - if (tag instanceof ImageTag) { - Component c = PreviewImage.createFolderPreviewImage(tag); - if (c != null) { - panel.add(c); - } - } - } - break;*/ + for (Tag tag : swf.tags) { + if (tag instanceof ImageTag) { + Component c = PreviewImage.createFolderPreviewImage(tag); + if (c != null) { + panel.add(c); + } + } + } + break;*/ case TagTreeModel.FOLDER_TEXTS: for (Tag tag : swf.tags) { if (tag instanceof TextTag) { @@ -3017,7 +3001,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec panel.revalidate(); panel.repaint(); } - + public void expandSwfNodes() { TreeModel model = tagTree.getModel(); Object node = model.getRoot(); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/PreviewImage.java b/trunk/src/com/jpexs/decompiler/flash/gui/PreviewImage.java index 35a81a283..d0a6e7793 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/PreviewImage.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/PreviewImage.java @@ -49,7 +49,7 @@ public class PreviewImage extends JPanel { private Tag tag; public PreviewImage(Tag tag) { - this.tag = tag; + this.tag = tag; Dimension dim = new Dimension(PREVIEW_SIZE, PREVIEW_SIZE); setMinimumSize(dim); setMaximumSize(dim); @@ -81,14 +81,14 @@ public class PreviewImage extends JPanel { }); return null; } - + }); } private Image renderImage(SWF swf, Tag tag) { BoundedTag boundedTag = (BoundedTag) tag; - RECT rect = boundedTag.getRect(swf.characters, new Stack()); + RECT rect = boundedTag.getRect(); Matrix m = new Matrix(); double scale = 1; if (rect.getWidth() > PREVIEW_SIZE * SWF.unitDivisor) { @@ -107,7 +107,7 @@ public class PreviewImage extends JPanel { SerializableImage image = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB); image.fillTransparent(); DrawableTag drawable = (DrawableTag) tag; - drawable.toImage(0, 0, swf.tags, swf.characters, new Stack(), image, m, new ColorTransform()); + drawable.toImage(0, 0, image, m, new ColorTransform()); return image.getBufferedImage(); } @@ -119,7 +119,7 @@ public class PreviewImage extends JPanel { @Override protected void paintComponent(Graphics g) { if (image != null) { - int x = (getWidth()- image.getWidth(this)) / 2; + int x = (getWidth() - image.getWidth(this)) / 2; int y = (getHeight() - image.getHeight(this)) / 2; g.drawImage(image, x, y, null); } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/WrapLayout.java b/trunk/src/com/jpexs/decompiler/flash/gui/WrapLayout.java index 4735947a7..ea11df952 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/WrapLayout.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/WrapLayout.java @@ -14,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - package com.jpexs.decompiler.flash.gui; /** @@ -26,183 +25,168 @@ import javax.swing.JScrollPane; import javax.swing.SwingUtilities; /** - * FlowLayout subclass that fully supports wrapping of components. - * - * Taken from: http://tips4java.wordpress.com/2008/11/06/wrap-layout/ + * FlowLayout subclass that fully supports wrapping of components. + * + * Taken from: http://tips4java.wordpress.com/2008/11/06/wrap-layout/ */ -public class WrapLayout extends FlowLayout -{ - private Dimension preferredLayoutSize; +public class WrapLayout extends FlowLayout { - /** - * Constructs a new WrapLayout with a left - * alignment and a default 5-unit horizontal and vertical gap. - */ - public WrapLayout() - { - super(); - } + private Dimension preferredLayoutSize; - /** - * Constructs a new FlowLayout with the specified - * alignment and a default 5-unit horizontal and vertical gap. - * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. - * @param align the alignment value - */ - public WrapLayout(int align) - { - super(align); - } + /** + * Constructs a new WrapLayout with a left alignment and a + * default 5-unit horizontal and vertical gap. + */ + public WrapLayout() { + super(); + } - /** - * Creates a new flow layout manager with the indicated alignment - * and the indicated horizontal and vertical gaps. - *

- * The value of the alignment argument must be one of - * WrapLayout, WrapLayout, - * or WrapLayout. - * @param align the alignment value - * @param hgap the horizontal gap between components - * @param vgap the vertical gap between components - */ - public WrapLayout(int align, int hgap, int vgap) - { - super(align, hgap, vgap); - } + /** + * Constructs a new FlowLayout with the specified alignment and + * a default 5-unit horizontal and vertical gap. The value of the alignment + * argument must be one of WrapLayout, WrapLayout, + * or WrapLayout. + * + * @param align the alignment value + */ + public WrapLayout(int align) { + super(align); + } - /** - * Returns the preferred dimensions for this layout given the - * visible components in the specified target container. - * @param target the component which needs to be laid out - * @return the preferred dimensions to lay out the - * subcomponents of the specified container - */ - @Override - public Dimension preferredLayoutSize(Container target) - { - return layoutSize(target, true); - } + /** + * Creates a new flow layout manager with the indicated alignment and the + * indicated horizontal and vertical gaps. + *

+ * The value of the alignment argument must be one of + * WrapLayout, WrapLayout, or + * WrapLayout. + * + * @param align the alignment value + * @param hgap the horizontal gap between components + * @param vgap the vertical gap between components + */ + public WrapLayout(int align, int hgap, int vgap) { + super(align, hgap, vgap); + } - /** - * Returns the minimum dimensions needed to layout the visible - * components contained in the specified target container. - * @param target the component which needs to be laid out - * @return the minimum dimensions to lay out the - * subcomponents of the specified container - */ - @Override - public Dimension minimumLayoutSize(Container target) - { - Dimension minimum = layoutSize(target, false); - minimum.width -= (getHgap() + 1); - return minimum; - } + /** + * Returns the preferred dimensions for this layout given the + * visible components in the specified target container. + * + * @param target the component which needs to be laid out + * @return the preferred dimensions to lay out the subcomponents of the + * specified container + */ + @Override + public Dimension preferredLayoutSize(Container target) { + return layoutSize(target, true); + } - /** - * Returns the minimum or preferred dimension needed to layout the target - * container. - * - * @param target target to get layout size for - * @param preferred should preferred size be calculated - * @return the dimension to layout the target container - */ - private Dimension layoutSize(Container target, boolean preferred) - { - synchronized (target.getTreeLock()) - { + /** + * Returns the minimum dimensions needed to layout the visible + * components contained in the specified target container. + * + * @param target the component which needs to be laid out + * @return the minimum dimensions to lay out the subcomponents of the + * specified container + */ + @Override + public Dimension minimumLayoutSize(Container target) { + Dimension minimum = layoutSize(target, false); + minimum.width -= (getHgap() + 1); + return minimum; + } + + /** + * Returns the minimum or preferred dimension needed to layout the target + * container. + * + * @param target target to get layout size for + * @param preferred should preferred size be calculated + * @return the dimension to layout the target container + */ + private Dimension layoutSize(Container target, boolean preferred) { + synchronized (target.getTreeLock()) { // Each row must fit with the width allocated to the containter. - // When the container width = 0, the preferred width of the container - // has not yet been calculated so lets ask for the maximum. + // When the container width = 0, the preferred width of the container + // has not yet been calculated so lets ask for the maximum. - int targetWidth = target.getSize().width; + int targetWidth = target.getSize().width; - if (targetWidth == 0) - targetWidth = Integer.MAX_VALUE; + if (targetWidth == 0) { + targetWidth = Integer.MAX_VALUE; + } - int hgap = getHgap(); - int vgap = getVgap(); - Insets insets = target.getInsets(); - int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); - int maxWidth = targetWidth - horizontalInsetsAndGap; + int hgap = getHgap(); + int vgap = getVgap(); + Insets insets = target.getInsets(); + int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2); + int maxWidth = targetWidth - horizontalInsetsAndGap; // Fit components into the allowed width + Dimension dim = new Dimension(0, 0); + int rowWidth = 0; + int rowHeight = 0; - Dimension dim = new Dimension(0, 0); - int rowWidth = 0; - int rowHeight = 0; + int nmembers = target.getComponentCount(); - int nmembers = target.getComponentCount(); + for (int i = 0; i < nmembers; i++) { + Component m = target.getComponent(i); - for (int i = 0; i < nmembers; i++) - { - Component m = target.getComponent(i); - - if (m.isVisible()) - { - Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); + if (m.isVisible()) { + Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize(); // Can't add the component to current row. Start a new row. - - if (rowWidth + d.width > maxWidth) - { - addRow(dim, rowWidth, rowHeight); - rowWidth = 0; - rowHeight = 0; - } + if (rowWidth + d.width > maxWidth) { + addRow(dim, rowWidth, rowHeight); + rowWidth = 0; + rowHeight = 0; + } // Add a horizontal gap for all components after the first + if (rowWidth != 0) { + rowWidth += hgap; + } - if (rowWidth != 0) - { - rowWidth += hgap; - } + rowWidth += d.width; + rowHeight = Math.max(rowHeight, d.height); + } + } - rowWidth += d.width; - rowHeight = Math.max(rowHeight, d.height); - } - } + addRow(dim, rowWidth, rowHeight); - addRow(dim, rowWidth, rowHeight); - - dim.width += horizontalInsetsAndGap; - dim.height += insets.top + insets.bottom + vgap * 2; + dim.width += horizontalInsetsAndGap; + dim.height += insets.top + insets.bottom + vgap * 2; // When using a scroll pane or the DecoratedLookAndFeel we need to - // make sure the preferred size is less than the size of the - // target containter so shrinking the container size works - // correctly. Removing the horizontal gap is an easy way to do this. + // make sure the preferred size is less than the size of the + // target containter so shrinking the container size works + // correctly. Removing the horizontal gap is an easy way to do this. + Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); - Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); + if (scrollPane != null && target.isValid()) { + dim.width -= (hgap + 1); + } - if (scrollPane != null && target.isValid()) - { - dim.width -= (hgap + 1); - } + return dim; + } + } - return dim; - } - } + /* + * A new row has been completed. Use the dimensions of this row + * to update the preferred size for the container. + * + * @param dim update the width and height when appropriate + * @param rowWidth the width of the row to add + * @param rowHeight the height of the row to add + */ + private void addRow(Dimension dim, int rowWidth, int rowHeight) { + dim.width = Math.max(dim.width, rowWidth); - /* - * A new row has been completed. Use the dimensions of this row - * to update the preferred size for the container. - * - * @param dim update the width and height when appropriate - * @param rowWidth the width of the row to add - * @param rowHeight the height of the row to add - */ - private void addRow(Dimension dim, int rowWidth, int rowHeight) - { - dim.width = Math.max(dim.width, rowWidth); + if (dim.height > 0) { + dim.height += getVgap(); + } - if (dim.height > 0) - { - dim.height += getVgap(); - } - - dim.height += rowHeight; - } + dim.height += rowHeight; + } } - diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java index 2d11903c0..ccb4f1834 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java @@ -218,22 +218,15 @@ public class DefineButton2Tag extends CharacterTag implements Container, Bounded private static final Cache rectCache = Cache.getInstance(true); @Override - public RECT getRect(Map allCharacters, Stack visited) { + public RECT getRect() { if (rectCache.contains(this)) { return (RECT) rectCache.get(this); } - if (visited.contains(buttonId)) { - return new RECT(); - } - visited.push(buttonId); RECT rect = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); for (BUTTONRECORD r : characters) { - CharacterTag ch = allCharacters.get(r.characterId); + CharacterTag ch = swf.characters.get(r.characterId); if (ch instanceof BoundedTag) { - if (visited.contains(ch.getCharacterId())) { - continue; - } - RECT r2 = ((BoundedTag) ch).getRect(allCharacters, visited); + RECT r2 = ((BoundedTag) ch).getRect(); MATRIX mat = r.placeMatrix; if (mat != null) { r2 = mat.apply(r2); @@ -244,7 +237,6 @@ public class DefineButton2Tag extends CharacterTag implements Container, Bounded rect.Ymax = Math.max(r2.Ymax, rect.Ymax); } } - visited.pop(); rectCache.put(this, rect); return rect; } @@ -255,20 +247,14 @@ public class DefineButton2Tag extends CharacterTag implements Container, Bounded } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { - if (visited.contains(buttonId)) { - return; - } - visited.push(buttonId); - visited.pop(); - RECT displayRect = getRect(characters, visited); - visited.push(buttonId); - SWF.frameToImage(getTimeline(), frame, displayRect, visited, image, transformation, colorTransform); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + RECT displayRect = getRect(); + SWF.frameToImage(getTimeline(), frame, image, transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { - RECT r = getRect(characters, visited); + public Point getImagePos(int frame) { + RECT r = getRect(); return new Point(r.Xmin / SWF.unitDivisor, r.Ymin / SWF.unitDivisor); } @@ -282,7 +268,7 @@ public class DefineButton2Tag extends CharacterTag implements Container, Bounded if (timeline != null) { return timeline; } - timeline = new Timeline(swf, new ArrayList(), buttonId); + timeline = new Timeline(swf, new ArrayList(), buttonId, getRect()); int maxDepth = 0; Frame fr = new Frame(); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 970e65834..9cc14bec5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -228,22 +228,15 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT private static final Cache rectCache = Cache.getInstance(true); @Override - public RECT getRect(Map allCharacters, Stack visited) { + public RECT getRect() { if (rectCache.contains(this)) { return (RECT) rectCache.get(this); } - if (visited.contains(buttonId)) { - return new RECT(); - } - visited.push(buttonId); RECT rect = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); for (BUTTONRECORD r : characters) { - CharacterTag ch = allCharacters.get(r.characterId); + CharacterTag ch = swf.characters.get(r.characterId); if (ch instanceof BoundedTag) { - if (visited.contains(ch.getCharacterId())) { - continue; - } - RECT r2 = ((BoundedTag) ch).getRect(allCharacters, visited); + RECT r2 = ((BoundedTag) ch).getRect(); MATRIX mat = r.placeMatrix; if (mat != null) { r2 = mat.apply(r2); @@ -254,7 +247,7 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT rect.Ymax = Math.max(r2.Ymax, rect.Ymax); } } - visited.pop(); + rectCache.put(this, rect); return rect; } @@ -276,22 +269,13 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { - if (visited.contains(buttonId)) { - return; - } - visited.push(buttonId); - - visited.pop(); - RECT displayRect = getRect(characters, visited); - visited.push(buttonId); - SWF.frameToImage(getTimeline(), frame, displayRect, visited, image, transformation, colorTransform); - visited.pop(); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + SWF.frameToImage(getTimeline(), frame, image, transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { - RECT r = getRect(characters, visited); + public Point getImagePos(int frame) { + RECT r = getRect(); return new Point(r.Xmin / SWF.unitDivisor, r.Ymin / SWF.unitDivisor); } @@ -325,7 +309,7 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT if (timeline != null) { return timeline; } - timeline = new Timeline(swf, new ArrayList(), buttonId); + timeline = new Timeline(swf, new ArrayList(), buttonId, getRect()); ColorTransform clrTrans = null; for (Tag t : swf.tags) { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 9f5394728..ef7a7d457 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -306,9 +306,9 @@ public class DefineEditTextTag extends TextTag { addCharacters(ret, txt, style); } }; - str = " \n" + - "]>" + str + ""; + str = " \n" + + "]>" + str + ""; saxParser.parse(new ByteArrayInputStream(str.getBytes(Utf8Helper.charset)), handler); } catch (ParserConfigurationException | SAXException | IOException ex) { Logger.getLogger(DefineEditTextTag.class.getName()).log(Level.SEVERE, null, ex); @@ -622,7 +622,7 @@ public class DefineEditTextTag extends TextTag { } @Override - public RECT getRect(Map allCharacters, Stack visited) { + public RECT getRect() { return bounds; } @@ -760,12 +760,12 @@ public class DefineEditTextTag extends TextTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { if (border) { // border is always black, fill color is always white? RGB borderColor = new RGBA(Color.black); RGB fillColor = new RGBA(Color.white); - drawBorder(swf, image, borderColor, fillColor, getRect(characters, visited), getTextMatrix(), transformation, colorTransform); + drawBorder(swf, image, borderColor, fillColor, getRect(), getTextMatrix(), transformation, colorTransform); } if (hasText) { DynamicTextModel textModel = new DynamicTextModel(); @@ -794,11 +794,11 @@ public class DefineEditTextTag extends TextTag { int advance; FontTag font = lastStyle.font; GLYPHENTRY ge = new GLYPHENTRY(); - ge.glyphIndex = font.charToGlyph(tags, c); + ge.glyphIndex = font.charToGlyph(swf.tags, c); if (font.hasLayout()) { int kerningAdjustment = 0; if (nextChar != null) { - kerningAdjustment = font.getGlyphKerningAdjustment(tags, ge.glyphIndex, font.charToGlyph(tags, nextChar)); + kerningAdjustment = font.getGlyphKerningAdjustment(swf.tags, ge.glyphIndex, font.charToGlyph(swf.tags, nextChar)); kerningAdjustment /= font.getDivider(); } advance = (int) Math.round(font.getDivider() * Math.round((double) lastStyle.fontHeight * (font.getGlyphAdvance(ge.glyphIndex) + kerningAdjustment) / (font.getDivider() * 1024.0))); @@ -933,7 +933,7 @@ public class DefineEditTextTag extends TextTag { } } - staticTextToImage(swf, characters, allTextRecords, 2, image, getTextMatrix(), transformation, colorTransform); + staticTextToImage(swf, allTextRecords, 2, image, getTextMatrix(), transformation, colorTransform); } } @@ -950,7 +950,7 @@ public class DefineEditTextTag extends TextTag { } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(bounds.Xmin / SWF.unitDivisor, bounds.Ymin / SWF.unitDivisor); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java index 56a696a37..73a2de6d4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java @@ -88,7 +88,7 @@ public class DefineMorphShape2Tag extends CharacterTag implements BoundedTag, Mo } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { RECT rect = new RECT(); rect.Xmin = Math.min(startBounds.Xmin, endBounds.Xmin); rect.Ymin = Math.min(startBounds.Ymin, endBounds.Ymin); @@ -316,7 +316,7 @@ public class DefineMorphShape2Tag extends CharacterTag implements BoundedTag, Mo } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { SHAPEWITHSTYLE shape = getShapeAtRatio(ratio); // shapeNum: 4 // todo: Currently the generated image is not cached, because the cache @@ -326,7 +326,7 @@ public class DefineMorphShape2Tag extends CharacterTag implements BoundedTag, Mo } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point( (startBounds.Xmin + (endBounds.Xmin - startBounds.Xmin) * frame / 65535) / SWF.unitDivisor, (startBounds.Ymin + (endBounds.Ymin - startBounds.Ymin) * frame / 65535) / SWF.unitDivisor); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java index f98714f18..12fd8199b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java @@ -135,7 +135,7 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { RECT rect = new RECT(); rect.Xmin = Math.min(startBounds.Xmin, endBounds.Xmin); rect.Ymin = Math.min(startBounds.Ymin, endBounds.Ymin); @@ -299,7 +299,7 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { SHAPEWITHSTYLE shape = getShapeAtRatio(ratio); // shapeNum: 3 // todo: Currently the generated image is not cached, because the cache @@ -309,7 +309,7 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point( (startBounds.Xmin + (endBounds.Xmin - startBounds.Xmin) * frame / 65535) / SWF.unitDivisor, (startBounds.Ymin + (endBounds.Ymin - startBounds.Ymin) * frame / 65535) / SWF.unitDivisor); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index d578d24a8..20dcb1d51 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -46,7 +46,7 @@ public class DefineShape2Tag extends CharacterTag implements ShapeTag { public static final int ID = 22; @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(shapeBounds.Xmin / SWF.unitDivisor, shapeBounds.Ymin / SWF.unitDivisor); } @@ -73,7 +73,7 @@ public class DefineShape2Tag extends CharacterTag implements ShapeTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { BitmapExporter.exportTo(swf, getShapes(), null, image, transformation, colorTransform); } @@ -83,7 +83,7 @@ public class DefineShape2Tag extends CharacterTag implements ShapeTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return shapeBounds; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index 957cdaefb..ed2da99e4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -46,7 +46,7 @@ public class DefineShape3Tag extends CharacterTag implements ShapeTag { public static final int ID = 32; @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(shapeBounds.Xmin / SWF.unitDivisor, shapeBounds.Ymin / SWF.unitDivisor); } @@ -66,7 +66,7 @@ public class DefineShape3Tag extends CharacterTag implements ShapeTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return shapeBounds; } @@ -78,7 +78,7 @@ public class DefineShape3Tag extends CharacterTag implements ShapeTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { BitmapExporter.exportTo(swf, getShapes(), null, image, transformation, colorTransform); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index 0291e5867..d787f7301 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -54,7 +54,7 @@ public class DefineShape4Tag extends CharacterTag implements ShapeTag { public static final int ID = 83; @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(shapeBounds.Xmin / SWF.unitDivisor, shapeBounds.Ymin / SWF.unitDivisor); } @@ -81,7 +81,7 @@ public class DefineShape4Tag extends CharacterTag implements ShapeTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { BitmapExporter.exportTo(swf, getShapes(), null, image, transformation, colorTransform); } @@ -91,7 +91,7 @@ public class DefineShape4Tag extends CharacterTag implements ShapeTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return shapeBounds; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java index e9396ce44..5d2683817 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java @@ -34,10 +34,7 @@ import com.jpexs.helpers.SerializableImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.Stack; public class DefineShapeTag extends CharacterTag implements ShapeTag { @@ -63,7 +60,7 @@ public class DefineShapeTag extends CharacterTag implements ShapeTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return shapeBounds; } @@ -106,12 +103,12 @@ public class DefineShapeTag extends CharacterTag implements ShapeTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { BitmapExporter.exportTo(swf, getShapes(), null, image, transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(shapeBounds.Xmin / SWF.unitDivisor, shapeBounds.Ymin / SWF.unitDivisor); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index c32d59a97..3b55f7d8c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -78,7 +78,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT @Override public Timeline getTimeline() { if (timeline == null) { - timeline = new Timeline(swf, subTags, spriteId); + timeline = new Timeline(swf, subTags, spriteId, getRect()); } return timeline; } @@ -88,23 +88,14 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT return spriteId; } - private RECT getCharacterBounds(Map allCharacters, Set characters, Stack visited) { - if (visited.contains(spriteId)) { - return new RECT(); - } - visited.push(spriteId); + private RECT getCharacterBounds(Set characters) { RECT ret = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); boolean foundSomething = false; for (int c : characters) { - Tag t = allCharacters.get(c); + Tag t = swf.characters.get(c); RECT r = null; if (t instanceof BoundedTag) { - if (t instanceof CharacterTag) { - if (visited.contains(((CharacterTag) t).getCharacterId())) { - continue; - } - } - r = ((BoundedTag) t).getRect(allCharacters, visited); + r = ((BoundedTag) t).getRect(); } if (r != null) { foundSomething = true; @@ -114,7 +105,6 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT ret.Ymax = Math.max(r.Ymax, ret.Ymax); } } - visited.pop(); if (!foundSomething) { return new RECT(); } @@ -123,14 +113,10 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT private static final Cache rectCache = Cache.getInstance(true); @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { if (rectCache.contains(this)) { return (RECT) rectCache.get(this); } - if (visited.contains(spriteId)) { - return new RECT(); - } - visited.push(spriteId); RECT emptyRet = new RECT(); RECT ret = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); HashMap depthMap = new HashMap<>(); @@ -157,14 +143,9 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT if (characterId == -1) { continue; } - HashSet need = new HashSet<>(); - if (visited.contains(characterId)) { - continue; - } + Set need = new HashSet<>(); need.add(characterId); - visited.pop(); - RECT r = getCharacterBounds(characters, need, visited); - visited.push(spriteId); + RECT r = getCharacterBounds(need); if (m != null) { AffineTransform trans = SWF.matrixToTransform(m); @@ -190,8 +171,6 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT ret.Ymax = Math.max(r.Ymax, ret.Ymax); foundSomething = true; } - visited.pop(); - if (!foundSomething) { ret = new RECT(); } @@ -289,18 +268,12 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { - if (visited.contains(spriteId)) { - return; - } - RECT rect = getRect(characters, visited); - visited.push(spriteId); - SWF.frameToImage(getTimeline(), frame, rect, visited, image, transformation, colorTransform); - visited.pop(); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + SWF.frameToImage(getTimeline(), frame, image, transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(0, 0); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index a46091936..922dbba42 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -412,7 +412,7 @@ public class DefineText2Tag extends TextTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return textBounds; } @@ -490,12 +490,12 @@ public class DefineText2Tag extends TextTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { - staticTextToImage(swf, characters, textRecords, 2, image, getTextMatrix(), transformation, colorTransform); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + staticTextToImage(swf, textRecords, 2, image, getTextMatrix(), transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(textBounds.Xmin / 20, textBounds.Ymin / 20); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index ee1c4eb51..9e06f9fe7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -490,7 +490,7 @@ public class DefineTextTag extends TextTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return textBounds; } @@ -506,12 +506,12 @@ public class DefineTextTag extends TextTag { } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { - staticTextToImage(swf, characters, textRecords, 1, image, getTextMatrix(), transformation, colorTransform); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + staticTextToImage(swf, textRecords, 1, image, getTextMatrix(), transformation, colorTransform); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(textBounds.Xmin / SWF.unitDivisor, textBounds.Ymin / SWF.unitDivisor); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java index 43e99fafc..9031ca2b5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineVideoStreamTag.java @@ -120,7 +120,7 @@ public class DefineVideoStreamTag extends CharacterTag implements BoundedTag { } @Override - public RECT getRect(Map characters, Stack visited) { + public RECT getRect() { return new RECT(0, (int) (SWF.unitDivisor * width), 0, (int) (SWF.unitDivisor * height)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java index b56e2ad12..ccd5af1b3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -37,6 +37,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -322,20 +323,15 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem, Serializ return new HashSet<>(); } - public Set getDeepNeededCharacters(HashMap characters, List visited) { + public Set getDeepNeededCharacters(Map characters) { Set ret = new HashSet<>(); Set needed = getNeededCharacters(); for (int ch : needed) { if (!characters.containsKey(ch)) { //TODO: use Import tag (?) continue; } - if (visited.contains(ch)) { - continue; - } else { - visited.add(ch); - } ret.add(ch); - ret.addAll(characters.get(ch).getDeepNeededCharacters(characters, visited)); + ret.addAll(characters.get(ch).getDeepNeededCharacters(characters)); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/BoundedTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/BoundedTag.java index f93990700..2c030ce73 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/BoundedTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/BoundedTag.java @@ -26,5 +26,5 @@ import java.util.Stack; */ public interface BoundedTag { - public RECT getRect(Map characters, Stack visited); + public RECT getRect(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/DrawableTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/DrawableTag.java index 70c508543..4cbd92912 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/DrawableTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/DrawableTag.java @@ -31,9 +31,9 @@ import java.util.Stack; */ public interface DrawableTag { - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform); + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform); - public Point getImagePos(int frame, Map characters, Stack visited); + public Point getImagePos(int frame); public int getNumFrames(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java index b504e141f..b2f2de0bb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -246,17 +246,17 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable return defaultFontName; } - public SerializableImage toImage(int frame, int ratio, List tags, Map characters, Stack visited, Matrix transformation, ColorTransform colorTransform) { + public SerializableImage toImage(int frame, int ratio, Matrix transformation, ColorTransform colorTransform) { return SHAPERECORD.shapeListToImage(swf, getGlyphShapeTable(), 500, 500, Color.black, colorTransform); } @Override - public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + public void toImage(int frame, int ratio, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { throw new Error("this overload of toImage call is not supported on FontTag"); } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(0, 0); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 39b5179dc..9e434302e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -252,7 +252,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab BitmapExporter.exportTo(swf, shape, null, image, mat, colorTransform); } - public static void staticTextToImage(SWF swf, Map characters, List textRecords, int numText, SerializableImage image, MATRIX textMatrix, Matrix transformation, ColorTransform colorTransform) { + public static void staticTextToImage(SWF swf, List textRecords, int numText, SerializableImage image, MATRIX textMatrix, Matrix transformation, ColorTransform colorTransform) { Color textColor = new Color(0, 0, 0); FontTag font = null; int textHeight = 12; @@ -269,7 +269,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab } } if (rec.styleFlagsHasFont) { - font = (FontTag) characters.get(rec.fontId); + font = (FontTag) swf.characters.get(rec.fontId); glyphs = font.getGlyphShapeTable(); textHeight = rec.textHeight; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index 9a0e93479..8ceb865ef 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -115,7 +115,7 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { } @Override - public SerializableImage toImage(int frame, int ratio, List tags, Map characters, Stack visited, Matrix transformation, ColorTransform colorTransform) { + public SerializableImage toImage(int frame, int ratio, Matrix transformation, ColorTransform colorTransform) { List shapes = new ArrayList<>(); for (int i = 0; i < shapeCache.size(); i++) { shapes.add(SHAPERECORD.resizeSHAPE(shapeCache.get(i), SWF.unitDivisor)); @@ -130,7 +130,7 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { } @Override - public Point getImagePos(int frame, Map characters, Stack visited) { + public Point getImagePos(int frame) { return new Point(0, 0); } diff --git a/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java index 4b79c2af7..bba61b039 100644 --- a/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.timeline; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.exporters.Matrix; import com.jpexs.decompiler.flash.tags.DoActionTag; import com.jpexs.decompiler.flash.tags.SetBackgroundColorTag; import com.jpexs.decompiler.flash.tags.ShowFrameTag; @@ -27,11 +28,14 @@ import com.jpexs.decompiler.flash.tags.base.RemoveTag; import com.jpexs.decompiler.flash.types.CLIPACTIONS; import com.jpexs.decompiler.flash.types.ColorTransform; import com.jpexs.decompiler.flash.types.MATRIX; +import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.filters.FILTER; +import com.jpexs.helpers.SerializableImage; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Stack; /** * @@ -43,6 +47,7 @@ public class Timeline { public int id; public Map characters = new HashMap<>(); public SWF swf; + public RECT displayRect; public Timeline() { } @@ -64,12 +69,13 @@ public class Timeline { } public Timeline(SWF swf) { - this(swf, swf.tags, 0); + this(swf, swf.tags, 0, swf.displayRect); } - public Timeline(SWF swf, List tags, int id) { + public Timeline(SWF swf, List tags, int id, RECT displayRect) { this.id = id; this.swf = swf; + this.displayRect = displayRect; Frame frame = new Frame(); for (Tag t : swf.tags) { if (t instanceof CharacterTag) { @@ -156,4 +162,8 @@ public class Timeline { } } } + + public void toImage(int frame, int ratio, List tags, Map characters, Stack visited, SerializableImage image, Matrix transformation, ColorTransform colorTransform) { + + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index ebfae0af8..e68f2ac51 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -1060,7 +1060,7 @@ public class XFLConverter { ret += " symbolType=\"graphic\" loop=\"loop\""; } else if (tag instanceof DefineSpriteTag) { DefineSpriteTag sprite = (DefineSpriteTag) tag; - RECT spriteRect = sprite.getRect(characters, new Stack()); + RECT spriteRect = sprite.getRect(); double centerPoint3DX = twipToPixel(matrix.translateX + spriteRect.getWidth() / 2); double centerPoint3DY = twipToPixel(matrix.translateY + spriteRect.getHeight() / 2); ret += " centerPoint3DX=\"" + centerPoint3DX + "\" centerPoint3DY=\"" + centerPoint3DY + "\""; diff --git a/trunk/src/com/jpexs/helpers/SerializableImage.java b/trunk/src/com/jpexs/helpers/SerializableImage.java index d7e68fba8..27fb0676a 100644 --- a/trunk/src/com/jpexs/helpers/SerializableImage.java +++ b/trunk/src/com/jpexs/helpers/SerializableImage.java @@ -82,7 +82,7 @@ public class SerializableImage implements Serializable { g.setColor(new Color(0, 0, 0, 0f)); g.fillRect(0, 0, getWidth(), getHeight()); } - + @Override protected Object clone() throws CloneNotSupportedException { SerializableImage retImage = new SerializableImage();