Code

a couple of trivial %d -> %u changes.
[inkscape.git] / src / extension / internal / gdkpixbuf-input.cpp
index 34e6c09fd3d42ecf61c95827336f779ec7e5cd9e..14effbeb7a991aaf66c554bf6e910f32b38df394 100644 (file)
@@ -6,6 +6,7 @@
 #include "prefs-utils.h"
 #include "extension/system.h"
 #include "gdkpixbuf-input.h"
+#include "selection-chemistry.h"
 
 namespace Inkscape {
 
@@ -17,16 +18,15 @@ 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);
-    sp_document_set_undo_sensitive(doc, FALSE); // no need to undo in this temporary document
     GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
-    Inkscape::XML::Node *rdoc = sp_document_repr_root(doc);
-    gchar const *docbase = rdoc->attribute("sodipodi:docbase");
-    gchar const *relname = sp_relative_path_from_path(uri, docbase);
 
     if (pb) {         /* We are readable */
+        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,44 +52,23 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
             }
         }
 
-        if (prefs_get_int_attribute("options.importbitmapsasimages", "value", 1) == 1) {
-            // import as <image>
-            repr = sp_repr_new("svg:image");
-            repr->setAttribute("xlink:href", relname);
-            repr->setAttribute("sodipodi:absref", uri);
-
-            sp_repr_set_svg_double(repr, "width", width);
-            sp_repr_set_svg_double(repr, "height", height);
-
-        } else {
-            // import as pattern-filled rect
-            Inkscape::XML::Node *pat = sp_repr_new("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 = sp_repr_new("svg:image");
-            im->setAttribute("xlink:href", relname);
-            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 = sp_repr_new("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);
-        }
+        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);
+
+        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);
         gdk_pixbuf_unref(pb);
+        //alter the canvas size to fit the image size
+        fit_canvas_to_drawing(doc);
         // restore undo, as now this document may be shown to the user if a bitmap was opened
-        sp_document_set_undo_sensitive(doc, TRUE);
+        sp_document_set_undo_sensitive(doc, saved);
     } else {
         printf("GdkPixbuf loader failed\n");
     }
@@ -131,7 +110,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"