[gimp] app: gimp_widget_load_icon() should actually always return a result.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: gimp_widget_load_icon() should actually always return a result.
- Date: Sun, 24 Jun 2018 16:27:34 +0000 (UTC)
commit 123dcc6f3fda9c562e76885a346c85fdc14d1cc8
Author: Jehan <jehan girinstud io>
Date: Sun Jun 24 18:21:24 2018 +0200
app: gimp_widget_load_icon() should actually always return a result.
When the "gimp-wilber-eek" fallback will fail to load, we just create an
ugly magenta square instead.
See Mitch's review at #1608.
Master adaptation for commit 32931c4606841ad81d0c647c9d7ea8b977487f0f.
app/widgets/gimpwidgets-utils.c | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index f2a9084d1f..f9a89f46b5 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -328,16 +328,13 @@ gimp_enum_radio_frame_add (GtkFrame *frame,
*
* Loads an icon into a pixbuf with size as close as possible to @size.
* If icon does not exist or fail to load, the function will fallback to
- * "gimp-wilber-eek" instead to prevent NULL pixbuf.
- * Nevertheless it is still possible for this function to return NULL,
- * in the edge case where "gimp-wilber-eek" is also missing, its file
- * corrupted or maybe other reasons. So calling code must take the NULL
- * return possibility into account.
+ * "gimp-wilber-eek" instead to prevent NULL pixbuf. As a last resort,
+ * if even the fallback failed to load, a magenta @size square will be
+ * returned, so this function is guaranteed to always return a
+ * #GdkPixbuf.
*
* Return value: a newly allocated #GdkPixbuf containing @icon_name at
- * size @size or a fallback icon/size. NULL return is a possibility in
- * if neither the requested icon nor fallback could be loaded
- * successfully.
+ * size @size or a fallback icon/size.
**/
GdkPixbuf *
gimp_widget_load_icon (GtkWidget *widget,
@@ -403,6 +400,31 @@ gimp_widget_load_icon (GtkWidget *widget,
pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
gtk_widget_get_style_context (widget),
NULL, NULL);
+ if (! pixbuf)
+ {
+ /* As last resort, just draw an ugly magenta square. */
+ guchar *data;
+ gint rowstride = 3 * size;
+ gint i, j;
+
+ g_printerr ("WARNING: icon '%s' failed to load. Check the files "
+ "in your icon theme.\n", GIMP_ICON_WILBER_EEK);
+
+ data = g_new (guchar, rowstride * size);
+ for (i = 0; i < size; i++)
+ {
+ for (j = 0; j < size; j++)
+ {
+ data[i * rowstride + j * 3] = 255;
+ data[i * rowstride + j * 3 + 1] = 0;
+ data[i * rowstride + j * 3 + 2] = 255;
+ }
+ }
+ pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE,
+ 8, size, size, rowstride,
+ (GdkPixbufDestroyNotify) g_free,
+ NULL);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]