Clone in a terminal:
Commit 3f9feec
Johan Mattsson - 2012-12-23T20:35:59+00:00
3f9feecf6faa7ab9d9fb26f66203749374425b21johan.mattsson.m@gmail.com

parse svg files

Changed files (6)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex f0bae42..6b9c566 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -297,7 +297,13 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		Gtk.MenuItem export_svg_item = new Gtk.MenuItem.with_mnemonic (_("_Export glyph as SVG")); 		edit_menu.append (export_svg_item); 		export_svg_item.activate.connect (() => { ExportTool.export_current_glyph (); });	-				+	+		if (Supplement.experimental) {+			Gtk.MenuItem import_svg_item = new Gtk.MenuItem.with_mnemonic (_("_Import SVG"));+			edit_menu.append (import_svg_item);+			import_svg_item.activate.connect (() => { ImportSvg.import (); });	+		}+		 		// Tab 		Gtk.MenuItem next_tab_item = new Gtk.MenuItem.with_mnemonic (_("_Next tab")); 		tab_menu.append (next_tab_item);diff --git a/dodo.py b/dodo.pyindex 628f8f8..bc195bf 100644--- a/dodo.py+++ b/dodo.py@@ -30,6 +30,7 @@ LIBS = [     ]  + def task_build ():     if not os.path.exists ("build/configured"):         print ("Project is not configured")@@ -106,3 +107,4 @@ def task_distclean ():     return  {         'actions': ['rm -rf build dodo.pyc libbirdfont/Config.vala'],         }+diff --git a/libbirdfont/ExportTool.vala b/libbirdfont/ExportTool.valaindex 3e22314..5b8066b 100644--- a/libbirdfont/ExportTool.vala+++ b/libbirdfont/ExportTool.vala@@ -101,8 +101,7 @@ public class ExportTool : Tool { 			os.put_string (@"style=\"fill:#000000;stroke-width:0px\" "); 			os.put_string (@"d=\"$(glyph_svg)\" id=\"path_$(name)$(pid++)\" />\n"); 		-			os.put_string ("""</g>-			+			os.put_string ("""</g>			 </svg>"""); 	 		} catch (Error e) {diff --git a/libbirdfont/ImportSvg.vala b/libbirdfont/ImportSvg.valanew file mode 100644index 0000000..3da51b9--- /dev/null+++ b/libbirdfont/ImportSvg.vala@@ -0,0 +1,96 @@+/*+    Copyright (C) 2012 Johan Mattsson++    This program is free software: you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation, either version 3 of the License, or+    (at your option) any later version.++    This program is distributed in the hope that it will be useful,+    but WITHOUT ANY WARRANTY; without even the implied warranty of+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+    GNU General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with this program.  If not, see <http://www.gnu.org/licenses/>.+*/+using Xml;++namespace Supplement {+	+public class ImportSvg {+	public ImportSvg () {+	}+	+	public static void import () {+		Xml.Doc* doc;+		Xml.Node* root = null;+		Xml.Node* node;+		string? p;+		string path;+		+		p = MainWindow.file_chooser ("Import");++		if (p == null) {+			return;+		}++		path = (!) p;++		Parser.init ();++		doc = Parser.parse_file (path);+		root = doc->get_root_element ();+				+		if (root == null) {+			delete doc;+			return;+		}++		node = root;+		+		for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {+			if (iter->name == "g") {+				parse_layer (iter);+			}+		}+				+		delete doc;+		Parser.cleanup ();				+	}+	+	private static void parse_layer (Xml.Node* node) {+		string attr_name = "";+		string attr_content;+		+		return_if_fail (node != null);+				+		for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {+			if (iter->name == "path") {+				parse_path (iter);+			}+		}+	}+	+	private static void parse_path (Xml.Node* node) {+		string attr_name = "";+		string attr_content;+		+		for (Xml.Attr* prop = node->properties; prop != null; prop = prop->next) {+			attr_name = prop->name;+			attr_content = prop->children->content;+			+			if (attr_name == "d") {+				parse_svg_data (attr_content);+			}+		}+	}+	+	private static void parse_svg_data (string data) {+	}+	+	static void parse_c (string[] data, int index, Path p, double posx, double posy) {+	}+}++}diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 6c27d01..ad7494c 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -58,7 +58,7 @@ public class Path { 	private static ImageSurface? selected_edit_point_image = null; 	private static ImageSurface? active_selected_edit_point_image = null; 	-	Path quadratic_path; // quadratic points for ttf export+	Path quadratic_path; // quadratic points for TrueType export 	 	public Path () { 		if (edit_point_image == null) {diff --git a/libbirdfont/Supplement.vala b/libbirdfont/Supplement.valaindex 2a5a290..f82f508 100644--- a/libbirdfont/Supplement.vala+++ b/libbirdfont/Supplement.vala@@ -24,7 +24,7 @@ namespace Supplement { 
 public class Supplement {
 	public static Argument args;
-	internal static bool experimental = false;
+	public static bool experimental = false;
 	internal static bool show_coordinates = false;
 	internal static bool fatal_wanings = false;
 	public static bool win32 = false;

Contact

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