Code

BUG 218090 opening of bitmap fails, now error message
[inkscape.git] / src / extension / internal / gdkpixbuf-input.cpp
index e8af0ec9d338b665b8150913e9f35cd26c12dced..64a099c8a42e3c673b89b3348936c0e4050d6174 100644 (file)
@@ -19,10 +19,11 @@ namespace Internal {
 SPDocument *
 GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
 {
-    SPDocument *doc = sp_document_new(NULL, TRUE, TRUE);
+    SPDocument *doc = NULL;
     GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
 
     if (pb) {         /* We are readable */
+        doc = sp_document_new(NULL, TRUE, TRUE);
         bool saved = sp_document_get_undo_sensitive(doc);
         sp_document_set_undo_sensitive(doc, false); // no need to undo in this temporary document
 
@@ -54,9 +55,22 @@ GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
         // import as <image>
         repr = xml_doc->createElement("svg:image");
-        // both are the same, as we don't know our base dir here and cannot relativate href (importer will fixupHrefs):
-        repr->setAttribute("xlink:href", uri);
-        repr->setAttribute("sodipodi:absref", uri);
+
+        // convert filename to uri
+        gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
+        if(_uri) {
+            repr->setAttribute("xlink:href", _uri);
+            g_free(_uri);
+        } else {
+            repr->setAttribute("xlink:href", uri);
+        }
+        /* impl: doc->base is currently NULL, so we can use uri for href whether it's absolute
+         * or relative.  The href will get rewritten by rebase_hrefs if by chance uri is relative
+         * and doc gets saved to a different directory.
+         *
+         * We don't bother setting sodipodi:absref, as we assume it's never useful to have
+         * sodipodi:absref with the same value as xlink:href, and rebase_hrefs will provide
+         * sodipodi:absref values where necessary. */
 
         sp_repr_set_svg_double(repr, "width", width);
         sp_repr_set_svg_double(repr, "height", height);