Commit 3264879
Faster overview tab
Changed files (7)
modifiedlibbirdfont/CharacterInfo.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/Test.valamodifiedlibbirdfont/TestBirdFont.valamodifiedresources/icons.bf
Diff
@@ -58,7 +58,7 @@ public class CharacterInfo : GLib.Object { } public bool is_over_icon (double px, double py) {- return (x <= px <= x + 12) && (y <= py <= y + 12);+ return (x <= px <= x + 12) && (y <= py <= y + 24); } public void draw_icon (Context cr) { @@ -446,7 +446,7 @@ public class OverView : FontDisplay { cr.restore (); foreach (OverViewItem i in visible_items) {- i.draw (cr);+ i.draw (allocation, cr); } if (visible_items.size == 0) {@@ -95,7 +95,15 @@ public class OverViewItem : GLib.Object { return selected; } - public void draw (Context cr) {+ public bool is_on_screen (WidgetAllocation allocation) {+ return y + height > 0 && y < allocation.height;+ }++ public void draw (WidgetAllocation allocation, Context cr) {+ if (!is_on_screen (allocation)) {+ return;+ }+ cr.save (); Theme.color (cr, "Background 1"); cr.rectangle (x, y, width, height);@@ -194,7 +202,7 @@ public class OverViewItem : GLib.Object { fallback.draw_at_baseline (c, gx, gy); c.restore (); }- + cr.save (); cr.set_source_surface (s, x, y - h); cr.paint ();@@ -238,35 +246,14 @@ public class OverViewItem : GLib.Object { ? name.str : ((!) glyphs).get_current ().name; - text = truncate_label (text); + 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.draw_at_baseline (cr, x + 0.08 * width, y + height - 6); }- - private string truncate_label (string label) {- Text text = new Text (label, 17);- double w = has_icons () ? width - 40 : width;- StringBuilder sb = new StringBuilder ();- StringBuilder result = new StringBuilder ();- int index = 0;- unichar c;- - while (label.get_next_char (ref index, out c)) {- sb.append_unichar (c);- text.set_text (sb.str);- - if (text.get_sidebearing_extent () >= w) {- break;- }- - result.append_unichar (c);- }- - return result.str;- } private void draw_character_info_icon (Context cr) { double px = x + width - 17;@@ -63,7 +63,8 @@ public class Text : Widget { double a = 1; bool use_cached_glyphs = true;- + double truncated_width = -1;+ public Text (string text = "", double size = 17, double margin_bottom = 0) { current_font = null; this.margin_bottom = margin_bottom;@@ -189,7 +190,7 @@ public class Text : Widget { kern = kc.get_kerning_for_pair (((!) prev).get_name (), ((!) g).get_name (), gr_left, gr_right); }- + // process glyph glyph = (g == null) ? font.get_not_def_character ().get_current () : (!) g; iter (glyph, kern, i + 1 == word_with_ligatures.glyph.size);@@ -353,17 +354,35 @@ public class Text : Widget { y = py; x = px; - if (use_cached_glyphs) { // FIXME:+ 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;+ }+ draw_chached (cr ,glyph, kerning, last, x, y, cc_y, cache_id, ratio);- x += glyph.get_width () * ratio;+ 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, cache_id, ratio);- x += glyph.get_width () * ratio;+ x = end; }); } }@@ -474,6 +493,10 @@ public class Text : Widget { public double get_scale () { return font_size / (font.top_limit - font.bottom_limit); }++ public void truncate (double max_width) {+ truncated_width = max_width;+ } } }@@ -36,12 +36,6 @@ public class Test : Object { public void timer_start () { time_stamp = GLib.get_real_time (); }-- public void timer_stop () {- double stop_time = GLib.get_real_time ();- print_time ("Timer stop after", stop_time);- time_stamp = stop_time - time_stamp;- } public double get_time () { double stop_time = GLib.get_real_time ();@@ -222,7 +222,7 @@ class TestBirdFont : GLib.Object { if (test.is_benchmark ()) { test.timer_start (); test.callback (); - test.timer_stop (); + test.print (); } else { test.callback (); } @@ -31,6 +31,11 @@ GNU Lesser General Public License</copyright> <background scale="1.0000" /> +<collection unicode="U+01">+ <selected id="1"/>+ <glyph id="1" left="-28" right="28">+ </glyph>+</collection> <collection unicode="U+5f"> <selected id="1"/> <glyph id="1" left="-28" right="28">@@ -135,7 +140,7 @@ GNU Lesser General Public License</copyright> </glyph> <glyph id="2" left="-32.797247476493389" right="33.128416240320774"> <path stroke="0" skew="0" data="B -27.1088183313,54.3847655693 M 27.1105242909,54.3847655693 M 27.1105242909,0.1654591265 M -27.1088183313,0.1654591265 M -27.1088183313,54.3847655693" />- <path stroke="0" skew="0" data="B -23.3764411353,2.2013472799 M -20.5619807589,4.8721883250 M -15.2103849146,3.0057465036 M -17.0635466273,8.8897693787 M -14.6212435542,11.6944957747 M -21.8306134081,26.6388242267 M -8.5808359207,18.2440323332 M -4.5400544615,21.9685548383 M 8.6704111470,14.7957780085 M 1.1259609382,28.6830595561 M 4.7143449552,32.0806207982 M -1.9220386362,45.6950395131 M 10.4555360248,37.2124086409 M 13.5668256212,41.0360058700 M 18.9070497252,40.6326845544 M 17.7624900365,46.3785412663 M 21.6212022466,50.9917151254 M -23.1889232170,50.9312954990 M -23.3764411353,2.2013472799" />+ <path stroke="0" skew="0" data="B -23.3764411353,2.2013472799 M -20.5619807589,4.8721883250 M -15.2103849146,3.0057465036 M -17.0635466273,8.8897693787 M -14.6212435542,11.6944957747 M -21.8306134081,26.6388242267 M -8.5808359207,18.2440323332 M -4.5400544615,21.9685548383 M 8.5381360147,14.7957780085 M 1.1259609382,28.6830595561 M 4.7143449552,32.0806207982 M -1.9220386362,45.6950395131 M 10.4555360248,37.2124086409 M 13.5668256212,41.0360058700 M 18.9070497252,40.6326845544 M 17.7624900365,46.3785412663 M 21.6212022466,50.9917151254 M -23.1889232170,50.9312954990 M -23.3764411353,2.2013472799" /> </glyph> </collection> <collection name="convert_point">@@ -222,7 +227,7 @@ GNU Lesser General Public License</copyright> <collection name="export_fonts"> <selected id="1"/> <glyph id="1" left="-28" right="28">- <path stroke="0" skew="0" data="B 19.9981427007,29.6917760640 M 19.9981427007,26.0738343640 M -23.8694004118,26.0738343640 M -23.8694004118,29.6917760640 M 19.9981427007,29.6917760640" />+ <path stroke="0" skew="0" data="B -23.8694004118,29.6917760640 M -23.8694004118,26.0738343640 M 19.9981427007,26.0738343640 M 19.9981427007,29.6917760640 M -23.8694004118,29.6917760640" /> <path stroke="0" skew="0" data="B 23.7291450788,27.8828052140 M 20.9026281257,25.5085309734 M 10.0488030257,38.3974482797 M 12.8753199788,40.7717225203 M 23.7291450788,27.8828052140" /> <path stroke="0" skew="0" data="B 23.9552664350,27.4305625015 M 12.7622593007,14.2024631609 M 10.0488030257,16.5767374015 M 21.1287494819,29.6917760640 M 23.9552664350,27.4305625015" /> </glyph>@@ -525,9 +530,9 @@ GNU Lesser General Public License</copyright> </collection> <collection name="reverse_path"> <selected id="1"/>- <glyph id="1" left="-28" right="47.265151515151544">- <path stroke="0" skew="0" data="B 24.7805035781,53.7044516520 C 24.7805035781,53.7044516520 28.6593735781,51.9177516520 32.7492035781,48.8919516520 C 36.8390835781,45.8661516520 41.3416835781,41.5666516520 42.2179535781,36.0169516520 C 43.0907735781,30.4891516520 40.4111735781,24.5013516520 37.6867035781,19.7982516520 C 35.9737435781,16.8411516520 34.4683235781,14.7798516520 33.3742035781,13.3606516520 M 41.9679535781,10.8294516520 M 46.4992035781,9.4856516520 M 41.9679535781,8.0482516520 M 16.6554535781,0.0794516520 M 14.7492035781,-0.5143483480 M 14.7805035781,1.4856516520 M 14.9055035781,20.8919516520 M 14.9055035781,23.5482516520 M 17.1555035781,22.0794516520 M 24.4367535781,17.2982516520 C 25.4828935781,19.0909516520 29.4612535781,26.1842516520 27.9367535781,32.8919516520 C 27.1405335781,36.3952516520 23.2866735781,39.5079516520 19.4367535781,41.6106516520 C 15.5868335781,43.7134516520 11.9367535781,44.8294516520 11.9367535781,44.8294516520 M 8.5305035781,45.8294516520 M 11.6867535781,47.4856516520 M 23.5305035781,53.6419516520 M 24.1555035781,53.9856516520 M 24.7805035781,53.7044516520" />- <path stroke="0" skew="0" data="B 24.2179535781,50.7356516520 M 15.9367035781,46.4232516520 C 17.3500835781,45.8594516520 18.9913735781,45.1674516520 20.8117035781,44.1732516520 C 24.9644335781,41.9050516520 29.6170535781,38.5295516520 30.7492035781,33.5482516520 C 32.8792135781,24.1763516520 26.2179535781,14.3919516520 26.2179535781,14.3919516520 M 25.4367035781,13.1732516520 M 24.2179535781,13.9856516520 M 17.7492035781,18.2356516520 M 17.6555035781,3.4232516520 M 36.6242535781,9.3919516520 M 30.5305035781,11.2044516520 M 28.4055035781,11.8294516520 M 29.8430035781,13.5169516520 C 29.8430035781,13.5169516520 32.6046335781,16.7782516520 35.1867535781,21.2356516520 C 37.7688735781,25.6931516520 40.0128735781,31.3057516520 39.3430035781,35.5482516520 C 38.6765835781,39.7688516520 34.8468535781,43.7559516520 31.0305035781,46.5794516520 C 27.7325435781,49.0194516520 25.0159935781,50.3559516520 24.2180035781,50.7356516520 M 24.2179535781,50.7356516520" />+ <glyph id="1" left="-26.309523809523803" right="45.383597883597901">+ <path stroke="0" skew="0" data="B 24.7000424278,52.6385195962 C 24.7000424278,52.6385195962 28.2755400756,50.9915601345 32.0454982193,48.2024125779 C 35.8155024524,45.4132650213 39.9659472235,41.4500354888 40.7736828072,36.3343860095 C 41.5782382208,31.2389236976 39.1082138330,25.7194386890 36.5968287965,21.3841753294 C 35.0178420166,18.6583546408 33.6301632161,16.7582720649 32.6216160139,15.4500698664 M 40.5432356894,13.1168388877 M 44.7200897001,11.8781395399 M 40.5432356894,10.5531607913 M 17.2104650087,3.2076128209 M 15.4533057353,2.6602548266 M 15.4821577144,4.5038317693 M 15.5973812733,22.3923353805 M 15.5973812733,24.8408820969 M 17.6714053338,23.4869591902 M 24.3831776407,19.0797041511 C 25.3474974321,20.7321943437 29.0147038150,27.2707165074 27.6094372904,33.4537970365 C 26.8754908738,36.6830985882 23.3230471556,39.5523495629 19.7742352841,41.4905941816 C 16.2254234125,43.4289309791 12.8608217491,44.4576469131 12.8608217491,44.4576469131 M 9.7209797686,45.3794353844 M 12.6303746312,46.9061014507 M 23.5478068386,52.5809078167 M 24.1239246332,52.8977265143 M 24.7000424278,52.6385195962" />+ <path stroke="0" skew="0" data="B 24.1814903232,49.9019139825 M 16.5479295450,45.9267933787 C 17.8507669346,45.4070890386 19.3636891347,44.7692114164 21.0416483427,43.8527693182 C 24.8695869813,41.7619687075 29.1583184588,38.6504717225 30.2019212766,34.0587668103 C 32.1653399384,25.4198574358 26.0250672659,16.4007103169 26.0250672659,16.4007103169 M 25.3049200227,15.2773267068 M 24.1814903232,16.0261876610 M 18.2186711493,19.9437886641 M 18.1322995695,6.2898891113 M 35.6174746351,11.7917679602 M 30.0003261379,13.4625095645 M 28.0415256363,14.0386273591 M 29.3665965639,15.5941454044 C 29.3665965639,15.5941454044 31.9122352600,18.6003741460 34.2924037076,22.7091540781 C 36.6725721552,26.8180261891 38.7410654849,31.9916561633 38.1235870416,35.9023437529 C 37.5092887685,39.7928441751 33.9790878062,43.4681069891 30.4612203736,46.0707767379 C 27.4211988667,48.3199406080 24.9171143949,49.5519108999 24.1815364126,49.9019139825 M 24.1814903232,49.9019139825" /> <path stroke="0" skew="0" data="B 2.0546235781,52.3710516520 M 1.9262535781,32.9589516520 M -5.6495264219,38.0974516520 C -5.6495264219,38.0974516520 -12.9863064219,29.1023516520 -11.0580064219,20.6176516520 C -9.1296364219,12.1329516520 5.9114635781,7.6333516520 5.9114635781,7.6333516520 M -5.9157164219,1.4627516520 C -5.9157164219,1.4627516520 -20.9643867219,8.2750516520 -22.4995067219,18.0464516520 C -24.4057467319,30.1802516520 -13.0213164219,41.2527516520 -13.0213164219,41.2527516520 M -23.2708067219,44.4005516520 M 2.0546235781,52.3710516520" /> </glyph> </collection>