[gtk+/gtk-3-8] Make symbolic icons work with the current rsvg



commit ad5889690abe26794f1a4f90bd94d8e7cabccd8b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 16 18:57:21 2013 -0400

    Make symbolic icons work with the current rsvg
    
    The rsvg loader now restricts what external files it will
    allow to load from an svg. Thus our xinclude trick doesn't work
    anymore. To work around that, embed the payload in a  data: uri.
    This is somewhat ugly, but the best we could come up with.

 gtk/gtkicontheme.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index e5234fd..ccbb8b6 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3810,7 +3810,9 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
   gchar *css_warning;
   gchar *css_error;
   gchar *data;
-  gchar *width, *height, *uri;
+  gchar *width, *height;
+  gchar *file_data, *escaped_file_data;
+  gsize file_len;
   SymbolicPixbufCache *symbolic_cache;
 
   if (use_cache)
@@ -3854,14 +3856,13 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
       css_error = gdk_color_to_css (&error_default_color);
     }
 
+  if (!g_file_get_contents (icon_info->filename, &file_data, &file_len, NULL))
+    return NULL;
+
   if (!icon_info->symbolic_pixbuf_size)
     {
-      stream = G_INPUT_STREAM (g_file_read (icon_info->icon_file, NULL, error));
-
-      if (!stream)
-        return NULL;
-
       /* Fetch size from the original icon */
+      stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL);
       pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
       g_object_unref (stream);
 
@@ -3876,7 +3877,9 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
 
   width = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->width);
   height = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->height);
-  uri = g_file_get_uri (icon_info->icon_file);
+
+  escaped_file_data = g_markup_escape_text (file_data, file_len);
+  g_free (file_data);
 
   data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
                       "<svg version=\"1.1\"\n"
@@ -3898,16 +3901,16 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
                       "      fill: ", css_success, " !important;\n"
                       "    }\n"
                       "  </style>\n"
-                      "  <xi:include href=\"", uri, "\"/>\n"
+                      "  <xi:include href=\"data:text/xml,", escaped_file_data, "\"/>\n"
                       "</svg>",
                       NULL);
+  g_free (escaped_file_data);
   g_free (css_fg);
   g_free (css_warning);
   g_free (css_error);
   g_free (css_success);
   g_free (width);
   g_free (height);
-  g_free (uri);
 
   stream = g_memory_input_stream_new_from_data (data, -1, g_free);
   pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,


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