diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index ee9fc408637de5e03e1622bcf647026d5b147add..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"
namespace Inkscape {
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
+ SPDocument *doc = NULL;
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 */
+ 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);
}
}
- 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);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+ // 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 = 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);
+ 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);
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");
}
return doc;
}
+#include "clear-n_.h"
void
GdkpixbufInput::init(void)
}
gchar *xmlString = g_strdup_printf(
- "<inkscape-extension>\n"
- "<name>%s GDK pixbuf Input</name>\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"
"<extension>.%s</extension>\n"