diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index 9f3360bab0f95febfa06992cb0ef7a9c3f0a9a75..64a099c8a42e3c673b89b3348936c0e4050d6174 100644 (file)
#endif
#include "document-private.h"
#include <dir-util.h>
-#include "prefs-utils.h"
#include "extension/system.h"
#include "gdkpixbuf-input.h"
#include "selection-chemistry.h"
SPDocument *
GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
{
- SPDocument *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
+ 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
+
Inkscape::XML::Node *repr = NULL;
double width = gdk_pixbuf_get_width(pb);
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);
}
gchar *xmlString = g_strdup_printf(
- "<inkscape-extension>\n"
+ "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
"<name>" N_("%s GDK pixbuf Input") "</name>\n"
"<id>org.inkscape.input.gdkpixbuf.%s</id>\n"
"<input>\n"