Move the maintained common-use packages back to the bockbuild repo
[mono.git] / bockbuild / MacSDK / gdk-pixbuf / 0001-pixbuf-load-2x-variants-as-pixbuf-gobject-data.patch
1 >From de5d91aa15cc98795a68c8e553eb4baadaa0e501 Mon Sep 17 00:00:00 2001
2 From: Carlos Garnacho <carlosg@gnome.org>
3 Date: Fri, 17 May 2013 15:56:28 +0200
4 Subject: [PATCH] pixbuf: load "@2x" variants as pixbuf gobject data
5
6 if a variant of the filename is found that has a "@2x" appended
7 to the file name (before the extension), such file is loaded
8 and added as GObject data to the pixbuf
9 ---
10  gdk-pixbuf/gdk-pixbuf-io.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
11  1 file changed, 55 insertions(+)
12
13 diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
14 index dac21b8..ed98cd3 100644
15 --- a/gdk-pixbuf/gdk-pixbuf-io.c
16 +++ b/gdk-pixbuf/gdk-pixbuf-io.c
17 @@ -1025,6 +1025,40 @@ _gdk_pixbuf_generic_image_load (GdkPixbufModule *module,
18          return pixbuf;
19  }
20
21 +static gboolean
22 +_gdk_pixbuf_file_is_scaled (const gchar *filename)
23 +{
24 +       gchar *basename, *ext;
25 +
26 +       basename = g_path_get_basename (filename);
27 +       ext = strrchr (basename, '.');
28 +
29 +       if (!ext)
30 +               ext = &basename[strlen(basename)];
31 +
32 +       if (ext > basename + 3 && strncmp (ext - 3, "@2x", 3) == 0)
33 +               return TRUE;
34 +
35 +       return FALSE;
36 +}
37 +
38 +static gchar *
39 +_gdk_pixbuf_compose_scaled_filename (const gchar *filename)
40 +{
41 +       gchar *ext, *first, *composed;
42 +
43 +       ext = strrchr (filename, '.');
44 +
45 +       if (!ext)
46 +               return NULL;
47 +
48 +       first = g_strndup (filename, ext - filename);
49 +       composed = g_strdup_printf ("%s@2x%s", first, ext);
50 +       g_free (first);
51 +
52 +       return composed;
53 +}
54 +
55  /**
56   * gdk_pixbuf_new_from_file:
57   * @filename: Name of file to load, in the GLib file name encoding
58 @@ -1049,11 +1083,13 @@ gdk_pixbuf_new_from_file (const char *filename,
59          guchar buffer[SNIFF_BUFFER_SIZE];
60          GdkPixbufModule *image_module;
61          gchar *display_name;
62 +       gboolean filename_is_scaled;
63
64          g_return_val_if_fail (filename != NULL, NULL);
65          g_return_val_if_fail (error == NULL || *error == NULL, NULL);
66
67          display_name = g_filename_display_name (filename);
68 +       filename_is_scaled = _gdk_pixbuf_file_is_scaled (filename);
69
70          f = g_fopen (filename, "rb");
71          if (!f) {
72 @@ -1097,6 +1133,25 @@ gdk_pixbuf_new_from_file (const char *filename,
73          pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
74          fclose (f);
75
76 +       if (pixbuf && !filename_is_scaled) {
77 +               GdkPixbuf *scaled_pixbuf = NULL;
78 +               gchar *scaled_filename;
79 +
80 +               scaled_filename = _gdk_pixbuf_compose_scaled_filename (filename);
81 +
82 +               if (scaled_filename) {
83 +                       scaled_pixbuf = gdk_pixbuf_new_from_file (scaled_filename, NULL);
84 +                       g_free (scaled_filename);
85 +               }
86 +
87 +               if (scaled_pixbuf) {
88 +                       g_object_set_data_full (G_OBJECT (pixbuf),
89 +                                                "gdk-pixbuf-2x-variant",
90 +                                                scaled_pixbuf,
91 +                                                (GDestroyNotify) g_object_unref);
92 +               }
93 +       }
94 +
95          if (pixbuf == NULL && error != NULL && *error == NULL) {
96
97                  /* I don't trust these crufty longjmp()'ing image libs
98 --
99 1.8.3.rc1