From 0d45ce68696bfdec1f4ff133514d4bfe2a2aef99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 9 Jun 2013 11:08:50 +0200 Subject: [PATCH] #102 Fixed shapes to FLA export --- .../decompiler/flash/xfl/XFLConverter.java | 332 +++++++++++------- 1 file changed, 210 insertions(+), 122 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 675954dc9..caf22f889 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -133,6 +133,7 @@ public class XFLConverter { public static final int KEY_MODE_CLASSIC_TWEEN = 22017; public static final int KEY_MODE_SHAPE_TWEEN = 17922; public static final int KEY_MODE_MOTION_TWEEN = 8195; + public static final int KEY_MODE_SHAPE_LAYERS = 8192; private XFLConverter() { } @@ -204,6 +205,9 @@ public class XFLConverter { if (ls.pixelHintingFlag) { params += " pixelHinting=\"true\""; } + if (ls.width == 1) { + params += " solidStyle=\"hairline\""; + } if ((!ls.noHScaleFlag) && (!ls.noVScaleFlag)) { params += " scaleMode=\"normal\""; } else if ((!ls.noHScaleFlag) && ls.noVScaleFlag) { @@ -212,7 +216,7 @@ public class XFLConverter { params += " scaleMode=\"vertical\""; } - switch (ls.startCapStyle) { //What about endCapStyle? + switch (ls.endCapStyle) { //What about endCapStyle? case LINESTYLE2.NO_CAP: params += " caps=\"none\""; break; @@ -413,28 +417,27 @@ public class XFLConverter { List edges = new ArrayList<>(); //int fillStyleCount = 0; int lineStyleCount = 0; - int lastFillStyleCount = 0; - int lastLineStyleCount = 0; - String edgeStyle = ""; int fillStyle0 = -1; int fillStyle1 = -1; int strokeStyle = -1; - String edgesStr = ""; + //String edgesStr = ""; String fillsStr = ""; String strokesStr = ""; fillsStr += ""; strokesStr += ""; - edgesStr += ""; + //edgesStr += ""; + List layers = new ArrayList<>(); + String currentLayer = ""; - List fillStylesStr = new ArrayList<>(); + int fillStyleCount = 0; + //List fillStylesStr = new ArrayList<>(); if (fillStyles != null) { for (FILLSTYLE fs : fillStyles.fillStyles) { - //fillsStr += ""; - fillStylesStr.add(convertFillStyle(mat, characters, fs, shapeNum)); - //fillsStr += ""; - //fillStyleCount++; + fillsStr += ""; + fillsStr += convertFillStyle(mat, characters, fs, shapeNum); + fillsStr += ""; + fillStyleCount++; } - lastFillStyleCount = fillStyles.fillStyles.length; } if (lineStyles != null) { if (lineStyles.lineStyles2 != null) { //(shapeNum == 4) { @@ -452,71 +455,148 @@ public class XFLConverter { lineStyleCount++; } } - lastLineStyleCount = lineStyleCount; } - for (SHAPERECORD edge : shapeRecords) { - if (edge instanceof StyleChangeRecord) { - StyleChangeRecord scr = (StyleChangeRecord) edge; - if (scr.stateNewStyles) { - for (int f = 0; f < scr.fillStyles.fillStyles.length; f++) { - fillStylesStr.add(convertFillStyle(mat, characters, scr.fillStyles.fillStyles[f], shapeNum)); - } - } - } - } - boolean usedFillStyles[] = new boolean[fillStylesStr.size()]; - int fillStyleCount = 0; - lastFillStyleCount = 0; - if (fillStyles != null) { - lastFillStyleCount = fillStyles.fillStyles.length; - fillStyleCount += lastFillStyleCount; - } - for (SHAPERECORD edge : shapeRecords) { - if (edge instanceof StyleChangeRecord) { - StyleChangeRecord scr = (StyleChangeRecord) edge; - if (scr.stateNewStyles) { - lastFillStyleCount = scr.fillStyles.fillStyles.length; - fillStyleCount += lastFillStyleCount; - } - if (scr.stateFillStyle0 && scr.fillStyle0 > 0) { - usedFillStyles[fillStyleCount - lastFillStyleCount + scr.fillStyle0 - 1] = true; - } - if (scr.stateFillStyle1 && scr.fillStyle1 > 0) { - usedFillStyles[fillStyleCount - lastFillStyleCount + scr.fillStyle1 - 1] = true; - } - } - } + fillsStr += ""; + strokesStr += ""; - int mapPos = 0; - HashMap fillStylesMap = new HashMap<>(); - for (int f = 0; f < fillStyleCount; f++) { - if (usedFillStyles[f]) { - fillStylesMap.put(f, mapPos); - mapPos++; - fillsStr += ""; - fillsStr += fillStylesStr.get(f); - fillsStr += ""; - } + int layer = 1; + + if ((fillStyleCount > 0) || (lineStyleCount > 0)) { + currentLayer += ""; //color=\"#4FFF4F\" + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += fillsStr; + currentLayer += strokesStr; + currentLayer += ""; } + //edgesStr += ""; + + /*for (SHAPERECORD edge : shapeRecords) { + if (edge instanceof StyleChangeRecord) { + StyleChangeRecord scr = (StyleChangeRecord) edge; + if (scr.stateNewStyles) { + for (int f = 0; f < scr.fillStyles.fillStyles.length; f++) { + fillStylesStr.add(convertFillStyle(mat, characters, scr.fillStyles.fillStyles[f], shapeNum)); + } + } + } + } + boolean usedFillStyles[] = new boolean[fillStylesStr.size()]; + int fillStyleCount = 0; + lastFillStyleCount = 0; + if (fillStyles != null) { + lastFillStyleCount = fillStyles.fillStyles.length; + fillStyleCount += lastFillStyleCount; + } + for (SHAPERECORD edge : shapeRecords) { + if (edge instanceof StyleChangeRecord) { + StyleChangeRecord scr = (StyleChangeRecord) edge; + if (scr.stateNewStyles) { + lastFillStyleCount = scr.fillStyles.fillStyles.length; + fillStyleCount += lastFillStyleCount; + } + if (scr.stateFillStyle0 && scr.fillStyle0 > 0) { + usedFillStyles[fillStyleCount - lastFillStyleCount + scr.fillStyle0 - 1] = true; + } + if (scr.stateFillStyle1 && scr.fillStyle1 > 0) { + usedFillStyles[fillStyleCount - lastFillStyleCount + scr.fillStyle1 - 1] = true; + } + } + } + */ + /*int mapPos = 0; + HashMap fillStylesMap = new HashMap<>(); + for (int f = 0; f < fillStyleCount; f++) { + if (usedFillStyles[f]) { + fillStylesMap.put(f, mapPos); + mapPos++; + fillsStr += ""; + fillsStr += fillStylesStr.get(f); + fillsStr += ""; + } + }*/ int x = 0; int y = 0; + int startEdgeX = 0; + int startEdgeY = 0; + LINESTYLEARRAY actualLinestyles = lineStyles; int strokeStyleOrig = 0; fillStyleCount = fillStyles.fillStyles.length; - lastFillStyleCount = fillStyleCount; for (SHAPERECORD edge : shapeRecords) { if (edge instanceof StyleChangeRecord) { StyleChangeRecord scr = (StyleChangeRecord) edge; + boolean styleChange = false; + int lastFillStyle1 = fillStyle1; + int lastFillStyle0 = fillStyle0; + int lastStrokeStyle = strokeStyle; if (scr.stateNewStyles) { - /*for (int f = 0; f < scr.fillStyles.fillStyles.length; f++) { - //fillsStr += ""; - fillStylesStr.add(convertFillStyle(mat, characters, scr.fillStyles.fillStyles[f], shapeNum)); - //fillsStr += ""; - //fillStyleCount++; - }*/ + fillsStr = ""; + strokesStr = ""; + if (fillStyleCount > 0) { + + if ((fillStyle0 > 0) || (fillStyle1 > 0) || (strokeStyle > 0)) { + + boolean empty = false; + if ((fillStyle0 <= 0) && (fillStyle1 <= 0) && (strokeStyle > 0) && morphshape) { + if (shapeNum == 4) { + if (strokeStyleOrig > 0) { + if (!actualLinestyles.lineStyles2[strokeStyleOrig].hasFillFlag) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.alpha == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.red == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.green == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.blue == 0) { + empty = true; + } + } + } + } + } + } + } + } + if (!empty) { + currentLayer += " -1) { + currentLayer += " fillStyle0=\"" + fillStyle0 + "\""; + } + if (fillStyle1 > -1) { + currentLayer += " fillStyle1=\"" + fillStyle1 + "\""; + } + if (strokeStyle > -1) { + currentLayer += " strokeStyle=\"" + strokeStyle + "\""; + } + currentLayer += " edges=\"" + convertShapeEdges(startEdgeX, startEdgeY, mat, edges) + "\" />"; + } + } + + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + layers.add(currentLayer); + currentLayer = ""; + } + + currentLayer += ""; //color=\"#4FFF4F\" + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + //ret += convertShape(characters, null, shape); + for (int f = 0; f < scr.fillStyles.fillStyles.length; f++) { + fillsStr += ""; + fillsStr += convertFillStyle(mat, characters, scr.fillStyles.fillStyles[f], shapeNum); + fillsStr += ""; + fillStyleCount++; + } if (shapeNum == 4) { for (int l = 0; l < scr.lineStyles.lineStyles2.length; l++) { @@ -533,41 +613,49 @@ public class XFLConverter { lineStyleCount++; } } - lastFillStyleCount = scr.fillStyles.fillStyles.length; - fillStyleCount += lastFillStyleCount; - lastLineStyleCount = (shapeNum == 4) ? scr.lineStyles.lineStyles2.length : scr.lineStyles.lineStyles.length; + fillsStr += ""; + strokesStr += ""; + currentLayer += fillsStr; + currentLayer += strokesStr; + currentLayer += ""; + //lastFillStyleCount = scr.fillStyles.fillStyles.length; + //fillStyleCount += lastFillStyleCount; + //lastLineStyleCount = (shapeNum == 4) ? scr.lineStyles.lineStyles2.length : scr.lineStyles.lineStyles.length; actualLinestyles = scr.lineStyles; } if (scr.stateFillStyle0) { /*edgeStyle += " fillStyle0=\""; edgeStyle += fillStyleCount - lastFillStyleCount + scr.fillStyle0; edgeStyle += "\"";*/ - int fillStyle0_new = scr.fillStyle0 == 0 ? 0 : fillStylesMap.get(fillStyleCount - lastFillStyleCount + scr.fillStyle0 - 1) + 1; + int fillStyle0_new = scr.fillStyle0;// == 0 ? 0 : fillStylesMap.get(fillStyleCount - lastFillStyleCount + scr.fillStyle0 - 1) + 1; //fillStyle0 = fillStyle0_new; if (morphshape) { //??? fillStyle1 = fillStyle0_new; } else { fillStyle0 = fillStyle0_new; } + styleChange = true; } if (scr.stateFillStyle1) { /*edgeStyle += " fillStyle1=\""; edgeStyle += fillStyleCount - lastFillStyleCount + scr.fillStyle1; edgeStyle += "\"";*/ - int fillStyle1_new = scr.fillStyle1 == 0 ? 0 : fillStylesMap.get(fillStyleCount - lastFillStyleCount + scr.fillStyle1 - 1) + 1; + int fillStyle1_new = scr.fillStyle1;// == 0 ? 0 : fillStylesMap.get(fillStyleCount - lastFillStyleCount + scr.fillStyle1 - 1) + 1; if (morphshape) { fillStyle0 = fillStyle1_new; } else { fillStyle1 = fillStyle1_new; } //fillStyle1 = fillStyle1_new; + styleChange = true; } if (scr.stateLineStyle) { /*edgeStyle += " strokeStyle=\""; edgeStyle += lineStyleCount - lastLineStyleCount + scr.lineStyle; edgeStyle += "\"";*/ - strokeStyle = scr.lineStyle == 0 ? 0 : lineStyleCount - lastLineStyleCount + scr.lineStyle; + strokeStyle = scr.lineStyle;// == 0 ? 0 : lineStyleCount - lastLineStyleCount + scr.lineStyle; strokeStyleOrig = scr.lineStyle - 1; + styleChange = true; } if (!edges.isEmpty()) { if ((fillStyle0 > 0) || (fillStyle1 > 0) || (strokeStyle > 0)) { @@ -575,37 +663,40 @@ public class XFLConverter { boolean empty = false; if ((fillStyle0 <= 0) && (fillStyle1 <= 0) && (strokeStyle > 0) && morphshape) { if (shapeNum == 4) { - - if (!actualLinestyles.lineStyles2[strokeStyleOrig].hasFillFlag) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.alpha == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.red == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.green == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.blue == 0) { - empty = true; + if (strokeStyleOrig > 0) { + if (!actualLinestyles.lineStyles2[strokeStyleOrig].hasFillFlag) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.alpha == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.red == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.green == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.blue == 0) { + empty = true; + } } } } } } } - if (!empty) { - edgesStr += " -1) { - edgesStr += " fillStyle0=\"" + fillStyle0 + "\""; - } - if (fillStyle1 > -1) { - edgesStr += " fillStyle1=\"" + fillStyle1 + "\""; - } - if (strokeStyle > -1) { - edgesStr += " strokeStyle=\"" + strokeStyle + "\""; - } - edgesStr += " edges=\"" + convertShapeEdges(x, y, mat, edges) + "\" />"; - } } - edgeStyle = ""; - strokeStyle = -1; - fillStyle0 = -1; - fillStyle1 = -1; + if (!empty) { + currentLayer += " -1) { + currentLayer += " fillStyle0=\"" + lastFillStyle0 + "\""; + } + if (fillStyle1 > -1) { + currentLayer += " fillStyle1=\"" + lastFillStyle1 + "\""; + } + if (strokeStyle > -1) { + currentLayer += " strokeStyle=\"" + lastStrokeStyle + "\""; + } + currentLayer += " edges=\"" + convertShapeEdges(startEdgeX, startEdgeY, mat, edges) + "\" />"; + } + + startEdgeX = x; + startEdgeY = y; + //strokeStyle = -1; + //fillStyle0 = -1; + //fillStyle1 = -1; } edges.clear(); } @@ -620,12 +711,14 @@ public class XFLConverter { boolean empty = false; if ((fillStyle0 <= 0) && (fillStyle1 <= 0) && (strokeStyle > 0) && morphshape) { if (shapeNum == 4) { - if (!actualLinestyles.lineStyles2[strokeStyleOrig].hasFillFlag) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.alpha == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.red == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.green == 0) { - if (actualLinestyles.lineStyles2[strokeStyleOrig].color.blue == 0) { - empty = true; + if (strokeStyleOrig > 0) { + if (!actualLinestyles.lineStyles2[strokeStyleOrig].hasFillFlag) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.alpha == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.red == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.green == 0) { + if (actualLinestyles.lineStyles2[strokeStyleOrig].color.blue == 0) { + empty = true; + } } } } @@ -634,34 +727,33 @@ public class XFLConverter { } } if (!empty) { - edgesStr += " -1) { - edgesStr += " fillStyle0=\"" + fillStyle0 + "\""; + currentLayer += " fillStyle0=\"" + fillStyle0 + "\""; } if (fillStyle1 > -1) { - edgesStr += " fillStyle1=\"" + fillStyle1 + "\""; + currentLayer += " fillStyle1=\"" + fillStyle1 + "\""; } if (strokeStyle > -1) { - edgesStr += " strokeStyle=\"" + strokeStyle + "\""; + currentLayer += " strokeStyle=\"" + strokeStyle + "\""; } - edgesStr += " edges=\"" + convertShapeEdges(x, y, mat, edges) + "\" />"; + currentLayer += " edges=\"" + convertShapeEdges(startEdgeX, startEdgeY, mat, edges) + "\" />"; } } - edgeStyle = ""; } edges.clear(); fillsStr += ""; strokesStr += ""; - edgesStr += ""; - - ret += ""; - /*ret+=""; - ret+=convertMatrix(mat); - ret+="";*/ - ret += fillsStr; - ret += strokesStr; - ret += edgesStr; - ret += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + currentLayer += ""; + layers.add(currentLayer); + for (int l = layers.size() - 1; l >= 0; l--) { + ret += layers.get(l); + } return ret; } @@ -683,6 +775,9 @@ public class XFLConverter { } private static List getOneInstanceShapes(List tags, HashMap characters) { + if (true) { //the feature was removed due to multiple layers in some shapes + return new ArrayList<>(); + } HashMap usages = new HashMap<>(); for (Tag t : tags) { if (t instanceof PlaceObjectTypeTag) { @@ -1262,15 +1357,7 @@ public class XFLConverter { ShapeTag shape = (ShapeTag) symbol; symbolStr += ""; symbolStr += ""; - symbolStr += ""; //color=\"#4FFF4F\" - symbolStr += ""; - symbolStr += ""; - symbolStr += ""; symbolStr += convertShape(characters, null, shape); - symbolStr += ""; - symbolStr += ""; - symbolStr += ""; - symbolStr += ""; symbolStr += ""; symbolStr += ""; } @@ -1539,6 +1626,7 @@ public class XFLConverter { transformer.transform(xmlInput, xmlOutput); return xmlOutput.getWriter().toString(); } catch (Exception e) { + System.err.println(input); Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, "Pretty print error", e); return input; }