css: Add data URL parsing to images

This commit is contained in:
Benjamin Otte 2019-05-09 03:11:48 +02:00
parent 5da58ba47d
commit 8be95ca348
5 changed files with 53 additions and 0 deletions

View File

@ -27,6 +27,8 @@
#include "gtkcssimagepaintableprivate.h"
#include "gtkstyleproviderprivate.h"
#include "gtk/css/gtkcssdataurlprivate.h"
G_DEFINE_TYPE (GtkCssImageUrl, _gtk_css_image_url, GTK_TYPE_CSS_IMAGE)
static GtkCssImage *
@ -52,6 +54,31 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url,
g_free (resource_path);
g_free (uri);
}
else if (g_file_has_uri_scheme (url->file, "data"))
{
GInputStream *stream;
char *uri;
GdkPixbuf *pixbuf;
GBytes *bytes;
uri = g_file_get_uri (url->file);
texture = NULL;
bytes = gtk_css_data_url_parse (uri, NULL, &local_error);
if (bytes)
{
stream = g_memory_input_stream_new_from_bytes (bytes);
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &local_error);
g_object_unref (stream);
if (pixbuf != NULL)
{
texture = gdk_texture_new_for_pixbuf (pixbuf);
g_object_unref (pixbuf);
}
}
g_free (uri);
}
else
{
texture = gdk_texture_new_from_file (url->file, &local_error);

View File

@ -0,0 +1,3 @@
.background {
background: red url('data:,<svg><rect width="20" height="20" style="fill:lime"/></svg>');
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow">
<property name="type">popup</property>
<child>
<object class="GtkPicture">
<property name="can-shrink">0</property>
<property name="paintable">green-20x20.png</property>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="width_request">20</property>
<property name="height_request">20</property>
<property name="type">popup</property>
</object>
</interface>

View File

@ -194,6 +194,9 @@ testdata = [
'css-multi-state.css',
'css-multi-state.ref.ui',
'css-multi-state.ui',
'data-url.css',
'data-url.ref.ui',
'data-url.ui',
'fixed-widget-stacking.ref.ui',
'fixed-widget-stacking.ui',
'flipping-icons.ref.ui',