From 9267c0dcea39368a9f9a7b2e442f51f36be001d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 7 Nov 2022 21:52:04 +0100 Subject: [PATCH] Fixed Java code does not export tags --- CHANGELOG.md | 1 + .../flash/exporters/swf/SwfJavaExporter.java | 36 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1844eb8d0..bc650a52b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Double warning/error when copy to / move to and same character id already exists - [#1862] Exporting selection to subfolders by SWFname when multiple SWFs selected - Java code export indentation +- Java code does not export tags ## [16.1.0] - 2022-11-06 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java index 704fb7436..1374b04db 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfJavaExporter.java @@ -16,13 +16,16 @@ */ package com.jpexs.decompiler.flash.exporters.swf; +import com.jpexs.decompiler.flash.ReadOnlyTagList; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.helpers.CodeFormatting; import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.helpers.LazyObject; +import com.jpexs.decompiler.flash.tags.DefineSpriteTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.timeline.Timelined; import com.jpexs.decompiler.flash.types.annotations.Internal; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Helper; @@ -54,7 +57,11 @@ public class SwfJavaExporter { "FILLSTYLEARRAY", "LINESTYLE", "LINESTYLE2", "LINESTYLEARRAY", "SHAPERECORD", "SHAPE", "SHAPEWITHSTYLE", "SHAPERECORDS", "SOUNDINFO", "SOUNDENVELOPE", "GLYPHENTRY", "TEXTRECORD", "MORPHGRADRECORD", "MORPHGRADIENT", "MORPHFOCALGRADIENT", "MORPHFILLSTYLE", "MORPHFILLSTYLEARRAY", "MORPHLINESTYLE", "MORPHLINESTYLE2", "MORPHLINESTYLEARRAY", "KERNINGRECORD", - "LANGCODE", "ZONERECORD", "ZONEDATA", "PIX15", "PIX24", "COLORMAPDATA", "BITMAPDATA", "ALPHABITMAPDATA", "ALPHACOLORMAPDATA"}; + "LANGCODE", "ZONERECORD", "ZONEDATA", "PIX15", "PIX24", "COLORMAPDATA", "BITMAPDATA", "ALPHABITMAPDATA", "ALPHACOLORMAPDATA", + + //GFX + "ContourType", "EdgeType", "FONTINFO", "FontType", "GLYPHIDX", "GlyphInfoType", "GlyphType", "KerningPairType", "TEXGLYPH" + }; public List exportJavaCode(SWF swf, String outdir) throws IOException { final File file = new File(outdir + File.separator + Helper.makeFileName("SwfFile.java")); @@ -76,7 +83,13 @@ public class SwfJavaExporter { writer.append("import com.jpexs.decompiler.flash.SWF;").newLine(); writer.append("import com.jpexs.decompiler.flash.SWFCompression;").newLine(); writer.append("import com.jpexs.decompiler.flash.tags.*;").newLine(); + if (swf.gfx) { + writer.append("import com.jpexs.decompiler.flash.tags.gfx.*;").newLine(); + } writer.append("import com.jpexs.decompiler.flash.types.*;").newLine(); + if (swf.gfx) { + writer.append("import com.jpexs.decompiler.flash.types.gfx.*;").newLine(); + } writer.append("import com.jpexs.decompiler.flash.types.filters.*;").newLine(); writer.append("import com.jpexs.decompiler.flash.types.shaperecords.*;").newLine(); writer.append("import com.jpexs.helpers.ByteArrayRange;").newLine(); @@ -102,7 +115,7 @@ public class SwfJavaExporter { writer.append(" SWF swf = getSwf();").newLine(); writer.append(" swf.clearModified();").newLine(); writer.append(" try (FileOutputStream fos = new FileOutputStream(fileName)) {").newLine(); - writer.append(" swf.saveTo(fos, SWFCompression.ZLIB);").newLine(); + writer.append(" swf.saveTo(fos);").newLine(); writer.append(" }").newLine(); writer.append(" }").newLine(); writer.append("}").newLine(); @@ -241,14 +254,29 @@ public class SwfJavaExporter { Logger.getLogger(SwfJavaExporter.class.getName()).log(Level.SEVERE, null, ex); } } + + if ((obj instanceof SWF) || (obj instanceof DefineSpriteTag)) { + Timelined tim = (Timelined) obj; + ReadOnlyTagList tags = tim.getTags(); + sb2.appendLine("Tag tag;"); + for (Tag t : tags) { + Object value2 = generateJavaCode(writer, sb2, objectNames, t, level + 1); + if (value2 != null) { + sb2.appendLine("tag = " + value2 + ";"); + sb2.appendLine(resultName + ".addTag(tag);"); + sb2.appendLine("tag.setTimelined(" + resultName + ");"); + } + } + } + writer.append("private ").append(className).append(" ").append(tagObjName).append("(").append(isSwf ? "" : "SWF swf").append(") {").newLine(); writer.indent(); writer.append(className).append(" ").append(resultName).append(" = new ").append(className).append("(").append(obj instanceof Tag ? "swf" : "").append(");"); writer.unindent().unindent(); - writer.newLine(); + writer.newLine(); writer.append(sb2.toString()); - writer.indent().indent(); + writer.indent().indent(); writer.append(indent).append("return ").append(resultName).append(";").newLine(); writer.unindent(); writer.append("}").newLine().newLine();