/*
5 * Authors: see git history
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
11#include <gdk-pixbuf/gdk-pixbuf.h>
12#include <gdkmm/pixbuf.h>
13#include <gdkmm/pixbufformat.h>
14#include <glib/gprintf.h>
15#include <glibmm/i18n.h>
40 bool ask = prefs->
getBool(
"/dialogs/import/ask");
41 bool forcexdpi = prefs->
getBool(
"/dialogs/import/forcexdpi");
42 Glib::ustring link = prefs->
getString(
"/dialogs/import/link");
47 ask = !mod->get_param_bool(
"do_not_ask");
48 forcexdpi = (strcmp(mod->get_param_optiongroup(
"dpi"),
"from_default") == 0);
49 link = mod->get_param_optiongroup(
"link");
50 scale = mod->get_param_optiongroup(
"scale");
52 prefs->
setBool(
"/dialogs/import/ask", ask );
53 prefs->
setBool(
"/dialogs/import/forcexdpi", forcexdpi);
54 prefs->
setString(
"/dialogs/import/link", link );
58 bool embed = (link ==
"embed");
60 std::unique_ptr<SPDocument> doc;
70 double width = pb->width();
71 double height = pb->height();
80 xscale = 960.0 / std::round(10.0 * ir.x());
81 yscale = 960.0 / std::round(10.0 * ir.y());
89 xscale = 96.0 / defaultxdpi;
90 yscale = 96.0 / defaultxdpi;
103 image_node->
setAttribute(
"preserveAspectRatio",
"none");
106 if(
scale.compare(
"auto" ) != 0 ) {
117 gchar* _uri = g_filename_to_uri(uri,
nullptr,
nullptr);
128 layer_node->
setAttribute(
"inkscape:groupmode",
"layer");
130 doc->getRoot()->appendChildRepr(layer_node);
137 if (!doc->getRoot()->viewBox_set) {
139 doc->setViewBox(
Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit())));
142 printf(
"GdkPixbuf loader failed\n");
153 static std::vector< Gdk::PixbufFormat > formatlist = Gdk::Pixbuf::get_formats();
154 for (
auto i: formatlist) {
155 GdkPixbufFormat *pixformat = i.gobj();
157 gchar *
name = gdk_pixbuf_format_get_name(pixformat);
158 gchar *description = gdk_pixbuf_format_get_description(pixformat);
159 gchar **extensions = gdk_pixbuf_format_get_extensions(pixformat);
160 gchar **mimetypes = gdk_pixbuf_format_get_mime_types(pixformat);
162 for (
int i = 0; extensions[i] !=
nullptr; i++) {
163 for (
int j = 0; mimetypes[j] !=
nullptr; j++) {
166 if (strcmp(extensions[i],
"svg") == 0) {
169 if (strcmp(extensions[i],
"svgz") == 0) {
172 if (strcmp(extensions[i],
"svg.gz") == 0) {
175 gchar *caption = g_strdup_printf(_(
"%s bitmap image import"),
name);
178 gchar *xmlString = g_strdup_printf(
179 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
181 "<id>org.inkscape.input.gdkpixbuf.%s</id>\n"
183 "<param name='link' type='optiongroup' gui-text='" N_(
"Image Import Type:")
"' gui-description='" N_(
"Embed results in stand-alone, larger SVG files. Link references a file outside this SVG document and all files must be moved together.")
"' >\n"
184 "<option value='embed' >" N_(
"Embed")
"</option>\n"
186 "<option value='link' >" N_(
"Link")
"</option>\n"
189 "<param name='dpi' type='optiongroup' gui-text='" N_(
"Image DPI:")
"' gui-description='" N_(
"Take information from file or use default bitmap import resolution as defined in the preferences.")
"' >\n"
190 "<option value='from_file' >" N_(
"From file")
"</option>\n"
191 "<option value='from_default' >" N_(
"Default import resolution")
"</option>\n"
194 "<param name='scale' type='optiongroup' gui-text='" N_(
"Image Rendering Mode:")
"' gui-description='" N_(
"When an image is upscaled, apply smoothing or keep blocky (pixelated). (Will not work in all browsers.)")
"' >\n"
195 "<option value='auto' >" N_(
"None (auto)")
"</option>\n"
196 "<option value='optimizeQuality' >" N_(
"Smooth (optimizeQuality)")
"</option>\n"
197 "<option value='optimizeSpeed' >" N_(
"Blocky (optimizeSpeed)")
"</option>\n"
200 "<param name=\"do_not_ask\" gui-description='" N_(
"Hide the dialog next time and always apply the same actions.")
"' gui-text=\"" N_(
"Don't ask again")
"\" type=\"bool\" >false</param>\n"
202 "<extension>.%s</extension>\n"
203 "<mimetype>%s</mimetype>\n"
204 "<filetypename>%s (*.%s)</filetypename>\n"
205 "<filetypetooltip>%s</filetypetooltip>\n"
207 "</inkscape-extension>",
225 g_strfreev(mimetypes);
226 g_strfreev(extensions);
Cairo integration helpers.
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
RAII-style mechanism for creating a temporary undo-insensitive context.
static Pixbuf * create_from_file(std::string const &fn, double svgddpi=0)
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
void setBool(Glib::ustring const &pref_path, bool value)
Set a Boolean value.
static double convert(double from_dist, Unit const *from, Unit const *to)
Convert distances.
Interface for refcounted XML nodes.
virtual void appendChild(Node *child)=0
Append a node as the last child of this node.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
bool setAttributeSvgDouble(Util::const_char_ptr key, double val)
For attributes where an exponent is allowed.
static std::unique_ptr< SPDocument > createNewDoc(char const *filename, bool keepalive, bool make_new=false, SPDocument *parent=nullptr)
Fetches document from filename, or creates new, if NULL; public document appears in document list.
A way to clear the N_ macro, which is defined as an inline function.
std::shared_ptr< Css const > css
TODO: insert short description here.
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
static R & release(R &r)
Decrements the reference count of a anchored object.
Singleton class to access the preferences file in a convenient way.
SPCSSAttr * sp_repr_css_attr_new()
Creates an empty SPCSSAttr (a class for manipulating CSS style properties).
void sp_repr_css_set(Node *repr, SPCSSAttr *css, gchar const *attr)
Sets an attribute (e.g.
void sp_repr_css_attr_unref(SPCSSAttr *css)
Unreferences an SPCSSAttr (will be garbage collected if no references remain).
void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value)
Set a style property to a new value (e.g.
bool fit_canvas_to_drawing(SPDocument *doc, bool with_margins)
void sp_embed_image(Inkscape::XML::Node *image_node, Inkscape::Pixbuf *pb)
SVG <image> implementation.
SPRoot: SVG <svg> implementation.
Interface for XML documents.
virtual Node * createElement(char const *name)=0