Canvas export - double values without .0 on the end

This commit is contained in:
Jindra Petk
2014-05-01 18:24:46 +02:00
parent f87b101057
commit 902d855fc9
4 changed files with 35 additions and 18 deletions

View File

@@ -2276,12 +2276,12 @@ public final class SWF implements TreeItem, Timelined {
sb.append("\t\t\tctx = fctx;\r\n");
}
sb.append("\t\t\tctx.save();\r\n");
sb.append("\t\t\tctx.transform(").append(placeMatrix.scaleX).append(",");
sb.append(placeMatrix.rotateSkew0).append(",");
sb.append(placeMatrix.rotateSkew1).append(",");
sb.append(placeMatrix.scaleY).append(",");
sb.append(placeMatrix.translateX).append(",");
sb.append(placeMatrix.translateY);
sb.append("\t\t\tctx.transform(").append(Helper.doubleStr(placeMatrix.scaleX)).append(",");
sb.append(Helper.doubleStr(placeMatrix.rotateSkew0)).append(",");
sb.append(Helper.doubleStr(placeMatrix.rotateSkew1)).append(",");
sb.append(Helper.doubleStr(placeMatrix.scaleY)).append(",");
sb.append(Helper.doubleStr(placeMatrix.translateX)).append(",");
sb.append(Helper.doubleStr(placeMatrix.translateY));
sb.append(");\r\n");
sb.append("\t\t\t").append(getTypePrefix(character)).append(layer.characterId).append("(ctx,").append(f).append(",").append(layer.ratio < 0 ? 0 : layer.ratio).append(");\r\n");
sb.append("\t\t\tctx.restore();\r\n");

View File

