Code

Added code to initialize DBus (if enabled.)
[inkscape.git] / src / extension / internal / gdkpixbuf-input.cpp
index 4a46b146df2979da59dfac0b752d79fc9e723c6f..64a099c8a42e3c673b89b3348936c0e4050d6174 100644 (file)
@@ -3,7 +3,6 @@
 #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"
@@ -18,14 +17,16 @@ namespace Extension {
 namespace Internal {
 
 SPDocument *
-GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
+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);
@@ -52,39 +53,27 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
         }
 
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
-        if (prefs_get_int_attribute("options.importbitmapsasimages", "value", 1) == 1) {
-            // 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); 
-
-            sp_repr_set_svg_double(repr, "width", width);
-            sp_repr_set_svg_double(repr, "height", height);
-
+        // import as <image>
+        repr = xml_doc->createElement("svg:image");
+
+        // convert filename to uri
+        gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
+        if(_uri) {
+            repr->setAttribute("xlink:href", _uri);
+            g_free(_uri);
         } else {
-            // import as pattern-filled rect
-            Inkscape::XML::Node *pat = xml_doc->createElement("svg:pattern");
-            pat->setAttribute("inkscape:collect", "always");
-            pat->setAttribute("patternUnits", "userSpaceOnUse");
-            sp_repr_set_svg_double(pat, "width", width);
-            sp_repr_set_svg_double(pat, "height", height);
-            SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->appendChild(pat);
-            gchar const *pat_id = pat->attribute("id");
-            SPObject *pat_object = doc->getObjectById(pat_id);
-
-            Inkscape::XML::Node *im = xml_doc->createElement("svg:image");
-            im->setAttribute("xlink:href", uri);
-            im->setAttribute("sodipodi:absref", uri);
-            sp_repr_set_svg_double(im, "width", width);
-            sp_repr_set_svg_double(im, "height", height);
-            SP_OBJECT_REPR(pat_object)->addChild(im, NULL);
-
-            repr = xml_doc->createElement("svg:rect");
-            repr->setAttribute("style", g_strdup_printf("stroke:none;fill:url(#%s)", pat_id));
-            sp_repr_set_svg_double(repr, "width", width);
-            sp_repr_set_svg_double(repr, "height", height);
+            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);
 
         SP_DOCUMENT_ROOT(doc)->appendChildRepr(repr);
         Inkscape::GC::release(repr);
@@ -134,7 +123,7 @@ GdkpixbufInput::init(void)
             }
 
             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"