Skip to content

Commit b6a6506

Browse files
committed
Fixed2: SVG importer - improper stroke width when using width/height with viewBox
Updated deprecated URL constructors in SVG importer
1 parent 9cf8de8 commit b6a6506

1 file changed

Lines changed: 14 additions & 29 deletions

File tree

libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import java.io.File;
6161
import java.io.IOException;
6262
import java.io.StringReader;
63+
import java.net.URI;
6364
import java.net.URL;
6465
import java.util.ArrayList;
6566
import java.util.HashMap;
@@ -107,8 +108,6 @@ public class SvgImporter {
107108

108109
private double height;
109110

110-
private double unitRatio;
111-
112111
/**
113112
* Constructor.
114113
* @param st Shape tag
@@ -286,27 +285,20 @@ private Tag importSvg(Tag st, ShapeTag endShape, String svgXml, boolean fill) {
286285
SvgStyle style = new SvgStyle(this, idMap, rootElement, cachedBitmaps);
287286
Matrix transform = new Matrix();
288287

289-
double ratioX = 1;
290-
double ratioY = 1;
291-
292288
if (fill) {
293-
ratioX = rect.getWidth() / width;
294-
ratioY = rect.getHeight() / height;
289+
double ratioX = rect.getWidth() / width;
290+
double ratioY = rect.getHeight() / height;
295291
transform = Matrix.getScaleInstance(ratioX / SWF.unitDivisor, ratioY / SWF.unitDivisor);
296292
transform.translate(origXmin / ratioX, origYmin / ratioY);
297293
}
298294

299295
transform = transform.preConcatenate(Matrix.getTranslateInstance(-viewBox.x, -viewBox.y));
300296
if (viewBox.height != 0 && viewBox.width != 0) {
301-
double ratio2x = width / viewBox.width;
302-
double ratio2y = height / viewBox.height;
303-
ratioX *= ratio2x;
304-
ratioY *= ratio2y;
305-
transform = transform.preConcatenate(Matrix.getScaleInstance(ratio2x, ratio2y));
297+
double ratioX = width / viewBox.width;
298+
double ratioY = height / viewBox.height;
299+
transform = transform.preConcatenate(Matrix.getScaleInstance(ratioX, ratioY));
306300
}
307-
308-
this.unitRatio = (ratioX + ratioY) / 2;
309-
301+
310302
processSvgObject(idMap, shapeNum, shapes, rootElement, transform, style, morphShape, cachedBitmaps, false);
311303
if (rootElement.hasAttribute("ffdec:objectType")
312304
&& "morphshape".equals(rootElement.getAttribute("ffdec:objectType"))
@@ -343,14 +335,6 @@ && applyAnimation(rootElement)) {
343335

344336
return (Tag) st;
345337
}
346-
347-
/**
348-
* Gets unit ratio.
349-
* @return Ratio value
350-
*/
351-
public double getUnitRatio() {
352-
return unitRatio;
353-
}
354338

355339
/**
356340
* Applies animation to the element.
@@ -650,7 +634,7 @@ private void processCommands(int shapeNum, SHAPEWITHSTYLE shapes, List<PathComma
650634
double x0 = 0;
651635
double y0 = 0;
652636

653-
StyleChangeRecord scrStyle = getStyleChangeRecord(shapeNum, style, morphShape);
637+
StyleChangeRecord scrStyle = getStyleChangeRecord(shapeNum, style, morphShape, transform);
654638
int fillStyle = morphShape ? scrStyle.fillStyle0 : scrStyle.fillStyle1;
655639
int lineStyle = scrStyle.lineStyle;
656640
scrStyle.stateFillStyle0 = true;
@@ -1481,11 +1465,11 @@ public Rectangle2D.Double getViewBox() {
14811465
private static void svgTest(String name) throws IOException, InterruptedException {
14821466
System.err.println("running test " + name);
14831467
if (!new File(name + ".original.svg").exists()) {
1484-
URL svgUrl = new URL("http://www.w3.org/Graphics/SVG/Test/20061213/svggen/" + name + ".svg");
1468+
URL svgUrl = URI.create("http://www.w3.org/Graphics/SVG/Test/20061213/svggen/" + name + ".svg").toURL();
14851469
byte[] svgData = Helper.readStream(svgUrl.openStream());
14861470
Helper.writeFile(name + ".orig.svg", svgData);
14871471

1488-
URL pngUrl = new URL("http://www.w3.org/Graphics/SVG/Test/20061213/png/full-" + name + ".png");
1472+
URL pngUrl = URI.create("http://www.w3.org/Graphics/SVG/Test/20061213/png/full-" + name + ".png").toURL();
14891473
byte[] pngData = Helper.readStream(pngUrl.openStream());
14901474
Helper.writeFile(name + ".orig.png", pngData);
14911475
}
@@ -2001,7 +1985,7 @@ private void applyStyleGradients(RECT bounds, StyleChangeRecord scr, Matrix tran
20011985
}
20021986
}
20031987

2004-
private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boolean morphShape) {
1988+
private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boolean morphShape, Matrix transform) {
20051989
StyleChangeRecord scr = new StyleChangeRecord();
20061990

20071991
scr.stateNewStyles = true;
@@ -2044,8 +2028,9 @@ private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boo
20442028
Color lineColor = strokeFill.toColor();
20452029

20462030
ILINESTYLE lineStyle = shapeNum <= 3 ? new LINESTYLE() : new LINESTYLE2();
2047-
lineStyle.setColor(getRGB(shapeNum, lineColor));
2048-
lineStyle.setWidth((int) Math.round(style.getStrokeWidth() * this.unitRatio * SWF.unitDivisor));
2031+
lineStyle.setColor(getRGB(shapeNum, lineColor));
2032+
double scale = Math.max(transform.scaleX, transform.scaleY);
2033+
lineStyle.setWidth((int) Math.round(style.getStrokeWidth() * scale * SWF.unitDivisor));
20492034
SvgLineCap lineCap = style.getStrokeLineCap();
20502035
SvgLineJoin lineJoin = style.getStrokeLineJoin();
20512036
if (lineStyle instanceof LINESTYLE2) {

0 commit comments

Comments
 (0)