From 881252274791976298cf2167f6525317efaa1fcf Mon Sep 17 00:00:00 2001 From: Honfika Date: Sat, 26 Apr 2014 15:49:56 +0200 Subject: [PATCH 1/2] svg text color fix --- .../com/jpexs/decompiler/flash/tags/base/TextTag.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 d80e2c917..a5ea45b16 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -418,6 +418,15 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab textElement.setAttribute("font-size", Double.toString(rat * 1024)); textElement.setAttribute("font-family", font.getFontName()); textElement.setTextContent(text.toString()); + + if (textColor != null) { + RGBA colorA = new RGBA(textColor); + textElement.setAttribute("fill", colorA.toHexRGB()); + if (colorA.alpha != 255) { + textElement.setAttribute("fill-opacity", Float.toString(colorA.getAlphaFloat())); + } + } + exporter.addToGroup(textElement); FontExportMode fontExportMode = FontExportMode.TTF; // todo: change this to WOFF exporter.addStyle(font.getFontName(), new FontExporter().exportFont(font, fontExportMode), fontExportMode); From ebf66106c22c208c1e33d374c0486b75a0c71f61 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sat, 26 Apr 2014 17:57:14 +0200 Subject: [PATCH 2/2] svg text export --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 6 +++++ .../flash/exporters/TextExporter.java | 25 +++++++++++++++++++ .../exporters/commonshape/SVGExporter.java | 6 ++--- .../flash/exporters/modes/TextExportMode.java | 3 ++- .../flash/gui/locales/ExportDialog.properties | 1 + 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index d7aa3b96f..08b217a1b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -1355,6 +1355,9 @@ public final class SWF implements TreeItem, Timelined { if(c instanceof TextTag){ return "text"; } + if(c instanceof ButtonTag){ + return "button"; + } if(c instanceof FontTag){ return "font"; } @@ -2311,6 +2314,9 @@ public final class SWF implements TreeItem, Timelined { if (tag instanceof TextTag) { return exporter.getUniqueId("text"); } + if (tag instanceof ButtonTag) { + return exporter.getUniqueId("button"); + } return exporter.getUniqueId("tag"); } diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/TextExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/TextExporter.java index 65a910670..1549aeb94 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/TextExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/TextExporter.java @@ -20,10 +20,13 @@ import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; import com.jpexs.decompiler.flash.RetryTask; import com.jpexs.decompiler.flash.RunnableIOEx; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle; +import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter; import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.TextTag; +import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; import com.jpexs.helpers.Helper; import com.jpexs.helpers.utf8.Utf8Helper; import java.io.File; @@ -56,6 +59,28 @@ public class TextExporter { } } + if (settings.mode == TextExportMode.SVG) { + for (Tag t : tags) { + if (t instanceof TextTag) { + final TextTag textTag = (TextTag) t; + final File file = new File(outdir + File.separator + textTag.getCharacterId() + ".svg"); + new RetryTask(new RunnableIOEx() { + @Override + public void run() throws IOException { + try (FileOutputStream fos = new FileOutputStream(file)) { + ExportRectangle rect = new ExportRectangle(textTag.getRect()); + SVGExporter exporter = new SVGExporter(rect); + textTag.toSVG(exporter, -2, new CXFORMWITHALPHA(), 0); + fos.write(Utf8Helper.getBytes(exporter.getSVG())); + } + } + }, handler).run(); + ret.add(file); + } + } + return ret; + } + if (settings.singleFile) { final File file = new File(outdir + File.separator + (settings.mode == TextExportMode.FORMATTED ? TEXT_EXPORT_FILENAME_FORMATTED : TEXT_EXPORT_FILENAME_PLAIN)); diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java index 965d980dc..98e4fc517 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/commonshape/SVGExporter.java @@ -107,7 +107,7 @@ public class SVGExporter { Element style = _svg.createElement("style"); _svgStyle = _svg.createCDATASection(""); style.appendChild(_svgStyle); - _svgDefs.appendChild(style); + getDefs().appendChild(style); } return _svgStyle; } @@ -215,10 +215,10 @@ public class SVGExporter { value += " font-family: \"" + fontFace + "\";" + Helper.newLine; switch (mode) { case TTF: - value += " src: url('data:font/truetype;base64,[" + base64Data + "]') format(\"truetype\");" + Helper.newLine; + value += " src: url('data:font/truetype;base64," + base64Data + "') format(\"truetype\");" + Helper.newLine; break; case WOFF: - value += " src: url('data:font/woff;base64,[" + base64Data + "]') format(\"woff\");" + Helper.newLine; + value += " src: url('data:font/woff;base64," + base64Data + "') format(\"woff\");" + Helper.newLine; break; } value += " }" + Helper.newLine; diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/modes/TextExportMode.java b/trunk/src/com/jpexs/decompiler/flash/exporters/modes/TextExportMode.java index 3d484b1b0..fc84a3750 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/modes/TextExportMode.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/modes/TextExportMode.java @@ -23,5 +23,6 @@ package com.jpexs.decompiler.flash.exporters.modes; public enum TextExportMode { PLAIN, - FORMATTED + FORMATTED, + SVG } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties index 10883e4c9..4f635c3b4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/ExportDialog.properties @@ -20,6 +20,7 @@ shapes.canvas = HTML5 Canvas texts = Texts texts.plain = Plain text texts.formatted = Formatted text +texts.svg = SVG images = Images images.png_jpeg = PNG/JPEG