[gtk+] Make the recoloring code more robust
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Make the recoloring code more robust
- Date: Wed, 8 Nov 2017 02:56:12 +0000 (UTC)
commit 1da7dc890cdad9ebb1074389aa9ac24b83766e23
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 7 21:27:38 2017 -0500
Make the recoloring code more robust
Pass both width+height and scale, so we can handle the case
where width+height are zero and we are using the file, scaled.
gtk/encodesymbolic.c | 2 +-
gtk/gdkpixbufutils.c | 31 ++++++++++++++++++++++---------
gtk/gdkpixbufutilsprivate.h | 3 +++
gtk/gtkicontheme.c | 2 ++
4 files changed, 28 insertions(+), 10 deletions(-)
---
diff --git a/gtk/encodesymbolic.c b/gtk/encodesymbolic.c
index 81493f8..7f94f30 100644
--- a/gtk/encodesymbolic.c
+++ b/gtk/encodesymbolic.c
@@ -104,7 +104,7 @@ main (int argc, char **argv)
return 1;
}
- symbolic = gtk_make_symbolic_pixbuf_from_data (data, len, width, height, &error);
+ symbolic = gtk_make_symbolic_pixbuf_from_data (data, len, width, height, 1.0, &error);
if (symbolic == NULL)
{
g_printerr (_("Can’t load file: %s\n"), error->message);
diff --git a/gtk/gdkpixbufutils.c b/gtk/gdkpixbufutils.c
index ac9863a..ae57455 100644
--- a/gtk/gdkpixbufutils.c
+++ b/gtk/gdkpixbufutils.c
@@ -136,6 +136,7 @@ load_symbolic_svg (const char *file_data,
gsize file_len,
int width,
int height,
+ double scale,
const GdkRGBA *fg,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
@@ -168,8 +169,13 @@ load_symbolic_svg (const char *file_data,
if (!pixbuf)
return NULL;
+ if (width == 0)
+ width = gdk_pixbuf_get_width (pixbuf) * scale;
+ if (height == 0)
+ height = gdk_pixbuf_get_height (pixbuf) * scale;
+
svg_width = g_strdup_printf ("%d", gdk_pixbuf_get_width (pixbuf));
- svg_height = g_strdup_printf ("%d",gdk_pixbuf_get_height (pixbuf));
+ svg_height = g_strdup_printf ("%d", gdk_pixbuf_get_height (pixbuf));
g_object_unref (pixbuf);
escaped_file_data = g_markup_escape_text (file_data, file_len);
@@ -253,18 +259,15 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data,
gsize file_len,
int width,
int height,
+ double scale,
GError **error)
{
GdkRGBA r = { 1,0,0,1}, g = {0,1,0,1};
GdkPixbuf *loaded;
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf = NULL;
int plane;
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
-
- gdk_pixbuf_fill (pixbuf, 0);
-
for (plane = 0; plane < 3; plane++)
{
/* Here we render the svg with all colors solid, this should
@@ -279,7 +282,7 @@ 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 (file_data, file_len, width, height,
+ loaded = load_symbolic_svg (file_data, file_len, width, height, scale,
&g,
plane == 0 ? &r : &g,
plane == 1 ? &r : &g,
@@ -288,6 +291,14 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data,
if (loaded == NULL)
return NULL;
+ if (pixbuf == NULL)
+ {
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+ gdk_pixbuf_get_width (loaded),
+ gdk_pixbuf_get_height (loaded));
+ gdk_pixbuf_fill (pixbuf, 0);
+ }
+
if (plane == 0)
extract_plane (loaded, pixbuf, 3, 3);
@@ -303,6 +314,7 @@ GdkPixbuf *
gtk_make_symbolic_pixbuf_from_resource (const char *path,
int width,
int height,
+ double scale,
GError **error)
{
GBytes *bytes;
@@ -316,7 +328,7 @@ gtk_make_symbolic_pixbuf_from_resource (const char *path,
data = g_bytes_get_data (bytes, &size);
- pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, error);
+ pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, error);
g_bytes_unref (bytes);
@@ -327,6 +339,7 @@ GdkPixbuf *
gtk_make_symbolic_pixbuf_from_file (GFile *file,
int width,
int height,
+ double scale,
GError **error)
{
char *data;
@@ -336,7 +349,7 @@ gtk_make_symbolic_pixbuf_from_file (GFile *file,
if (!g_file_load_contents (file, NULL, &data, &size, NULL, error))
return NULL;
- pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, error);
+ pixbuf = gtk_make_symbolic_pixbuf_from_data (data, size, width, height, scale, error);
g_free (data);
diff --git a/gtk/gdkpixbufutilsprivate.h b/gtk/gdkpixbufutilsprivate.h
index 1ea23dc..8e398e1 100644
--- a/gtk/gdkpixbufutilsprivate.h
+++ b/gtk/gdkpixbufutilsprivate.h
@@ -34,14 +34,17 @@ GdkPixbuf *gtk_make_symbolic_pixbuf_from_data (const char *data,
gsize len,
int width,
int height,
+ double scale,
GError **error);
GdkPixbuf *gtk_make_symbolic_pixbuf_from_file (GFile *file,
int width,
int height,
+ double scale,
GError **error);
GdkPixbuf *gtk_make_symbolic_pixbuf_from_resource (const char *path,
int width,
int height,
+ double scale,
GError **error);
G_END_DECLS
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 94e0323..a6af4f4 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -3796,6 +3796,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info)
if (gtk_icon_info_is_symbolic (icon_info))
source_pixbuf = gtk_make_symbolic_pixbuf_from_resource (icon_info->filename,
size, size,
+ icon_info->desired_scale,
&icon_info->load_error);
else if (size == 0)
source_pixbuf = _gdk_pixbuf_new_from_resource_scaled (icon_info->filename,
@@ -3836,6 +3837,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info)
if (gtk_icon_info_is_symbolic (icon_info) && icon_info->icon_file)
source_pixbuf = gtk_make_symbolic_pixbuf_from_file (icon_info->icon_file,
size, size,
+ icon_info->desired_scale,
&icon_info->load_error);
else if (size == 0)
source_pixbuf = _gdk_pixbuf_new_from_stream_scaled (stream,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]