The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Better cache in rendering of bf fonts

These changes was commited to the Birdfont repository Mon, 16 Mar 2015 19:29:35 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 16 Mar 2015 19:29:35 +0000]

Updated Files

libbirdfont/OverViewItem.vala
libbirdfont/Renderer/Text.vala
libbirdfont/Theme.vala
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -109,11 +109,11 @@ cr.rectangle (x, y, width, height); cr.fill (); cr.restore (); - + cr.save (); - Theme.color (cr, "Foreground 1"); + Theme.color (cr, "Foreground 3"); cr.rectangle (x, y, width, height); - cr.set_line_width (0.5); + cr.set_line_width (1); cr.stroke (); cr.restore (); @@ -192,7 +192,7 @@ } else { c.save (); fallback = new Text (); - fallback.set_source_rgba (219 / 255.0, 221 / 255.0, 233 / 255.0, 1); + Theme.text_color (fallback, "Foreground 7"); fallback.set_text ((!) character.to_string ()); font_size = height * 0.8; fallback.set_font_size (font_size); @@ -249,8 +249,8 @@ double w = has_icons () ? width - 43 : width; label = new Text (text, 17); label.truncate (w); - label.use_cache (false); // Fixme: Improve cache - Theme.text_color (label, "Foreground 1"); + label.use_cache (true); + Theme.text_color (label, "Foreground 6"); label.draw_at_baseline (cr, x + 0.08 * width, y + height - 6); } @@ -273,8 +273,8 @@ icon = new Text ("dropdown_menu", 17); icon.load_font ("icons.bf"); - icon.use_cache (false); - Theme.text_color (icon, "Foreground 1"); + icon.use_cache (true); + Theme.text_color (icon, "Foreground 6"); icon.draw_at_top (cr, x + width - 32, y + height - 19); g = (!) glyphs;
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -350,13 +350,7 @@ double x, y; double ratio; double cc_y; - string cache_id; - int offset_x, offset_y; - - offset_x = (int) (10 * (px - (int) px)); - offset_y = (int) (10 * (py - (int) py)); - cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid; - + ratio = get_scale (); cc_y = (font.top_limit - font.base_line) * ratio; @@ -366,6 +360,8 @@ if (use_cached_glyphs) { iterate ((glyph, kerning, last) => { double end; + int offset_x, offset_y; + string cache_id; x += kerning * ratio; end = x + glyph.get_width () * ratio; @@ -376,7 +372,7 @@ } draw_chached (cr ,glyph, kerning, last, x, y, cc_y, - cache_id, ratio, offset_x, offset_y); + ratio, cacheid); x = end; }); @@ -419,15 +415,24 @@ } void draw_chached (Context cr, Glyph glyph, double kerning, bool last, - double x, double y, double cc_y, string cache_id, double ratio, - int offset_x, int offset_y) { + double x, double y, double cc_y, double ratio, + string cacheid = "") { double lsb; Surface cache; Context cc; + string cache_id; + double xp = x; + double yp = y - cc_y; + int offset_x, offset_y; + + offset_x = (int) (10 * (xp - (int) xp)); + offset_y = (int) (10 * (yp - (int) yp)); + cache_id = (cacheid == "") ? get_cache_id (offset_x, offset_y) : cacheid; + if (unlikely (!glyph.has_cache (cache_id))) { - cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) (glyph.get_width () * ratio) + 1, (int) font_size + 1); + cache = new Surface.similar (cr.get_target (), Cairo.Content.COLOR_ALPHA, (int) (glyph.get_width () * ratio) + 2, (int) font_size + 2); cc = new Context (cache); lsb = glyph.left_limit; @@ -446,7 +451,7 @@ glyph.set_cache (cache_id, cache); } - cr.set_source_surface (glyph.get_cache (cache_id), (int) x, (int) (y - cc_y)); + cr.set_source_surface (glyph.get_cache (cache_id), (int) xp, (int) yp); cr.paint (); }
--- a/libbirdfont/Theme.vala +++ b/libbirdfont/Theme.vala @@ -115,6 +115,8 @@ Theme.set_default_color ("Foreground 4", 40 / 255.0, 57 / 255.0, 65 / 255.0, 1); Theme.set_default_color ("Foreground 5", 70 / 255.0, 77 / 255.0, 83 / 255.0, 1); Theme.set_default_color ("Foreground 6", 45 / 255.0, 45 / 255.0, 45 / 255.0, 1); + Theme.set_default_color ("Foreground 7", 219 / 255.0, 221 / 255.0, 233 / 255.0, 1); + Theme.set_default_color ("Foreground Inverted", 1, 1, 1, 1); Theme.set_default_color ("Menu Foreground", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); @@ -166,6 +168,8 @@ t_("Foreground 3"); t_("Foreground 4"); t_("Foreground 5"); + t_("Foreground 6"); + t_("Foreground 7"); t_("Foreground Inverted"); t_("Menu Foreground");