[gtk/wip/baedert/for-master: 9/23] pixbufutils: Only convert icon size to string once




commit e747ea7dfd6fd7880083d37a90591367bbe862a2
Author: Timm Bäder <mail baedert org>
Date:   Thu Dec 17 19:29:16 2020 +0100

    pixbufutils: Only convert icon size to string once

 gtk/tools/gdkpixbufutils.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
---
diff --git a/gtk/tools/gdkpixbufutils.c b/gtk/tools/gdkpixbufutils.c
index 1d6eb4feff..09802f5ef8 100644
--- a/gtk/tools/gdkpixbufutils.c
+++ b/gtk/tools/gdkpixbufutils.c
@@ -251,9 +251,8 @@ static GdkPixbuf *
 load_symbolic_svg (const char     *escaped_file_data,
                    int             width,
                    int             height,
-                   double          scale,
-                   int             icon_width,
-                   int             icon_height,
+                   const char     *icon_width_str,
+                   const char     *icon_height_str,
                    const char     *fg_string,
                    const char     *success_color_string,
                    const char     *warning_color_string,
@@ -263,22 +262,13 @@ load_symbolic_svg (const char     *escaped_file_data,
   GInputStream *stream;
   GdkPixbuf *pixbuf;
   char *data;
-  char *svg_width, *svg_height;
-
-  if (width == 0)
-    width = icon_width * scale;
-  if (height == 0)
-    height = icon_height * scale;
-
-  svg_width = g_strdup_printf ("%d", icon_width);
-  svg_height = g_strdup_printf ("%d", icon_height);
 
   data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
                       "<svg version=\"1.1\"\n"
                       "     xmlns=\"http://www.w3.org/2000/svg\"\n";
                       "     xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n";
-                      "     width=\"", svg_width, "\"\n"
-                      "     height=\"", svg_height, "\">\n"
+                      "     width=\"", icon_width_str, "\"\n"
+                      "     height=\"", icon_height_str, "\">\n"
                       "  <style type=\"text/css\">\n"
                       "    rect,circle,path {\n"
                       "      fill: ", fg_string," !important;\n"
@@ -296,8 +286,6 @@ load_symbolic_svg (const char     *escaped_file_data,
                       "  <xi:include href=\"data:text/xml;base64,", escaped_file_data, "\"/>\n"
                       "</svg>",
                       NULL);
-  g_free (svg_width);
-  g_free (svg_height);
 
   stream = g_memory_input_stream_new_from_data (data, -1, g_free);
   pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, width, height, TRUE, NULL, error);
@@ -446,6 +434,8 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
 {
   const char *r_string = "rgb(255,0,0)";
   const char *g_string = "rgb(0,255,0)";
+  char *icon_width_str;
+  char *icon_height_str;
   GdkPixbuf *loaded;
   GdkPixbuf *pixbuf = NULL;
   int plane;
@@ -468,6 +458,13 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
   }
 
   escaped_file_data = g_base64_encode ((guchar *) file_data, file_len);
+  icon_width_str = g_strdup_printf ("%d", icon_width);
+  icon_height_str = g_strdup_printf ("%d", icon_height);
+
+  if (width == 0)
+    width = icon_width * scale;
+  if (height == 0)
+    height = icon_height * scale;
 
   for (plane = 0; plane < 3; plane++)
     {
@@ -483,16 +480,16 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
        * channels, with the color of the fg being implicitly
        * the "rest", as all color fractions should add up to 1.
        */
-      loaded = load_symbolic_svg (escaped_file_data, width, height, scale,
-                                  icon_width,
-                                  icon_height,
+      loaded = load_symbolic_svg (escaped_file_data, width, height,
+                                  icon_width_str,
+                                  icon_height_str,
                                   g_string,
                                   plane == 0 ? r_string : g_string,
                                   plane == 1 ? r_string : g_string,
                                   plane == 2 ? r_string : g_string,
                                   error);
       if (loaded == NULL)
-        return NULL;
+        goto out;
 
       if (pixbuf == NULL)
         {
@@ -512,6 +509,10 @@ gtk_make_symbolic_pixbuf_from_data (const char  *file_data,
 
   g_free (escaped_file_data);
 
+out:
+  g_free (icon_width_str);
+  g_free (icon_height_str);
+
   return pixbuf;
 }
 


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