I have come across a gtk rendering bug with SVG images that contain an embedded image. This bug appears in 14.2 but wasn't present in 14.1.
Any simple gtk image viewer will show the bug (such as gpicview, or the demo from
gnome).
I can't seem to find the source of the bug. I thought it may have been in rsvg but no. I can simply convert my svg with embedded image with rsvg-convert to a PNG with no problem. Maybe a glib regression?
I have built a simple program to demonstrate:
gtk_svg_test.c
Code:
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
if(argc != 2) return 1;
GtkWidget *window;
GtkWidget *image;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "Image");
image = gtk_image_new_from_file(argv[1]);
gtk_container_add(GTK_CONTAINER(window), image);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Just compile it against gtk+-2.0 or gtk+-3.0 like so:
Code:
gcc -o gtk_svg_test gtk_svg_test.c `pkg-config --libs --cflags gtk+-2.0`
Also, you need the svg image. (Attached is the demo0.png needed to build it - put them all in the same dir along with the script below).
Below is the svg source image (just a circle filled with yellow) that gets the PNG embedded and a script to do the work.
demo0.svg:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="200px" width="200px" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="yellow" />
</svg>
The script to build the embedded png inside the svg (needed because the path needs to be absolute)
mk_icon.sh:
Code:
#!/bin/sh
CWD=`pwd`
infile=demo0.svg
outfile=demo1.svg
pngfile=demo0.png
newline=" <image xlink:href=\"${CWD}/${pngfile}\" width=\"100\" height=\"100\" id=\"image0\"/>"
cat ${infile}|while read -r line;do
[ "$line" == "</svg>" ] && break || echo -e "$line" >> ./${outfile}
done
echo -e "$newline" >> ./${outfile}
echo '</svg>' >> ./${outfile}
Once you have everything built just pass the demo1.svg as an arg to
gtk_svg_test binary. You will see the difference running it in 14.1 as to 14.2. I tested in 32 bit and 64 bit. Note that the generated image opens fine in a browser or an image editor such as inkscape or gimp.
I can work around this bug for my purposes using rsvg-convert but it would be nice if anyone can identify the source of the issue.
Thanks for any feedback.