Cache fontdescs
authorEnrico Zini <enrico@enricozini.org>
Tue, 8 Dec 2009 23:07:57 +0000 (23:07 +0000)
committerEnrico Zini <enrico@enricozini.org>
Tue, 8 Dec 2009 23:07:57 +0000 (23:07 +0000)
src/fisheye.vala

index 325c624db3cc09deeb622a888e42ae26467cec7b..62251208442cbc9962a7864fb84c41b4d6bed737 100644 (file)
@@ -28,6 +28,8 @@ public class FisheyeList : Gtk.DrawingArea
        protected int cur_el;
        protected double distortion_factor;
 
+       protected Pango.FontDescription[] fontdesc_cache;
+
        // Number of items shown before and after the focus element
        protected int focus_first;
        protected int focus_end;
@@ -44,6 +46,10 @@ public class FisheyeList : Gtk.DrawingArea
                for (int i = 0; i < 300; ++i)
                        list[i] = "Lorem Ipsum %d".printf(i);
 
+               fontdesc_cache = new Pango.FontDescription[30];
+               for (int i = 0; i < 30; ++i)
+                       fontdesc_cache[i] = null;
+
                cur_el = 0;
                focus_centre = 0;
                focus_size = 20;
@@ -198,13 +204,17 @@ public class FisheyeList : Gtk.DrawingArea
                        }
 
                        var layout = create_pango_layout(list[idx]);
-
-                       var fd = style.font_desc.copy();
-                       //fd.set_size((y1-y0)*Pango.SCALE);
-                       int size = (y1-y0)*Pango.SCALE*80/100;
-                       if (size <= 0) size = Pango.SCALE;
-                       fd.set_absolute_size(size);
-                       layout.set_font_description(fd);
+               
+                       
+                       int size = (y1-y0)*80/100;
+                       if (size <= 0) size = 1;
+                       if (size >= fontdesc_cache.length) size = fontdesc_cache.length - 1;
+                       if (fontdesc_cache[size] == null)
+                       {
+                               fontdesc_cache[size] = style.font_desc.copy();
+                               fontdesc_cache[size].set_absolute_size(size*Pango.SCALE);
+                       }
+                       layout.set_font_description(fontdesc_cache[size]);
                        //stderr.printf("AZAZA %p\n", layout.get_attributes());
                        //var attrlist = layout.get_attributes().copy();
                        //stderr.printf("AL %p\n", attrlist);