diff options
author | Benjamin Otte <otte@redhat.com> | 2015-11-28 07:06:37 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-12-02 00:29:29 +0100 |
commit | afd0e284375baa0da4a86c31fd1994a3612e1a24 (patch) | |
tree | 1a14b147f5e03867894f744079e9f48d4e24dafc /gtk/gtkiconhelper.c | |
parent | 071d2a1d69c5bad3d6d4b451a9f7568fbf2507a8 (diff) | |
download | gtk+-afd0e284375baa0da4a86c31fd1994a3612e1a24.tar.gz |
iconhelper: Improve size determination for surfaces
Instead of just working for image surface, this should now work for all
bounded surfaces.
Test included.
Diffstat (limited to 'gtk/gtkiconhelper.c')
-rw-r--r-- | gtk/gtkiconhelper.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c index d4b5aa0b23..89488c3d63 100644 --- a/gtk/gtkiconhelper.c +++ b/gtk/gtkiconhelper.c @@ -346,22 +346,26 @@ get_surface_size (GtkIconHelper *self, int *width, int *height) { - double x_scale, y_scale; + GdkRectangle clip; + cairo_t *cr; - if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE) + cr = cairo_create (surface); + if (gdk_cairo_get_clip_rectangle (cr, &clip)) { - x_scale = y_scale = 1; - - cairo_surface_get_device_scale (surface, &x_scale, &y_scale); - - /* Assume any set scaling is icon scale */ - *width = - ceil (cairo_image_surface_get_width (surface) / x_scale); - *height = - ceil (cairo_image_surface_get_height (surface) / y_scale); + if (clip.x != 0 || clip.y != 0) + { + g_warning ("origin of surface is %d %d, not supported", clip.x, clip.y); + } + *width = clip.width; + *height = clip.height; } else - ensure_icon_size (self, width, height); + { + g_warning ("infinite surface size not supported"); + ensure_icon_size (self, width, height); + } + + cairo_destroy (cr); } static void |