Clone in a terminal:
Commit 86e6a64
Johan Mattsson - 2014-10-05T15:38:14+00:00
86e6a6421507adf1c8012e4f0ec7069ea62015a6johan.mattsson.m@gmail.com

Insert characters by unicode value in kerning tab

Changed files (3)

Diff

diff --git a/icons/insert_unichar.png b/icons/insert_unichar.pngnew file mode 100644index 0000000..baef5e1Binary files /dev/null and b/icons/insert_unichar.png differdiff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex ce9ca7f..504a093 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -585,43 +585,86 @@ public class KerningDisplay : FontDisplay { 		if (suppress_input) { 			return; 		}-		-		if (keyval == Key.LEFT && KeyBindings.modifier == NONE) {-			first_update = true;-			set_space (selected_handle, -1 / KerningTools.font_size);-		}-		-		if (keyval == Key.RIGHT && KeyBindings.modifier == NONE) {-			first_update = true;-			set_space (selected_handle, 1 / KerningTools.font_size);-		} -		if (KeyBindings.modifier == CTRL && (keyval == Key.LEFT || keyval == Key.RIGHT)) {-			if (keyval == Key.LEFT) { -				selected_handle--;+		if (keyval == 'u' || keyval == 'U' && KeyBindings.has_ctrl ()) {+			insert_unichar ();+		} else {+			if (keyval == Key.LEFT && KeyBindings.modifier == NONE) {+				first_update = true;+				set_space (selected_handle, -1 / KerningTools.font_size); 			} 			-			if (keyval == Key.RIGHT) {-				selected_handle++;+			if (keyval == Key.RIGHT && KeyBindings.modifier == NONE) {+				first_update = true;+				set_space (selected_handle, 1 / KerningTools.font_size);+			}++			if (KeyBindings.modifier == CTRL && (keyval == Key.LEFT || keyval == Key.RIGHT)) {+				if (keyval == Key.LEFT) { +					selected_handle--;+				}+				+				if (keyval == Key.RIGHT) {+					selected_handle++;+				}+				+				set_selected_handle (selected_handle); 			} 			-			set_selected_handle (selected_handle);+			if (KeyBindings.modifier == NONE || KeyBindings.modifier == SHIFT) {		+				if (keyval == Key.BACK_SPACE && row.size > 0 && row.get (0).glyph.size > 0) {+					row.get (0).glyph.remove_at (row.get (0).glyph.size - 1);+					row.get (0).ranges.remove_at (row.get (0).ranges.size - 1);+				}+				+				if (row.size == 0 || c == Key.ENTER) {+					new_line ();+				}+				+				add_character (c);+			} 		} 		-		if (KeyBindings.modifier == NONE || KeyBindings.modifier == SHIFT) {		-			if (keyval == Key.BACK_SPACE && row.size > 0 && row.get (0).glyph.size > 0) {-				row.get (0).glyph.remove_at (row.get (0).glyph.size - 1);-				row.get (0).ranges.remove_at (row.get (0).ranges.size - 1);-			}+		GlyphCanvas.redraw ();+	}+	+	public void insert_unichar () {+		TextListener listener;+		string submitted_value = "";+		string unicodestart;+		+		unicodestart = (KeyBindings.has_shift ()) ? "" : "U+";++		listener = new TextListener (t_("Unicode"), unicodestart, t_("Insert"));+		+		listener.signal_text_input.connect ((text) => {+			submitted_value = text; 			-			if (row.size == 0 || c == Key.ENTER) {-				new_line ();+			if (MenuTab.suppress_event) {+				return; 			} 			-			add_character (c);-		}+			GlyphCanvas.redraw ();+		}); 		-		GlyphCanvas.redraw ();+		listener.signal_submit.connect (() => {+			unichar c;+			MainWindow.native_window.hide_text_input ();+			+			text_input = false;+			suppress_input = false;+			+			if (submitted_value.has_prefix ("u+") || submitted_value.has_prefix ("U+")) {+				c = Font.to_unichar (submitted_value);+				add_character (c);+			} else {+				add_text (submitted_value);+			}+		});+		+		suppress_input = true;+		text_input = true;+		MainWindow.native_window.set_text_listener (listener); 	} 	 	public void new_line () {@@ -809,7 +852,7 @@ public class KerningDisplay : FontDisplay { 		text_input = true; 		MainWindow.native_window.set_text_listener (listener); 		-		GlyphCanvas.redraw ();		+		GlyphCanvas.redraw (); 	} 	 	public override void button_press (uint button, double ex, double ey) {diff --git a/libbirdfont/KerningTools.vala b/libbirdfont/KerningTools.valaindex 4d4322c..b1c5542 100644--- a/libbirdfont/KerningTools.vala+++ b/libbirdfont/KerningTools.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2013 Johan Mattsson+    Copyright (C) 2013 2014 Johan Mattsson      This library is free software; you can redistribute it and/or modify      it under the terms of the GNU Lesser General Public License as @@ -63,6 +63,13 @@ public class KerningTools : ToolCollection  { 			GlyphCanvas.redraw (); 		}); 		kerning_tools.add_tool (insert_last);++		Tool insert_unicode = new Tool ("insert_unichar", t_("Insert character by unicode value"), 'U', CTRL);+		insert_unicode.select_action.connect ((self) => {+			KerningDisplay d = MainWindow.get_kerning_display ();+			d.insert_unichar ();+		});+		kerning_tools.add_tool (insert_unicode); 				 		SpinButton font_size1 = new SpinButton ("kerning_font_size_one", t_("Font size")); 

Contact

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