Commit d41702d
Fix offsets in text rendering, release freetype resources on error and switch themes.
Changed files (7)
modifiedlibbirdfont/FileTools.valamodifiedlibbirdfont/GlyphRange.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/ToolCollection.valamodifiedlibbirdfont/overview_glyph.c
Diff
@@ -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_")) {@@ -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;@@ -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) {@@ -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 () { } @@ -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 ();@@ -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 ();@@ -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; }