diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java index a3d1ad1b8..8e7009c64 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape2Tag.java @@ -63,7 +63,7 @@ public class DefineShape2Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - return shapes.toSVG(2, swf.tags); + return shapes.toSVG(2, swf.tags, shapeBounds); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java index fa8c0a0ba..9df2e0ef3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape3Tag.java @@ -68,7 +68,7 @@ public class DefineShape3Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - return shapes.toSVG(3, swf.tags); + return shapes.toSVG(3, swf.tags, shapeBounds); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java index b12d9c63d..01a96453c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShape4Tag.java @@ -67,7 +67,7 @@ public class DefineShape4Tag extends CharacterTag implements BoundedTag, ShapeTa @Override public String toSVG() { - return shapes.toSVG(4, swf.tags); + return shapes.toSVG(4, swf.tags, shapeBounds); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java index 105173d82..44b426c40 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineShapeTag.java @@ -76,7 +76,7 @@ public class DefineShapeTag extends CharacterTag implements BoundedTag, ShapeTag @Override public String toSVG() { - return shapes.toSVG(1, swf.tags); + return shapes.toSVG(1, swf.tags, shapeBounds); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java b/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java index 021b34a23..cc91df85d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/SHAPE.java @@ -51,7 +51,7 @@ public class SHAPE implements NeedsCharacters { * @return String with XML representation of this shape (SVG) */ public String toSVG(int shapeNum, List tags) { - return SHAPERECORD.shapeToSVG(tags, shapeNum, null, null, numFillBits, numLineBits, shapeRecords); + return SHAPERECORD.shapeToSVG(tags, shapeNum, null, null, numFillBits, numLineBits, shapeRecords, new RECT()); } public BufferedImage toImage(int shapeNum, List tags, Color defaultColor, boolean putToCache) { diff --git a/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java b/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java index c8185b87c..b0ee22255 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/SHAPEWITHSTYLE.java @@ -50,10 +50,12 @@ public class SHAPEWITHSTYLE implements NeedsCharacters { * Converts shape to SVG * * @param shapeNum Type of DefineShape + * @param tags + * @param bounds * @return String with XML representation of this shape (SVG) */ - public String toSVG(int shapeNum, List tags) { - return SHAPERECORD.shapeToSVG(tags, shapeNum, fillStyles, lineStyles, numFillBits, numLineBits, shapeRecords); + public String toSVG(int shapeNum, List tags, RECT bounds) { + return SHAPERECORD.shapeToSVG(tags, shapeNum, fillStyles, lineStyles, numFillBits, numLineBits, shapeRecords, bounds); } public BufferedImage toImage(int shapeNum, List tags) { diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java index ce8724ee0..132bd9250 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java @@ -39,8 +39,12 @@ public class CurvedEdgeRecord extends SHAPERECORD { } @Override - public String toSWG(int oldX, int oldY) { - return "Q " + SWF.twipToPixel(oldX + controlDeltaX) + " " + SWF.twipToPixel(oldY + controlDeltaY) + " " + SWF.twipToPixel(oldX + controlDeltaX + anchorDeltaX) + " " + SWF.twipToPixel(oldY + controlDeltaY + anchorDeltaY); + public String toSVG(int oldX, int oldY, SVGRenderingContext context) { + String result = ""; + if (!context.wasMoveTo) { + result = "M " + SWF.twipToPixel(oldX) + " " + SWF.twipToPixel(oldY) + " "; + } + return result + "Q " + SWF.twipToPixel(oldX + controlDeltaX) + " " + SWF.twipToPixel(oldY + controlDeltaY) + " " + SWF.twipToPixel(oldX + controlDeltaX + anchorDeltaX) + " " + SWF.twipToPixel(oldY + controlDeltaY + anchorDeltaY); } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java index 79f5e02ba..a5e117fe2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/EndShapeRecord.java @@ -31,7 +31,7 @@ public class EndShapeRecord extends SHAPERECORD { } @Override - public String toSWG(int oldX, int oldY) { + public String toSVG(int oldX, int oldY, SVGRenderingContext context) { return ""; } 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 4aace160f..b5a219a7c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java @@ -55,6 +55,7 @@ import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -101,7 +102,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali public Point start; public Point end; - public void draw(int startX, int startY, Graphics2D g, int shapeNum) { + 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; @@ -161,7 +162,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali g.setClip(null); } - public void fill(List tags, int startX, int startY, Graphics2D g, int shapeNum) { + private void fill(List tags, int startX, int startY, Graphics2D g, int shapeNum) { if (fillStyle0 == null) { return; } @@ -480,8 +481,9 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali String points = ""; int x = 0; int y = 0; + context.wasMoveTo = false; for (SHAPERECORD r : edges) { - points += " " + r.toSWG(x, y); + points += " " + r.toSVG(x, y, context); x = r.changeX(x); y = r.changeY(y); } @@ -490,7 +492,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali } } - public abstract String toSWG(int oldX, int oldY); + public abstract String toSVG(int oldX, int oldY, SVGRenderingContext context); public abstract int changeX(int x); @@ -849,22 +851,25 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali * @param records * @return Shape converted to SVG */ - public static String shapeToSVG(List tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, int numFillBits, int numLineBits, List records) { + public static String shapeToSVG(List tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, int numFillBits, int numLineBits, List records, RECT bounds) { String ret = ""; - RECT bounds = new RECT(); - List paths = getPaths(bounds, shapeNum, fillStyles, lineStylesList, /*numFillBits, numLineBits,*/ records); + RECT rect = new RECT(); + List paths = getPaths(rect, shapeNum, fillStyles, lineStylesList, /*numFillBits, numLineBits,*/ records); ret = ""; SVGRenderingContext context = new SVGRenderingContext(); + ret += "\n"; for (Path p : paths) { - ret += p.toSVG(tags, shapeNum, context); + ret += p.toSVG(tags, shapeNum, context) + "\n"; } + ret += "\n"; ret = " \n" + "\n" - + "" + ret + "" + + " xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n" + ret + "" + ""; return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SVGRenderingContext.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SVGRenderingContext.java index 0ae376784..c8f50a332 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SVGRenderingContext.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SVGRenderingContext.java @@ -24,4 +24,5 @@ package com.jpexs.decompiler.flash.types.shaperecords; public class SVGRenderingContext { public int patternCount = 0; + public boolean wasMoveTo; } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java index f0281ce49..71e6ea8f7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java @@ -39,13 +39,17 @@ public class StraightEdgeRecord extends SHAPERECORD { } @Override - public String toSWG(int oldX, int oldY) { + public String toSVG(int oldX, int oldY, SVGRenderingContext context) { + String result = ""; + if (!context.wasMoveTo) { + result = "M " + SWF.twipToPixel(oldX) + " " + SWF.twipToPixel(oldY) + " "; + } if (generalLineFlag) { - return "L " + SWF.twipToPixel(oldX + deltaX) + " " + SWF.twipToPixel(oldY + deltaY); + return result + "L " + SWF.twipToPixel(oldX + deltaX) + " " + SWF.twipToPixel(oldY + deltaY); } else if (vertLineFlag) { - return "V " + SWF.twipToPixel(oldY + deltaY); + return result + "V " + SWF.twipToPixel(oldY + deltaY); } else { - return "H " + SWF.twipToPixel(oldX + deltaX); + return result + "H " + SWF.twipToPixel(oldX + deltaX); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java index 132acb5a1..732d4005b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java @@ -64,9 +64,12 @@ public class StyleChangeRecord extends SHAPERECORD implements Cloneable { } @Override - public String toSWG(int oldX, int oldY) { + public String toSVG(int oldX, int oldY, SVGRenderingContext context) { if (stateMoveTo) { - return "M " + SWF.twipToPixel(moveDeltaX) + " " + SWF.twipToPixel(moveDeltaY); + if ((!context.wasMoveTo) || ((moveDeltaX != oldX) || (moveDeltaY != oldY))) { + context.wasMoveTo = true; + return "M " + SWF.twipToPixel(moveDeltaX) + " " + SWF.twipToPixel(moveDeltaY); + } } return ""; }