|
60 | 60 | import java.io.File; |
61 | 61 | import java.io.IOException; |
62 | 62 | import java.io.StringReader; |
| 63 | +import java.net.URI; |
63 | 64 | import java.net.URL; |
64 | 65 | import java.util.ArrayList; |
65 | 66 | import java.util.HashMap; |
@@ -107,8 +108,6 @@ public class SvgImporter { |
107 | 108 |
|
108 | 109 | private double height; |
109 | 110 |
|
110 | | - private double unitRatio; |
111 | | - |
112 | 111 | /** |
113 | 112 | * Constructor. |
114 | 113 | * @param st Shape tag |
@@ -286,27 +285,20 @@ private Tag importSvg(Tag st, ShapeTag endShape, String svgXml, boolean fill) { |
286 | 285 | SvgStyle style = new SvgStyle(this, idMap, rootElement, cachedBitmaps); |
287 | 286 | Matrix transform = new Matrix(); |
288 | 287 |
|
289 | | - double ratioX = 1; |
290 | | - double ratioY = 1; |
291 | | - |
292 | 288 | if (fill) { |
293 | | - ratioX = rect.getWidth() / width; |
294 | | - ratioY = rect.getHeight() / height; |
| 289 | + double ratioX = rect.getWidth() / width; |
| 290 | + double ratioY = rect.getHeight() / height; |
295 | 291 | transform = Matrix.getScaleInstance(ratioX / SWF.unitDivisor, ratioY / SWF.unitDivisor); |
296 | 292 | transform.translate(origXmin / ratioX, origYmin / ratioY); |
297 | 293 | } |
298 | 294 |
|
299 | 295 | transform = transform.preConcatenate(Matrix.getTranslateInstance(-viewBox.x, -viewBox.y)); |
300 | 296 | 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)); |
306 | 300 | } |
307 | | - |
308 | | - this.unitRatio = (ratioX + ratioY) / 2; |
309 | | - |
| 301 | + |
310 | 302 | processSvgObject(idMap, shapeNum, shapes, rootElement, transform, style, morphShape, cachedBitmaps, false); |
311 | 303 | if (rootElement.hasAttribute("ffdec:objectType") |
312 | 304 | && "morphshape".equals(rootElement.getAttribute("ffdec:objectType")) |
@@ -343,14 +335,6 @@ && applyAnimation(rootElement)) { |
343 | 335 |
|
344 | 336 | return (Tag) st; |
345 | 337 | } |
346 | | - |
347 | | - /** |
348 | | - * Gets unit ratio. |
349 | | - * @return Ratio value |
350 | | - */ |
351 | | - public double getUnitRatio() { |
352 | | - return unitRatio; |
353 | | - } |
354 | 338 |
|
355 | 339 | /** |
356 | 340 | * Applies animation to the element. |
@@ -650,7 +634,7 @@ private void processCommands(int shapeNum, SHAPEWITHSTYLE shapes, List<PathComma |
650 | 634 | double x0 = 0; |
651 | 635 | double y0 = 0; |
652 | 636 |
|
653 | | - StyleChangeRecord scrStyle = getStyleChangeRecord(shapeNum, style, morphShape); |
| 637 | + StyleChangeRecord scrStyle = getStyleChangeRecord(shapeNum, style, morphShape, transform); |
654 | 638 | int fillStyle = morphShape ? scrStyle.fillStyle0 : scrStyle.fillStyle1; |
655 | 639 | int lineStyle = scrStyle.lineStyle; |
656 | 640 | scrStyle.stateFillStyle0 = true; |
@@ -1481,11 +1465,11 @@ public Rectangle2D.Double getViewBox() { |
1481 | 1465 | private static void svgTest(String name) throws IOException, InterruptedException { |
1482 | 1466 | System.err.println("running test " + name); |
1483 | 1467 | 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(); |
1485 | 1469 | byte[] svgData = Helper.readStream(svgUrl.openStream()); |
1486 | 1470 | Helper.writeFile(name + ".orig.svg", svgData); |
1487 | 1471 |
|
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(); |
1489 | 1473 | byte[] pngData = Helper.readStream(pngUrl.openStream()); |
1490 | 1474 | Helper.writeFile(name + ".orig.png", pngData); |
1491 | 1475 | } |
@@ -2001,7 +1985,7 @@ private void applyStyleGradients(RECT bounds, StyleChangeRecord scr, Matrix tran |
2001 | 1985 | } |
2002 | 1986 | } |
2003 | 1987 |
|
2004 | | - private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boolean morphShape) { |
| 1988 | + private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boolean morphShape, Matrix transform) { |
2005 | 1989 | StyleChangeRecord scr = new StyleChangeRecord(); |
2006 | 1990 |
|
2007 | 1991 | scr.stateNewStyles = true; |
@@ -2044,8 +2028,9 @@ private StyleChangeRecord getStyleChangeRecord(int shapeNum, SvgStyle style, boo |
2044 | 2028 | Color lineColor = strokeFill.toColor(); |
2045 | 2029 |
|
2046 | 2030 | 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)); |
2049 | 2034 | SvgLineCap lineCap = style.getStrokeLineCap(); |
2050 | 2035 | SvgLineJoin lineJoin = style.getStrokeLineJoin(); |
2051 | 2036 | if (lineStyle instanceof LINESTYLE2) { |
|
0 commit comments