After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 311011 - gdk pixbuf loader for svg doesn't work with most files
gdk pixbuf loader for svg doesn't work with most files
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 311264 311302 (view as bug list)
Depends on:
Blocks: 311277
 
 
Reported: 2005-07-20 14:27 UTC by William Jon McCann
Modified: 2010-07-10 04:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (1.54 KB, patch)
2005-07-20 14:28 UTC, William Jon McCann
rejected Details | Review

Description William Jon McCann 2005-07-20 14:27:23 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.
Comment 1 William Jon McCann 2005-07-20 14:28:52 UTC
Created attachment 49465 [details] [review]
patch

Look ok?
Comment 2 Dominic Lachowicz 2005-07-20 14:32:53 UTC
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.
Comment 3 Matthias Clasen 2005-07-20 17:47:15 UTC
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.
Comment 4 Matthias Clasen 2005-07-20 20:53:05 UTC
I have done 1) in cvs now.
Comment 5 Christian Fredrik Kalager Schaller 2005-07-21 08:25:29 UTC
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.
Comment 6 Matthias Clasen 2005-07-21 14:32:35 UTC
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
Comment 7 Matthias Clasen 2005-07-21 22:41:18 UTC
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.
Comment 8 Matthias Clasen 2005-07-22 04:39:13 UTC
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.
Comment 9 Robert Ögren 2005-07-22 09:45:02 UTC
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.
Comment 10 Priit Laes (IRC: plaes) 2005-07-22 11:03:46 UTC
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
Comment 11 Owen Taylor 2005-07-22 15:31:05 UTC
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.
Comment 12 Owen Taylor 2005-07-22 15:31:36 UTC
Sorry, wrong tab.
Comment 13 Matthias Clasen 2005-07-22 15:36:28 UTC
2005-07-22  Matthias Clasen  <mclasen@redhat.com>

	* gdk-pixbuf-io.c (format_check): Make anchored patterns work 
	as they did before.
Comment 14 Matthias Clasen 2005-07-22 15:51:11 UTC
*** Bug 311264 has been marked as a duplicate of this bug. ***
Comment 15 William Jon McCann 2005-07-22 17:09:07 UTC
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";
Comment 16 Richard Hoelscher 2005-07-22 21:25:31 UTC
*** Bug 311302 has been marked as a duplicate of this bug. ***
Comment 17 Matthias Clasen 2005-07-26 05:41:33 UTC
The patch in comment #15 has been applied.