Clone in a terminal:
Commit ca5babd
Johan Mattsson - 2012-12-25T18:26:55+00:00
ca5babd358713ed11400ae51c669f346bf877e75johan.mattsson.m@gmail.com

paste svg from inkscape

Changed files (5)

Diff

diff --git a/README b/READMEindex 33cc3fc..7d6d267 100644--- a/README+++ b/README@@ -14,7 +14,7 @@ Building from source --------------------  Install vala and all required libraries, they are most likely in packages -with a -dev or -devel affix. You can run this as root if you are using Debian:+with a -dev or -devel affix. You can run this if you are using Debian:  sudo apt-get install valac python-doit libglib2.0-dev libgtk2.0-dev libxml2-dev libwebkitgtk-dev diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex b930cb2..b2e5758 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -39,12 +39,15 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	GlyphCanvasArea glyph_canvas_area; 	 	static List<uint> key_pressed = new List<uint> ();+	Clipboard clipboard; 	 	public GtkWindow (string title) { 		((Gtk.Window)this).set_title ("Birdfont"); 	} 	 	public void init () {+		clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD);+		 		margin_bottom = new DrawingArea (); 		margin_right = new DrawingArea (); 	@@ -228,7 +231,19 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		 		show_all (); 	}+	+	public string get_clipboard () {+		SelectionData selection_data;+		Atom target;+		target = Atom.intern_static_string ("image/svg+xml");+		selection_data = clipboard.wait_for_contents (target);+		return (string) selection_data.data;+	} +	public void set_clipboard (string data) {+		clipboard.set_text (data, -1);+	}+	 	MenuBar create_menu () { 		MenuBar menubar = new MenuBar (); 		Gtk.Menu file_menu = new Gtk.Menu ();@@ -735,7 +750,7 @@ public class GlyphCanvasArea : DrawingArea  { 			 			glyph_canvas.current_display.button_release (2, e.x, e.y); 			return true;-		});		+		}); 	}  	static void set_modifier (int k) {diff --git a/libbirdfont/ClipTool.vala b/libbirdfont/ClipTool.valaindex 0472373..a56b9aa 100644--- a/libbirdfont/ClipTool.vala+++ b/libbirdfont/ClipTool.vala@@ -60,7 +60,9 @@ public class ClipTool : Tool { 		Glyph? destination = null; 		unichar new_char; 		Path inserted;+		string svg; 		+		// paste internal 		if (fd is OverView) { 			gc = overview.get_selected_char (); 			destination = font.get_glyph (gc);@@ -95,6 +97,12 @@ public class ClipTool : Tool { 			 			((!)destination).update_view (); 		}+		+		// paste from clipboard+		if (fd is Glyph) {+			svg = MainWindow.get_singleton ().native_window.get_clipboard ();+			ImportSvg.import_svg (svg);+		} 	}  }diff --git a/libbirdfont/ImportSvg.vala b/libbirdfont/ImportSvg.valaindex 30ee36b..14e50d4 100644--- a/libbirdfont/ImportSvg.vala+++ b/libbirdfont/ImportSvg.vala@@ -25,7 +25,6 @@ public class ImportSvg { 	public static void import () { 		Xml.Doc* doc; 		Xml.Node* root = null;-		Xml.Node* node; 		string? p; 		string path; 		@@ -34,11 +33,9 @@ public class ImportSvg { 		if (p == null) { 			return; 		}- 		path = (!) p;  		Parser.init ();- 		doc = Parser.parse_file (path); 		root = doc->get_root_element (); 				@@ -47,6 +44,35 @@ public class ImportSvg { 			return; 		} +		parse_svg_file (root);+				+		delete doc;+		Parser.cleanup ();+	}+	+	public static void import_svg (string data) {+		Xml.Doc* doc;+		Xml.Node* root = null;+		+		Parser.init ();+		+		doc = Parser.parse_doc (data);+		root = doc->get_root_element ();+				+		if (root == null) {+			delete doc;+			return;+		}++		parse_svg_file (root);		+		+		delete doc;+		Parser.cleanup ();+	}+	+	private static void parse_svg_file (Xml.Node* root) {+		Xml.Node* node;+		 		node = root; 		 		for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {@@ -57,10 +83,7 @@ public class ImportSvg { 			if (iter->name == "path") { 				parse_path (iter); 			}-		}-				-		delete doc;-		Parser.cleanup ();				+		}		 	} 	 	private static void parse_layer (Xml.Node* node) {diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex 3adf50b..00d460a 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -26,6 +26,9 @@ public interface NativeWindow : GLib.Object { 	 	public abstract void update_window_size (); +	public abstract string get_clipboard ();+	public abstract void set_clipboard (string data);+ 	protected void webkit_callback (string s) { 		FontDisplay fd = MainWindow.get_current_display (); 		fd.process_property (s);

Contact

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