Clone in a terminal:
Commit d41702d
Johan Mattsson - 2015-12-18T23:01:15+00:00
d41702ddb867221208b81b641618b52a0f1b97b0johan.mattsson.m@gmail.com

Fix offsets in text rendering, release freetype resources on error and switch themes.

Changed files (7)

Diff

diff --git a/libbirdfont/FileTools.vala b/libbirdfont/FileTools.valaindex 250a35d..63a54ed 100644--- a/libbirdfont/FileTools.vala+++ b/libbirdfont/FileTools.vala@@ -71,16 +71,18 @@ public class FileTools : ToolCollection  { 				 				Preferences.set ("theme", theme_file); 				Theme.load_theme (theme_file);-+				 				Toolbox.redraw_tool_box (); 				GlyphCanvas.redraw (); 				-				file_tools.redraw ();-				font_name.redraw ();+				file_tools.clear_cache ();+				font_name.clear_cache ();+				themes.clear_cache ();+				 				tb.redraw (0, 0, tb.width, tb.height); 				 				foreach (ToolCollection tc in toolbox.tool_sets) {-					tc.redraw ();+					tc.clear_cache (); 				}  				OverViewItem.label_background = null;@@ -93,6 +95,7 @@ public class FileTools : ToolCollection  { 				} 				 				self.set_selected (true);+				themes.clear_cache (); 			}); 			 			if (!theme.has_prefix ("generated_")) {diff --git a/libbirdfont/GlyphRange.vala b/libbirdfont/GlyphRange.valaindex 5a97dcc..6bb165c 100644--- a/libbirdfont/GlyphRange.vala+++ b/libbirdfont/GlyphRange.vala@@ -426,7 +426,7 @@ public class GlyphRange { 		} 	} 	-	/** Find a range which containd index. */+	/** Find a range which contains index. */ 	private void get_unirange_index (uint32 index, out UniRange? range, out uint32 range_start_index) { 		int lower = 0; 		int upper = index_size - 1;diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 1cda11c..4b3a671 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -639,7 +639,6 @@ public class OverView : FontDisplay { 			process_item_list_update (); 		} 		-		Test test = new Test.time("Overview.draw"); 		this.allocation = allocation; 		 		// clear canvas@@ -660,8 +659,6 @@ public class OverView : FontDisplay { 		if (unlikely (character_info != null)) { 			draw_character_info (cr); 		}-		-		warning (test.get_test_time ()); 	} 		 	void draw_empty_canvas (WidgetAllocation allocation, Context cr) {diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex ad14b39..16e4723 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -47,14 +47,7 @@ public class OverViewItem : GLib.Object { 	public static Surface? selected_label_background = null; 	public static Surface? label_background_no_menu = null; 	public static Surface? selected_label_background_no_menu = null;-	-	private static Task thumbnail_task;-	private static Gee.PriorityQueue<OverViewItem> thumbnail_queue;-	private static Cond has_thumnail_task = new Cond ();-	private static Mutex thumbnail_mutex = new Mutex ();-	-	private bool cancel_thumbnail = false;-	+		 	public OverViewItem () {	 	} diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex 0a5e5dd..a5d368a 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -330,10 +330,17 @@ public class Text : Widget { 	} 	 	public void set_source_rgba (double r, double g, double b, double a) {-		this.r = r;-		this.g = g;-		this.b = b;-		this.a = a;+		if (this.r != r || +			this.g != g || +			this.b != b || +			this.a != a) {+		+			this.r = r;+			this.g = g;+			this.b = b;+			this.a = a;+			cache = null;+		} 	} 	 	public string get_cache_id (int offset_x, int offset_y) {@@ -472,11 +479,11 @@ public class Text : Widget { 		cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid; 				 		if (!glyph.has_cache (cache_id)) {-			int w = (int) ((glyph_margin_left * ratio + glyph.get_width ()) * ratio) + 2;+			int w = (int) ((2 * glyph_margin_left * ratio + glyph.get_width ()) * ratio) + 2; 			int h = (int) font_size + 2; 			cache = Screen.create_background_surface (w, h); 			cc = new Context (cache);-+			 			cc.scale(Screen.get_scale (), Screen.get_scale ()); 			 			lsb = glyph.left_limit - glyph_margin_left;@@ -486,7 +493,7 @@ public class Text : Widget { 			cc.new_path ();  			foreach (Path path in glyph.get_visible_paths ()) {-				draw_path (cc, glyph, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio);+				draw_path (cc, glyph, path, lsb, glyph_margin_left * ratio + offset_x / 10.0, cc_y + offset_y / 10.0, ratio); 			} 			 			cc.fill ();diff --git a/libbirdfont/ToolCollection.vala b/libbirdfont/ToolCollection.valaindex 098cbad..408c430 100644--- a/libbirdfont/ToolCollection.vala+++ b/libbirdfont/ToolCollection.vala@@ -42,6 +42,12 @@ public abstract class ToolCollection : GLib.Object  { 		} 	} 	+	public void clear_cache () {+		foreach (Expander e in get_expanders ()) {+			e.clear_cache ();+		}+	}+	 	public void redraw () { 		foreach (Expander e in get_expanders ()) { 			e.redraw ();diff --git a/libbirdfont/overview_glyph.c b/libbirdfont/overview_glyph.cindex f6c6e60..b66f5e9 100644--- a/libbirdfont/overview_glyph.c+++ b/libbirdfont/overview_glyph.c@@ -50,6 +50,7 @@ gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble w 
 	error = FT_New_Face (library, font_file, 0, &face);
 	if (error) {
+		FT_Done_FreeType (library);
 		g_warning ("Freetype font face error %d\n", error);
 		return FALSE;
 	}
@@ -60,18 +61,24 @@ gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble w 	error = FT_Select_Charmap (face , FT_ENCODING_UNICODE);
 	if (error) {
 		g_warning ("Freetype can not use Unicode, error: %d\n", error);
+		FT_Done_Face (face);
+		FT_Done_FreeType (library);
 		return FALSE;
 	}
 
 	error = FT_Set_Char_Size (face, 0, 64, (int) height, (int) height);
 	if (error) {
 		g_warning ("FT_Set_Char_Size, error: %d.\n", error);
+		FT_Done_Face (face);
+		FT_Done_FreeType (library);
 		return FALSE;
 	}
 
 	error = FT_Set_Pixel_Sizes (face, 0, (int) (height * 0.5));
 	if (error) {
 		g_warning ("FT_Set_Pixel_Sizes, error: %d.\n", error);
+		FT_Done_Face (face);
+		FT_Done_FreeType (library);
 		return FALSE;
 	}
 
@@ -86,7 +93,8 @@ gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble w 		advance = face->glyph->metrics.horiAdvance;
 		advance *= units;
 	} else {
-		g_warning("Glyph not found: %s", text);
+		FT_Done_Face (face);
+		FT_Done_FreeType (library);
 		return FALSE;
 	}
 

Contact

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