18
18
namespace Internal {
21
GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri)
21
GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
23
23
SPDocument *doc = sp_document_new(NULL, TRUE, TRUE);
24
24
bool saved = sp_document_get_undo_sensitive(doc);
25
25
sp_document_set_undo_sensitive(doc, false); // no need to undo in this temporary document
26
26
GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
27
Inkscape::XML::Node *rdoc = sp_document_repr_root(doc);
28
gchar const *docbase = rdoc->attribute("sodipodi:docbase");
29
gchar const *relname = sp_relative_path_from_path(uri, docbase);
31
28
if (pb) { /* We are readable */
32
29
Inkscape::XML::Node *repr = NULL;
57
if (prefs_get_int_attribute("options.importbitmapsasimages", "value", 1) == 1) {
59
repr = sp_repr_new("svg:image");
60
repr->setAttribute("xlink:href", relname);
61
repr->setAttribute("sodipodi:absref", uri);
63
sp_repr_set_svg_double(repr, "width", width);
64
sp_repr_set_svg_double(repr, "height", height);
67
// import as pattern-filled rect
68
Inkscape::XML::Node *pat = sp_repr_new("svg:pattern");
69
pat->setAttribute("inkscape:collect", "always");
70
pat->setAttribute("patternUnits", "userSpaceOnUse");
71
sp_repr_set_svg_double(pat, "width", width);
72
sp_repr_set_svg_double(pat, "height", height);
73
SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->appendChild(pat);
74
gchar const *pat_id = pat->attribute("id");
75
SPObject *pat_object = doc->getObjectById(pat_id);
77
Inkscape::XML::Node *im = sp_repr_new("svg:image");
78
im->setAttribute("xlink:href", relname);
79
im->setAttribute("sodipodi:absref", uri);
80
sp_repr_set_svg_double(im, "width", width);
81
sp_repr_set_svg_double(im, "height", height);
82
SP_OBJECT_REPR(pat_object)->addChild(im, NULL);
84
repr = sp_repr_new("svg:rect");
85
repr->setAttribute("style", g_strdup_printf("stroke:none;fill:url(#%s)", pat_id));
86
sp_repr_set_svg_double(repr, "width", width);
87
sp_repr_set_svg_double(repr, "height", height);
54
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
56
repr = xml_doc->createElement("svg:image");
57
// both are the same, as we don't know our base dir here and cannot relativate href (importer will fixupHrefs):
58
repr->setAttribute("xlink:href", uri);
59
repr->setAttribute("sodipodi:absref", uri);
61
sp_repr_set_svg_double(repr, "width", width);
62
sp_repr_set_svg_double(repr, "height", height);
90
64
SP_DOCUMENT_ROOT(doc)->appendChildRepr(repr);
91
65
Inkscape::GC::release(repr);