18#include <giomm/file.h>
40#include <glibmm/i18n.h>
64 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
65 "<name>" N_(
"SVG Input")
"</name>\n"
66 "<id>" SP_MODULE_KEY_INPUT_SVG
"</id>\n"
67 SVG_COMMON_INPUT_PARAMS
68 "<input priority='1'>\n"
69 "<extension>.svg</extension>\n"
70 "<mimetype>image/svg+xml</mimetype>\n"
71 "<filetypename>" N_(
"Scalable Vector Graphic (*.svg)")
"</filetypename>\n"
72 "<filetypetooltip>" N_(
"Inkscape native file format and W3C standard")
"</filetypetooltip>\n"
74 "</inkscape-extension>", std::make_unique<Svg>());
78 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
79 "<name>" N_(
"SVG Output Inkscape")
"</name>\n"
80 "<id>" SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
"</id>\n"
81 "<output is_exported='true' priority='1'>\n"
82 "<extension>.svg</extension>\n"
83 "<mimetype>image/x-inkscape-svg</mimetype>\n"
84 "<filetypename>" N_(
"Inkscape SVG (*.svg)")
"</filetypename>\n"
85 "<filetypetooltip>" N_(
"SVG format with Inkscape extensions")
"</filetypetooltip>\n"
86 "<dataloss>false</dataloss>\n"
88 "<action>prune-proprietary-namespaces</action>\n"
89 "<action>set-svg-version-2</action>\n"
90 "<action>set-inkscape-version</action>\n"
91 "<action pref='!/dialogs/save_as/enable_svgexport'>reverse-auto-start-markers</action>\n"
92 "<action pref='!/dialogs/save_as/enable_svgexport'>remove-marker-context-paint</action>\n"
93 "<action pref='!/dialogs/save_as/enable_svgexport'>set-svg-version-1</action>\n"
94 "<action pref='/options/svgexport/text_insertfallback'>insert-text-fallback</action>\n"
95 "<action pref='/options/svgexport/mesh_insertpolyfill'>insert-mesh-polyfill</action>\n"
96 "<action pref='/options/svgexport/hatch_insertpolyfill'>insert-hatch-polyfill</action>\n"
97 "</inkscape-extension>", std::make_unique<Svg>());
101 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
102 "<name>" N_(
"SVG Output")
"</name>\n"
103 "<id>" SP_MODULE_KEY_OUTPUT_SVG
"</id>\n"
104 "<output is_exported='true' priority='2'>\n"
105 "<extension>.svg</extension>\n"
106 "<mimetype>image/svg+xml</mimetype>\n"
107 "<filetypename>" N_(
"Plain SVG (*.svg)")
"</filetypename>\n"
108 "<filetypetooltip>" N_(
"Scalable Vector Graphics format as defined by the W3C")
"</filetypetooltip>\n"
110 "<action>set-svg-version-2</action>\n"
111 "<action pref='!/dialogs/save_as/enable_svgexport'>reverse-auto-start-markers</action>\n"
112 "<action pref='!/dialogs/save_as/enable_svgexport'>remove-marker-context-paint</action>\n"
113 "<action pref='!/dialogs/save_as/enable_svgexport'>set-svg-version-1</action>\n"
114 "<action pref='/options/svgexport/text_insertfallback'>insert-text-fallback</action>\n"
115 "<action>prune-proprietary-namespaces</action>\n"
116 "<action>prune-inkscape-namespaces</action>\n"
117 "</inkscape-extension>", std::make_unique<Svg>());
145 auto file = Gio::File::create_for_commandline_arg(uri);
146 const auto path = file->get_path();
164 bool ask_svg = prefs->
getBool(
"/dialogs/import/ask_svg");
165 Glib::ustring import_mode_svg = prefs->
getString(
"/dialogs/import/import_mode_svg");
170 auto page_nums = INKSCAPE.get_pages();
174 if(mod->get_gui() && ask_svg) {
175 ask_svg = !mod->get_param_bool(
"do_not_ask");
176 import_mode_svg = mod->get_param_optiongroup(
"import_mode_svg");
177 scale = mod->get_param_optiongroup(
"scale");
179 prefs->
setBool(
"/dialogs/import/ask_svg", ask_svg);
180 prefs->
setString(
"/dialogs/import/import_mode_svg", import_mode_svg );
184 bool const import_pages = import_mode_svg ==
"pages";
185 bool const import_new = import_mode_svg ==
"new";
188 if (is_importing && import_mode_svg !=
"include" && !import_pages && !import_new) {
202 Glib::ustring display_unit = doc->getDisplayUnit()->abbr;
203 double width = ret->getWidth().value(display_unit);
204 double height = ret->getHeight().value(display_unit);
214 image_node->
setAttribute(
"preserveAspectRatio",
"none");
216 double svgdpi = mod->get_param_float(
"svgdpi");
224 if(
scale !=
"auto") {
232 if (import_mode_svg ==
"embed") {
239 gchar* _uri = g_filename_to_uri(uri,
nullptr,
nullptr);
253 layer_node->
setAttribute(
"inkscape:groupmode",
"layer");
255 doc->getRoot()->appendChildRepr(layer_node);
262 if (!doc->getRoot()->viewBox_set) {
263 doc->setViewBox(
Geom::Rect::from_xywh(0, 0, doc->getWidth().value(doc->getDisplayUnit()), doc->getHeight().value(doc->getDisplayUnit())));
271 if (!file->get_uri_scheme().empty()) {
276 file->load_contents(contents, length);
278 }
catch (Gio::Error &e) {
279 g_warning(
"Could not load contents of non-local URI %s\n", uri);
292 if (doc && !page_nums.empty()) {
293 doc->prunePages(page_nums,
true);
298 if (doc && is_importing && !import_new) {
299 doc->setPages(import_pages);
317 g_return_if_fail(doc !=
nullptr);
318 g_return_if_fail(filename !=
nullptr);
Cairo integration helpers.
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
std::unique_ptr< SPDocument > open(Inkscape::Extension::Input *mod, char const *uri, bool is_importing) override
This function takes in a filename of a SVG document and turns it into a SPDocument.
static void init()
What would an SVG editor be without loading/saving SVG files. This function sets that up.
void save(Inkscape::Extension::Output *mod, SPDocument *doc, char const *filename) override
This is the function that does all of the SVG saves in Inkscape. It detects whether it should do a In...
Generic failure for an undescribed reason.
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.
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.
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.
Typed SVG document implementation.
static std::unique_ptr< SPDocument > createNewDocFromMem(std::span< char const > buffer, bool keepalive, std::string const &filename="")
char const * getDocumentBase() const
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.
Inkscape::XML::Document * getReprDoc()
Our Inkscape::XML::Document.
A way to clear the N_ macro, which is defined as an inline function.
std::shared_ptr< Css const > css
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.
Glib::ustring format_classic(T const &... args)
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 sp_repr_save_rebased_file(Document *doc, gchar const *const filename, gchar const *default_ns, gchar const *old_base, gchar const *for_filename)
Returns true if file successfully saved.
bool fit_canvas_to_drawing(SPDocument *doc, bool with_margins)
void sp_embed_svg(Inkscape::XML::Node *image_node, std::string const &fn)
SVG <image> implementation.
SPRoot: SVG <svg> implementation.
Interface for XML documents.
virtual Node * createElement(char const *name)=0