Clone in a terminal:
Commit 92b92a6
Johan Mattsson - 2014-09-02T19:18:18+00:00
92b92a6f29d5f8938139739e1e1f8fe0fc1ac732johan.mattsson.m@gmail.com

Copy glyphs from overview to clipboard

Changed files (5)

Diff

diff --git a/libbirdfont/ClipTool.vala b/libbirdfont/ClipTool.valaindex bcf5a73..8e44de8 100644--- a/libbirdfont/ClipTool.vala+++ b/libbirdfont/ClipTool.vala@@ -31,7 +31,7 @@ public class ClipTool : Tool { 		} 		 		if (fd is OverView) {-			MainWindow.get_overview ().copy ();+			copy_overview_glyphs (); 		}			 	} @@ -42,13 +42,31 @@ public class ClipTool : Tool { 		string data; 			 		svg_data = ExportTool.export_to_inkscape_clipboard (glyph, false);-		bf_data = export_paths_to_birdfont_clipboard (glyph, false);+		bf_data = export_paths_to_birdfont_clipboard (false, false); 		 		data = svg_data + bf_data; 		MainWindow.native_window.set_clipboard (data); 		MainWindow.native_window.set_inkscape_clipboard (data);	 	} +	public static void copy_overview_glyphs () {+		string svg_data = "";+		string bf_data = "";+		string data;+		OverView o = MainWindow.get_overview ();+		+		if (o.selected_items.size > 0) {+			svg_data = ExportTool.export_to_inkscape_clipboard (+				o.selected_items.get (0).get_current (), false);++			bf_data = export_paths_to_birdfont_clipboard (true, false);+			+			data = svg_data + bf_data;+			MainWindow.native_window.set_clipboard (data);+			MainWindow.native_window.set_inkscape_clipboard (data);	+		}+	}+	 	public static void paste_in_place () { 		paste_paths (true); 	}@@ -78,7 +96,7 @@ public class ClipTool : Tool { 		} 		 		if (fd is OverView) {-			MainWindow.get_overview ().paste ();+			paste_to_overview (); 		}	 	} 	@@ -99,6 +117,12 @@ public class ClipTool : Tool { 		BirdFont.get_current_font ().touch (); 	} 	+	static void paste_to_overview () {+		string data = MainWindow.native_window.get_clipboard_data ();+		import_birdfont_clipboard (data, true, true);+		GlyphCanvas.redraw ();+	}+	 	static void paste_to_glyph (bool bf_clipboard_data, bool paste_guide_lines) { 		FontDisplay fd = MainWindow.get_current_display (); 		Glyph? destination = null;@@ -112,7 +136,7 @@ public class ClipTool : Tool { 		data = MainWindow.native_window.get_clipboard_data ();  		if (bf_clipboard_data) {-			import_birdfont_clipboard (data, paste_guide_lines);+			import_birdfont_clipboard (data, paste_guide_lines, false); 		} else if (data != "") { 			SvgParser.import_svg_data (data); 		}@@ -121,82 +145,117 @@ public class ClipTool : Tool { 	}  	static string export_selected_paths_to_birdfont_clipboard () {-		return export_paths_to_birdfont_clipboard (MainWindow.get_current_glyph (), true);+		return export_paths_to_birdfont_clipboard (false, true); 	} 	-	static string export_paths_to_birdfont_clipboard (Glyph glyph, bool selected = false) {+	static string export_paths_to_birdfont_clipboard (bool overview, bool selected = false) { 		StringBuilder s = new StringBuilder ();+		Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> (); 		Path new_path;-		List<Path> paths = new List<Path> ();+		Glyph glyph;+		OverView o; 		-		s.append ("\n");-		s.append ("<!-- BirdFontClipboard\n");+		if (overview) {+			o = MainWindow.get_overview ();+			foreach (GlyphCollection gc in o.selected_items) {+				s.append ("\n");+				s.append ("<!-- BirdFontClipboard\n"); -		s.append ("BF left: ");-		s.append (@"$(glyph.left_limit)");-		s.append ("\n");-		-		s.append ("BF right: ");-		s.append (@"$(glyph.right_limit)");-		s.append ("\n");-								-		if (!selected) {-			foreach (Path path in glyph.path_list) {-				s.append ("BF path: ");-				s.append (BirdFontFile.get_point_data (path));+				s.append ("BF glyph: ");+				s.append (@"$(Font.to_hex (gc.get_unicode_character ()))"); 				s.append ("\n");-			}-		} else if (glyph.path_list.size > 0) {-			foreach (Path path in glyph.active_paths) {-				s.append ("BF path: ");-				s.append (BirdFontFile.get_point_data (path));+				+				s.append ("BF left: ");+				s.append (@"$(gc.get_current ().left_limit)");+				s.append ("\n");+				+				s.append ("BF right: ");+				s.append (@"$(gc.get_current ().right_limit)"); 				s.append ("\n");++				foreach (Path path in gc.get_current ().path_list) {+					s.append ("BF path: ");+					s.append (BirdFontFile.get_point_data (path));+					s.append ("\n");+				}+				+				s.append ("BF end -->"); 			} 		} else {+			glyph = MainWindow.get_current_glyph ();+			+			s.append ("\n");+			s.append ("<!-- BirdFontClipboard\n");++			s.append ("BF glyph: ");+			s.append (@"$(Font.to_hex (glyph.unichar_code))");+			s.append ("\n");+			+			s.append ("BF left: ");+			s.append (@"$(glyph.left_limit)");+			s.append ("\n"); 			-			new_path = new Path ();-			foreach (Path path in glyph.path_list) {-				if (path.points.size > 0-					&& path.points.get (0).is_selected ()-					&& path.points.get (path.points.size - 1).is_selected ()) {+			s.append ("BF right: ");+			s.append (@"$(glyph.right_limit)");+			s.append ("\n");+									+			if (!selected) {+				foreach (Path path in glyph.path_list) {+					s.append ("BF path: ");+					s.append (BirdFontFile.get_point_data (path));+					s.append ("\n");+				}+			} else if (glyph.path_list.size > 0) {+				foreach (Path path in glyph.active_paths) {+					s.append ("BF path: ");+					s.append (BirdFontFile.get_point_data (path));+					s.append ("\n");+				}+			} else {+				new_path = new Path ();+				foreach (Path path in glyph.path_list) {+					if (path.points.size > 0+						&& path.points.get (0).is_selected ()+						&& path.points.get (path.points.size - 1).is_selected ()) {+						+						foreach (EditPoint ep in path.points) {+							if (!ep.is_selected ()) {+								path.set_new_start (ep);+								break;+							}	+						}+					} 					 					foreach (EditPoint ep in path.points) { 						if (!ep.is_selected ()) {-							path.set_new_start (ep);-							break;-						}	+							if (path.points.size > 0) {+								paths.add (new_path);+								new_path = new Path ();+							}+						} else {+							new_path.add_point (ep);+						}+					}++					if (all_points_selected (path)) {+						new_path.close (); 					} 				} 				-				foreach (EditPoint ep in path.points) {-					if (!ep.is_selected ()) {-						if (path.points.size > 0) {-							paths.append (new_path);-							new_path = new Path ();-						}-					} else {-						new_path.add_point (ep);+				paths.add (new_path);+				+				foreach (Path path in paths) {+					if (path.points.size > 0) {+						s.append ("BF path: ");+						s.append (BirdFontFile.get_point_data (path));+						s.append ("\n"); 					} 				}--				if (all_points_selected (path)) {-					new_path.close ();-				} 			} 			-			paths.append (new_path);-			-			foreach (Path path in paths) {-				if (path.points.size > 0) {-					s.append ("BF path: ");-					s.append (BirdFontFile.get_point_data (path));-					s.append ("\n");-				}-			}+			s.append ("-->"); 		} 		-		s.append ("-->");-		 		return s.str; 	} 	@@ -209,38 +268,74 @@ public class ClipTool : Tool { 		return true; 	} 	-	static void import_birdfont_clipboard (string data, bool paste_guide_lines) {-		Glyph glyph = MainWindow.get_current_glyph ();+	static void import_birdfont_clipboard (string data, bool paste_guide_lines, bool overview) {+		Gee.ArrayList<Glyph> glyphs = new Gee.ArrayList<Glyph> ();+		Glyph glyph = new Glyph ("null", '\0'); 		string[] items = data.split ("\nBF "); 		string d; 		int i;+		unichar c;+		Glyph destination;+		GlyphCollection gc;+		OverView o; 		 		foreach (string p in items) {+			if (p.has_prefix ("glyph:")) {+				p = p.replace ("glyph: ", "");+				p = p.replace ("\n", "");+				c = Font.to_unichar (p);+				glyph = new Glyph ((!) c.to_string (), c);+				glyphs.add (glyph);+			}+			 			if (p.has_prefix ("path:")) {-				i = p.index_of ("\n");-				if (i > -1) {-					p = p.substring (0, i);-				}-				d = p.replace ("path: ", "");-				import_birdfont_path (d);+				p = p.replace ("path: ", "");+				p = p.replace ("\n", "");+				import_birdfont_path (glyph, p); 			} 			-			if (paste_guide_lines && p.has_prefix ("left:")) {+			if (p.has_prefix ("left:")) { 				glyph.left_limit = double.parse (p.replace ("left: ", "")); 				glyph.remove_lines (); 				glyph.add_help_lines ();			 			} 			-			if (paste_guide_lines && p.has_prefix ("right:")) {+			if (p.has_prefix ("right:")) { 				glyph.right_limit = double.parse (p.replace ("right: ", "")); 				glyph.remove_lines (); 				glyph.add_help_lines ();	 			}-		}	+		}+		+		if (!overview) {+			return_if_fail (glyphs.size > 0);+			destination = MainWindow.get_current_glyph ();+			glyph = glyphs.get (0);+			foreach (Path p in glyph.path_list) {+				destination.add_path (p);+			}+			+			if (paste_guide_lines) {+				destination.left_limit = glyph.left_limit;+				destination.right_limit = glyph.right_limit;+				destination.update_other_spacing_classes ();+			}+		} else {+			o = MainWindow.get_overview ();+			o.copied_glyphs.clear ();+			foreach (Glyph g in glyphs) {+				+				print (@"g.unichar_code, g.name  $((!) g.unichar_code.to_string ()) $(g.name)\n");	+						+				gc = new GlyphCollection (g.unichar_code, g.name);+				gc.add_glyph (g);+				o.copied_glyphs.add (gc);+			}+			o.paste ();+		} 	} 	-	static void import_birdfont_path (string data) {-		Glyph glyph = MainWindow.get_current_glyph ();+	static void import_birdfont_path (Glyph glyph, string data) { 		Path path = BirdFontFile.parse_path_data (data);  		if (path.points.size > 0) {diff --git a/libbirdfont/DrawingTools.vala b/libbirdfont/DrawingTools.valaindex 71894e0..60c6522 100644--- a/libbirdfont/DrawingTools.vala+++ b/libbirdfont/DrawingTools.vala@@ -75,10 +75,10 @@ public class DrawingTools : ToolCollection  { 	Tool reflect_handle; 	Tool create_line; -	Tool delete_button +	Tool delete_button; 	public Tool inser_point_on_path_tool;-	Tool undo_tool-	Tool select_all_button+	Tool undo_tool;+	Tool select_all_button; 					 	public DrawingTools (GlyphCanvas main_glyph_canvas) { 		glyph_canvas = main_glyph_canvas;@@ -146,11 +146,11 @@ public class DrawingTools : ToolCollection  { 				 		// Tools on android 		// Delete key-		Tool delete_button = new Tool ("delete_button", t_("Delete"));+		delete_button = new Tool ("delete_button", t_("Delete")); 		delete_button.select_action.connect ((self) => { 			TabContent.key_press (Key.DEL); 		});-		key_tools.add_tool (delete_buton);+		key_tools.add_tool (delete_button); 		 		// Select all points or paths 		select_all_button = new Tool ("select_all", t_("Select all points or paths"));diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 0e7862a..dd958ee 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -45,7 +45,6 @@ public class Glyph : FontDisplay { 	double zoom_distance = 0; 	bool change_view;  -	 	bool ignore_input = false; 	 	// Current pointer positiondiff --git a/libbirdfont/GlyphCollection.vala b/libbirdfont/GlyphCollection.valaindex 0d7a549..75110c0 100644--- a/libbirdfont/GlyphCollection.vala+++ b/libbirdfont/GlyphCollection.vala@@ -28,6 +28,10 @@ public class GlyphCollection : GLib.Object { 		versions = new VersionList (null, this); 	} +	public void add_glyph (Glyph g) {+		get_version_list ().add_glyph (g);+	}+ 	public VersionList get_version_list () { 		return versions; 	}diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 24d3a0a..82f2636 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -22,8 +22,8 @@ public class OverView : FontDisplay { 	 	OverViewItem selected_item = new OverViewItem (null, '\0', 0, 0); -	Gee.ArrayList<GlyphCollection> copied_glyphs = new Gee.ArrayList<GlyphCollection> ();-	Gee.ArrayList<GlyphCollection> selected_items = new Gee.ArrayList<GlyphCollection> ();	+	public Gee.ArrayList<GlyphCollection> copied_glyphs = new Gee.ArrayList<GlyphCollection> ();+	public Gee.ArrayList<GlyphCollection> selected_items = new Gee.ArrayList<GlyphCollection> ();	 	 	int selected = 0; 	int first_visible = 0;@@ -1064,18 +1064,6 @@ public class OverView : FontDisplay { 		cr.restore ();		 	} 	-	public void copy () {-		copied_glyphs.clear ();-		-		foreach (GlyphCollection gc in selected_items) {-			copied_glyphs.add (gc.copy ());-		}-		-		if (copied_glyphs.size != 0) {-			ClipTool.copy_glyph (selected_items.get (copied_glyphs.size - 1).get_current ());-		}-	}-	 	public void paste () { 		GlyphCollection gc = new GlyphCollection ('\0', ""); 		GlyphCollection? c;@@ -1083,6 +1071,7 @@ public class OverView : FontDisplay { 		uint32 index; 		int i; 		int skip = 0;+		int s; 		string character_string; 		Gee.ArrayList<GlyphCollection> glyps = new Gee.ArrayList<GlyphCollection> (); 		Font f = BirdFont.get_current_font ();@@ -1116,9 +1105,10 @@ public class OverView : FontDisplay { 				gc = (!) c;  			} else {				 				if (i != 0) {-					skip = (int) copied_glyphs.get (i).get_unicode_character ();-					skip -= (int) copied_glyphs.get (i - 1).get_unicode_character ();-					skip -= 1;+					s = (int) copied_glyphs.get (i).get_unicode_character ();+					s -= (int) copied_glyphs.get (i - 1).get_unicode_character ();+					s -= 1;+					skip += s; 				} 				 				character_string = glyph_range.get_char ((uint32) (index + skip));

Contact

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