@@ -511,7 +511,7 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase {
}
private String useRatioPos(double a, double b) {
return (a / unitDivisor) + "+ratio*(" + ((b - a) / unitDivisor) + ")/" + DefineMorphShapeTag.MAX_RATIO;
return Helper.doubleStr(a / unitDivisor) + "+ratio*(" + Helper.doubleStr((b - a) / unitDivisor) + ")/" + DefineMorphShapeTag.MAX_RATIO;
}
private String useRatioInt(int a, int b) {
@@ -519,7 +519,7 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase {
}
private String useRatioDouble(double a, double b) {
return "" + a + "+ratio*(" + ((b - a)) + ")/" + DefineMorphShapeTag.MAX_RATIO;
return "" + a + "+ratio*(" + (Helper.doubleStr(b - a)) + ")/" + DefineMorphShapeTag.MAX_RATIO;
}
public String getShapeData() {
@@ -529,4 +529,5 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase {
private String useRatioColor(RGB color, RGB colorEnd) {
return "\"rgba(\"+" + useRatioInt(color.red, colorEnd.red) + "+\",\"+" + useRatioInt(color.green, colorEnd.green) + "+\",\"+" + useRatioInt(color.blue, colorEnd.blue) + "+\",\"+((" + useRatioInt((color instanceof RGBA) ? ((RGBA) color).alpha : 255, (colorEnd instanceof RGBA) ? ((RGBA) colorEnd).alpha : 255) + ")/255)+\")\"";
}
}

View File

@@ -30,6 +30,7 @@ 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.Helper;
import com.jpexs.helpers.SerializableImage;
import java.awt.Color;
@@ -409,16 +410,16 @@ public class CanvasShapeExporter extends ShapeExporterBase {
x += deltaX;
y += deltaY;
pathData += "\tctx.moveTo("
+ (x / unitDivisor) + ","
+ (y / unitDivisor) + ");\r\n";
+ Helper.doubleStr(x / unitDivisor) + ","
+ Helper.doubleStr(y / unitDivisor) + ");\r\n";
}
@Override
public void lineTo(double x, double y) {
x += deltaX;
y += deltaY;
pathData += "\tctx.lineTo(" + (x / unitDivisor) + ","
+ (y / unitDivisor) + ");\r\n";
pathData += "\tctx.lineTo(" + Helper.doubleStr(x / unitDivisor) + ","
+ Helper.doubleStr(y / unitDivisor) + ");\r\n";
}
@Override
@@ -427,10 +428,10 @@ public class CanvasShapeExporter extends ShapeExporterBase {
anchorX += deltaX;
controlY += deltaY;
anchorY += deltaY;
pathData += "\tctx.quadraticCurveTo(" + (controlX / unitDivisor) + ","
+ (controlY / unitDivisor) + ","
+ (anchorX / unitDivisor) + ","
+ (anchorY / unitDivisor) + ");\r\n";
pathData += "\tctx.quadraticCurveTo(" + Helper.doubleStr(controlX / unitDivisor) + ","
+ Helper.doubleStr(controlY / unitDivisor) + ","
+ Helper.doubleStr(anchorX / unitDivisor) + ","
+ Helper.doubleStr(anchorY / unitDivisor) + ");\r\n";
}
protected void finalizePath() {
@@ -455,7 +456,7 @@ public class CanvasShapeExporter extends ShapeExporterBase {
preLineFillData += "\tctx.fillStyle=\"" + lineLastRadColor + "\";\r\n ctx.fill(\"evenodd\");\r\n";
}
preLineFillData += "\tctx.transform(" + lineFillMatrix.scaleX + "," + lineFillMatrix.rotateSkew0 + "," + lineFillMatrix.rotateSkew1 + "," + lineFillMatrix.scaleY + "," + lineFillMatrix.translateX + "," + lineFillMatrix.translateY + ");\r\n";
preLineFillData += "\tctx.transform(" + Helper.doubleStr(lineFillMatrix.scaleX) + "," + Helper.doubleStr(lineFillMatrix.rotateSkew0) + "," + Helper.doubleStr(lineFillMatrix.rotateSkew1) + "," + Helper.doubleStr(lineFillMatrix.scaleY) + "," + Helper.doubleStr(lineFillMatrix.translateX) + "," + Helper.doubleStr(lineFillMatrix.translateY) + ");\r\n";
lineFillData = preLineFillData + lineFillData;
lineFillData += "\tctx.fillRect(" + (-16384 - 32768 * lineRepeatCnt) + "," + (-16384 - 32768 * lineRepeatCnt) + "," + (2 * 16384 + 32768 * 2 * lineRepeatCnt) + "," + (2 * 16384 + 32768 * 2 * lineRepeatCnt) + ");\r\n";
@@ -484,7 +485,7 @@ public class CanvasShapeExporter extends ShapeExporterBase {
}
pathData += "\tctx.save();\r\n";
pathData += "\tctx.clip();\r\n";
pathData += "\tctx.transform(" + fillMatrix.scaleX + "," + fillMatrix.rotateSkew0 + "," + fillMatrix.rotateSkew1 + "," + fillMatrix.scaleY + "," + fillMatrix.translateX + "," + fillMatrix.translateY + ");\r\n";
pathData += "\tctx.transform(" + Helper.doubleStr(fillMatrix.scaleX) + "," + Helper.doubleStr(fillMatrix.rotateSkew0) + "," + Helper.doubleStr(fillMatrix.rotateSkew1) + "," + Helper.doubleStr(fillMatrix.scaleY) + "," + Helper.doubleStr(fillMatrix.translateX) + "," + Helper.doubleStr(fillMatrix.translateY) + ");\r\n";
pathData += fillData;
pathData += "\tctx.fillRect(" + (-16384 - 32768 * repeatCnt) + "," + (-16384 - 32768 * repeatCnt) + "," + (2 * 16384 + 32768 * 2 * repeatCnt) + "," + (2 * 16384 + 32768 * 2 * repeatCnt) + ");\r\n";
pathData += "\tctx.restore();\r\n";
@@ -515,4 +516,6 @@ public class CanvasShapeExporter extends ShapeExporterBase {
lineLastRadColor = null;
lineFillMatrix = null;
}
}

View File

@@ -851,4 +851,17 @@ public class Helper {
}
return area;
}
/**
* Formats double value (removes .0 from end)
* @param d
* @return String
*/
public static String doubleStr(double d){
String ret= ""+d;
if(ret.endsWith(".0")){
ret = ret.substring(0,ret.length()-2);
}
return ret;
}
}