Clone in a terminal:
Commit 982c80b
Johan Mattsson - 2016-11-29T19:07:59+00:00
982c80b242a2627ee7d38e48ed533247e11e8c9fjohan.mattsson.m@gmail.com

Transform paths in SVG to BF conversion

Changed files (4)

Diff

diff --git a/libbirdfont/EmbeddedSvg.vala b/libbirdfont/EmbeddedSvg.valaindex 872c85f..6cfe4ab 100644--- a/libbirdfont/EmbeddedSvg.vala+++ b/libbirdfont/EmbeddedSvg.vala@@ -90,7 +90,7 @@ public class EmbeddedSvg : SvgBird.Object { 		svg.append ("""<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">"""); 		svg.append ("\n"); 		-		string transforms = transforms.get_xml ();+		string transforms = drawing.transforms.get_xml (); 		 		if (transforms != "") { 			svg.append ("<g");diff --git a/libbirdfont/SvgParser.vala b/libbirdfont/SvgParser.valaindex 15611ef..ff0217c 100644--- a/libbirdfont/SvgParser.vala+++ b/libbirdfont/SvgParser.vala@@ -162,6 +162,7 @@ public class SvgParser {  		// parse the file 		if (!has_format) {+			parser.set_format (SvgFormat.ILLUSTRATOR); 			warn_if_test ("No format identifier found in SVG parser.\n"); 		} @@ -226,7 +227,6 @@ public class SvgParser { 		} 	 		foreach (XmlElement t in tag) {-			 			if (t.get_name () == "g") { 				parse_layer (t, pl); 			}@@ -269,13 +269,11 @@ public class SvgParser { 		} 		 		PathList paths = LayerUtils.get_all_paths (pl);- 		ViewBox? box = SvgFile.parse_view_box (tag);+		 		if (box != null) { 			ViewBox view_box = (!) box;-			Cairo.Matrix matrix = Cairo.Matrix.identity ();-			Cairo.Matrix view_box_matrix = view_box.get_matrix (width, height);-			view_box_matrix.multiply (view_box_matrix, matrix);+			Matrix view_box_matrix = view_box.get_matrix (width, height); 			SvgTransform t = new SvgTransform.for_matrix (view_box_matrix); 			SvgTransforms transforms = new SvgTransforms (); 			transforms.add (t);@@ -347,14 +345,7 @@ public class SvgParser { 			} 		} 		-		PathList paths = new PathList ();-		-		foreach (SvgBird.Object object in pl.objects) {-			if (object is Path) {-				paths.add ((Path) object);-			}-		}-		+		PathList paths = LayerUtils.get_all_paths (pl); 		SvgTransforms transforms = SvgFile.get_transform (tag.get_attributes ()); 		transform_paths (transforms, paths); 	}diff --git a/libsvgbird/SvgFile.vala b/libsvgbird/SvgFile.valaindex 0d49c2b..cc4c748 100644--- a/libsvgbird/SvgFile.vala+++ b/libsvgbird/SvgFile.vala@@ -101,8 +101,14 @@ public class SvgFile : GLib.Object { 		bool slice = true; 		bool preserve_aspect_ratio = true; 		+		if (tag.get_name () != "svg") {+			warning (@"viewBox is not the svg tag: $(tag.get_name ())");+			return null;+		}+		 		foreach (Attribute attribute in tag.get_attributes ()) { 			if (attribute.get_name () == "viewBox") {+				print (@"$(attribute.get_name ()): $(attribute.get_content ())\n"); 				parameters = attribute.get_content (); 			} 			@@ -123,6 +129,7 @@ public class SvgFile : GLib.Object { 			} 		} 		+		print (@"parameters: $parameters\n"); 		arguments = parameters.replace (",", " "); 		 		while (arguments.index_of ("  ") > -1) {@@ -131,8 +138,9 @@ public class SvgFile : GLib.Object { 		 		string[] view_box_parameters = arguments.split (" "); 		-		if (view_box_parameters.length != 4) {+		if (unlikely (view_box_parameters.length != 4)) { 			warning ("Expecting four arguments in view box.");+			warning (@"Content: $arguments ($parameters)"); 			return null; 		} diff --git a/libsvgbird/SvgTransforms.vala b/libsvgbird/SvgTransforms.valaindex cf6214c..c7407d7 100644--- a/libsvgbird/SvgTransforms.vala+++ b/libsvgbird/SvgTransforms.vala@@ -134,6 +134,10 @@ public class SvgTransforms : GLib.Object { 		return copy_transforms; 	} +	public void insert (int position, SvgTransform transform) {+		transforms.insert (position, transform);+	}+ 	public void add (SvgTransform transform) { 		transforms.add (transform); 	}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112