Clone in a terminal:
Commit 99fff57
Johan Mattsson - 2014-08-09T22:05:28+00:00
99fff57f1dd66cb7cf317e1c6532758ab866e764johan.mattsson.m@gmail.com

Adjust right side bearing (RSB) in the kerning tab

Changed files (5)

Diff

diff --git a/icons/side_bearings.png b/icons/side_bearings.pngnew file mode 100644index 0000000..5bb48f0Binary files /dev/null and b/icons/side_bearings.png differdiff --git a/libbirdfont/ClipTool.vala b/libbirdfont/ClipTool.valaindex 1fa9978..e3447f5 100644--- a/libbirdfont/ClipTool.vala+++ b/libbirdfont/ClipTool.vala@@ -32,7 +32,7 @@ public class ClipTool : Tool { 	}  	public static void paste_in_place () {-		paste_paths ();+		paste_paths (true); 	} 	 	/** Paste at cursor. */@@ -43,7 +43,7 @@ public class ClipTool : Tool { 		double dx, dy; 		 		if (fd is Glyph) {-			paste_paths ();+			paste_paths (false); 			 			g.selection_boundaries (out x, out y, out w, out h); 			@@ -60,7 +60,7 @@ public class ClipTool : Tool { 		} 	} 	-	static void paste_paths () {+	static void paste_paths (bool paste_guide_lines) { 		bool is_bf_clipboard; 		FontDisplay fd; 		string clipboard_data = MainWindow.native_window.get_clipboard_data ();@@ -71,13 +71,13 @@ public class ClipTool : Tool { 		is_bf_clipboard = clipboard_data.index_of ("BirdFontClipboard") > -1;   		if (fd is Glyph) {-			paste_to_glyph (is_bf_clipboard);+			paste_to_glyph (is_bf_clipboard, paste_guide_lines); 		} 		 		BirdFont.get_current_font ().touch (); 	} 	-	static void paste_to_glyph (bool bf_clipboard_data) {+	static void paste_to_glyph (bool bf_clipboard_data, bool paste_guide_lines) { 		FontDisplay fd = MainWindow.get_current_display (); 		Glyph? destination = null; 		string data;@@ -90,7 +90,7 @@ public class ClipTool : Tool { 		data = MainWindow.native_window.get_clipboard_data ();  		if (bf_clipboard_data) {-			import_birdfont_clipboard (data);+			import_birdfont_clipboard (data, paste_guide_lines); 		} else if (data != "") { 			SvgParser.import_svg_data (data); 		}@@ -106,7 +106,15 @@ public class ClipTool : Tool { 		 		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 (glyph.path_list.size > 0) { 			foreach (Path path in glyph.active_paths) { 				s.append ("BF path: ");@@ -170,12 +178,13 @@ public class ClipTool : Tool { 		return true; 	} 	-	static void import_birdfont_clipboard (string data) {-		string[] paths = data.split ("\nBF ");+	static void import_birdfont_clipboard (string data, bool paste_guide_lines) {+		Glyph glyph = MainWindow.get_current_glyph ();+		string[] items = data.split ("\nBF "); 		string d; 		int i; 		-		foreach (string p in paths) {+		foreach (string p in items) { 			if (p.has_prefix ("path:")) { 				i = p.index_of ("\n"); 				if (i > -1) {@@ -184,6 +193,18 @@ public class ClipTool : Tool { 				d = p.replace ("path: ", ""); 				import_birdfont_path (d); 			}+			+			if (paste_guide_lines && 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:")) {+				glyph.right_limit = double.parse (p.replace ("right: ", ""));+				glyph.remove_lines ();+				glyph.add_help_lines ();	+			} 		}	 	} 	diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 44ef44e..9b70c91 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -406,7 +406,7 @@ public class Glyph : FontDisplay { 		} 	} 	-	private void remove_lines () {+	public void remove_lines () { 		vertical_help_lines.clear (); 		horizontal_help_lines.clear ();	 	}diff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex ffad6d3..e8313a7 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -25,6 +25,7 @@ public class KerningDisplay : FontDisplay { 	int active_handle = -1; 	int selected_handle = -1; 	bool moving = false;+	Glyph left_active_glyph = new Glyph ("null", '\0'); 	 	double begin_handle_x = 0; 	double begin_handle_y = 0;@@ -359,11 +360,15 @@ public class KerningDisplay : FontDisplay { 			return; 		} 		-		kern = get_kerning_for_handle (handle);-		set_kerning (handle, val - kern);+		if (!KerningTools.adjust_side_bearings) {+			kern = get_kerning_for_handle (handle);+			set_space (handle, val - kern);	+		} 	} -	private void set_kerning (int handle, double val) {++	/** Adjust kerning or right side bearing. */+	private void set_space (int handle, double val) { 		string a, b; 		Font font; 		GlyphRange? gr_left, gr_right;@@ -371,8 +376,14 @@ public class KerningDisplay : FontDisplay { 		font = BirdFont.get_current_font (); 		font.touch (); -		get_kerning_pair (handle, out a, out b, out gr_left, out gr_right);-		set_kerning_pair (a, b, ref gr_left, ref gr_right, val);+		if (!KerningTools.adjust_side_bearings) {+			get_kerning_pair (handle, out a, out b, out gr_left, out gr_right);+			set_kerning_pair (a, b, ref gr_left, ref gr_right, val);+		} else {+			left_active_glyph.right_limit += val;+			left_active_glyph.remove_lines ();+			left_active_glyph.add_help_lines ();+		} 	}  	/** Class based gpos kerning. */@@ -505,6 +516,7 @@ public class KerningDisplay : FontDisplay { 	}  	void set_selected_handle (int handle) {+		Glyph? g; 		selected_handle = handle; 		 		if (selected_handle <= 0) {@@ -517,6 +529,13 @@ public class KerningDisplay : FontDisplay { 		 		set_active_handle_index (handle); 		+		if (0 <= selected_handle - 1 < row.get (0).glyph.size) {+			g = row.get (0).glyph.get (selected_handle - 1);+			if (g != null) {+				left_active_glyph = (!) g;+			}+		}+		 		GlyphCanvas.redraw (); 	} @@ -561,12 +580,12 @@ public class KerningDisplay : FontDisplay { 		 		if (keyval == Key.LEFT && KeyBindings.modifier == NONE) { 			first_update = true;-			set_kerning (selected_handle, -1 / KerningTools.font_size);+			set_space (selected_handle, -1 / KerningTools.font_size); 		} 		 		if (keyval == Key.RIGHT && KeyBindings.modifier == NONE) { 			first_update = true;-			set_kerning (selected_handle, 1 / KerningTools.font_size);+			set_space (selected_handle, 1 / KerningTools.font_size); 		}  		if (KeyBindings.modifier == CTRL && (keyval == Key.LEFT || keyval == Key.RIGHT)) {@@ -624,7 +643,7 @@ public class KerningDisplay : FontDisplay { 			row.get (0).glyph.add (g); 			row.get (0).ranges.add (null); 			-			selected_handle = (int) row.get (0).glyph.size - 1;+			set_selected_handle ((int) row.get (0).glyph.size - 1); 			set_active_handle_index (selected_handle); 		} 	}@@ -647,7 +666,7 @@ public class KerningDisplay : FontDisplay { 			 			k = (ex - last_handle_x) / y; // y-axis is for variable precision 			k /= KerningTools.font_size;-			set_kerning (selected_handle, k);+			set_space (selected_handle, k); 			GlyphCanvas.redraw (); 		} 		@@ -753,7 +772,7 @@ public class KerningDisplay : FontDisplay { 		} 				 		if (selected_handle == -1) {-			selected_handle = 0;+			set_selected_handle (0); 		} 		 		listener = new TextListener (t_("Kerning"), kerning, t_("Close"));@@ -791,7 +810,7 @@ public class KerningDisplay : FontDisplay { 		} 		 		set_active_handle (ex, ey);-		selected_handle = active_handle;+		set_selected_handle (active_handle); 		begin_handle_x = ex; 		begin_handle_y = ey; 		last_handle_x = ex;diff --git a/libbirdfont/KerningTools.vala b/libbirdfont/KerningTools.valaindex d8424fa..b3e65d6 100644--- a/libbirdfont/KerningTools.vala+++ b/libbirdfont/KerningTools.vala@@ -21,6 +21,7 @@ public class KerningTools : ToolCollection  { 	public static List<Expander> expanders; 	public static int next_class = 0; 	public static Expander classes;+	public static bool adjust_side_bearings = false; 	 	public static double font_size = 1; 	@@ -46,6 +47,26 @@ public class KerningTools : ToolCollection  { 		}); 		kerning_tools.add_tool (text_kerning); +		Tool side_bearings = new Tool ("side_bearings", t_("Adjust right side bearing."));+		side_bearings.select_action.connect ((self) => {+			KerningTools.adjust_side_bearings = true;+		});+		+		side_bearings.deselect_action.connect ((self) => {+			KerningTools.adjust_side_bearings = false;+		});+		+		side_bearings.set_persistent (true);+		kerning_tools.add_tool (side_bearings);++		Tool insert_last = new Tool ("insert_last_glyph", t_("Insert last edited glyph"));+		insert_last.select_action.connect ((self) => {+			KerningDisplay d = MainWindow.get_kerning_display ();+			d.inser_glyph (MainWindow.get_current_glyph ());+			GlyphCanvas.redraw ();+		});+		kerning_tools.add_tool (insert_last);+				 		SpinButton font_size1 = new SpinButton ("kerning_font_size_one", t_("Font size"));  		font_size1.set_max (9);@@ -95,14 +116,6 @@ public class KerningTools : ToolCollection  { 		}); 		kerning_tools.add_tool (font_size2); -		Tool insert_last = new Tool ("insert_last_glyph", t_("Insert last edited glyph"));-		insert_last.select_action.connect ((self) => {-			KerningDisplay d = MainWindow.get_kerning_display ();-			d.inser_glyph (MainWindow.get_current_glyph ());-			GlyphCanvas.redraw ();-		});-		kerning_tools.add_tool (insert_last);- 		kerning_tools.set_persistent (false); 		kerning_tools.set_unique (false); 

Contact

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