The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Faster text and icon rendering

These changes was commited to the Birdfont repository Sun, 13 Dec 2015 17:30:42 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 13 Dec 2015 17:30:42 +0000]

Updated Files

libbirdfont/CharacterInfo.vala
libbirdfont/DrawingTools.vala
libbirdfont/Expander.vala
libbirdfont/Path.vala
libbirdfont/Renderer/Text.vala
libbirdfont/Renderer/TextArea.vala
libbirdfont/TabBar.vala
libbirdfont/Tool.vala
--- a/libbirdfont/CharacterInfo.vala +++ b/libbirdfont/CharacterInfo.vala @@ -36,7 +36,6 @@ ligature = ((!) gc).is_unassigned (); name = ((!) gc).get_name (); icon.load_font ("icons.bf"); - icon.use_cache (true); } }
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -108,7 +108,11 @@ static Tool line_cap_butt; static Tool line_cap_round; static Tool line_cap_square; - + + private Text backgrounds_headline = new Text (t_("Background Tools")); + private Text control_points_headline = new Text (t_("Control Points")); + private Text object_tools_headline = new Text (t_("Object Tools")); + public DrawingTools (GlyphCanvas main_glyph_canvas) { bool selected_line; @@ -1324,7 +1328,7 @@ } void show_background_tool_modifiers () { - draw_tool_modifiers.set_headline (t_("Background Tools")); + draw_tool_modifiers.set_headline (backgrounds_headline); cut_background.set_tool_visibility (true); show_bg.set_tool_visibility (true); @@ -1339,7 +1343,7 @@ } void show_point_tool_modifiers () { - draw_tool_modifiers.set_headline (t_("Control Points")); + draw_tool_modifiers.set_headline (control_points_headline); tie_handles.set_tool_visibility (true); reflect_handle.set_tool_visibility (true); @@ -1355,7 +1359,7 @@ } void show_object_tool_modifiers () { - draw_tool_modifiers.set_headline (t_("Object Tools")); + draw_tool_modifiers.set_headline (object_tools_headline); x_coordinate.set_tool_visibility (true); y_coordinate.set_tool_visibility (true);
--- a/libbirdfont/Expander.vala +++ b/libbirdfont/Expander.vala @@ -53,7 +53,7 @@ title = new Text (); if (headline != null) { - set_headline(headline); + title.set_text ((!) headline); } tool = new Gee.ArrayList<Tool> (); @@ -63,9 +63,9 @@ cached = null; } - public void set_headline (string? h) { - headline = h; - title.set_text ((!) headline); + public void set_headline (Text h) { + headline = h.get_text (); + title = h; } public double get_content_height () { @@ -217,7 +217,6 @@ } public void redraw () { - cached = null; Toolbox.redraw_tool_box (); } @@ -290,11 +289,12 @@ } draw_content (cc, offset_y); - cached = (!) cache; + cached = (!) cache; } if (cached != null) { cache = (!) cached; + cr.set_antialias (Cairo.Antialias.NONE); Screen.paint_background_surface (cr, cache, 0, (int) (y + scroll)); } }
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -320,7 +320,7 @@ double max = Glyph.CANVAS_MIN; Text arrow; double x, y, angle; - double size = 50 * Glyph.ivz (); + double size = 50 * Screen.get_scale (); foreach (EditPoint e in points) { if (e.y > max) { @@ -331,7 +331,6 @@ arrow = new Text ("orientation_arrow", size); arrow.load_font ("icons.bf"); - arrow.use_cache (false); Theme.text_color_opacity (arrow, "Highlighted 1", opacity); @@ -342,6 +341,8 @@ if (points.size > 0) { cr.save (); cr.translate (x, y); + double inverted_zoom = Glyph.ivz (); + cr.scale (inverted_zoom, inverted_zoom); cr.rotate (-angle); cr.translate (-x, -y);
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -20,7 +20,9 @@ public class Text : Widget { FontCache font_cache; public CachedFont cached_font; - + + Surface? cache = null; + public string text; GlyphSequence glyph_sequence { @@ -44,8 +46,6 @@ public double g = 0; public double b = 0; public double a = 1; - - bool use_cached_glyphs = true; double truncated_width = -1; public Text (string text = "", double size = 17, double margin_bottom = 0) { @@ -57,8 +57,8 @@ set_font_size (size); } - public void use_cache (bool cache) { - use_cached_glyphs = cache; + public string get_text () { + return text; } /** Set font for this text area. @@ -331,50 +331,62 @@ double x, y; double ratio; double cc_y; + + if (cache == null) { + cache = draw_on_cache_surface (cacheid); + } + + double s = get_font_scale (); + double cache_y = py - s * (cached_font.top_limit - cached_font.base_line); + cr.set_source_surface ((!) cache, (int) px, (int) cache_y); + cr.paint (); + } + + Surface draw_on_cache_surface (string cacheid) { + double x, y; + double ratio; + double cc_y; + Context cr; + Surface cache_surface; + double screen_scale = Screen.get_scale(); + double h = font_size * screen_scale + 1; + double w = get_sidebearing_extent () * screen_scale + 1; + + cache_surface = Screen.create_background_surface ((int) w, (int) h); + cr = new Context (cache_surface); + cr.scale(screen_scale, screen_scale); ratio = get_font_scale (); cc_y = (cached_font.top_limit - cached_font.base_line) * ratio; - y = py; - x = px; + double px = 0; + double py = cc_y; + + y = cc_y; + x = 0; if (unlikely (cached_font.base_line != 0)) { warning ("Base line not zero."); } - if (use_cached_glyphs) { - iterate ((glyph, kerning, last) => { - double end; - - x += kerning * ratio; - end = x + glyph.get_width () * ratio; - - // truncation - if (truncated_width > 0 && end - px > truncated_width) { - return; - } + iterate ((glyph, kerning, last) => { + double end; + + x += kerning * ratio; + end = x + glyph.get_width () * ratio; + + // truncation + if (truncated_width > 0 && end - px > truncated_width) { + return; + } - draw_chached (cr, glyph, kerning, last, x, y, cc_y, - ratio, cacheid); - - x = end; - }); - } else { - iterate ((glyph, kerning, last) => { - double end; - - x += kerning * ratio; - end = x + glyph.get_width () * ratio; - - // truncation - if (truncated_width > 0 && end - px > truncated_width) { - return; - } - - draw_without_cache (cr, glyph, kerning, last, x, y, cc_y, ratio); - x = end; - }); - } + draw_chached (cr, glyph, kerning, last, x, y, cc_y, + ratio, cacheid); + + x = end; + }); + + return cache_surface; } void draw_without_cache (Context cr, Glyph glyph, double kerning, bool last,
--- a/libbirdfont/Renderer/TextArea.vala +++ b/libbirdfont/Renderer/TextArea.vala @@ -64,7 +64,6 @@ bool store_undo_state_at_next_event = false; public bool editable; - public bool use_cache = true; public TextArea (double font_size = 20, Color? c = null) { this.font_size = font_size; @@ -1068,7 +1067,6 @@ cr.save (); word = new Text (); - word.use_cache (use_cache); width = this.width - padding; x += padding;
--- a/libbirdfont/TabBar.vala +++ b/libbirdfont/TabBar.vala @@ -681,8 +681,6 @@ wheel.set_font_size (progress_size); wheel.widget_x = middlex; wheel.widget_y = middley; - - wheel.use_cache (false); cr.save (); if (!has_stop_button ()) { @@ -801,7 +799,6 @@ // tab label label = new Text (); - label.use_cache (false); label.set_text (t.get_label ()); text_height = (int) (16 / scale); label.set_font_size (text_height);
--- a/libbirdfont/Tool.vala +++ b/libbirdfont/Tool.vala @@ -240,7 +240,6 @@ icon_file = Theme.get_icon_file (); icon_font = new Text ((!) name); found = icon_font.load_font (icon_file); - icon_font.use_cache (true); icon_font.set_font_size (40 * Toolbox.get_scale ()); if (!found) {