4
#include "document-private.h"
6
#include "extension/system.h"
7
#include "gdkpixbuf-input.h"
8
#include "selection-chemistry.h"
13
GdkPixbuf* pixbuf_new_from_file( char const *utf8name, GError **error );
20
GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
22
SPDocument *doc = NULL;
23
GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
25
if (pb) { /* We are readable */
26
doc = sp_document_new(NULL, TRUE, TRUE);
27
bool saved = sp_document_get_undo_sensitive(doc);
28
sp_document_set_undo_sensitive(doc, false); // no need to undo in this temporary document
30
Inkscape::XML::Node *repr = NULL;
32
double width = gdk_pixbuf_get_width(pb);
33
double height = gdk_pixbuf_get_height(pb);
34
gchar const *str = gdk_pixbuf_get_option( pb, "Inkscape::DpiX" );
38
if ( dpi > 0 && dpi != 72 )
40
double scale = 72.0 / (double)dpi;
44
str = gdk_pixbuf_get_option( pb, "Inkscape::DpiY" );
48
if ( dpi > 0 && dpi != 72 )
50
double scale = 72.0 / (double)dpi;
55
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
57
repr = xml_doc->createElement("svg:image");
59
// convert filename to uri
60
gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
62
repr->setAttribute("xlink:href", _uri);
65
repr->setAttribute("xlink:href", uri);
67
/* impl: doc->base is currently NULL, so we can use uri for href whether it's absolute
68
* or relative. The href will get rewritten by rebase_hrefs if by chance uri is relative
69
* and doc gets saved to a different directory.
71
* We don't bother setting sodipodi:absref, as we assume it's never useful to have
72
* sodipodi:absref with the same value as xlink:href, and rebase_hrefs will provide
73
* sodipodi:absref values where necessary. */
75
sp_repr_set_svg_double(repr, "width", width);
76
sp_repr_set_svg_double(repr, "height", height);
78
SP_DOCUMENT_ROOT(doc)->appendChildRepr(repr);
79
Inkscape::GC::release(repr);
81
//alter the canvas size to fit the image size
82
fit_canvas_to_drawing(doc);
83
// restore undo, as now this document may be shown to the user if a bitmap was opened
84
sp_document_set_undo_sensitive(doc, saved);
86
printf("GdkPixbuf loader failed\n");
95
GdkpixbufInput::init(void)
97
GSList * formatlist, * formatlisthead;
99
/* \todo I'm not sure if I need to free this list */
100
for (formatlist = formatlisthead = gdk_pixbuf_get_formats();
102
formatlist = g_slist_next(formatlist)) {
104
GdkPixbufFormat *pixformat = (GdkPixbufFormat *)formatlist->data;
106
gchar *name = gdk_pixbuf_format_get_name(pixformat);
107
gchar *description = gdk_pixbuf_format_get_description(pixformat);
108
gchar **extensions = gdk_pixbuf_format_get_extensions(pixformat);
109
gchar **mimetypes = gdk_pixbuf_format_get_mime_types(pixformat);
111
for (int i = 0; extensions[i] != NULL; i++) {
112
for (int j = 0; mimetypes[j] != NULL; j++) {
114
/* thanks but no thanks, we'll handle SVG extensions... */
115
if (strcmp(extensions[i], "svg") == 0) {
118
if (strcmp(extensions[i], "svgz") == 0) {
121
if (strcmp(extensions[i], "svg.gz") == 0) {
125
gchar *xmlString = g_strdup_printf(
126
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
127
"<name>" N_("%s GDK pixbuf Input") "</name>\n"
128
"<id>org.inkscape.input.gdkpixbuf.%s</id>\n"
130
"<extension>.%s</extension>\n"
131
"<mimetype>%s</mimetype>\n"
132
"<filetypename>%s (*.%s)</filetypename>\n"
133
"<filetypetooltip>%s</filetypetooltip>\n"
135
"</inkscape-extension>",
145
Inkscape::Extension::build_from_mem(xmlString, new GdkpixbufInput());
151
g_strfreev(mimetypes);
152
g_strfreev(extensions);
155
g_slist_free(formatlisthead);
158
} } } /* namespace Inkscape, Extension, Implementation */
163
c-file-style:"stroustrup"
164
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
169
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :