2014-05-12 16:19:47 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-05-13 01:17:15 +00:00
|
|
|
#define SCALABLE_IMAGE_SIZE (128)
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
static GtkIconTheme *
|
2014-06-24 01:24:41 +00:00
|
|
|
get_test_icontheme (gboolean force_reload)
|
2014-05-12 16:19:47 +00:00
|
|
|
{
|
|
|
|
static GtkIconTheme *icon_theme = NULL;
|
2020-02-18 05:56:37 +00:00
|
|
|
const char *current_dir[2];
|
2014-05-12 16:19:47 +00:00
|
|
|
|
2014-06-24 01:24:41 +00:00
|
|
|
if (force_reload)
|
|
|
|
g_clear_object (&icon_theme);
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
if (icon_theme)
|
|
|
|
return icon_theme;
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_new ();
|
2020-02-18 05:56:37 +00:00
|
|
|
gtk_icon_theme_set_theme_name (icon_theme, "icons");
|
|
|
|
current_dir[0] = g_test_get_dir (G_TEST_DIST);
|
|
|
|
current_dir[1] = NULL;
|
|
|
|
gtk_icon_theme_set_search_path (icon_theme, current_dir);
|
2014-05-12 16:19:47 +00:00
|
|
|
|
|
|
|
return icon_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
lookup_flags_to_string (GtkIconLookupFlags flags)
|
|
|
|
{
|
|
|
|
GValue flags_value = { 0, }, string_value = { 0, };
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
g_value_init (&flags_value, GTK_TYPE_ICON_LOOKUP_FLAGS);
|
|
|
|
g_value_init (&string_value, G_TYPE_STRING);
|
|
|
|
|
|
|
|
g_value_set_flags (&flags_value, flags);
|
|
|
|
if (!g_value_transform (&flags_value, &string_value))
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
result = g_value_dup_string (&string_value);
|
|
|
|
|
|
|
|
g_value_unset (&flags_value);
|
|
|
|
g_value_unset (&string_value);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-14 19:06:57 +00:00
|
|
|
assert_icon_lookup_size (const char *icon_name,
|
2020-07-24 13:54:49 +00:00
|
|
|
int size,
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkTextDirection direction,
|
2014-06-14 19:06:57 +00:00
|
|
|
GtkIconLookupFlags flags,
|
2020-02-04 03:26:19 +00:00
|
|
|
gboolean fallbacks,
|
2014-06-14 19:06:57 +00:00
|
|
|
const char *filename,
|
2020-07-24 13:54:49 +00:00
|
|
|
int pixbuf_size)
|
2014-05-12 16:19:47 +00:00
|
|
|
{
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *info;
|
2020-02-10 11:33:17 +00:00
|
|
|
GFile *file;
|
|
|
|
char *path = NULL;
|
2014-05-12 16:19:47 +00:00
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
if (fallbacks)
|
|
|
|
{
|
|
|
|
GThemedIcon *fallback_icons = G_THEMED_ICON (g_themed_icon_new_with_default_fallbacks (icon_name));
|
|
|
|
const char **fallback_names = (const char **) g_themed_icon_get_names (fallback_icons);
|
|
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, &fallback_names[1], size, 1, direction, flags);
|
|
|
|
g_object_unref (fallback_icons);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
|
|
|
|
}
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
g_error ("Could not look up an icon for \"%s\" with flags %s at size %d",
|
|
|
|
icon_name, lookup_flags_to_string (flags), size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-10 11:33:17 +00:00
|
|
|
file = gtk_icon_paintable_get_file (info);
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
path = g_file_get_path (file);
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
2014-06-17 18:38:18 +00:00
|
|
|
if (filename)
|
2014-05-12 16:19:47 +00:00
|
|
|
{
|
2020-02-10 11:33:17 +00:00
|
|
|
if (path == NULL || !g_str_has_suffix (path, filename))
|
2014-06-17 18:38:18 +00:00
|
|
|
{
|
|
|
|
g_error ("Icon for \"%s\" with flags %s at size %d should be \"...%s\" but is \"...%s\"",
|
|
|
|
icon_name, lookup_flags_to_string (flags), size,
|
2020-02-10 11:33:17 +00:00
|
|
|
filename, path);
|
2014-06-17 18:38:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_null (path);
|
2014-05-12 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 11:33:17 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
g_assert_cmpint (gdk_paintable_get_intrinsic_width (GDK_PAINTABLE (info)), ==, size);
|
2014-06-14 19:06:57 +00:00
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:06:57 +00:00
|
|
|
static void
|
|
|
|
assert_icon_lookup (const char *icon_name,
|
2020-07-24 13:54:49 +00:00
|
|
|
int size,
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkTextDirection direction,
|
2014-06-14 19:06:57 +00:00
|
|
|
GtkIconLookupFlags flags,
|
2020-02-04 03:26:19 +00:00
|
|
|
gboolean fallbacks,
|
2014-06-14 19:06:57 +00:00
|
|
|
const char *filename)
|
|
|
|
{
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size (icon_name, size, direction, flags, fallbacks, filename, -1);
|
2014-06-14 19:06:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 01:17:15 +00:00
|
|
|
static void
|
|
|
|
assert_icon_lookup_fails (const char *icon_name,
|
2020-07-24 13:54:49 +00:00
|
|
|
int size,
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkTextDirection direction,
|
2014-05-13 01:17:15 +00:00
|
|
|
GtkIconLookupFlags flags)
|
|
|
|
{
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *info;
|
2014-05-13 01:17:15 +00:00
|
|
|
|
2020-02-04 02:53:22 +00:00
|
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
|
2014-05-13 13:07:40 +00:00
|
|
|
|
2020-02-05 16:08:29 +00:00
|
|
|
/* We never truly *fail*, but check that we got the image-missing fallback */
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_nonnull (info);
|
2020-02-06 16:28:19 +00:00
|
|
|
g_assert_cmpstr (gtk_icon_paintable_get_icon_name (info), ==, "image-missing");
|
2014-05-13 01:17:15 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 02:13:58 +00:00
|
|
|
static GList *lookups = NULL;
|
|
|
|
|
2016-08-03 03:23:43 +00:00
|
|
|
static GLogWriterOutput
|
|
|
|
log_writer (GLogLevelFlags log_level,
|
|
|
|
const GLogField *fields,
|
|
|
|
gsize n_fields,
|
|
|
|
gpointer user_data)
|
2014-05-14 02:13:58 +00:00
|
|
|
{
|
2016-08-03 03:23:43 +00:00
|
|
|
const char *domain = NULL;
|
|
|
|
const char *msg = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++)
|
|
|
|
{
|
|
|
|
if (strcmp (fields[i].key, "GLIB_DOMAIN") == 0)
|
|
|
|
domain = fields[i].value;
|
|
|
|
if (strcmp (fields[i].key, "MESSAGE") == 0)
|
|
|
|
msg = fields[i].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_level != G_LOG_LEVEL_MESSAGE || g_strcmp0 (domain, "Gtk") != 0)
|
|
|
|
return g_log_writer_default (log_level, fields, n_fields, user_data);
|
|
|
|
|
|
|
|
if (g_str_has_prefix (msg, "\tlookup name: "))
|
2014-05-14 02:13:58 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *s;
|
2016-08-03 03:23:43 +00:00
|
|
|
s = g_strchomp (g_strdup (msg + strlen ("\tlookup name: ")));
|
2014-05-14 02:13:58 +00:00
|
|
|
lookups = g_list_append (lookups, s);
|
|
|
|
}
|
2016-08-03 03:23:43 +00:00
|
|
|
|
|
|
|
return G_LOG_WRITER_HANDLED;
|
2014-05-14 02:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
assert_lookup_order (const char *icon_name,
|
2020-07-24 13:54:49 +00:00
|
|
|
int size,
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkTextDirection direction,
|
2014-05-14 02:13:58 +00:00
|
|
|
GtkIconLookupFlags flags,
|
2020-02-04 03:26:19 +00:00
|
|
|
gboolean fallbacks,
|
2014-05-14 02:13:58 +00:00
|
|
|
const char *first,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
guint debug_flags;
|
|
|
|
va_list args;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *s;
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *info;
|
2014-05-14 02:13:58 +00:00
|
|
|
GList *l;
|
|
|
|
|
2020-02-13 15:56:26 +00:00
|
|
|
/* this hack is only usable in debug builds */
|
|
|
|
#ifndef G_ENABLE_DEBUG
|
|
|
|
g_assert_not_reached ();
|
|
|
|
#endif
|
|
|
|
|
2014-05-14 02:13:58 +00:00
|
|
|
debug_flags = gtk_get_debug_flags ();
|
|
|
|
gtk_set_debug_flags (debug_flags | GTK_DEBUG_ICONTHEME);
|
2016-08-03 03:23:43 +00:00
|
|
|
g_log_set_writer_func (log_writer, NULL, NULL);
|
2014-05-14 02:13:58 +00:00
|
|
|
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_null (lookups);
|
2016-02-28 20:36:14 +00:00
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
if (fallbacks)
|
|
|
|
{
|
|
|
|
GThemedIcon *fallback_icons = G_THEMED_ICON (g_themed_icon_new_with_default_fallbacks (icon_name));
|
|
|
|
const char **fallback_names = (const char **) g_themed_icon_get_names (fallback_icons);
|
|
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, &fallback_names[1], size, 1, direction, flags);
|
|
|
|
g_object_unref (fallback_icons);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = gtk_icon_theme_lookup_icon (get_test_icontheme (FALSE), icon_name, NULL, size, 1, direction, flags);
|
|
|
|
}
|
|
|
|
|
2014-05-14 02:13:58 +00:00
|
|
|
if (info)
|
|
|
|
g_object_unref (info);
|
|
|
|
|
|
|
|
va_start (args, first);
|
|
|
|
s = first;
|
|
|
|
l = lookups;
|
|
|
|
while (s != NULL)
|
|
|
|
{
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_nonnull (l);
|
2014-05-14 02:13:58 +00:00
|
|
|
g_assert_cmpstr (s, ==, l->data);
|
2020-07-24 18:40:36 +00:00
|
|
|
s = va_arg (args, char *);
|
2014-05-14 02:13:58 +00:00
|
|
|
l = l->next;
|
|
|
|
}
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_null (l);
|
2014-05-14 02:13:58 +00:00
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
g_list_free_full (lookups, g_free);
|
|
|
|
lookups = NULL;
|
|
|
|
|
2016-08-03 03:23:43 +00:00
|
|
|
g_log_set_writer_func (g_log_writer_default, NULL, NULL);
|
2014-05-14 02:13:58 +00:00
|
|
|
gtk_set_debug_flags (debug_flags);
|
|
|
|
}
|
2014-05-13 01:17:15 +00:00
|
|
|
|
2020-02-13 15:56:26 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
#define require_debug()
|
|
|
|
#else
|
|
|
|
#define require_debug() \
|
|
|
|
g_test_skip ("requires G_ENABLE_DEBUG"); \
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
static void
|
|
|
|
test_basics (void)
|
|
|
|
{
|
2014-05-13 13:07:40 +00:00
|
|
|
/* just a basic boring lookup so we know everything works */
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup ("simple", 16, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16x16/simple.png");
|
2014-05-12 16:19:47 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 02:13:58 +00:00
|
|
|
static void
|
|
|
|
test_lookup_order (void)
|
|
|
|
{
|
2020-02-13 15:56:26 +00:00
|
|
|
require_debug ();
|
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"foo-bar-baz",
|
|
|
|
"foo-bar",
|
|
|
|
"foo",
|
2020-02-04 03:26:19 +00:00
|
|
|
"foo-bar-baz-symbolic",
|
|
|
|
"foo-bar-symbolic",
|
|
|
|
"foo-symbolic",
|
2014-05-14 02:13:58 +00:00
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, TRUE,
|
2014-06-25 17:52:18 +00:00
|
|
|
"foo-bar-baz-rtl",
|
|
|
|
"foo-bar-baz",
|
|
|
|
"foo-bar-rtl",
|
|
|
|
"foo-bar",
|
|
|
|
"foo-rtl",
|
|
|
|
"foo",
|
2020-02-04 03:26:19 +00:00
|
|
|
"foo-bar-baz-symbolic-rtl",
|
|
|
|
"foo-bar-baz-symbolic",
|
|
|
|
"foo-bar-symbolic-rtl",
|
|
|
|
"foo-bar-symbolic",
|
|
|
|
"foo-symbolic-rtl",
|
|
|
|
"foo-symbolic",
|
2014-06-25 17:52:18 +00:00
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, FALSE,
|
2014-06-25 17:52:18 +00:00
|
|
|
"foo-bar-baz-rtl",
|
|
|
|
"foo-bar-baz",
|
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("foo-bar-baz-symbolic", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"foo-bar-baz-symbolic",
|
|
|
|
"foo-bar-symbolic",
|
|
|
|
"foo-symbolic",
|
|
|
|
"foo-bar-baz",
|
|
|
|
"foo-bar",
|
|
|
|
"foo",
|
|
|
|
NULL);
|
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bla-bla", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bla-bla-symbolic",
|
|
|
|
"bla-symbolic",
|
2020-02-04 03:26:19 +00:00
|
|
|
"bla-bla-symbolic", /* awkward */
|
|
|
|
"bla-symbolic", /* awkward */
|
2014-05-14 02:13:58 +00:00
|
|
|
"bla-bla",
|
|
|
|
"bla",
|
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bla-bla-symbolic", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bla-bla-symbolic",
|
|
|
|
"bla-symbolic",
|
|
|
|
"bla-bla-symbolic", /* awkward */
|
|
|
|
"bla-symbolic", /* awkward */
|
|
|
|
"bla-bla",
|
|
|
|
"bla",
|
|
|
|
NULL);
|
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bar-baz", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-symbolic-rtl",
|
|
|
|
"bar-baz-symbolic",
|
|
|
|
"bar-symbolic-rtl",
|
|
|
|
"bar-symbolic",
|
2020-02-04 03:26:19 +00:00
|
|
|
"bar-baz-symbolic-rtl", /* awkward */
|
|
|
|
"bar-baz-symbolic", /* awkward */
|
|
|
|
"bar-symbolic-rtl", /* awkward */
|
|
|
|
"bar-symbolic", /* awkward */
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-rtl",
|
|
|
|
"bar-baz",
|
|
|
|
"bar-rtl",
|
|
|
|
"bar",
|
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bar-baz-symbolic", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-symbolic-rtl",
|
|
|
|
"bar-baz-symbolic",
|
|
|
|
"bar-symbolic-rtl",
|
|
|
|
"bar-symbolic",
|
|
|
|
"bar-baz-symbolic-rtl", /* awkward */
|
|
|
|
"bar-baz-symbolic", /* awkward */
|
|
|
|
"bar-symbolic-rtl", /* awkward */
|
|
|
|
"bar-symbolic", /* awkward */
|
|
|
|
"bar-baz-rtl",
|
|
|
|
"bar-baz",
|
|
|
|
"bar-rtl",
|
|
|
|
"bar",
|
|
|
|
NULL);
|
|
|
|
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bar-baz", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-symbolic-ltr",
|
|
|
|
"bar-baz-symbolic",
|
|
|
|
"bar-symbolic-ltr",
|
|
|
|
"bar-symbolic",
|
2020-02-04 03:26:19 +00:00
|
|
|
"bar-baz-symbolic-ltr", /* awkward */
|
|
|
|
"bar-baz-symbolic", /* awkward */
|
|
|
|
"bar-symbolic-ltr", /* awkward */
|
|
|
|
"bar-symbolic", /* awkward */
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-ltr",
|
|
|
|
"bar-baz",
|
|
|
|
"bar-ltr",
|
|
|
|
"bar",
|
|
|
|
NULL);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_lookup_order ("bar-baz-symbolic", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
|
2014-05-14 02:13:58 +00:00
|
|
|
"bar-baz-symbolic-ltr",
|
|
|
|
"bar-baz-symbolic",
|
|
|
|
"bar-symbolic-ltr",
|
|
|
|
"bar-symbolic",
|
|
|
|
"bar-baz-symbolic-ltr", /* awkward */
|
|
|
|
"bar-baz-symbolic", /* awkward */
|
|
|
|
"bar-symbolic-ltr", /* awkward */
|
|
|
|
"bar-symbolic", /* awkward */
|
|
|
|
"bar-baz-ltr",
|
|
|
|
"bar-baz",
|
|
|
|
"bar-ltr",
|
|
|
|
"bar",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2014-05-13 13:23:53 +00:00
|
|
|
static void
|
|
|
|
test_generic_fallback (void)
|
|
|
|
{
|
|
|
|
/* simple test for generic fallback */
|
|
|
|
assert_icon_lookup ("simple-foo-bar",
|
|
|
|
16,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-13 13:23:53 +00:00
|
|
|
"/icons/16x16/simple.png");
|
|
|
|
|
|
|
|
/* Check generic fallback also works for symbolics falling back to regular items */
|
|
|
|
assert_icon_lookup ("simple-foo-bar-symbolic",
|
|
|
|
16,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-13 13:23:53 +00:00
|
|
|
"/icons/16x16/simple.png");
|
|
|
|
|
|
|
|
/* Check we fall back to more generic symbolic icons before falling back to
|
|
|
|
* non-symbolics */
|
|
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-13 13:23:53 +00:00
|
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
}
|
|
|
|
|
2014-05-13 01:17:15 +00:00
|
|
|
static void
|
|
|
|
test_force_symbolic (void)
|
|
|
|
{
|
|
|
|
/* check forcing symbolic works */
|
|
|
|
assert_icon_lookup ("everything",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
/* check forcing symbolic also works for symbolic icons (d'oh) */
|
|
|
|
assert_icon_lookup ("everything-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
|
|
|
|
/* check all the combos for fallbacks on an icon that only exists as symbolic */
|
|
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
|
|
|
|
/* check all the combos for fallbacks, this time for an icon that only exists as regular */
|
|
|
|
assert_icon_lookup ("everything-justregular",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
assert_icon_lookup ("everything-justregular",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
assert_icon_lookup_fails ("everything-justregular-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
|
|
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-symbolic.svg");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_force_regular (void)
|
|
|
|
{
|
|
|
|
/* check forcing regular works (d'oh) */
|
|
|
|
assert_icon_lookup ("everything",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
/* check forcing regular also works for symbolic icons ) */
|
|
|
|
assert_icon_lookup ("everything-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
|
|
|
|
/* check all the combos for fallbacks on an icon that only exists as regular */
|
|
|
|
assert_icon_lookup ("everything-justregular",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
assert_icon_lookup ("everything-justregular",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
assert_icon_lookup ("everything-justregular-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justregular.svg");
|
|
|
|
|
|
|
|
/* check all the combos for fallbacks, this time for an icon that only exists as symbolic */
|
|
|
|
assert_icon_lookup_fails ("everything-justsymbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR);
|
|
|
|
assert_icon_lookup ("everything-justsymbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-13 01:17:15 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything-justsymbolic-symbolic.svg");
|
|
|
|
assert_icon_lookup ("everything-justsymbolic-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
GTK_ICON_LOOKUP_FORCE_REGULAR,
|
|
|
|
TRUE,
|
2014-05-13 01:17:15 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
}
|
|
|
|
|
2014-05-14 02:52:55 +00:00
|
|
|
static void
|
|
|
|
test_rtl (void)
|
|
|
|
{
|
|
|
|
assert_icon_lookup ("everything",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything-rtl.svg");
|
|
|
|
assert_icon_lookup ("everything-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything-symbolic-rtl.svg");
|
|
|
|
|
|
|
|
assert_icon_lookup_fails ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-05-14 02:52:55 +00:00
|
|
|
0);
|
|
|
|
assert_icon_lookup_fails ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_LTR,
|
|
|
|
0);
|
2014-05-14 02:52:55 +00:00
|
|
|
assert_icon_lookup ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything-justrtl-rtl.svg");
|
|
|
|
|
|
|
|
assert_icon_lookup ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
assert_icon_lookup ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_LTR,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything.svg");
|
|
|
|
assert_icon_lookup ("everything-justrtl",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-05-14 02:52:55 +00:00
|
|
|
"/icons/scalable/everything-justrtl-rtl.svg");
|
|
|
|
}
|
|
|
|
|
2014-06-12 10:28:07 +00:00
|
|
|
static void
|
|
|
|
test_symbolic_single_size (void)
|
|
|
|
{
|
|
|
|
/* Check we properly load a symbolic icon from a sized directory */
|
|
|
|
assert_icon_lookup ("only32-symbolic",
|
|
|
|
32,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-06-12 10:28:07 +00:00
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-06-12 10:28:07 +00:00
|
|
|
"/icons/32x32/only32-symbolic.svg");
|
|
|
|
/* Check that we still properly load it even if a different size is requested */
|
|
|
|
assert_icon_lookup ("only32-symbolic",
|
|
|
|
16,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-06-12 10:28:07 +00:00
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-06-12 10:28:07 +00:00
|
|
|
"/icons/32x32/only32-symbolic.svg");
|
|
|
|
assert_icon_lookup ("only32-symbolic",
|
|
|
|
128,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2014-06-12 10:28:07 +00:00
|
|
|
0,
|
2020-02-04 03:26:19 +00:00
|
|
|
FALSE,
|
2014-06-12 10:28:07 +00:00
|
|
|
"/icons/32x32/only32-symbolic.svg");
|
|
|
|
}
|
|
|
|
|
2014-06-14 19:06:57 +00:00
|
|
|
static void
|
|
|
|
test_svg_size (void)
|
|
|
|
{
|
|
|
|
/* Check we properly load a svg icon from a sized directory */
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("twosize-fixed", 48, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32/twosize-fixed.svg", 48);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size ("twosize-fixed", 32, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32/twosize-fixed.svg", 32);
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("twosize-fixed", 20, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32/twosize-fixed.svg", 20);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size ("twosize-fixed", 16, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16x16/twosize-fixed.svg", 16);
|
2014-06-14 19:06:57 +00:00
|
|
|
|
|
|
|
/* Check that we still properly load it even if a different size is requested */
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("twosize", 64, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32s/twosize.svg", 64);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size ("twosize", 48, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32s/twosize.svg", 48);
|
|
|
|
assert_icon_lookup_size ("twosize", 32, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32s/twosize.svg", 32);
|
|
|
|
assert_icon_lookup_size ("twosize", 24, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/32x32s/twosize.svg", 24);
|
|
|
|
assert_icon_lookup_size ("twosize", 16, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16x16s/twosize.svg", 16);
|
|
|
|
assert_icon_lookup_size ("twosize", 12, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16x16s/twosize.svg", 12);
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("twosize", 8, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16x16s/twosize.svg", 8);
|
2014-06-14 19:06:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-18 22:19:39 +00:00
|
|
|
static void
|
|
|
|
test_size (void)
|
|
|
|
{
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size ("size-test", 12, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/15/size-test.png", 15);
|
|
|
|
assert_icon_lookup_size ("size-test", 13, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/15/size-test.png", 15);
|
|
|
|
assert_icon_lookup_size ("size-test", 14, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/15/size-test.png", 15);
|
|
|
|
assert_icon_lookup_size ("size-test", 15, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/15/size-test.png", 15);
|
|
|
|
assert_icon_lookup_size ("size-test", 16, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16-22/size-test.png", 19);
|
|
|
|
assert_icon_lookup_size ("size-test", 17, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16-22/size-test.png", 19);
|
|
|
|
assert_icon_lookup_size ("size-test", 18, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16-22/size-test.png", 19);
|
|
|
|
assert_icon_lookup_size ("size-test", 19, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/16-22/size-test.png", 19);
|
2014-06-20 18:30:36 +00:00
|
|
|
/* the next 3 are because we never scale up */
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("size-test", 20, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 20);
|
|
|
|
assert_icon_lookup_size ("size-test", 21, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 21);
|
|
|
|
assert_icon_lookup_size ("size-test", 22, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 22);
|
2020-02-04 03:26:19 +00:00
|
|
|
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("size-test", 23, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 23);
|
|
|
|
assert_icon_lookup_size ("size-test", 23, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 23);
|
2020-02-04 03:26:19 +00:00
|
|
|
assert_icon_lookup_size ("size-test", 25, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 25);
|
|
|
|
assert_icon_lookup_size ("size-test", 28, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/25+/size-test.svg", 28);
|
2014-06-20 18:30:36 +00:00
|
|
|
/* the next 2 are because we never scale up */
|
IconTheme: Simplify icon scaling
We had a pretty complex setup where we tried to avoid scaling up themes from dirs
that specified a size. However, not only was it very complex, but it didn't quite
work with window scales, because when using e.g. a size 32 directory for 16@2x
the dir size is wrong anyway. Additionally it turns out most code either picks
an existing icon size, or uses the FORCE_SIZE flags, so it doesn't seem
like a useful behaviour.
This change drops the FORCE_SIZE flags, and always scales
icons. Additionally it moves the scaling of the icon to rendering,
which seems more modern, and allows us to (later) share icons loaded
for different sizes that happened to use the same source file (at
different scales).
Note that this changes the behaviour of
gtk_icon_paintable_download_texture() is it now returns the unscaled
source icon. However, ignore thats, as I plan to remove this function
and replace it with a way to render a paintable to a cairo-surface
instead.
2020-02-05 14:47:23 +00:00
|
|
|
assert_icon_lookup_size ("size-test", 31, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/35+/size-test.svg", 31);
|
|
|
|
assert_icon_lookup_size ("size-test", 34, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/35+/size-test.svg", 34);
|
2020-02-04 03:26:19 +00:00
|
|
|
|
|
|
|
assert_icon_lookup_size ("size-test", 37, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/35+/size-test.svg", 37);
|
|
|
|
assert_icon_lookup_size ("size-test", 40, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/35+/size-test.svg", 40);
|
|
|
|
assert_icon_lookup_size ("size-test", 45, GTK_TEXT_DIR_NONE, 0, FALSE, "/icons/35+/size-test.svg", 45);
|
2014-06-18 22:19:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 00:56:06 +00:00
|
|
|
static void
|
|
|
|
test_list (void)
|
|
|
|
{
|
|
|
|
GtkIconTheme *theme;
|
2020-02-18 05:56:37 +00:00
|
|
|
char **icons;
|
2014-06-20 00:56:06 +00:00
|
|
|
|
2014-06-24 01:24:41 +00:00
|
|
|
theme = get_test_icontheme (TRUE);
|
2020-02-18 05:56:37 +00:00
|
|
|
icons = gtk_icon_theme_get_icon_names (theme);
|
|
|
|
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "size-test"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "simple"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "twosize-fixed"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "twosize"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "only32-symbolic"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-rtl"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-symbolic"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-justregular"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-justrtl-rtl"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-symbolic-rtl"));
|
|
|
|
g_assert_true (g_strv_contains ((const char * const *)icons, "everything-justsymbolic-symbolic"));
|
|
|
|
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "size-test"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "simple"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "twosize-fixed"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "twosize"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "only32-symbolic"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-rtl"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-symbolic"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-justregular"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-justrtl-rtl"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-symbolic-rtl"));
|
|
|
|
g_assert_true (gtk_icon_theme_has_icon (theme, "everything-justsymbolic-symbolic"));
|
2014-06-20 00:56:06 +00:00
|
|
|
|
2020-02-18 05:56:37 +00:00
|
|
|
g_strfreev (icons);
|
2014-06-20 00:56:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 20:28:15 +00:00
|
|
|
static void
|
|
|
|
test_inherit (void)
|
|
|
|
{
|
|
|
|
assert_icon_lookup ("one-two-three",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons/scalable/one-two.svg");
|
|
|
|
assert_icon_lookup ("one-two-three",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons/scalable/one-two-rtl.svg");
|
|
|
|
assert_icon_lookup ("one-two-three-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons2/scalable/one-two-three-symbolic.svg");
|
|
|
|
assert_icon_lookup ("one-two-three-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons2/scalable/one-two-three-symbolic.svg");
|
|
|
|
assert_icon_lookup ("one-two-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_NONE,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons2/scalable/one-two-symbolic.svg");
|
|
|
|
assert_icon_lookup ("one-two-symbolic",
|
|
|
|
SCALABLE_IMAGE_SIZE,
|
2020-02-01 23:27:14 +00:00
|
|
|
GTK_TEXT_DIR_RTL,
|
2020-02-04 03:26:19 +00:00
|
|
|
0,
|
|
|
|
TRUE,
|
2014-09-21 20:28:15 +00:00
|
|
|
"/icons2/scalable/one-two-symbolic-rtl.svg");
|
|
|
|
}
|
|
|
|
|
2020-02-10 12:12:26 +00:00
|
|
|
static void
|
|
|
|
test_nonsquare_symbolic (void)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int width, height, size;
|
2020-02-10 12:12:26 +00:00
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
GtkIconPaintable *info;
|
|
|
|
GFile *file;
|
|
|
|
GIcon *icon;
|
|
|
|
GError *error = NULL;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
GskRenderNode *node;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *path = g_build_filename (g_test_get_dir (G_TEST_DIST),
|
2020-02-10 12:12:26 +00:00
|
|
|
"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);
|
2021-04-12 20:12:25 +00:00
|
|
|
g_assert_cmpint (bounds.size.width, ==, width);
|
|
|
|
g_assert_cmpint (bounds.size.height, ==, height);
|
2020-02-10 12:12:26 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
g_free (path);
|
|
|
|
g_object_unref (file);
|
|
|
|
g_object_unref (icon);
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:09:24 +00:00
|
|
|
static void
|
|
|
|
require_env (const char *var)
|
|
|
|
{
|
|
|
|
if (g_getenv (var) == NULL)
|
|
|
|
g_warning ("Some tests require %s to be set", var);
|
|
|
|
}
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2020-02-11 19:09:24 +00:00
|
|
|
require_env ("G_TEST_SRCDIR");
|
|
|
|
|
2014-05-12 16:19:47 +00:00
|
|
|
gtk_test_init (&argc, &argv);
|
|
|
|
|
|
|
|
g_test_add_func ("/icontheme/basics", test_basics);
|
2014-05-14 02:13:58 +00:00
|
|
|
g_test_add_func ("/icontheme/lookup-order", test_lookup_order);
|
|
|
|
g_test_add_func ("/icontheme/generic-fallback", test_generic_fallback);
|
2014-05-13 01:17:15 +00:00
|
|
|
g_test_add_func ("/icontheme/force-symbolic", test_force_symbolic);
|
|
|
|
g_test_add_func ("/icontheme/force-regular", test_force_regular);
|
2014-05-14 02:52:55 +00:00
|
|
|
g_test_add_func ("/icontheme/rtl", test_rtl);
|
2014-06-12 10:28:07 +00:00
|
|
|
g_test_add_func ("/icontheme/symbolic-single-size", test_symbolic_single_size);
|
2014-06-14 19:06:57 +00:00
|
|
|
g_test_add_func ("/icontheme/svg-size", test_svg_size);
|
2014-06-18 22:19:39 +00:00
|
|
|
g_test_add_func ("/icontheme/size", test_size);
|
2014-06-20 00:56:06 +00:00
|
|
|
g_test_add_func ("/icontheme/list", test_list);
|
2014-09-21 20:28:15 +00:00
|
|
|
g_test_add_func ("/icontheme/inherit", test_inherit);
|
2020-02-10 12:12:26 +00:00
|
|
|
g_test_add_func ("/icontheme/nonsquare-symbolic", test_nonsquare_symbolic);
|
2014-05-12 16:19:47 +00:00
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|