svg import: miter limit, svg export: cap,join styles

This commit is contained in:
honfika@gmail.com
2015-12-26 11:48:15 +01:00
parent 06762009b7
commit 2db1205d6c
8 changed files with 40 additions and 10 deletions

View File

@@ -44,6 +44,8 @@ public class LineStyle {
public int joinStyle;
public boolean noClose;
public int miterLimitFactor;
public boolean hasFillFlag;
@@ -62,6 +64,7 @@ public class LineStyle {
startCapStyle = lineStyle2.startCapStyle;
endCapStyle = lineStyle2.endCapStyle;
joinStyle = lineStyle2.joinStyle;
noClose = lineStyle2.noClose;
miterLimitFactor = lineStyle2.miterLimitFactor;
hasFillFlag = lineStyle2.hasFillFlag;
fillType = lineStyle2.fillType == null ? null : new FillStyle(lineStyle2.fillType);

View File

@@ -184,7 +184,11 @@ public class BitmapExporter extends ShapeExporterBase {
}
@Override
public void endLines() {
public void endLines(boolean close) {
if (close) {
path.closePath();
}
finalizePath();
}

View File

@@ -179,7 +179,11 @@ public class CanvasShapeExporter extends ShapeExporterBase {
}
@Override
public void endLines() {
public void endLines(boolean close) {
if (close) {
pathData.append('Z').append(" ");
}
finalizePath();
}

View File

@@ -65,7 +65,11 @@ public abstract class DefaultSVGShapeExporter extends ShapeExporterBase {
}
@Override
public void endLines() {
public void endLines(boolean close) {
if (close) {
pathData.append("Z");
}
finalizePath();
}

View File

@@ -37,7 +37,7 @@ public interface IShapeExporter {
public void beginLines();
public void endLines();
public void endLines(boolean close);
public void beginFill(RGB color);

View File

@@ -77,7 +77,7 @@ public class PathExporter extends ShapeExporterBase {
}
@Override
public void endLines() {
public void endLines(boolean close) {
finalizePath();
}

View File

@@ -328,6 +328,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
int posY = Integer.MAX_VALUE;
int lineStyleIdx = Integer.MAX_VALUE;
if (path.size() > 0) {
boolean autoClose = true;
beginLines();
for (int i = 0; i < path.size(); i++) {
IEdge e = path.get(i);
@@ -348,7 +349,11 @@ public abstract class ShapeExporterBase implements IShapeExporter {
int joinStyle = LINESTYLE2.ROUND_JOIN;
int miterLimitFactor = 3;
boolean hasFillFlag = false;
autoClose = true;
if (lineStyle.isLineStyle2) {
if (lineStyle.noClose) {
autoClose = false;
}
if (lineStyle.noHScaleFlag && lineStyle.noVScaleFlag) {
scaleMode = "NONE";
} else if (lineStyle.noHScaleFlag) {
@@ -408,7 +413,8 @@ public abstract class ShapeExporterBase implements IShapeExporter {
posX = e.getToX();
posY = e.getToY();
}
endLines();
IEdge firstEdge = path.get(0);
endLines(autoClose && firstEdge.getFromX() == posX && firstEdge.getFromY() == posY);
}
}

View File

@@ -303,8 +303,14 @@ public class ShapeImporter {
scrStyle.lineStyle = 0;
shapes.shapeRecords.add(scrStyle);
for (PathCommand command : commands) {
LINESTYLE lineStyleObj = scrStyle.lineStyles.lineStyles.length < 1 ? null : scrStyle.lineStyles.lineStyles[0];
LINESTYLE2 lineStyle2Obj = null;
if (lineStyleObj instanceof LINESTYLE2) {
lineStyle2Obj = (LINESTYLE2) lineStyleObj;
lineStyle2Obj.noClose = true;
}
for (PathCommand command : commands) {
double x = x0;
double y = y0;
Point p;
@@ -341,6 +347,9 @@ public class ShapeImporter {
prevPoint = p;
serz.generalLineFlag = true;
shapes.shapeRecords.add(serz);
if (lineStyle2Obj != null) {
lineStyle2Obj.noClose = false;
}
break;
case 'L':
StraightEdgeRecord serl = new StraightEdgeRecord();
@@ -1245,7 +1254,7 @@ public class ShapeImporter {
scr.fillStyles.fillStyles[0].color = shapeNum >= 3 ? new RGBA(colorFill) : new RGB(colorFill);
scr.fillStyles.fillStyles[0].fillStyleType = FILLSTYLE.SOLID;
} else if (fill instanceof SvgGradient) {
//...aply in second step - applyStyleGradients
//...apply in second step - applyStyleGradients
}
scr.fillStyle1 = 1;
@@ -1260,7 +1269,7 @@ public class ShapeImporter {
Color lineColor = strokeFill.toColor();
scr.lineStyles.lineStyles = new LINESTYLE[1];
LINESTYLE lineStyle = shapeNum <= 3 ? new LINESTYLE() : new LINESTYLE2();;
LINESTYLE lineStyle = shapeNum <= 3 ? new LINESTYLE() : new LINESTYLE2();
lineStyle.color = shapeNum >= 3 ? new RGBA(lineColor) : new RGB(lineColor);
lineStyle.width = (int) Math.round(style.strokeWidth * SWF.unitDivisor);
SvgLineCap lineCap = style.strokeLineCap;
@@ -1277,7 +1286,7 @@ public class ShapeImporter {
: lineJoin == SvgLineJoin.ROUND ? LINESTYLE2.ROUND_JOIN
: lineJoin == SvgLineJoin.BEVEL ? LINESTYLE2.BEVEL_JOIN : 0;
lineStyle2.joinStyle = swfJoin;
lineStyle2.miterLimitFactor = (int) style.strokeMiterLimit;
lineStyle2.miterLimitFactor = (int) Math.round(style.strokeMiterLimit * 256);
} else {
if (lineCap != SvgLineCap.ROUND) {
showWarning("lineCapNotSupported", "LineCap style not supported in shape " + shapeNum);