Clone in a terminal:
Commit a6e824b
Johan Mattsson - 2013-09-02T12:33:55+00:00
a6e824b36f50ba604d381f05c86ce01bfa660c60johan.mattsson.m@gmail.com

set allocation before glyph is displayed

Changed files (3)

Diff

diff --git a/libbirdfont/DropMenu.vala b/libbirdfont/DropMenu.valaindex 1a6d2e1..70d4161 100644--- a/libbirdfont/DropMenu.vala+++ b/libbirdfont/DropMenu.vala@@ -57,7 +57,7 @@ public class DropMenu : GLib.Object { 	public MenuAction get_action_no2 () { 		if (actions.length () < 2) { 			warning ("No such action");-			return new MenuAction ("NULL");+			return new MenuAction ("None"); 		} 		 		return actions.nth (1).data;diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex fe6ebc8..32b3800 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -731,7 +731,11 @@ public class Glyph : FontDisplay {  		view_offset_x += x / view_zoom; 		view_offset_y += y / view_zoom;-			+		+		if (unlikely (allocation.width == 0 || allocation.height == 0)) {+			warning (@"Allocation is not set in $(get_name ())");+		}+		 		view_zoom_x = allocation.width * view_zoom / w; 		view_zoom_y = allocation.height * view_zoom / h; 				@@ -785,37 +789,54 @@ public class Glyph : FontDisplay { 		zoom_y2 = ny; 	} +	public static void validate_zoom () {+		Glyph g = MainWindow.get_current_glyph ();+		if (unlikely (g.view_zoom == 0)) {+			warning ("Zoom is zero.");+			g.reset_zoom ();+			+			if (g.view_zoom == 0) {+				g.view_zoom = 1;+				g.view_offset_x = 0;+				g.view_offset_y = 0;+			}+		}	+	}+ 	public static double path_coordinate_x (double x) { 		Glyph g = MainWindow.get_current_glyph ();-		return_val_if_fail (g.view_zoom != 0, 0);+		validate_zoom (); 		return x * ivz () - xc () + g.view_offset_x; 	}  	public static int reverse_path_coordinate_x (double x) { 		Glyph g = MainWindow.get_current_glyph ();-		return_val_if_fail (g.view_zoom != 0, 0);+		validate_zoom (); 		return (int) Math.rint ((x - g.view_offset_x + xc ()) * g.view_zoom); 	}  	public static double precise_reverse_path_coordinate_x (double x) { 		Glyph g = MainWindow.get_current_glyph ();-		return_val_if_fail (g.view_zoom != 0, 0);+		validate_zoom (); 		return (x - g.view_offset_x + xc ()) * g.view_zoom; 	} 	 	public static double path_coordinate_y (double y) { 		Glyph g = MainWindow.get_current_glyph ();+		validate_zoom (); 		return yc () - y * ivz () - g.view_offset_y; 	}  	public static int reverse_path_coordinate_y (double y) { 		Glyph g = MainWindow.get_current_glyph ();+		validate_zoom (); 		y =  Math.rint ((y + g.view_offset_y - yc ()) * g.view_zoom);	 		return (int) (-y); 	}  	public static double precise_reverse_path_coordinate_y (double y) { 		Glyph g = MainWindow.get_current_glyph ();+		validate_zoom (); 		y = (y + g.view_offset_y - yc ()) * g.view_zoom;	 		return -y; 	}@@ -1359,9 +1380,13 @@ public class Glyph : FontDisplay { 		} 	} 	+	public void set_allocation (WidgetAllocation a) {+		allocation = a;+	}+	 	public override void draw (WidgetAllocation allocation, Context cr) { 		Tool tool;-		+			 		this.allocation = allocation;  		ImageSurface ps = new ImageSurface (Format.ARGB32, allocation.width, allocation.height);diff --git a/libbirdfont/VersionList.vala b/libbirdfont/VersionList.valaindex 73c026b..5779d99 100644--- a/libbirdfont/VersionList.vala+++ b/libbirdfont/VersionList.vala@@ -85,6 +85,8 @@ public class VersionList : DropMenu { 	 	private void set_selected_item (MenuAction ma) { 		int i = ma.index;+		Glyph current_glyph = MainWindow.get_current_glyph ();+		unowned List<Glyph> g; 				 		return_if_fail (0 <= i < glyphs.length ()); @@ -96,6 +98,15 @@ public class VersionList : DropMenu { 		ma.set_selected (true); 		 		reload_all_open_glyphs ();+		+		g = glyphs.nth (current_version);+		+		if (unlikely (is_null (g.data))) {+			warning ("No data in glyph collection.");+		} else {+			g.data.set_allocation (current_glyph.allocation);+			g.data.default_zoom ();+		} 	} 	 	/** Reload a glyph when a new version is selected. Updates the path

Contact

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