Commit ca5babd
paste svg from inkscape
Changed files (5)
modifiedREADMEmodifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/ClipTool.valamodifiedlibbirdfont/ImportSvg.valamodifiedlibbirdfont/NativeWindow.vala
Diff
@@ -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 @@ -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) {@@ -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);+ } } }@@ -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) {@@ -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);