[gtk+/wip/scale-to-fit: 3/6] GtkIconHelper: Preserve aspect ratio when scaling



commit c8856b593b8850a095e0949b4fb8ca667483dda3
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 1 12:06:34 2014 +0200

    GtkIconHelper: Preserve aspect ratio when scaling
    
    When scaling to a given size, preserve the aspect ratio of
    the original image. This will be used for the GtkImage::scale-to-fit
    property.

 gtk/gtkiconhelper.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index a263b05..84db340 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -562,8 +562,16 @@ get_pixbuf_size (GtkIconHelper   *self,
 
   if (self->priv->width != 0 && self->priv->height != 0)
     {
+      gdouble s;
+      gdouble orig_width, orig_height;
+
+      /* We preserve the aspect ratio when fitting to size */
+      orig_width = gdk_pixbuf_get_width (self->priv->orig_pixbuf);
+      orig_height = gdk_pixbuf_get_height (self->priv->orig_pixbuf);
+      s = MIN (width * scale / orig_width, height * scale / orig_height);
+
       pixbuf = gdk_pixbuf_scale_simple (self->priv->orig_pixbuf,
-                                        width * scale, height * scale,
+                                        s * orig_width, s * orig_height,
                                        GDK_INTERP_BILINEAR);
     }
   else if (self->priv->force_scale_pixbuf &&


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