Code

Optimized text output by not repeating glyph coordinates when they are identical
[inkscape.git] / src / extension / internal / gdkpixbuf-input.cpp
index 7f44fb55393515b79e10fed4191105c061427491..4a46b146df2979da59dfac0b752d79fc9e723c6f 100644 (file)
@@ -24,9 +24,6 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
     bool saved = sp_document_get_undo_sensitive(doc);
     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 */
         Inkscape::XML::Node *repr = NULL;
@@ -54,18 +51,20 @@ 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 = sp_repr_new("svg:image");
-            repr->setAttribute("xlink:href", relname);
-            repr->setAttribute("sodipodi:absref", uri);
+            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);
 
         } else {
             // import as pattern-filled rect
-            Inkscape::XML::Node *pat = sp_repr_new("svg:pattern");
+            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);
@@ -74,14 +73,14 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
             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);
+            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 = sp_repr_new("svg:rect");
+            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);