GNOME Bugzilla – Bug 311011
gdk pixbuf loader for svg doesn't work with most files
Last modified: 2010-07-10 04:06:34 UTC
The gdk pixbuf loader for svg doesn't work with most files. This is because it looks for for the following prefixes: "<svg", "<!DOCTYPE svg", It succeeds if the file starts with either of them. However, most SVG files start with something like: <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" or like the ones used by GDM: <?xml version="1.0" encoding="iso-8859-1"?> <!-- Generator: Adobe Illustrator 9.0, SVG Export Plug-In --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN" So, for these cases is good to at least partially match on the "<?xml " characters. As it is now GDM and gnome-games are broken.
Created attachment 49465 [details] [review] patch Look ok?
sorry, the patch doesn't look ok. i explictly removed "<?xml" from the loader simply because we kept on being fed XHTML, DocBook, and etc. files to render. i'm moving this bug upstream to GTK+. its type identification code should probably be made to scan through a bit more of the document before giving up.
I would propose three things that can be done to improve this: 1) make use of the fact that we know the file format already in the icon theme code. There is no need for letting the pixbuf loader sniff when we are calling it in a function called load_svg_at_size(). 2) allow patterns that match in the middle of the buffer. I'm thinking of allowing to specify a "*" as first character in the mask to mean that. 3) increase the size of the buffer we use for sniffing. Currently we are using 128. Increasing it to 256 or 512 should cover the few lines which may occur before the doctype in a typical xml file.
I have done 1) in cvs now.
Thanks Matthias, since this means we base it on filename extension I hope this fix covers both .svg and .svgz files, not just .svg. Anyway thanks for the quick response.
Not sure about svgz. Does the icon theme spec cover that ? I'd have to check the icon theme code, but I think it only recognizes .svg
Adding to the three points mentioned above: 4) When the simple pattern sniffing fails, do more expensive mime-type sniffing, and match against the mime-types supported by the modules. Unfortunately this requires a mime-type sniffing api below gdk-pixbuf in the stack. Currently all we have is the private xdgmime copy in gtk.
2) and 3) also done now. the svg loader can now add patterns like " <!DOCTYPE svg" "* " 100 " <svg>" "* " 100 to match those strings anywhere in the first 256 bytes 2005-07-22 Matthias Clasen <mclasen@redhat.com> * gdk-pixbuf-io.c (format_check): Interpret patterns where the first byte of the mask is '*' as unanchored. (#311011) (gdk_pixbuf_new_from_file): Use the first 256 bytes for sniffing the file format.
Matthias: your last change to gdk-pixbuf-io.c is broken - loading of PNG files fail. If unanchored is false, the outer loop won't be run at all. Reopening.
This also breaks build. amd@dma ~/code/gtk+/gtk/stock-icons $ make GDK_PIXBUF_MODULE_FILE=../../gdk-pixbuf/gdk-pixbuf.loaders ../../gdk-pixbuf/gdk-pixbuf-csource \ --raw --build-list stock_about_16 ./stock_about_16.png stock_about_24 ./stock_about_24.png stock_add_16 ./stock_add_16.png stock_add_24 ./stock_add_24.png stock_align_center_16 ./stock_align_center_16.png stock_align_center_24 ./stock_align_center_24.png stock_align_justify_16 ./stock_align_justify_16.png stock_align_justify_24 ./stock_align_justify_24.png stock_align_left_16 ./stock_align_left_16.png stock_align_left_24 ./stock_align_left_24.png stock_align_right_16 ./stock_align_right_16.png stock_align_right_24 ./stock_align_right_24.png stock_apply_20 ./stock_apply_20.png stock_cancel_20 ./stock_cancel_20.png stock_dnd_multiple_32 ./stock_dnd_multiple_32.png stock_bottom_16 ./stock_bottom_16.png stock_bottom_24 ./stock_bottom_24.png stock_cdrom_16 ./stock_cdrom_16.png stock_cdrom_24 ./stock_cdrom_24.png stock_clear_24 ./stock_clear_24.png stock_close_20 ./stock_close_20.png stock_close_24 ./stock_close_24.png stock_colorselector_24./stock_colorselector_24.png stock_color_picker_25 ./stock_color_picker_25.png > gtkstockpixbufs.h || \ ( rm -f gtkstockpixbufs.h && false ) failed to load "./stock_about_16.png": Couldn't recognize the image file format for file './stock_about_16.png' make: *** [gtkstockpixbufs.h] Error 1
2005-07-21 Owen Taylor <otaylor@redhat.com> Based on patch from Gustavo J. A. M. Carneiro (#305975) * pango/pango-layout.[ch] (pango_layout_line_ref) pango/pango-attributes.[ch] (pango_attr_list_ref): Return the argument to _ref() functions. * pango/pango-item.[ch]: Register PangoItem boxed type. * pango/pango-layout.[ch]: Register PangoLayoutLine boxed type.
Sorry, wrong tab.
2005-07-22 Matthias Clasen <mclasen@redhat.com> * gdk-pixbuf-io.c (format_check): Make anchored patterns work as they did before.
*** Bug 311264 has been marked as a duplicate of this bug. ***
Needs the following also. Thanks a lot! Index: gdk-pixbuf/queryloaders.c =================================================================== RCS file: /cvs/gnome/gtk+/gdk-pixbuf/queryloaders.c,v retrieving revision 1.14 diff -p -u -r1.14 queryloaders.c --- gdk-pixbuf/queryloaders.c 22 Dec 2004 06:20:26 -0000 1.14 +++ gdk-pixbuf/queryloaders.c 22 Jul 2005 17:08:01 -0000 @@ -81,7 +81,7 @@ loader_sanity_check (const char *path, G goto error; } - if (strspn (pattern->mask, " !xzn") < mask_len) + if (strspn (pattern->mask, " !xzn*") < mask_len) { error = "bad char in mask";
*** Bug 311302 has been marked as a duplicate of this bug. ***
The patch in comment #15 has been applied.