diff --git a/format/svg/SVGData.hx b/format/svg/SVGData.hx index 732b97b..0652e1c 100644 --- a/format/svg/SVGData.hx +++ b/format/svg/SVGData.hx @@ -37,6 +37,7 @@ class SVGData extends Group { private static var mURLMatch = ~/url\(('|"?)#(.*)\1\)/; private static var mRGBMatch = ~/rgb\s*\(\s*(\d+)\s*(%)?\s*,\s*(\d+)\s*(%)?\s*,\s*(\d+)\s*(%)?\s*\)/; private static var defaultFill = FillSolid(0x000000); + private static var tempMatrix = new Matrix(); public var height (default, null):Float; public var width (default, null):Float; @@ -121,7 +122,7 @@ class SVGData extends Group { } else if (mMatrixMatch.match (inTrans)) { - var m = new Matrix ( + tempMatrix.setTo ( Std.parseFloat (mMatrixMatch.matched (1)), Std.parseFloat (mMatrixMatch.matched (2)), Std.parseFloat (mMatrixMatch.matched (3)), @@ -130,14 +131,9 @@ class SVGData extends Group { Std.parseFloat (mMatrixMatch.matched (6)) ); - m.concat (ioMatrix); + tempMatrix.concat (ioMatrix); - ioMatrix.a = m.a; - ioMatrix.b = m.b; - ioMatrix.c = m.c; - ioMatrix.d = m.d; - ioMatrix.tx = m.tx; - ioMatrix.ty = m.ty; + ioMatrix.copyFrom (tempMatrix); scale = Math.sqrt (ioMatrix.a * ioMatrix.a + ioMatrix.c * ioMatrix.c); } else if (mRotationMatch.match (inTrans)) { @@ -358,31 +354,37 @@ class SVGData extends Group { } - private function getStyles (inNode:Xml, inPrevStyles:StringMap):StringMap { + private function getMatrix (inNode:Xml, inPrevMatrix:Matrix):Matrix { - if (!inNode.exists ("style")) - return inPrevStyles; - - var styles = new StringMap (); + var matrix = inPrevMatrix != null ? inPrevMatrix.clone () : new Matrix (); - if (inPrevStyles != null) { + if (inNode.exists ("transform")) { - for (s in inPrevStyles.keys ()) { - - styles.set (s, inPrevStyles.get (s)); - - } + applyTransform (matrix, inNode.get ("transform")); } - - var style = inNode.get ("style"); - var strings = mStyleSplit.split (style); - for (s in strings) { + return matrix; - if (mStyleValue.match (s)) { - - styles.set (mStyleValue.matched (1), mStyleValue.matched (2)); + } + + + private function getStyles (inNode:Xml, inPrevStyles:StringMap):StringMap { + + var styles = inPrevStyles != null ? inPrevStyles.copy() : new StringMap (); + + if (inNode.exists ("style")) { + + var style = inNode.get ("style"); + var strings = mStyleSplit.split (style); + + for (s in strings) { + + if (mStyleValue.match (s)) { + + styles.set (mStyleValue.matched (1), mStyleValue.matched (2)); + + } } @@ -513,14 +515,9 @@ class SVGData extends Group { } - public function loadGroup (g:Group, inG:Xml, matrix:Matrix, inStyles:StringMap ):Group { + public function loadGroup (g:Group, inG:Xml, inMatrix:Matrix, inStyles:StringMap ):Group { - if (inG.exists ("transform")) { - - matrix = matrix.clone (); - applyTransform (matrix, inG.get ("transform")); - - } + var matrix = getMatrix(inG, inMatrix); if (inG.exists ("inkscape:label")) { @@ -543,13 +540,11 @@ class SVGData extends Group { */ + if (inG.exists("opacity")) { var opacity = inG.get("opacity"); - if (styles == null) - styles = new StringMap(); - if (styles.exists("opacity")) opacity = Std.string( Std.parseFloat(opacity) * Std.parseFloat(styles.get("opacity")) ); @@ -558,10 +553,7 @@ class SVGData extends Group { } if (inG.exists("stroke")) { - var stroke = inG.get("stroke"); - - if (styles == null) - styles = new StringMap(); + var stroke = inG.get("stroke"); styles.set("stroke", stroke); @@ -570,9 +562,6 @@ class SVGData extends Group { var strokeWidth = inG.get("stroke-width"); - if (styles == null) - styles = new StringMap(); - styles.set("stroke-width", strokeWidth); } @@ -580,9 +569,6 @@ class SVGData extends Group { var fill = inG.get("fill"); - if (styles == null) - styles = new StringMap(); - styles.set("fill", fill); } @@ -656,14 +642,9 @@ class SVGData extends Group { } - public function loadPath (inPath:Xml, matrix:Matrix, inStyles:StringMap, inIsRect:Bool, inIsEllipse:Bool, inIsCircle:Bool=false):Path { + public function loadPath (inPath:Xml, inMatrix:Matrix, inStyles:StringMap, inIsRect:Bool, inIsEllipse:Bool, inIsCircle:Bool=false):Path { - if (inPath.exists ("transform")) { - - matrix = matrix.clone (); - applyTransform (matrix, inPath.get ("transform")); - - } + var matrix = getMatrix(inPath, inMatrix); var styles = getStyles (inPath, inStyles); var name = inPath.exists ("id") ? inPath.get ("id") : ""; @@ -764,15 +745,9 @@ class SVGData extends Group { } - public function loadText (inText:Xml, matrix:Matrix, inStyles:StringMap ):Text { - - if (inText.exists ("transform")) { - - matrix = matrix.clone (); - applyTransform (matrix, inText.get ("transform")); - - } + public function loadText (inText:Xml, inMatrix:Matrix, inStyles:StringMap ):Text { + var matrix = getMatrix(inText, inMatrix); var styles = getStyles (inText, inStyles); var text = new Text ();