diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index bfa612893..5c89bc1c7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -76,6 +76,7 @@ import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.Container; import com.jpexs.decompiler.flash.tags.base.ShapeTag; +import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.types.RECT; import java.io.*; import java.util.ArrayList; @@ -769,6 +770,40 @@ public class SWF { } } + public void exportTexts(String outdir, List tags, boolean formatted) throws IOException { + if (tags.isEmpty()) { + return; + } + if (!(new File(outdir)).exists()) { + (new File(outdir)).mkdirs(); + } + for (Tag t : tags) { + if (t instanceof TextTag) { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(outdir + File.separator + ((TextTag) t).getCharacterID() + ".txt"); + if (formatted) { + fos.write(((TextTag) t).getFormattedText(this.tags).getBytes("UTF-8")); + } else { + fos.write(((TextTag) t).getText(this.tags).getBytes("UTF-8")); + } + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception ex) { + //ignore + } + } + } + } + } + } + + public void exportTexts(String outdir, boolean formatted) throws IOException { + exportTexts(outdir, tags, formatted); + } + public static void exportShapes(String outdir, List tags) throws IOException { if (tags.isEmpty()) { return; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java index 5851bef3a..bcfd73284 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ExportDialog.java @@ -19,6 +19,7 @@ public class ExportDialog extends JDialog { boolean cancelled = false; String options[][] = { {"SVG"}, + {"Plain Text", "Formatted text"}, {"PNG/JPEG"}, {"FLV (No audio)"}, {"MP3/FLV", "FLV (Audio only)"}, @@ -26,16 +27,18 @@ public class ExportDialog extends JDialog { }; String optionNames[] = { "Shapes", + "Texts", "Images", "Movies", "Sounds", "ActionScript" }; public static final int OPTION_SHAPES = 0; - public static final int OPTION_IMAGES = 1; - public static final int OPTION_MOVIES = 2; - public static final int OPTION_SOUNDS = 3; - public static final int OPTION_ACTIONSCRIPT = 4; + public static final int OPTION_TEXTS = 1; + public static final int OPTION_IMAGES = 2; + public static final int OPTION_MOVIES = 3; + public static final int OPTION_SOUNDS = 4; + public static final int OPTION_ACTIONSCRIPT = 5; private JComboBox combos[]; public int getOption(int index) { @@ -58,10 +61,10 @@ public class ExportDialog extends JDialog { int top = 10; for (int i = 0; i < optionNames.length; i++) { JLabel lab = new JLabel(optionNames[i]); - lab.setBounds(10, top, 60, 25); + lab.setBounds(10, top, 75, 25); cnt.add(lab); combos[i] = new JComboBox(options[i]); - combos[i].setBounds(75, top, 105, 25); + combos[i].setBounds(90, top, 125, 25); cnt.add(combos[i]); top += 25; } @@ -75,7 +78,7 @@ public class ExportDialog extends JDialog { setVisible(false); } }); - okButton.setBounds(25, top, 75, 25); + okButton.setBounds(43, top, 75, 25); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @@ -85,11 +88,15 @@ public class ExportDialog extends JDialog { setVisible(false); } }); - cancelButton.setBounds(100, top, 75, 25); + cancelButton.setBounds(118, top, 75, 25); + top += 25; cnt.add(okButton); cnt.add(cancelButton); - setSize(210, top + 70); + + top += 15; + pack(); + setSize(245, top + getInsets().top); View.centerScreen(this); View.setWindowIcon(this); getRootPane().setDefaultButton(okButton); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index d1618b764..b4bae6516 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1176,6 +1176,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi Configuration.setConfig("lastExportDir", chooser.getSelectedFile().getParentFile().getAbsolutePath()); final boolean isPcode = export.getOption(ExportDialog.OPTION_ACTIONSCRIPT) == 1; final boolean isMp3 = export.getOption(ExportDialog.OPTION_SOUNDS) == 0; + final boolean isFormatted = export.getOption(ExportDialog.OPTION_TEXTS) == 1; final boolean onlySel = e.getActionCommand().endsWith("SEL"); (new Thread() { @Override @@ -1196,6 +1197,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi List shapes = new ArrayList(); List movies = new ArrayList(); List sounds = new ArrayList(); + List texts = new ArrayList(); List actionNodes = new ArrayList(); List binaryData = new ArrayList(); for (Object d : sel) { @@ -1219,6 +1221,9 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi if ("binaryData".equals(getTagType(n.tag))) { binaryData.add((Tag) n.tag); } + if ("text".equals(getTagType(n.tag))) { + texts.add((Tag) n.tag); + } } if (d instanceof TreeElement) { if (((TreeElement) d).isLeaf()) { @@ -1228,6 +1233,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } SWF.exportImages(selFile + File.separator + "images", images, jtt); SWF.exportShapes(selFile + File.separator + "shapes", shapes); + swf.exportTexts(selFile + File.separator + "texts", texts, isFormatted); swf.exportMovies(selFile + File.separator + "movies", movies); swf.exportSounds(selFile + File.separator + "sounds", sounds, isMp3); swf.exportBinaryData(selFile + File.separator + "binaryData", binaryData); @@ -1250,6 +1256,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi } else { swf.exportImages(selFile + File.separator + "images"); swf.exportShapes(selFile + File.separator + "shapes"); + swf.exportTexts(selFile + File.separator + "texts", isFormatted); swf.exportMovies(selFile + File.separator + "movies"); swf.exportSounds(selFile + File.separator + "sounds", isMp3); swf.exportBinaryData(selFile + File.separator + "binaryData"); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 162fd8f8a..84f9c310e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -71,17 +71,49 @@ public class DefineEditTextTag extends CharacterTag implements BoundedTag, TextT public String variableName; public String initialText; + private String stripTags(String inp) { + boolean intag = false; + String outp = ""; + for (int i = 0; i < inp.length(); ++i) { + if (!intag && inp.charAt(i) == '<') { + intag = true; + continue; + } + if (intag && inp.charAt(i) == '>') { + intag = false; + continue; + } + if (!intag) { + outp = outp + inp.charAt(i); + } + } + return outp; + } + + private String entitiesReplace(String s) { + s = s.replace("<", "<"); + s = s.replace(">", ">"); + s = s.replace("&", "&"); + s = s.replace(""", "\""); + return s; + } + @Override public String getText(List tags) { - if (hasText) { - return initialText; + String ret = getFormattedText(tags); + if (html) { + ret = stripTags(ret); + ret = entitiesReplace(ret); } - return ""; + return ret; } @Override public String getFormattedText(List tags) { - return getText(tags); + if (hasText) { + return initialText; + } + return ""; } @Override 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 8466df034..fd187363e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -31,4 +31,6 @@ public interface TextTag { public String getFormattedText(List tags); public void setFormattedText(List tags, String text) throws ParseException; + + public int getCharacterID(); }