[gtk: 29/31] icon-theme: Add back and fix test for handling non-square icons



commit ad0e9010611a9a4bfea9e5f691792491f32e1d09
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Feb 10 13:12:26 2020 +0100

    icon-theme: Add back and fix test for handling non-square icons
    
    We test this by looking at the produced render nodes now that
    we don't actualluy scale the icon. Also, it turns out that this
    code was broken due to some typos, so we also fix those.

 gtk/gtkicontheme.c        |  4 ++--
 testsuite/gtk/icontheme.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 92d7c43e36..4adacf54ce 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3721,7 +3721,7 @@ gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
     }
 
   texture_width = gdk_texture_get_width (texture);
-  texture_height = gdk_texture_get_width (texture);
+  texture_height = gdk_texture_get_height (texture);
 
   /* Keep aspect ratio and center */
   if (texture_width >= texture_height)
@@ -3739,7 +3739,7 @@ gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
                                &GRAPHENE_RECT_INIT ((width - render_width) / 2,
                                                     (height - render_height) / 2,
                                                     render_width,
-                                                    render_width));
+                                                    render_height));
 
   if (symbolic)
     gtk_snapshot_pop (snapshot);
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index 1760c3a431..c6c7b638b1 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -715,6 +715,64 @@ test_inherit (void)
                       "/icons2/scalable/one-two-symbolic-rtl.svg");
 }
 
+static void
+test_nonsquare_symbolic (void)
+{
+  gint width, height, size;
+  GtkIconTheme *icon_theme;
+  GtkIconPaintable *info;
+  GFile *file;
+  GIcon *icon;
+  GError *error = NULL;
+  GdkPixbuf *pixbuf;
+  GtkSnapshot *snapshot;
+  GskRenderNode *node;
+  graphene_rect_t bounds;
+
+  gchar *path = g_build_filename (g_test_get_dir (G_TEST_DIST),
+                                  "icons",
+                                  "scalable",
+                                  "nonsquare-symbolic.svg",
+                                  NULL);
+
+  /* load the original image for reference */
+  pixbuf = gdk_pixbuf_new_from_file (path, &error);
+
+  g_assert_no_error (error);
+  g_assert_nonnull (pixbuf);
+
+  width = gdk_pixbuf_get_width (pixbuf);
+  height = gdk_pixbuf_get_height (pixbuf);
+  size = MAX (width, height);
+  g_object_unref (pixbuf);
+
+  g_assert_cmpint (width, !=, height);
+
+  /* now load it through GtkIconTheme */
+  icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
+  file = g_file_new_for_path (path);
+  icon = g_file_icon_new (file);
+  info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon,
+                                         height, 1, GTK_TEXT_DIR_NONE, 0);
+  g_assert_nonnull (info);
+
+  snapshot = gtk_snapshot_new ();
+  gdk_paintable_snapshot (GDK_PAINTABLE (info), snapshot, size, size);
+  node = gtk_snapshot_free_to_node (snapshot);
+
+  /* the original dimensions have been preserved */
+
+  gsk_render_node_get_bounds (node, &bounds);
+  g_assert (bounds.size.width == width);
+  g_assert (bounds.size.height == height);
+
+  gsk_render_node_unref (node);
+  g_free (path);
+  g_object_unref (file);
+  g_object_unref (icon);
+  g_object_unref (info);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -731,6 +789,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/icontheme/size", test_size);
   g_test_add_func ("/icontheme/list", test_list);
   g_test_add_func ("/icontheme/inherit", test_inherit);
+  g_test_add_func ("/icontheme/nonsquare-symbolic", test_nonsquare_symbolic);
 
   return g_test_run();
 }


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