Clone in a terminal:
Commit 29358ae
Johan Mattsson - 2013-08-08T21:25:39+00:00
29358aed96702a7973225c29a60ebb94e2a07cc8johan.mattsson.m@gmail.com

use glyphs as backgrounds

Changed files (6)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 394a84d..6d2b30e 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -550,7 +550,15 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		edit_menu.append (glyph_sequence_item); 		glyph_sequence_item.activate.connect (() => { MainWindow.update_glyph_sequence (); }); 		glyph_sequence_item.add_accelerator ("activate", accel_group, 'Q', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);-		++		Gtk.MenuItem background_glyph_item = new Gtk.MenuItem.with_mnemonic (_("Set Glyph _Background"));+		edit_menu.append (background_glyph_item);+		background_glyph_item.activate.connect (() => { MenuTab.use_current_glyph_as_background (); });++		Gtk.MenuItem reset_background_glyph_item = new Gtk.MenuItem.with_mnemonic (_("Remove Glyph _Background"));+		edit_menu.append (reset_background_glyph_item);+		reset_background_glyph_item.activate.connect (() => { MenuTab.reset_glyph_background (); });+ 		edit_menu.append (new SeparatorMenuItem ());  		Gtk.MenuItem select_point_above = new Gtk.MenuItem.with_mnemonic (" Ctrl+↑  " + _("_Select Point Above"));diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 4715cc4..49a8479 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -85,6 +85,8 @@ public class Glyph : FontDisplay { 	bool ligature = false; 	string substitution = ""; 	+	public static Glyph? background_glyph = null;+	 	public Glyph (string name, unichar unichar_code = 0) { 		this.name = name; 		this.unichar_code = unichar_code;@@ -1355,7 +1357,10 @@ public class Glyph : FontDisplay { 		left = get_line ("left").pos; 		 		if (!is_open ()) {+			cr.save ();+			cr.set_source_rgba (0, 0, 0, 1); 			Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () + baseline);+			cr.restore (); 		} 		 		if (is_open ()) {@@ -1421,6 +1426,7 @@ public class Glyph : FontDisplay { 			((!)background_image).draw (cr, allocation, view_offset_x, view_offset_y, view_zoom); 		} 		+		draw_background_glyph (allocation, cr); 		juxtapose (allocation, cr);  		if (BirdFont.show_coordinates) {@@ -1599,8 +1605,10 @@ public class Glyph : FontDisplay { 		 		cr = new Context (img); 		+		cr.save ();+		cr.set_source_rgba (0, 0, 0, 1); 		Svg.draw_svg_path (cr, get_svg_data (), gx, gy);	-		+		cr.restore (); 		return img; 	} @@ -1704,7 +1712,7 @@ public class Glyph : FontDisplay { 		 		return false; 	}-+	 	public void juxtapose (WidgetAllocation allocation, Context cr) { 		string glyph_sequence = Preferences.get ("glyph_sequence"); 		unichar c;@@ -1743,6 +1751,7 @@ public class Glyph : FontDisplay { 				cr.save (); 				cr.scale (glyph.view_zoom, glyph.view_zoom); 				cr.translate (-glyph.view_offset_x, -glyph.view_offset_y);+				cr.set_source_rgba (0, 0, 0, 1); 				Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x + kern, Glyph.yc () + baseline); 				cr.restore (); 			}@@ -1771,7 +1780,7 @@ public class Glyph : FontDisplay { 				cr.save (); 				cr.scale (glyph.view_zoom, glyph.view_zoom); 				cr.translate (-glyph.view_offset_x, -glyph.view_offset_y);-+				cr.set_source_rgba (0, 0, 0, 1); 				Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x, Glyph.yc () + baseline); 				cr.restore (); 			}@@ -1779,6 +1788,29 @@ public class Glyph : FontDisplay { 			last_name = name; 		}	 	}+	+	void draw_background_glyph (WidgetAllocation allocation, Context cr) {+		double left, baseline, current_baseline, current_left;+		Glyph g;+		+		current_baseline = get_line ("baseline").pos;+		current_left = get_line ("left").pos;+		+		if (background_glyph != null) {+			g = (!) background_glyph;+			baseline = get_line ("baseline").pos;+			left = g.get_line ("left").pos;+			cr.save ();+			cr.scale (view_zoom, view_zoom);+			cr.translate (-view_offset_x, -view_offset_y);+			cr.set_source_rgba (0.2, 0.2, 0.2, 0.5);+			Svg.draw_svg_path (cr, g.get_svg_data (), +				Glyph.xc () + left - (left - current_left) , +				Glyph.yc () + baseline - (current_baseline - baseline));+			cr.restore ();+		}+		+	} }  }diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex 7a3e6f9..e6cb174 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -512,5 +512,17 @@ c.append (""" 	public static void select_language () { 		MainWindow.get_tab_bar ().add_unique_tab (new LanguageSelectionTab (), 120, false); 	}++	public static void use_current_glyph_as_background () {+		Glyph.background_glyph = MainWindow.get_current_glyph ();+		+		if (MainWindow.get_current_display () is OverView) {+			Glyph.background_glyph = MainWindow.get_overview ().get_current_glyph ();+		}+	}+	+	public static void reset_glyph_background () {+		Glyph.background_glyph = null;+	} } }diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex a315d4c..f8b57ff 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -102,6 +102,15 @@ public class OverView : FontDisplay { 		update_scrollbar (); 	} 	+	public Glyph? get_current_glyph () +	requires (selected > 0 && selected < visible_items.length ()) {+		OverViewItem oi = visible_items.nth (selected).data;+		if (oi.glyphs != null) {+			return ((!) oi.glyphs).get_current ();+		}+		return null;+	}+	 	private void set_initial_zoom () { 		Toolbox tools = MainWindow.get_toolbox (); 		ZoomTool z = (ZoomTool) tools.get_tool ("zoom_tool");diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex 78349ca..70fbcd3 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -66,7 +66,7 @@ public class OverViewItem : GLib.Object { 		if (has_icons () && info.is_over_icon (px, py)) { 			MainWindow.get_overview ().set_character_info (info); 		}-		+				 		return selected; 	} diff --git a/libbirdfont/Svg.vala b/libbirdfont/Svg.valaindex 940e0f5..376b8a0 100644--- a/libbirdfont/Svg.vala+++ b/libbirdfont/Svg.vala@@ -234,8 +234,7 @@ class Svg { 		 		cr.save (); -		cr.set_line_width (1);-		cr.set_source_rgba (0, 0, 0, 1);+		cr.set_line_width (0); 		 		if (svg == "") { 			return;

Contact

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