diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java index 5704ed74d..53325d34b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java @@ -43,14 +43,6 @@ public class IggyFile implements StructureInterface { return iggySwf; } - public int getFontCount() { - return iggySwf.fonts.size(); - } - - public IggyFont getFont(int fontId) { - return iggySwf.fonts.get(fontId); - } - public IggyFile(String filePath) throws IOException { this(new File(filePath)); } @@ -234,33 +226,16 @@ public class IggyFile implements StructureInterface { for (int i = 0; i < subFileEntries.size(); i++) { IggySubFileEntry entry = subFileEntries.get(i); - if (entry.type != IggySubFileEntry.TYPE_FLASH || entry.type != IggySubFileEntry.TYPE_INDEX) { - continue; - } entry.offset = currentOffset; currentOffset += entry.size; entry.writeToDataStream(stream); } for (int i = 0; i < subFileEntries.size(); i++) { - IggySubFileEntry entry = subFileEntries.get(i); - if (entry.type != IggySubFileEntry.TYPE_FLASH || entry.type != IggySubFileEntry.TYPE_INDEX) { - continue; - } - byte[] entryData = subFileEntriesData.get(i); stream.writeBytes(entryData); } - for (int i = 0; i < subFileEntries.size(); i++) { - IggySubFileEntry entry = subFileEntries.get(i); - if (entry.type != IggySubFileEntry.TYPE_FLASH || entry.type != IggySubFileEntry.TYPE_INDEX) { - subFileEntries.remove(i); - subFileEntriesData.remove(i); - i--; - } - } - } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java index b7d63576d..03734b25d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggySwf.java @@ -21,9 +21,9 @@ public class IggySwf implements StructureInterface { @IggyFieldType(value = DataType.wchar_t, count = 48) String name; - List fonts = new ArrayList<>(); + private List fonts = new ArrayList<>(); // private List font_data_addresses = new ArrayList<>(); - List add_fonts = new ArrayList<>(); + private List add_fonts = new ArrayList<>(); // private List add_font_data_addresses = new ArrayList<>(); private IggyFlashHeader64 hdr; @@ -52,6 +52,22 @@ public class IggySwf implements StructureInterface { return hdr; } + public List getFonts() { + return fonts; + } + + public List getAddFonts() { + return add_fonts; + } + + public List getTexts() { + return texts; + } + + public List getAddTexts() { + return add_texts; + } + @Override public void readFromDataStream(ReadDataStreamInterface s) throws IOException { this.hdr = new IggyFlashHeader64(s); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java index 8aee23b66..221d3daa9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyText.java @@ -191,4 +191,8 @@ public class IggyText implements StructureInterface { return initialText; } + public void setInitialText(String initialText) { + this.initialText = initialText; + } + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggySwfBundle.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggySwfBundle.java index b3125b96d..e2010e7ed 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggySwfBundle.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggySwfBundle.java @@ -108,21 +108,7 @@ public class IggySwfBundle implements SWFBundle { public boolean putSWF(String key, InputStream is) throws IOException { try { SWF swf = new SWF(is, false, false); - List fontTags = new ArrayList<>(); - for (Tag t : swf.getTags()) { - if (t instanceof DefineFont2Tag) { - fontTags.add((DefineFont2Tag) t); - } - } - int fontCount = iggyFile.getFontCount(); - if (fontCount != fontTags.size()) { - throw new IOException("Font count is different from original iggy file"); - } - for (int i = 0; i < fontCount; i++) { - IggyFont iggyFont = iggyFile.getFont(i); - DefineFont2Tag fontTag = fontTags.get(i); - SwfToIggyConvertor.updateIggyFont(iggyFont, fontTag); - } + SwfToIggyConvertor.updateIggy(iggyFile.getSwf(), swf); iggyFile.saveChanges(); return true; } catch (InterruptedException ex) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggyToSwfConvertor.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggyToSwfConvertor.java index 3fcaafad2..f8bd1674d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggyToSwfConvertor.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/IggyToSwfConvertor.java @@ -70,6 +70,10 @@ public class IggyToSwfConvertor { return (int) (val * 1024.0); } + private static int makeLengthsTwip(double val) { + return (int) (val * SWF.unitDivisor); + } + public static SWF getSwf(IggyFile file) { SWF swf = new SWF(); swf.compression = SWFCompression.NONE; @@ -77,10 +81,10 @@ public class IggyToSwfConvertor { swf.frameRate = file.getSwfFrameRate(); swf.gfx = false; swf.displayRect = new RECT( - (int) (file.getSwfXMin() * SWF.unitDivisor), - (int) (file.getSwfXMax() * SWF.unitDivisor), - (int) (file.getSwfYMin() * SWF.unitDivisor), - (int) (file.getSwfYMax() * SWF.unitDivisor)); + makeLengthsTwip(file.getSwfXMin()), + makeLengthsTwip(file.getSwfXMax()), + makeLengthsTwip(file.getSwfYMin()), + makeLengthsTwip(file.getSwfYMax())); swf.version = 10; //FIXME FileAttributesTag fat = new FileAttributesTag(swf); @@ -88,14 +92,13 @@ public class IggyToSwfConvertor { fat.hasMetadata = false; fat.useNetwork = false; swf.addTag(fat); - //Set fontIndices = file.getFontIds(swfIndex); - int fontCount = file.getFontCount(); + IggySwf iggySwf = file.getSwf(); int currentCharId = 0; Map fontIndex2CharId = new HashMap<>(); - for (int fontIndex = 0; fontIndex < fontCount; fontIndex++) { - IggyFont iggyFont = file.getFont(fontIndex); + for (int fontIndex = 0; fontIndex < iggySwf.getFonts().size(); fontIndex++) { + IggyFont iggyFont = iggySwf.getFonts().get(fontIndex); DefineFont2Tag fontTag = new DefineFont2Tag(swf); currentCharId++; fontIndex2CharId.put(fontIndex, currentCharId); @@ -158,17 +161,13 @@ public class IggyToSwfConvertor { swf.addTag(fontTag); } - /* - //TODO: Texts, they are incomplete - Map textIndex2CharId = new HashMap<>(); - Set textIds = file.getTextIds(swfIndex); - for (int textId : textIds) { - IggyText iggyText = file.getText(swfIndex, textId); + for (int textIndex = 0; textIndex < iggySwf.getTexts().size(); textIndex++) { + IggyText iggyText = iggySwf.getTexts().get(textIndex); DefineEditTextTag textTag = new DefineEditTextTag(swf); currentCharId++; - textIndex2CharId.put(iggyText.getTextIndex(), currentCharId); + textIndex2CharId.put(textIndex, currentCharId); textTag.characterID = currentCharId; textTag.hasText = true; textTag.initialText = iggyText.getInitialText(); @@ -185,10 +184,10 @@ public class IggyToSwfConvertor { //textTag.fontHeight = 40; //?? textTag.readOnly = true; textTag.bounds = new RECT( - makeLengthsTwip(iggyText.getPar3()), makeLengthsTwip(iggyText.getPar1()), - makeLengthsTwip(iggyText.getPar4()), - makeLengthsTwip(iggyText.getPar2()) + makeLengthsTwip(iggyText.getPar3()), + makeLengthsTwip(iggyText.getPar2()), + makeLengthsTwip(iggyText.getPar4()) ); //textTag.hasFont = true; @@ -196,7 +195,7 @@ public class IggyToSwfConvertor { textTag.setModified(true); swf.addTag(textTag); } - */ + swf.addTag( new EndTag(swf)); swf.setModified( diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/SwfToIggyConvertor.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/SwfToIggyConvertor.java index 649135c3b..331516073 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/SwfToIggyConvertor.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/conversion/SwfToIggyConvertor.java @@ -1,14 +1,20 @@ package com.jpexs.decompiler.flash.iggy.conversion; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.iggy.IggyCharAdvances; import com.jpexs.decompiler.flash.iggy.IggyCharIndices; import com.jpexs.decompiler.flash.iggy.IggyCharKerning; import com.jpexs.decompiler.flash.iggy.IggyCharOffset; import com.jpexs.decompiler.flash.iggy.IggyFont; import com.jpexs.decompiler.flash.iggy.IggyShape; +import com.jpexs.decompiler.flash.iggy.IggySwf; +import com.jpexs.decompiler.flash.iggy.IggyText; +import com.jpexs.decompiler.flash.tags.DefineEditTextTag; import com.jpexs.decompiler.flash.tags.DefineFont2Tag; +import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.types.KERNINGRECORD; import com.jpexs.decompiler.flash.types.SHAPE; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -22,6 +28,43 @@ public class SwfToIggyConvertor { return (val / 1024f); } + public static void updateIggy(IggySwf iggySwf, SWF swf) throws IOException { + List fontTags = new ArrayList<>(); + List textTags = new ArrayList<>(); + + for (Tag t : swf.getTags()) { + if (t instanceof DefineFont2Tag) { + fontTags.add((DefineFont2Tag) t); + } + if (t instanceof DefineEditTextTag) { + textTags.add((DefineEditTextTag) t); + } + } + int fontCount = iggySwf.getFonts().size(); + if (fontCount != fontTags.size()) { + throw new IOException("Font count is different from original iggy file"); + } + for (int i = 0; i < fontCount; i++) { + IggyFont iggyFont = iggySwf.getFonts().get(i); + DefineFont2Tag fontTag = fontTags.get(i); + SwfToIggyConvertor.updateIggyFont(iggyFont, fontTag); + } + + int textCount = iggySwf.getTexts().size(); + if (textCount != textTags.size()) { + throw new IOException("Text count is different from original iggy file"); + } + for (int i = 0; i < textCount; i++) { + IggyText iggyText = iggySwf.getTexts().get(i); + DefineEditTextTag textTag = textTags.get(i); + SwfToIggyConvertor.updateIggyText(iggyText, textTag); + } + } + + public static void updateIggyText(IggyText iggyText, DefineEditTextTag textTag) { + iggyText.setInitialText(textTag.initialText); + } + public static void updateIggyFont(IggyFont iggyFont, DefineFont2Tag fontTag) { /*byte zeroone[] = new byte[28]; zeroone[12] = 1; @@ -90,14 +133,6 @@ public class SwfToIggyConvertor { iggyFont.setCodePoints(codePoints); iggyFont.setCharScales(charScales); iggyFont.setCharKernings(charKernings); - /* - IggyFont iggyFont = new IggyFont(IggyFont.ID, 0, zeroone, fontTag.getCharacterCount(), - fontTag.getAscent(), fontTag.getDescent(), fontTag.getLeading(), flags, - fontTag.fontKerningTable.size(), unk_float, 0, what_2, 0, 1, - xscale, yscale, 0, ssr1, ssr2, fontTag.getCharacterCount(), 0, what_3, zeroes48a, zeroes48b, - sss1, 1, sss2, 1, sss3, 1, sss4, 1, fontTag.getFontName(), - charOffsets, glyphs, codePoints, charScales, charKernings); - */ } public static IggyFont createIggyFont(DefineFont2Tag fontTag) {