Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 36 additions & 61 deletions format/svg/SVGData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand All @@ -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)) {
Expand Down Expand Up @@ -358,31 +354,37 @@ class SVGData extends Group {
}


private function getStyles (inNode:Xml, inPrevStyles:StringMap<String>):StringMap <String> {
private function getMatrix (inNode:Xml, inPrevMatrix:Matrix):Matrix {

if (!inNode.exists ("style"))
return inPrevStyles;

var styles = new StringMap <String> ();
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<String>):StringMap <String> {

var styles = inPrevStyles != null ? inPrevStyles.copy() : new StringMap <String> ();

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));

}

}

Expand Down Expand Up @@ -513,14 +515,9 @@ class SVGData extends Group {
}


public function loadGroup (g:Group, inG:Xml, matrix:Matrix, inStyles:StringMap <String>):Group {
public function loadGroup (g:Group, inG:Xml, inMatrix:Matrix, inStyles:StringMap <String>):Group {

if (inG.exists ("transform")) {

matrix = matrix.clone ();
applyTransform (matrix, inG.get ("transform"));

}
var matrix = getMatrix(inG, inMatrix);

if (inG.exists ("inkscape:label")) {

Expand All @@ -543,13 +540,11 @@ class SVGData extends Group {
</g>
</g>
*/

if (inG.exists("opacity")) {

var opacity = inG.get("opacity");

if (styles == null)
styles = new StringMap<String>();

if (styles.exists("opacity"))
opacity = Std.string( Std.parseFloat(opacity) * Std.parseFloat(styles.get("opacity")) );

Expand All @@ -558,10 +553,7 @@ class SVGData extends Group {
}
if (inG.exists("stroke")) {

var stroke = inG.get("stroke");

if (styles == null)
styles = new StringMap<String>();
var stroke = inG.get("stroke");

styles.set("stroke", stroke);

Expand All @@ -570,19 +562,13 @@ class SVGData extends Group {

var strokeWidth = inG.get("stroke-width");

if (styles == null)
styles = new StringMap<String>();

styles.set("stroke-width", strokeWidth);

}
if (inG.exists("fill")) {

var fill = inG.get("fill");

if (styles == null)
styles = new StringMap<String>();

styles.set("fill", fill);

}
Expand Down Expand Up @@ -656,14 +642,9 @@ class SVGData extends Group {
}


public function loadPath (inPath:Xml, matrix:Matrix, inStyles:StringMap<String>, inIsRect:Bool, inIsEllipse:Bool, inIsCircle:Bool=false):Path {
public function loadPath (inPath:Xml, inMatrix:Matrix, inStyles:StringMap<String>, 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") : "";
Expand Down Expand Up @@ -764,15 +745,9 @@ class SVGData extends Group {
}


public function loadText (inText:Xml, matrix:Matrix, inStyles:StringMap <String>):Text {

if (inText.exists ("transform")) {

matrix = matrix.clone ();
applyTransform (matrix, inText.get ("transform"));

}
public function loadText (inText:Xml, inMatrix:Matrix, inStyles:StringMap <String>):Text {

var matrix = getMatrix(inText, inMatrix);
var styles = getStyles (inText, inStyles);
var text = new Text ();

Expand Down