Clone in a terminal:
Commit b7fc171
Johan Mattsson - 2013-01-29T23:39:53+00:00
b7fc171910e8a30e4389b14b2234aeb907d9e7fbjohan.mattsson.m@gmail.com

import svg file without libxml2

Changed files (2)

Diff

diff --git a/libbirdfont/ImportSvg.vala b/libbirdfont/ImportSvg.valaindex 90c3c75..88b43d2 100644--- a/libbirdfont/ImportSvg.vala+++ b/libbirdfont/ImportSvg.vala@@ -34,29 +34,55 @@ public class ImportSvg { 			return; 		} 		path = (!) p;--		Parser.init ();-		doc = Parser.parse_file (path);-		root = doc->get_root_element ();+		+		// FIXME: libxml2 (2.7.8) refuses to parse svg files created with Adobe Illustrator on +		// windows. This is a way around it.+		if (Supplement.win32) {+			File f = File.new_for_path (path);+			DataInputStream dis = new DataInputStream (f.read ());+			string xml_data;+			string? line;+			StringBuilder sb = new StringBuilder ();+			string svg;+			+			while ((line = dis.read_line (null)) != null) {+				sb.append ((!) line);+				sb.append ("\n");+			}+			+			xml_data = sb.str;+			+			foreach (string svg_data in xml_data.split ("d=\"")) {+				svg = svg_data.substring (0, svg_data.index_of ("\"")); 				-		if (root == null) {+				if (svg.has_prefix ("M")) {+					parse_svg_data (svg);+				}+			}+		} else {+			Parser.init ();+			doc = Parser.parse_file (path);+			root = doc->get_root_element ();+					+			if (root == null) {+				delete doc;+				return;+			}++			parse_svg_file (root);+					 			delete doc;-			return;+			Parser.cleanup (); 		}--		parse_svg_file (root);-				-		delete doc;-		Parser.cleanup (); 	} 	-	public static void import_svg (string data) {+	public static void import_svg (string file) { 		Xml.Doc* doc; 		Xml.Node* root = null; 		 		Parser.init (); 		-		doc = Parser.parse_doc (data);+		doc = Parser.parse_doc (file); 		root = doc->get_root_element (); 				 		if (root == null) {@@ -145,6 +171,8 @@ public class ImportSvg { 		data = data.replace ("z", " z "); 		data = data.replace ("-", " -"); 		data = data.replace ("\t", " ");+		data = data.replace ("\r\n", " ");+		data = data.replace ("\n", " "); 		 		while (data.index_of ("  ") > -1) { 			data = data.replace ("  ", " ");diff --git a/libbirdfont/Supplement.vala b/libbirdfont/Supplement.valaindex 53d892f..354115c 100644--- a/libbirdfont/Supplement.vala+++ b/libbirdfont/Supplement.vala@@ -226,8 +226,8 @@ public bool is_null (void* n) { 	return n == null;
 }
 
-public bool has_flag (uint32 a, uint32 b) {
-	return (a & b) > 0;
+public bool has_flag (uint32 flag, uint32 mask) {
+	return (flag & mask) > 0;
 }
 
 }

Contact

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