From ae842cb30d4a9a5dd1d8f89876b980ef3749e425 Mon Sep 17 00:00:00 2001 From: Honfika Date: Mon, 27 Jan 2014 15:39:32 +0100 Subject: [PATCH] Using new BitmapExporter for generating font preview --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 2 - .../flash/exporters/BitmapExporter.java | 34 +- .../exporters/DefaultSVGShapeExporter.java | 6 +- .../flash/exporters/SVGShapeExporter.java | 6 +- .../flash/exporters/ShapeExporterBase.java | 18 +- .../flash/tags/DefineBitsJPEG3Tag.java | 1 - .../flash/tags/DefineMorphShape2Tag.java | 15 +- .../flash/tags/DefineMorphShapeTag.java | 15 +- .../flash/tags/DefineShape2Tag.java | 11 +- .../flash/tags/DefineShape3Tag.java | 11 +- .../flash/tags/DefineShape4Tag.java | 11 +- .../decompiler/flash/tags/DefineShapeTag.java | 11 +- .../decompiler/flash/tags/DefineText2Tag.java | 2 +- .../decompiler/flash/tags/DefineTextTag.java | 2 +- .../decompiler/flash/tags/base/FontTag.java | 2 +- .../decompiler/flash/tags/base/ShapeTag.java | 5 - .../decompiler/flash/tags/base/TextTag.java | 6 +- .../flash/tags/gfx/DefineCompactedFont.java | 2 +- .../jpexs/decompiler/flash/types/SHAPE.java | 7 - .../flash/types/SHAPEWITHSTYLE.java | 19 +- .../flash/types/shaperecords/SHAPERECORD.java | 695 +----------------- 21 files changed, 81 insertions(+), 800 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index e6160300f..19c629860 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -105,7 +105,6 @@ import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.filters.BlendComposite; import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.decompiler.flash.types.filters.Filtering; -import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.sound.AdpcmDecoder; import com.jpexs.decompiler.flash.xfl.XFLConverter; import com.jpexs.decompiler.graph.ExportMode; @@ -2078,7 +2077,6 @@ public final class SWF implements TreeItem { public void clearImageCache() { cache.clear(); - SHAPERECORD.clearShapeCache(); BitmapExporter.clearShapeCache(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java index 4fa053971..42af4add0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java @@ -19,13 +19,13 @@ package com.jpexs.decompiler.flash.exporters; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ImageTag; -import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.FILLSTYLE; import com.jpexs.decompiler.flash.types.GRADIENT; import com.jpexs.decompiler.flash.types.GRADRECORD; import com.jpexs.decompiler.flash.types.LINESTYLE2; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.RGB; +import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.SerializableImage; import com.jpexs.helpers.Cache; @@ -56,6 +56,7 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter private BufferedImage image; private Graphics2D graphics; private final Color defaultColor; + private final boolean putToCache; private double xMin; private double yMin; private final SWF swf; @@ -67,19 +68,34 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter private Stroke lineStroke; private Stroke defaultStroke; - public BitmapExporter(SWF swf, ShapeTag tag) { - this(swf, tag, null); + public static BufferedImage export(SWF swf, SHAPE shape, Color defaultColor, boolean putToCache) { + BitmapExporter exporter = new BitmapExporter(swf, shape, defaultColor, putToCache); + exporter.export(); + return exporter.getImage(); + } + + public BitmapExporter(SWF swf, SHAPE shape) { + this(swf, shape, null, true); } - public BitmapExporter(SWF swf, ShapeTag tag, Color defaultColor) { - super(tag); - this.defaultColor = defaultColor; + public BitmapExporter(SWF swf, SHAPE shape, boolean putToCache) { + this(swf, shape, null, putToCache); + } + + public BitmapExporter(SWF swf, SHAPE shape, Color defaultColor) { + this(swf, shape, defaultColor, true); + } + + public BitmapExporter(SWF swf, SHAPE shape, Color defaultColor, boolean putToCache) { + super(shape); this.swf = swf; + this.defaultColor = defaultColor; + this.putToCache = putToCache; } @Override public void export() { - List records = tag.getShapes().shapeRecords; + List records = shape.shapeRecords; String key = "shape_" + records.hashCode() + "_" + (defaultColor == null ? "null" : defaultColor.hashCode()); if (cache.contains(key)) { image = (BufferedImage) ((SerializableImage) cache.get(key)).getImage(); @@ -96,7 +112,9 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); defaultStroke = graphics.getStroke(); super.export(); - cache.put(key, new SerializableImage(image)); + if (putToCache) { + cache.put(key, new SerializableImage(image)); + } } public BufferedImage getImage() { diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/DefaultSVGShapeExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/DefaultSVGShapeExporter.java index fed863e8d..5b265caf0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/DefaultSVGShapeExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/DefaultSVGShapeExporter.java @@ -16,9 +16,9 @@ */ package com.jpexs.decompiler.flash.exporters; -import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.GRADRECORD; import com.jpexs.decompiler.flash.types.RGB; +import com.jpexs.decompiler.flash.types.SHAPE; /** * @@ -32,8 +32,8 @@ public class DefaultSVGShapeExporter extends ShapeExporterBase implements IShape protected String currentDrawCommand = ""; protected String pathData; - public DefaultSVGShapeExporter(ShapeTag tag) { - super(tag); + public DefaultSVGShapeExporter(SHAPE shape) { + super(shape); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/SVGShapeExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/SVGShapeExporter.java index 2f837cf57..433819853 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/SVGShapeExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/SVGShapeExporter.java @@ -19,13 +19,13 @@ package com.jpexs.decompiler.flash.exporters; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ImageTag; -import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.FILLSTYLE; import com.jpexs.decompiler.flash.types.GRADIENT; import com.jpexs.decompiler.flash.types.GRADRECORD; import com.jpexs.decompiler.flash.types.LINESTYLE2; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.RGBA; +import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.helpers.Helper; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -70,8 +70,8 @@ public class SVGShapeExporter extends DefaultSVGShapeExporter { protected int lastPatternId; private final SWF swf; - public SVGShapeExporter(SWF swf, ShapeTag tag) { - super(tag); + public SVGShapeExporter(SWF swf, SHAPE shape) { + super(shape); this.swf = swf; } diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java b/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java index 337bd1114..4d86e32d2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/ShapeExporterBase.java @@ -16,12 +16,13 @@ */ package com.jpexs.decompiler.flash.exporters; -import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.FILLSTYLE; import com.jpexs.decompiler.flash.types.FOCALGRADIENT; import com.jpexs.decompiler.flash.types.LINESTYLE; import com.jpexs.decompiler.flash.types.LINESTYLE2; import com.jpexs.decompiler.flash.types.RGB; +import com.jpexs.decompiler.flash.types.SHAPE; +import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; @@ -41,7 +42,7 @@ import java.util.Map; */ public abstract class ShapeExporterBase implements IShapeExporter { - protected final ShapeTag tag; + protected final SHAPE shape; protected static final double unitDivisor = 20; @@ -58,12 +59,15 @@ public abstract class ShapeExporterBase implements IShapeExporter { private boolean edgeMapsCreated; - public ShapeExporterBase(ShapeTag tag) { - this.tag = tag; + public ShapeExporterBase(SHAPE shape) { + this.shape = shape; _fillStyles = new ArrayList<>(); - _fillStyles.addAll(Arrays.asList(tag.getShapes().fillStyles.fillStyles)); _lineStyles = new ArrayList<>(); - _lineStyles.addAll(Arrays.asList(tag.getShapes().lineStyles.lineStyles)); + if (shape instanceof SHAPEWITHSTYLE) { + SHAPEWITHSTYLE shapeWithStyle = (SHAPEWITHSTYLE) shape; + _fillStyles.addAll(Arrays.asList(shapeWithStyle.fillStyles.fillStyles)); + _lineStyles.addAll(Arrays.asList(shapeWithStyle.lineStyles.lineStyles)); + } } public void export() { @@ -100,7 +104,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { lineEdgeMaps = new ArrayList<>(); currentFillEdgeMap = new HashMap<>(); currentLineEdgeMap = new HashMap<>(); - List records = tag.getShapes().shapeRecords; + List records = shape.shapeRecords; for (int i = 0; i < records.size(); i++) { SHAPERECORD shapeRecord = records.get(i); if (shapeRecord instanceof StyleChangeRecord) { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java index 2578e2094..ce5099f6b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java @@ -27,7 +27,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java index 934b1a749..901e45e18 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShape2Tag.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +import com.jpexs.decompiler.flash.exporters.BitmapExporter; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.DrawableTag; @@ -29,13 +30,13 @@ import com.jpexs.decompiler.flash.types.MORPHFILLSTYLEARRAY; import com.jpexs.decompiler.flash.types.MORPHLINESTYLEARRAY; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPE; +import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -187,11 +188,6 @@ public class DefineMorphShape2Tag extends CharacterTag implements BoundedTag, Mo return 2; } - //@Override - public List getPaths(List tags) { - return null; //FIXME - } - @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { List finalRecords = new ArrayList<>(); @@ -262,7 +258,12 @@ public class DefineMorphShape2Tag extends CharacterTag implements BoundedTag, Mo cer.anchorDeltaY = cer1.anchorDeltaY + (cer2.anchorDeltaY - cer1.anchorDeltaY) * frame / 65535; finalRecords.add(cer); } - return SHAPERECORD.shapeToImage(tags, 4, fillStyles, lineStyles, finalRecords); + SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE(); + shape.fillStyles = fillStyles; + shape.lineStyles = lineStyles; + shape.shapeRecords = finalRecords; + // shapeNum: 4 + return BitmapExporter.export(swf, shape, null, true); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java index e3003df9e..09b6d82da 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineMorphShapeTag.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +import com.jpexs.decompiler.flash.exporters.BitmapExporter; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.DrawableTag; @@ -29,13 +30,13 @@ import com.jpexs.decompiler.flash.types.MORPHFILLSTYLEARRAY; import com.jpexs.decompiler.flash.types.MORPHLINESTYLEARRAY; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPE; +import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -174,11 +175,6 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor return 1; } - // @Override - public List getPaths(List tags) { - return null; //FIXME - } - @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { List finalRecords = new ArrayList<>(); @@ -249,7 +245,12 @@ public class DefineMorphShapeTag extends CharacterTag implements BoundedTag, Mor cer.anchorDeltaY = cer1.anchorDeltaY + (cer2.anchorDeltaY - cer1.anchorDeltaY) * frame / 65535; finalRecords.add(cer); } - return SHAPERECORD.shapeToImage(tags, 3, fillStyles, lineStyles, finalRecords); + SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE(); + shape.fillStyles = fillStyles; + shape.lineStyles = lineStyles; + shape.shapeRecords = finalRecords; + // shapeNum: 3 + return BitmapExporter.export(swf, shape, null, true); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index 8ff12dfb1..39f7218de 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; -import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -65,14 +63,14 @@ public class DefineShape2Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - SVGShapeExporter exporter = new SVGShapeExporter(swf, this); + SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes()); exporter.export(); return exporter.getSVG(); } @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - BitmapExporter exporter = new BitmapExporter(swf, this); + BitmapExporter exporter = new BitmapExporter(swf, getShapes()); exporter.export(); return exporter.getImage(); } @@ -95,11 +93,6 @@ public class DefineShape2Tag extends CharacterTag implements BoundedTag, ShapeTa shapes = sis.readSHAPEWITHSTYLE(2); } - @Override - public List getPaths(List tags) { - return SHAPERECORD.shapeToPaths(tags, 2, shapes.shapeRecords); - } - @Override public int getNumFrames() { return 1; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index 94e2833aa..941a9cb7a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; -import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -70,14 +68,14 @@ public class DefineShape3Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - SVGShapeExporter exporter = new SVGShapeExporter(swf, this); + SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes()); exporter.export(); return exporter.getSVG(); } @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - BitmapExporter exporter = new BitmapExporter(swf, this); + BitmapExporter exporter = new BitmapExporter(swf, getShapes()); exporter.export(); return exporter.getImage(); } @@ -95,11 +93,6 @@ public class DefineShape3Tag extends CharacterTag implements BoundedTag, ShapeTa shapes = sis.readSHAPEWITHSTYLE(3); } - @Override - public List getPaths(List tags) { - return SHAPERECORD.shapeToPaths(tags, 3, shapes.shapeRecords); - } - @Override public int getNumFrames() { return 1; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index bd5944b30..15f8774c1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -25,9 +25,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; -import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -69,14 +67,14 @@ public class DefineShape4Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - SVGShapeExporter exporter = new SVGShapeExporter(swf, this); + SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes()); exporter.export(); return exporter.getSVG(); } @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - BitmapExporter exporter = new BitmapExporter(swf, this); + BitmapExporter exporter = new BitmapExporter(swf, getShapes()); exporter.export(); return exporter.getImage(); } @@ -104,11 +102,6 @@ public class DefineShape4Tag extends CharacterTag implements BoundedTag, ShapeTa shapes = sis.readSHAPEWITHSTYLE(4); } - @Override - public List getPaths(List tags) { - return SHAPERECORD.shapeToPaths(tags, 4, shapes.shapeRecords); - } - @Override public int getNumFrames() { return 1; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java index f342852db..12e20518b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java @@ -26,9 +26,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; -import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import java.awt.Point; -import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -99,14 +97,14 @@ public class DefineShapeTag extends CharacterTag implements BoundedTag, ShapeTag @Override public String toSVG() { - SVGShapeExporter exporter = new SVGShapeExporter(swf, this); + SVGShapeExporter exporter = new SVGShapeExporter(swf, getShapes()); exporter.export(); return exporter.getSVG(); } @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - BitmapExporter exporter = new BitmapExporter(swf, this); + BitmapExporter exporter = new BitmapExporter(swf, getShapes()); exporter.export(); return exporter.getImage(); } @@ -116,11 +114,6 @@ public class DefineShapeTag extends CharacterTag implements BoundedTag, ShapeTag return new Point(shapeBounds.Xmin / 20, shapeBounds.Ymin / 20); } - @Override - public List getPaths(List tags) { - return SHAPERECORD.shapeToPaths(tags, 1, shapes.shapeRecords); - } - @Override public int getNumFrames() { return 1; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index 585a219dd..a367b0171 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -489,7 +489,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - return staticTextToImage(tags, characters, textRecords, textBounds, 2); + return staticTextToImage(swf, characters, textRecords, textBounds, 2); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index 780e39a79..9be6fbc2f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -505,7 +505,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - return staticTextToImage(tags, characters, textRecords, textBounds, 1); + return staticTextToImage(swf, characters, textRecords, textBounds, 1); } @Override 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 f515802a2..dff43b3bd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -248,7 +248,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable @Override public BufferedImage toImage(int frame, List tags, RECT displayRect, HashMap characters, Stack visited) { - return SHAPERECORD.shapeListToImage(getGlyphShapeTable(), 500, 500, Color.black); + return SHAPERECORD.shapeListToImage(swf, getGlyphShapeTable(), 500, 500, Color.black); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java index 546ec3ea5..46398e19d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ShapeTag.java @@ -16,10 +16,7 @@ */ package com.jpexs.decompiler.flash.tags.base; -import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; -import java.awt.geom.GeneralPath; -import java.util.List; /** * @@ -32,6 +29,4 @@ public interface ShapeTag extends DrawableTag { public String toSVG(); public int getShapeNum(); - - public List getPaths(List tags); } 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 a6f13a993..6ede47b07 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.exporters.BitmapExporter; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.text.ParseException; import com.jpexs.decompiler.flash.types.GLYPHENTRY; @@ -191,7 +192,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { return att; } - public static BufferedImage staticTextToImage(List tags, HashMap characters, List textRecords, RECT textBounds, int numText) { + public static BufferedImage staticTextToImage(SWF swf, HashMap characters, List textRecords, RECT textBounds, int numText) { int fixX = -textBounds.Xmin; int fixY = -textBounds.Ymin; BufferedImage ret = new BufferedImage(textBounds.getWidth() / 20, textBounds.getHeight() / 20, BufferedImage.TYPE_INT_ARGB); @@ -232,7 +233,8 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { rect.Xmin /= font.getDivider(); rect.Ymax /= font.getDivider(); rect.Ymin /= font.getDivider(); - BufferedImage img = SHAPERECORD.shapeToImage(tags, 1, null, null, glyphs.get(entry.glyphIndex).shapeRecords, textColor, true); + // shapeNum: 1 + BufferedImage img = BitmapExporter.export(swf, glyphs.get(entry.glyphIndex), textColor, true); AffineTransform tr = new AffineTransform(); tr.setToIdentity(); float rat = textHeight / 1024f; 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 5d9c304b9..a90a3be81 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -161,7 +161,7 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { if (size / cols < 30) { size = cols * 30; } - BufferedImage ret = SHAPERECORD.shapeListToImage(shapes, size, size, Color.black); + BufferedImage ret = SHAPERECORD.shapeListToImage(swf, shapes, size, size, Color.black); imageCache.put("font" + fontId, new SerializableImage(ret)); return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java b/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java index ade2c9e22..8bb204c56 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java @@ -16,11 +16,8 @@ */ package com.jpexs.decompiler.flash.types; -import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; -import java.awt.Color; -import java.awt.image.BufferedImage; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -44,10 +41,6 @@ public class SHAPE implements NeedsCharacters { return ret; } - public BufferedImage toImage(int shapeNum, List tags, Color defaultColor, boolean putToCache) { - return SHAPERECORD.shapeToImage(tags, shapeNum, null, null,/* numFillBits, numLineBits, */ shapeRecords, defaultColor, putToCache); - } - public RECT getBounds() { return SHAPERECORD.getBounds(shapeRecords); } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java b/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java index c02281a85..34273941b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java @@ -16,42 +16,27 @@ */ package com.jpexs.decompiler.flash.types; -import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; -import java.awt.image.BufferedImage; import java.util.HashSet; -import java.util.List; import java.util.Set; /** * * @author JPEXS */ -public class SHAPEWITHSTYLE implements NeedsCharacters { +public class SHAPEWITHSTYLE extends SHAPE implements NeedsCharacters { public FILLSTYLEARRAY fillStyles; public LINESTYLEARRAY lineStyles; - public int numFillBits; - public int numLineBits; - public List shapeRecords; @Override public Set getNeededCharacters() { - HashSet ret = new HashSet<>(); + Set ret = new HashSet<>(); ret.addAll(fillStyles.getNeededCharacters()); for (SHAPERECORD r : shapeRecords) { ret.addAll(r.getNeededCharacters()); } return ret; } - - public BufferedImage toImage(int shapeNum, List tags) { - // todo: honfika: remove this method - return SHAPERECORD.shapeToImage(tags, shapeNum, fillStyles, lineStyles, /*numFillBits, numLineBits,*/ shapeRecords); - } - - public RECT getBounds() { - return SHAPERECORD.getBounds(shapeRecords); - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java index 0f1aa6ff5..7611dbd25 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java @@ -18,40 +18,22 @@ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFOutputStream; -import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.exporters.BitmapExporter; import com.jpexs.decompiler.flash.tags.base.FontTag; -import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; import com.jpexs.decompiler.flash.types.FILLSTYLE; import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY; -import com.jpexs.decompiler.flash.types.FOCALGRADIENT; -import com.jpexs.decompiler.flash.types.GRADIENT; import com.jpexs.decompiler.flash.types.LINESTYLE; -import com.jpexs.decompiler.flash.types.LINESTYLE2; import com.jpexs.decompiler.flash.types.LINESTYLEARRAY; import com.jpexs.decompiler.flash.types.RECT; -import com.jpexs.decompiler.flash.types.RGB; -import com.jpexs.decompiler.flash.types.RGBA; import com.jpexs.decompiler.flash.types.SHAPE; -import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; -import java.awt.AlphaComposite; -import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.LinearGradientPaint; -import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.Point; -import java.awt.RadialGradientPaint; -import java.awt.Rectangle; -import java.awt.RenderingHints; import java.awt.Shape; -import java.awt.TexturePaint; import java.awt.font.GlyphVector; -import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; @@ -72,8 +54,6 @@ import javax.swing.JPanel; */ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Serializable { - private static final float DESCALE = 20; - public abstract void calculateBits(); @Override @@ -82,336 +62,6 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali return ret; } - private static class Path { - - public boolean used = false; - public LINESTYLE lineStyle; - public FILLSTYLE fillStyle0; - public FILLSTYLE fillStyle1; - public List edges = new ArrayList<>(); - public Point start; - public Point end; - - private void draw(int startX, int startY, Graphics2D g, int shapeNum) { - AffineTransform oldAf = g.getTransform(); - AffineTransform trans20 = AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE); - boolean ok = false; - if (shapeNum == 4) { - LINESTYLE2 lineStyle2 = (LINESTYLE2) lineStyle; - if (lineStyle2 == null) { - ok = false; - } else if (!lineStyle2.hasFillFlag) { - RGBA color = (RGBA) lineStyle2.color; - g.setPaint(new Color(color.red, color.green, color.blue, color.alpha)); - int capStyle = 0; - switch (lineStyle2.startCapStyle) { - case LINESTYLE2.NO_CAP: - capStyle = BasicStroke.CAP_BUTT; - break; - case LINESTYLE2.ROUND_CAP: - capStyle = BasicStroke.CAP_ROUND; - break; - case LINESTYLE2.SQUARE_CAP: - capStyle = BasicStroke.CAP_SQUARE; - break; - } - int joinStyle = 0; - switch (lineStyle2.joinStyle) { - case LINESTYLE2.BEVEL_JOIN: - joinStyle = BasicStroke.JOIN_BEVEL; - break; - case LINESTYLE2.MITER_JOIN: - joinStyle = BasicStroke.JOIN_MITER; - break; - case LINESTYLE2.ROUND_JOIN: - joinStyle = BasicStroke.JOIN_ROUND; - break; - } - if (joinStyle == BasicStroke.JOIN_MITER) { - g.setStroke(new BasicStroke(lineStyle2.width / DESCALE, capStyle, joinStyle, lineStyle2.miterLimitFactor)); - } else { - g.setStroke(new BasicStroke(lineStyle2.width / DESCALE, capStyle, joinStyle)); - } - ok = true; - } - } else { - if (lineStyle == null) { - ok = false; - } else { - g.setPaint(lineStyle.color.toColor()); - g.setStroke(new BasicStroke(lineStyle.width / DESCALE, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - ok = true; - } - } - if (ok) { - g.draw(trans20.createTransformedShape(toGeneralPath(startX, startY))); - } - g.setTransform(oldAf); - g.setClip(null); - } - - private void fill(List tags, int startX, int startY, Graphics2D g, int shapeNum) { - if (fillStyle0 == null) { - return; - } - AffineTransform oldAf = g.getTransform(); - AffineTransform trans20 = AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE); - g.setTransform(trans20); - int maxRepeat = 10; //TODO:better handle gradient repeating - boolean ok = false; - switch (fillStyle0.fillStyleType) { - case FILLSTYLE.NON_SMOOTHED_REPEATING_BITMAP: - case FILLSTYLE.REPEATING_BITMAP: - case FILLSTYLE.CLIPPED_BITMAP: - case FILLSTYLE.NON_SMOOTHED_CLIPPED_BITMAP: - ImageTag image = null; - for (Tag t : tags) { - if (t instanceof ImageTag) { - ImageTag i = (ImageTag) t; - if (i.getCharacterId() == fillStyle0.bitmapId) { - image = i; - break; - } - } - } - if (image != null) { - g.setClip(toGeneralPath(startX, startY)); - AffineTransform btrans = SWF.matrixToTransform(fillStyle0.bitmapMatrix); - btrans.preConcatenate(AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE)); - btrans.preConcatenate(AffineTransform.getTranslateInstance(startX / DESCALE, startY / DESCALE)); - g.setTransform(btrans); - BufferedImage img = image.getImage(tags); - if (img != null) { - g.setPaint(new TexturePaint(img, new Rectangle(img.getWidth(), img.getHeight()))); - } - g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); - g.setTransform(oldAf); - g.setClip(null); - } - break; - case FILLSTYLE.FOCAL_RADIAL_GRADIENT: - - FOCALGRADIENT focalGradient = (FOCALGRADIENT) fillStyle0.gradient; - List colorsFocRad = new ArrayList<>(); - List ratiosFocRad = new ArrayList<>(); - for (int i = 0; i < focalGradient.gradientRecords.length; i++) { - if ((i > 0) && (focalGradient.gradientRecords[i - 1].ratio == focalGradient.gradientRecords[i].ratio)) { - continue; - } - ratiosFocRad.add(focalGradient.gradientRecords[i].getRatioFloat()); - RGB color = focalGradient.gradientRecords[i].color; - if (shapeNum >= 3) { - RGBA colorA = (RGBA) color; - colorsFocRad.add(new Color(colorA.red, colorA.green, colorA.blue, colorA.alpha)); - } else { - colorsFocRad.add(new Color(color.red, color.green, color.blue)); - } - } - - float[] focRadFractions = new float[ratiosFocRad.size()]; - for (int i = 0; i < ratiosFocRad.size(); i++) { - focRadFractions[i] = ratiosFocRad.get(i); - } - Color[] focRadColors = colorsFocRad.toArray(new Color[colorsFocRad.size()]); - - RGB focEndColor = focalGradient.gradientRecords[focalGradient.gradientRecords.length - 1].color; - if (shapeNum >= 3) { - RGBA focEndColorA = (RGBA) focEndColor; - g.setPaint(new Color(focEndColorA.red, focEndColorA.green, focEndColorA.blue, focEndColorA.alpha)); - } else { - g.setPaint(new Color(focEndColor.red, focEndColor.green, focEndColor.blue)); - } - GeneralPath focPath = toGeneralPath(startX, startY); - g.fill(focPath); - g.setClip(focPath); - AffineTransform focTrans = SWF.matrixToTransform(fillStyle0.gradientMatrix); - focTrans.preConcatenate(AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE)); - focTrans.preConcatenate(AffineTransform.getTranslateInstance(startX / DESCALE, startY / DESCALE)); - g.setTransform(focTrans); - CycleMethod cm = CycleMethod.NO_CYCLE; - if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_PAD_MODE) { - cm = CycleMethod.NO_CYCLE; - } else if (focalGradient.spreadMode == GRADIENT.SPREAD_REFLECT_MODE) { - cm = CycleMethod.REFLECT; - } else if (focalGradient.spreadMode == GRADIENT.SPREAD_REPEAT_MODE) { - cm = CycleMethod.REPEAT; - } - - g.setPaint(new RadialGradientPaint(new Point(0, 0), 16384, new Point((int) (focalGradient.focalPoint * 16384), 0), focRadFractions, focRadColors, cm)); - g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); - g.setTransform(oldAf); - g.setClip(null); - return; - case FILLSTYLE.RADIAL_GRADIENT: - List colorsRad = new ArrayList<>(); - List ratiosRad = new ArrayList<>(); - for (int i = 0; i < fillStyle0.gradient.gradientRecords.length; i++) { - if ((i > 0) && (fillStyle0.gradient.gradientRecords[i - 1].ratio == fillStyle0.gradient.gradientRecords[i].ratio)) { - continue; - } - ratiosRad.add(fillStyle0.gradient.gradientRecords[i].getRatioFloat()); - RGB color = fillStyle0.gradient.gradientRecords[i].color; - if (shapeNum >= 3) { - RGBA colorA = (RGBA) color; - colorsRad.add(new Color(colorA.red, colorA.green, colorA.blue, colorA.alpha)); - } else { - colorsRad.add(new Color(color.red, color.green, color.blue)); - } - } - - float[] ratiosRadAr = new float[ratiosRad.size()]; - for (int i = 0; i < ratiosRad.size(); i++) { - ratiosRadAr[i] = ratiosRad.get(i); - } - Color[] colorsRadArr = colorsRad.toArray(new Color[colorsRad.size()]); - - RGB endColor = fillStyle0.gradient.gradientRecords[fillStyle0.gradient.gradientRecords.length - 1].color; - if (shapeNum >= 3) { - RGBA endColorA = (RGBA) endColor; - g.setPaint(new Color(endColorA.red, endColorA.green, endColorA.blue, endColorA.alpha)); - } else { - g.setPaint(new Color(endColor.red, endColor.green, endColor.blue)); - } - GeneralPath path = toGeneralPath(startX, startY); - g.fill(path); - g.setClip(path); - AffineTransform trans = SWF.matrixToTransform(fillStyle0.gradientMatrix); - trans.preConcatenate(AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE)); - trans.preConcatenate(AffineTransform.getTranslateInstance(startX / DESCALE, startY / DESCALE)); - g.setTransform(trans); - - CycleMethod cmRad = CycleMethod.NO_CYCLE; - if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_PAD_MODE) { - cmRad = CycleMethod.NO_CYCLE; - } else if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_REFLECT_MODE) { - cmRad = CycleMethod.REFLECT; - } else if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_REPEAT_MODE) { - cmRad = CycleMethod.REPEAT; - } - - g.setPaint(new RadialGradientPaint(new Point(0, 0), 16384, ratiosRadAr, colorsRadArr, cmRad)); - g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); - g.setTransform(oldAf); - g.setClip(null); - return; - case FILLSTYLE.LINEAR_GRADIENT: - List colors = new ArrayList<>(); - List ratios = new ArrayList<>(); - for (int i = 0; i < fillStyle0.gradient.gradientRecords.length; i++) { - if ((i > 0) && (fillStyle0.gradient.gradientRecords[i - 1].ratio == fillStyle0.gradient.gradientRecords[i].ratio)) { - continue; - } - ratios.add(fillStyle0.gradient.gradientRecords[i].getRatioFloat()); - RGB color = fillStyle0.gradient.gradientRecords[i].color; - if (shapeNum >= 3) { - RGBA colorA = (RGBA) color; - colors.add(new Color(colorA.red, colorA.green, colorA.blue, colorA.alpha)); - } else { - colors.add(new Color(color.red, color.green, color.blue)); - } - } - - float[] ratiosAr = new float[ratios.size()]; - for (int i = 0; i < ratios.size(); i++) { - ratiosAr[i] = ratios.get(i); - } - Color[] colorsArr = colors.toArray(new Color[colors.size()]); - - GeneralPath pathLin = toGeneralPath(startX, startY); - g.fill(pathLin); - g.setClip(pathLin); - AffineTransform transLin = SWF.matrixToTransform(fillStyle0.gradientMatrix); - transLin.preConcatenate(AffineTransform.getScaleInstance(1 / DESCALE, 1 / DESCALE)); - transLin.preConcatenate(AffineTransform.getTranslateInstance(startX / DESCALE, startY / DESCALE)); - g.setTransform(transLin); - - CycleMethod cmLin = CycleMethod.NO_CYCLE; - if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_PAD_MODE) { - cmLin = CycleMethod.NO_CYCLE; - } else if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_REFLECT_MODE) { - cmLin = CycleMethod.REFLECT; - } else if (fillStyle0.gradient.spreadMode == GRADIENT.SPREAD_REPEAT_MODE) { - cmLin = CycleMethod.REPEAT; - } - - g.setPaint(new LinearGradientPaint(new Point(-16384, 0), new Point(16384, 0), ratiosAr, colorsArr, cmLin)); - g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); - g.setTransform(oldAf); - g.setClip(null); - return; - case FILLSTYLE.SOLID: - Color c = null; - RGB color = fillStyle0.color; - if (shapeNum >= 3) { - RGBA colorA = (RGBA) color; - c = new Color(colorA.red, colorA.green, colorA.blue, colorA.alpha); - } else { - c = new Color(color.red, color.green, color.blue); - } - g.setPaint(c); - ok = true; - break; - } - if (ok) { - GeneralPath path = toGeneralPath(startX, startY); - g.fill(path); - } - g.setTransform(oldAf); - g.setClip(null); - } - - public void drawTo(List tags, int startX, int startY, Graphics2D g, int shapeNum) { - g.setComposite(AlphaComposite.SrcOver); - fill(tags, startX, startY, g, shapeNum); - draw(startX, startY, g, shapeNum); - } - - public GeneralPath toGeneralPath(int startX, int startY) { - - GeneralPath ret = new GeneralPath(); - int x = startX; - int y = startY; - boolean wasMoveTo = false; - for (SHAPERECORD rec : edges) { - int nx = rec.changeX(x); - int ny = rec.changeY(y); - if (rec instanceof StyleChangeRecord) { - StyleChangeRecord scr = (StyleChangeRecord) rec; - if (scr.stateMoveTo) { - nx += startX; - ny += startY; - if ((!wasMoveTo) || ((nx != x) || (ny != y))) { - ret.moveTo(nx, ny); - } - wasMoveTo = true; - } - } - if (rec instanceof StraightEdgeRecord) { - if (!wasMoveTo) { - ret.moveTo(x, y); - wasMoveTo = true; - } - ret.lineTo(nx, ny); - } - if (rec instanceof CurvedEdgeRecord) { - if (!wasMoveTo) { - ret.moveTo(x, y); - wasMoveTo = true; - } - CurvedEdgeRecord cer = (CurvedEdgeRecord) rec; - ret.quadTo((x + cer.controlDeltaX), (y + cer.controlDeltaY), (x + cer.controlDeltaX + cer.anchorDeltaX), (y + cer.controlDeltaY + cer.anchorDeltaY)); - } - x = nx; - y = ny; - } - return ret; - } - - public boolean sameStyle(Path p) { - return fillStyle0 == p.fillStyle0 && p.lineStyle == lineStyle; - } - } - public abstract int changeX(int x); public abstract int changeY(int y); @@ -449,293 +99,6 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali } return new RECT(min_x, max_x, min_y, max_y); } - static int cnt = 0; - - private static List getPaths(RECT bounds, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, List records) { - List paths = new ArrayList<>(); - Path path = null; - int x = 0; - int y = 0; - int max_x = 0; - int max_y = 0; - int min_x = Integer.MAX_VALUE; - int min_y = Integer.MAX_VALUE; - boolean started = false; - FILLSTYLE lastFillStyle0 = null; - FILLSTYLE lastFillStyle1 = null; - LINESTYLE lastLineStyle = null; - for (SHAPERECORD r : records) { - if (r instanceof StyleChangeRecord) { - StyleChangeRecord scr = (StyleChangeRecord) r; - if (path != null) { - path.end = new Point(x, y); - paths.add(path); - } - path = new Path(); - - if (scr.stateNewStyles) { - fillStyles = scr.fillStyles; - lineStylesList = scr.lineStyles; - //numFillBits = scr.numFillBits; - //numLineBits = scr.numLineBits; - } - if (scr.stateFillStyle0) { - if ((scr.fillStyle0 == 0) || (fillStyles == null)) { - path.fillStyle0 = null; - } else { - path.fillStyle0 = fillStyles.fillStyles[scr.fillStyle0 - 1]; - } - } else { - path.fillStyle0 = lastFillStyle0; - } - - lastFillStyle0 = path.fillStyle0; - if (scr.stateFillStyle1) { - if ((scr.fillStyle1 == 0) || (fillStyles == null)) { - path.fillStyle1 = null; - } else { - path.fillStyle1 = fillStyles.fillStyles[scr.fillStyle1 - 1]; - } - } else { - path.fillStyle1 = lastFillStyle1; - } - lastFillStyle1 = path.fillStyle1; - if (scr.stateLineStyle) { - if (shapeNum >= 4) { - if (scr.lineStyle == 0) { - path.lineStyle = null; - } else { - path.lineStyle = lineStylesList.lineStyles[scr.lineStyle - 1]; - } - } else { - if (scr.lineStyle == 0) { - path.lineStyle = null; - } else { - path.lineStyle = lineStylesList.lineStyles[scr.lineStyle - 1]; - } - } - } else { - path.lineStyle = lastLineStyle; - } - - lastLineStyle = path.lineStyle; - if (started && (!scr.stateMoveTo)) { - scr.stateMoveTo = true; - scr.moveDeltaX = x; - scr.moveDeltaY = y; - } - } - if (path == null) { - path = new Path(); - path.start = new Point(x, y); - } - path.edges.add(r); - x = r.changeX(x); - y = r.changeY(y); - if (path.start == null) { - path.start = new Point(x, y); - } - if (r.isMove()) { - started = true; - } - if (x > max_x) { - max_x = x; - } - if (y > max_y) { - max_y = y; - } - if (started) { - if (y < min_y) { - min_y = y; - } - if (x < min_x) { - min_x = x; - } - } - } - path.end = new Point(x, y); - paths.add(path); - List paths2 = new ArrayList<>(); - for (Path p : paths) { - if ((p.fillStyle0 == null) && (p.fillStyle1 == null)) { - paths2.add(p); - } - if (p.fillStyle0 != null) { - paths2.add(p); - } - if (p.fillStyle1 != null) { - Path f = new Path(); - boolean flip = true; - f.fillStyle0 = p.fillStyle1; - f.lineStyle = p.lineStyle; - f.edges = new ArrayList<>(); - f.start = p.end; - f.end = p.start; - if (!flip) { - f.edges = p.edges; - } else { - x = 0; - y = 0; - boolean revstarted = false; - List chedges = new ArrayList<>(); - for (SHAPERECORD r : p.edges) { - int oldX = x; - int oldY = y; - x = r.changeX(x); - y = r.changeY(y); - if (r instanceof StyleChangeRecord) { - StyleChangeRecord mv = (StyleChangeRecord) r; - if (mv.stateMoveTo) { - StyleChangeRecord mv2 = (StyleChangeRecord) mv.clone(); - mv2.moveDeltaX = oldX; - mv2.moveDeltaY = oldY; - r = mv2; - if (!revstarted) { - revstarted = true; - continue; - } - } - } - chedges.add(r); - } - int finishX = x; - int finishY = y; - StyleChangeRecord scr = new StyleChangeRecord(); - scr.stateMoveTo = true; - scr.moveDeltaX = finishX; - scr.moveDeltaY = finishY; - f.edges.add(scr); - - x = finishX; - y = finishY; - for (int e = chedges.size() - 1; e >= 0; e--) { - SHAPERECORD r = chedges.get(e); - SHAPERECORD r2 = null; - try { - r2 = (SHAPERECORD) r.clone(); - } catch (CloneNotSupportedException ex) { - Logger.getLogger(SHAPERECORD.class.getName()).log(Level.SEVERE, null, ex); - } - r2.flip(); - - x = r.changeX(x); - y = r.changeY(y); - f.edges.add(r2); - } - } - paths2.add(f); - } - } - List> groupedPaths = new ArrayList<>(); - for (Path p1 : paths2) { - boolean found = false; - for (List list : groupedPaths) { - if (list.contains(p1)) { - continue; - } - if (p1.sameStyle(list.get(0))) { - list.add(p1); - found = true; - break; - } - } - if (!found) { - List newitem = new ArrayList<>(); - newitem.add(p1); - groupedPaths.add(newitem); - } - } - List subpath; - List edges; - Point k2; - Point k1; - - List ret = new ArrayList<>(); - - for (int e = 0; e < groupedPaths.size(); e++) { - List pathList = groupedPaths.get(e); - List> m = new ArrayList<>(); - Map> ind = new HashMap<>(); - int usedCount = 0; - for (int f = 0; f < pathList.size(); f++) { - path = pathList.get(f); - if (path.start.equals(path.end)) { - path.used = true; - usedCount++; - List psh = new ArrayList<>(); - psh.add(path); - m.add(psh); - } else { - path.used = false; - if (!ind.containsKey(path.start)) { - ind.put(path.start, new ArrayList()); - } - ind.get(path.start).add(path); - } - } - for (int f = 0; f < pathList.size(); f++) { - if (usedCount == pathList.size()) { - break; - } - path = pathList.get(f); - if (!path.used) { - subpath = new ArrayList<>(); - subpath.add(path); - path.used = true; - usedCount++; - edges = ind.get(path.start); - for (int l = 0; l < edges.size(); l++) { - if (edges.get(l) == path) { - edges.remove(l); - } - } - k1 = path.start; - k2 = path.end; - while (!k2.equals(k1)) { - if (!ind.containsKey(k2)) { - break; - } - edges = ind.get(k2); - if (edges.isEmpty()) { - break; - } - path = edges.remove(0); - subpath.add(path); - path.used = true; - usedCount++; - k2 = path.end; - } - m.add(subpath); - } - } - - if (!m.isEmpty()) { - Path onepath = null; - for (List list : m) { - for (Path p : list) { - if (onepath == null) { - onepath = new Path(); - onepath.fillStyle0 = p.fillStyle0; - onepath.lineStyle = p.lineStyle; - } - if (onepath.start == null) { - onepath.start = p.start; - } - onepath.edges.addAll(p.edges); - onepath.end = p.end; - } - } - if (onepath != null) { - ret.add(onepath); - } - } - } - bounds.Xmax = max_x; - bounds.Ymax = max_y; - bounds.Xmin = min_x; - bounds.Ymin = min_y; - return ret; - } public static CurvedEdgeRecord straightToCurve(StraightEdgeRecord ser) { CurvedEdgeRecord ret = new CurvedEdgeRecord(); @@ -746,27 +109,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali return ret; } - private static final Cache cache = Cache.getInstance(false); - - public static void clearShapeCache() { - cache.clear(); - } - - public static BufferedImage shapeToImage(List tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, List records) { - return shapeToImage(tags, shapeNum, fillStyles, lineStylesList, records, null, true); - } - - public static List shapeToPaths(List tags, int shapeNum, List records) { - RECT rect = new RECT(); - List paths = getPaths(rect, shapeNum, null, null, records); - List ret = new ArrayList<>(); - for (Path p : paths) { - ret.add(p.toGeneralPath(-rect.Xmin, -rect.Ymin)); - } - return ret; - } - - public static BufferedImage shapeListToImage(List shapes, int prevWidth, int prevHeight, Color color) { + public static BufferedImage shapeListToImage(SWF swf, List shapes, int prevWidth, int prevHeight, Color color) { BufferedImage ret = new BufferedImage(prevWidth, prevHeight, BufferedImage.TYPE_INT_ARGB); Graphics g = ret.getGraphics(); @@ -807,7 +150,8 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali break loopy; } - BufferedImage img = shapes.get(pos).toImage(1, new ArrayList(), color, false); + // shapeNum: 1 + BufferedImage img = BitmapExporter.export(swf, shapes.get(pos), color, false); int w1 = img.getWidth(); int h1 = img.getHeight(); @@ -818,43 +162,12 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali int py = y * h2 + w2 - h; g.drawImage(img, px, py, px + w, py + h, 0, 0, w1, h1, null); pos++; - SHAPERECORD.clearShapeCache(); } } return ret; } - public static BufferedImage shapeToImage(List tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, List records, Color defaultColor, boolean putToCache) { - String key = "shape_" + records.hashCode() + "_" + (defaultColor == null ? "null" : defaultColor.hashCode()); - if (cache.contains(key)) { - return (BufferedImage) ((SerializableImage) cache.get(key)).getImage(); - } - RECT rect = new RECT(); - List paths = getPaths(rect, shapeNum, fillStyles, lineStylesList, /*numFillBits, numLineBits,*/ records); - BufferedImage ret = new BufferedImage( - (int) (rect.getWidth() / DESCALE + 2), (int) (rect.getHeight() / DESCALE + 2), BufferedImage.TYPE_INT_ARGB); - Graphics2D g = (Graphics2D) ret.getGraphics(); - g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - for (Path p : paths) { - if ((p.fillStyle0 == null) && (p.lineStyle == null) && (defaultColor != null)) { - p.fillStyle0 = new FILLSTYLE(); - p.fillStyle0.fillStyleType = FILLSTYLE.SOLID; - p.fillStyle0.color = new RGB(defaultColor); - } - p.drawTo(tags, -rect.Xmin, -rect.Ymin, g, shapeNum); - } - - if (putToCache) { - cache.put(key, new SerializableImage(ret)); - } - - return ret; - } - public abstract boolean isMove(); public static List systemFontCharactersToSHAPES(String fontName, int fontStyle, int fontSize, String characters) {