Clone in a terminal:
Commit 89b4e54
Johan Mattsson - 2014-11-29T12:39:20+00:00
89b4e54ffeb1cb681e0d3dad9e8aa22540e40ce1johan.mattsson.m@gmail.com

Add new glyphs to the font when background images is assigned to a character

Changed files (6)

Diff

diff --git a/libbirdfont/BackgroundTab.vala b/libbirdfont/BackgroundTab.valaindex 0fce1d0..58a72b6 100644--- a/libbirdfont/BackgroundTab.vala+++ b/libbirdfont/BackgroundTab.vala@@ -52,6 +52,7 @@ public class BackgroundTab : Glyph { 		gc.add_glyph (this); 		canvas.set_current_glyph_collection (gc, false); 		DrawingTools.background_scale.set_tool_visibility (true);+		ZoomTool.zoom_full_background_image (); 	} 	 	public override void draw (WidgetAllocation allocation, Context cr) {diff --git a/libbirdfont/BackgroundTools.vala b/libbirdfont/BackgroundTools.valaindex 0b4866c..3b9f8e6 100644--- a/libbirdfont/BackgroundTools.vala+++ b/libbirdfont/BackgroundTools.vala@@ -101,20 +101,17 @@ public class BackgroundTools : ToolCollection  { 					((!) pgc).get_current ().set_background_image (null); 				}		 				-				bpl.selection.assigned_glyph = gc.get_name ();-				bpl.label = gc.get_name ();-				gc.get_current ().set_background_image (bpl.selection.image);-				-				if (bpl.selection.image != null) {-					((!) bpl.selection.image).center_in_glyph (gc.get_current ());-				}-				-				set_default_canvas ();-				ZoomTool.zoom_full_background_image ();+				set_new_background_image (gc, bpl);+			});+			+			gs.open_new_glyph_signal.connect ((character) => {+				GlyphCollection gc = gs.create_new_glyph (character);+				set_new_background_image (gc, bpl); 			}); 			 			if (!bpl.deleted) { 				GlyphCanvas.set_display (gs);+				Toolbox.set_toolbox_from_tab ("Overview"); 			}			 		}); 		@@ -133,8 +130,7 @@ public class BackgroundTools : ToolCollection  { 				if (gc != null) { 					((!) gc).get_current ().set_background_image (null); 				}-				-			+ 				parts.tool.remove (bpl); 				bpl.selection.parent_image.selections.remove (bpl.selection); 				MainWindow.get_toolbox ().update_expanders ();@@ -154,6 +150,19 @@ public class BackgroundTools : ToolCollection  { 		} 	} +	void set_new_background_image (GlyphCollection gc, BackgroundPartLabel bpl) {+		bpl.selection.assigned_glyph = gc.get_name ();+		bpl.label = gc.get_name ();+		gc.get_current ().set_background_image (bpl.selection.image);+		+		if (bpl.selection.image != null) {+			((!) bpl.selection.image).center_in_glyph (gc.get_current ());+		}+		+		set_default_canvas ();+		ZoomTool.zoom_full_background_image ();+	}+ 	public override Gee.ArrayList<Expander> get_expanders () { 		return expanders; 	}diff --git a/libbirdfont/KerningRange.vala b/libbirdfont/KerningRange.valaindex 09990a2..1ca8df1 100644--- a/libbirdfont/KerningRange.vala+++ b/libbirdfont/KerningRange.vala@@ -68,26 +68,31 @@ public class KerningRange : Tool { 		string new_range; 		string ch; 		-		glyph_range.parse_ranges (r);-		new_range = glyph_range.get_all_ranges ();-		-		malformed = false;-		-		for (int i = 0; i < glyph_range.get_length (); i++) {-			ch = glyph_range.get_char (i);+		try {+			glyph_range.parse_ranges (r);+			new_range = glyph_range.get_all_ranges ();+			+			malformed = false; 			-			foreach (string c in spacing.get_all_connections (ch)) {-				if (!glyph_range.has_character (c) && c != "" && c != "?") {-					new_range += " " + GlyphRange.serialize (c);+			for (int i = 0; i < glyph_range.get_length (); i++) {+				ch = glyph_range.get_char (i);+				+				foreach (string c in spacing.get_all_connections (ch)) {+					if (!glyph_range.has_character (c) && c != "" && c != "?") {+						new_range += " " + GlyphRange.serialize (c);+					}+				}+				+				if (!font.has_glyph (ch)) {+					malformed = true; 				} 			} 			-			if (!font.has_glyph (ch)) {-				malformed = true;-			}+			set_one_range (new_range);+		} catch (GLib.MarkupError e) {+			warning (e.message);+			malformed = true; 		}-		-		set_one_range (new_range); 	} 		 	private void set_one_range (string r) throws MarkupError {diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex a553dcd..7248a3b 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -78,31 +78,7 @@ public class OverView : FontDisplay { 			});  			this.open_new_glyph_signal.connect ((character) => {-				StringBuilder name = new StringBuilder ();-				TabBar tabs = MainWindow.get_tab_bar ();-				bool selected;-				Glyph glyph;-				GlyphCollection glyph_collection;-				GlyphCanvas canvas;-					-				name.append_unichar (character);-				selected = tabs.select_char (name.str);-						-				if (!selected) {-					glyph_collection = add_character_to_font (character);-					-					glyph = glyph_collection.get_current ();-					tabs.add_tab (glyph, true, glyph_collection);-					-					selected_items.add (glyph_collection);-					-					canvas = MainWindow.get_glyph_canvas ();-					canvas.set_current_glyph_collection (glyph_collection);-					-					set_initial_zoom ();-				}-				-				OverviewTools.update_overview_characterset ();+				create_new_glyph (character); 			}); 		} 		@@ -110,6 +86,37 @@ public class OverView : FontDisplay { 		reset_zoom (); 	} 	+	public GlyphCollection create_new_glyph (unichar character) {+		StringBuilder name = new StringBuilder ();+		TabBar tabs = MainWindow.get_tab_bar ();+		bool selected;+		Glyph glyph;+		GlyphCollection glyph_collection = MainWindow.get_current_glyph_collection ();+		GlyphCanvas canvas;+			+		name.append_unichar (character);+		selected = tabs.select_char (name.str);+				+		if (!selected) {+			glyph_collection = add_character_to_font (character);+			+			glyph = glyph_collection.get_current ();+			tabs.add_tab (glyph, true, glyph_collection);+			+			selected_items.add (glyph_collection);+			+			canvas = MainWindow.get_glyph_canvas ();+			canvas.set_current_glyph_collection (glyph_collection);+			+			set_initial_zoom ();+		} else {+			warning ("Glyph is already open");+		}+		+		OverviewTools.update_overview_characterset ();+		return glyph_collection;+	}+	 	public GlyphCollection add_empty_character_to_font (unichar character, bool unassigned, string name) { 		return add_character_to_font (character, true, unassigned); 	}diff --git a/libbirdfont/OverviewTools.vala b/libbirdfont/OverviewTools.valaindex aa0a3cc..e2bd6c5 100644--- a/libbirdfont/OverviewTools.vala+++ b/libbirdfont/OverviewTools.vala@@ -40,14 +40,14 @@ public class OverviewTools : ToolCollection  {  		zoom_bar = new ZoomBar (); 		zoom_bar.new_zoom.connect ((z) => {-			MainWindow.get_overview ().set_zoom (z);+			get_overview ().set_zoom (z); 		}); 		zoom_expander.add_tool (zoom_bar); 						 		all_glyphs = new LabelTool (t_("All Glyphs")); 		all_glyphs.has_counter = true; 		all_glyphs.select_action.connect ((self) => {-			OverView overview = MainWindow.get_overview ();+			OverView overview = get_overview (); 			overview.display_all_available_glyphs (); 			update_overview_characterset (); 		});@@ -56,7 +56,7 @@ public class OverviewTools : ToolCollection  { 		default_glyphs = new LabelTool (t_("Default")); 		default_glyphs.has_counter = true; 		default_glyphs.select_action.connect ((self) => {-			OverView overview = MainWindow.get_overview ();+			OverView overview = get_overview (); 			GlyphRange gr = new GlyphRange (); 			DefaultCharacterSet.use_default_range (gr); 			overview.set_glyph_range (gr);@@ -67,7 +67,7 @@ public class OverviewTools : ToolCollection  { 		unicode = new LabelTool (t_("Unicode")); 		unicode.has_counter = true; 		unicode.select_action.connect ((self) => {-			OverView overview = MainWindow.get_overview ();+			OverView overview = get_overview (); 			GlyphRange gr = new GlyphRange (); 			DefaultCharacterSet.use_full_unicode_range (gr); 			overview.set_glyph_range (gr);@@ -83,6 +83,18 @@ public class OverviewTools : ToolCollection  { 		expanders.add (character_sets); 	} 	+	public OverView get_overview () {+		FontDisplay fd = MainWindow.get_current_display ();+		+		if (fd is OverView || fd is GlyphSelection) {+			return (OverView) fd;+		}+		+		warning ("Current tab is not overview.");+		+		return new OverView ();+	}+	 	public static void show_all_available_characters () { 		all_glyphs.select_action (all_glyphs); 	}diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex c10af7a..2219d27 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -64,29 +64,31 @@ public class Toolbox : GLib.Object  { 		 		tab_bar.signal_tab_selected.connect ((tab) => { 			string tab_name = tab.get_display ().get_name ();-			-			if (tab_name == "Kerning") {-				current_set = kerning_tools;-			} else if (tab_name == "Preview") {-				current_set = preview_tools;-			} else if (tab_name == "Overview") {-				current_set = overview_tools;-			} else if (tab_name == "Backgrounds") {-				current_set = background_tools;-			} else if (tab.get_display () is Glyph) {-				current_set = drawing_tools;-			} else {-				current_set = new EmptySet ();-			} -		-			-			update_expanders ();-			redraw (0, 0, allocation_width, allocation_height);+			set_toolbox_from_tab (tab_name, tab); 		}); 		 		update_expanders (); 	} +	public static void set_toolbox_from_tab (string tab_name, Tab? t = null) {		+		if (tab_name == "Kerning") {+			current_set = (ToolCollection) kerning_tools;+		} else if (tab_name == "Preview") {+			current_set = (ToolCollection) preview_tools;+		} else if (tab_name == "Overview") {+			current_set = (ToolCollection) overview_tools;+		} else if (tab_name == "Backgrounds") {+			current_set = (ToolCollection) background_tools;+		} else if (t != null && ((!) t).get_display () is Glyph) {+			current_set = (ToolCollection) drawing_tools;+		} else {+			current_set = new EmptySet ();+		}+		+		MainWindow.get_toolbox ().update_expanders ();+		redraw_tool_box ();+	}+ 	public static Tool get_move_tool () { 		return DrawingTools.move_tool; 	}

Contact

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