[geary] Fix remaining icon issues with bug #732065



commit d7e8136cd56cd5f5024101cfdde8e66107e4cc8a
Author: Jim Nelson <jim yorba org>
Date:   Fri Oct 3 15:01:25 2014 -0700

    Fix remaining icon issues with bug #732065
    
    Archive button now loads and miscellaneous icons (including close icon
    used in viewer pane) are scaled properly.
    
    Spam icon remains too small under GTK+ 3.14.  That will be fixed with
    bug #737862.

 src/client/components/icon-factory.vala |   24 ++++++++++++++++++++++--
 src/client/components/pill-toolbar.vala |   20 +++++++++++++++-----
 2 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/src/client/components/icon-factory.vala b/src/client/components/icon-factory.vala
index c1478be..6277d8a 100644
--- a/src/client/components/icon-factory.vala
+++ b/src/client/components/icon-factory.vala
@@ -123,6 +123,26 @@ public class IconFactory {
             icon_theme.lookup_icon("document-symbolic", size, flags);
     }
     
+    // GTK+ 3.14 no longer scales icons via the IconInfo, so perform manually until we
+    // properly install the icons as per 3.14's expectations.
+    private Gdk.Pixbuf aspect_scale_down_pixbuf(Gdk.Pixbuf pixbuf, int size) {
+        if (pixbuf.width <= size && pixbuf.height <= size)
+            return pixbuf;
+        
+        int scaled_width, scaled_height;
+        if (pixbuf.width >= pixbuf.height) {
+            double aspect = (double) size / (double) pixbuf.width;
+            scaled_width = size;
+            scaled_height = (int) Math.round((double) pixbuf.height * aspect);
+        } else {
+            double aspect = (double) size / (double) pixbuf.height;
+            scaled_width = (int) Math.round((double) pixbuf.width * aspect);
+            scaled_height = size;
+        }
+        
+        return pixbuf.scale_simple(scaled_width, scaled_height, Gdk.InterpType.BILINEAR);
+    }
+    
     public Gdk.Pixbuf? load_symbolic(string icon_name, int size, Gtk.StyleContext style,
         Gtk.IconLookupFlags flags = 0) {
         Gtk.IconInfo? icon_info = icon_theme.lookup_icon(icon_name, size, flags);
@@ -130,7 +150,7 @@ public class IconFactory {
         // Attempt to load as a symbolic icon.
         if (icon_info != null) {
             try {
-                return icon_info.load_symbolic_for_context(style);
+                return aspect_scale_down_pixbuf(icon_info.load_symbolic_for_context(style), size);
             } catch (Error e) {
                 message("Couldn't load icon: %s", e.message);
             }
@@ -151,7 +171,7 @@ public class IconFactory {
         // Attempt to load as a symbolic icon.
         if (icon_info != null) {
             try {
-                return icon_info.load_symbolic(color);
+                return aspect_scale_down_pixbuf(icon_info.load_symbolic(color), size);
             } catch (Error e) {
                 warning("Couldn't load icon: %s", e.message);
             }
diff --git a/src/client/components/pill-toolbar.vala b/src/client/components/pill-toolbar.vala
index 1c9a1a9..b4ea51d 100644
--- a/src/client/components/pill-toolbar.vala
+++ b/src/client/components/pill-toolbar.vala
@@ -39,16 +39,26 @@ public interface PillBar : Gtk.Container {
         b.tooltip_text = b.related_action.tooltip;
         b.related_action.notify["tooltip"].connect(() => { b.tooltip_text = b.related_action.tooltip; });
         
+        // Load icon by name with this fallback order: specified icon name, the action's icon name,
+        // the action's stock ID ... although stock IDs are being deprecated, that's how we specify
+        // the icon in the GtkActionEntry (also being deprecated) and GTK+ 3.14 doesn't support that
+        // any longer
+        string? icon_to_load = icon_name ?? b.related_action.icon_name;
+        if (icon_to_load == null)
+            icon_to_load = b.related_action.stock_id;
+        
         // set pixel size to force GTK+ to load our images from our installed directory, not the theme
         // directory
-        Gtk.Image image = new Gtk.Image.from_icon_name(icon_name != null ? icon_name :
-            b.related_action.icon_name, Gtk.IconSize.MENU);
-        image.set_pixel_size(16);
-        b.image = image;
+        if (icon_to_load != null) {
+            Gtk.Image image = new Gtk.Image.from_icon_name(icon_to_load, Gtk.IconSize.MENU);
+            image.set_pixel_size(16);
+            b.image = image;
+        }
         
         // Unity buttons are a bit tight
 #if ENABLE_UNITY
-        b.image.margin = b.image.margin + 4;
+        if (b.image != null)
+            b.image.margin = b.image.margin + 4;
 #endif
         b.always_show_image = true;
         


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]