summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2018-05-12 20:50:17 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2018-05-12 20:50:17 +0000
commitb81edb009eabf2b10f7d34c416af691a8d4952f8 (patch)
treeaa0ead927103d164bf2356a8def0574dec81269a /src
parentFixes bugs: #1770760, #1770761, #1770763, #1770769 related to linked SVG (diff)
downloadinkscape-b81edb009eabf2b10f7d34c416af691a8d4952f8.tar.gz
inkscape-b81edb009eabf2b10f7d34c416af691a8d4952f8.zip
Allow embed on SVG imports
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/svg.cpp78
-rw-r--r--src/extension/system.cpp14
-rw-r--r--src/object/sp-image.cpp40
-rw-r--r--src/object/sp-image.h1
4 files changed, 77 insertions, 56 deletions
diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp
index c5ddb084c..bf4924b2a 100644
--- a/src/extension/internal/svg.cpp
+++ b/src/extension/internal/svg.cpp
@@ -28,16 +28,19 @@
#include "inkscape.h"
#include "preferences.h"
#include "extension/output.h"
+#include "extension/input.h"
#include "extension/system.h"
#include "file.h"
#include "svg.h"
#include "file.h"
+#include "display/cairo-utils.h"
#include "extension/system.h"
#include "extension/output.h"
#include "xml/attribute-record.h"
#include "xml/simple-document.h"
#include "object/sp-namedview.h"
+#include "object/sp-image.h"
#include "object/sp-root.h"
#include "util/units.h"
#include "selection-chemistry.h"
@@ -134,6 +137,19 @@ Svg::init(void)
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
"<name>" N_("SVG Input") "</name>\n"
"<id>" SP_MODULE_KEY_INPUT_SVG "</id>\n"
+ "<param name='method' type='optiongroup' appearance='full' _gui-text='" N_("Method to import SVG:") "' _gui-description='" N_("Select the way the SVG is imported.") "' >\n"
+ "<_option value='include' >" N_("Include SVG image as editable object(s) in the current file") "</_option>\n"
+ "<_option value='link' >" N_("Link the SVG file in a image tag (not editable in this document") "</_option>\n"
+ "<_option value='embed' >" N_("Embed the SVG file in a image tag (not editable in this document") "</_option>\n"
+ "</param>\n"
+
+ "<param name='scale' appearance='minimal' 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"
+ "<_option value='auto' >" N_("None (auto)") "</_option>\n"
+ "<_option value='optimizeQuality' >" N_("Smooth (optimizeQuality)") "</_option>\n"
+ "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "</_option>\n"
+ "</param>\n"
+
+ "<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=\"boolean\" >false</param>\n"
"<input>\n"
"<extension>.svg</extension>\n"
"<mimetype>image/svg+xml</mimetype>\n"
@@ -184,48 +200,35 @@ Svg::init(void)
This function is really simple, it just calls sp_document_new...
*/
SPDocument *
-Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri)
+Svg::open (Inkscape::Extension::Input *mod, const gchar *uri)
{
auto file = Gio::File::create_for_uri(uri);
const auto path = file->get_path();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- bool link = prefs->getBool("/dialogs/import/link_svg", false);
bool ask = prefs->getBool("/dialogs/import/ask");
+ Glib::ustring method = prefs->getString("/dialogs/import/method");
+ Glib::ustring scale = prefs->getString("/dialogs/import/scale");
bool is_import = false;
if (strcmp(prefs->getString("/options/openmethod/value").c_str(), "import") == 0) {
is_import = true;
}
- if (INKSCAPE.use_gui() && is_import && ask) {
- Gtk::Dialog svg_open_dialog(_("Import SVG image"));
- svg_open_dialog.set_transient_for( *(INKSCAPE.active_desktop()->getToplevel()) );
- svg_open_dialog.set_border_width(10);
- svg_open_dialog.set_resizable(false);
- Gtk::RadioButton::Group c1, c2;
- Gtk::Label choice1_label;
- choice1_label.set_markup(_("Include SVG image as editable object(s) in the current file"));
- Gtk::RadioButton choice1(c1);
- choice1.add(choice1_label);
- Gtk::RadioButton choice2(c1, _("Only add a link to the SVG file (not editable in this document)"));
- Gtk::CheckButton notask(_("Don't ask again"));
- Gtk::Box *content = svg_open_dialog.get_content_area();
- content->pack_start(choice1, false, false, 5);
- content->pack_start(choice2, false, false, 5);
- content->pack_start(notask, false, false, 5);
- Gtk::Button *ok_button = svg_open_dialog.add_button(_("OK"), GTK_RESPONSE_ACCEPT);
- svg_open_dialog.show_all_children();
- ok_button->grab_focus();
- int status = svg_open_dialog.run();
- if ( status == GTK_RESPONSE_ACCEPT ) {
- link = choice2.get_active();
- prefs->setBool("/dialogs/import/ask", !notask.get_active());
-
+ if(INKSCAPE.use_gui() && is_import && ask) {
+ Glib::ustring mod_method = mod->get_param_optiongroup("method");
+ Glib::ustring mod_scale = mod->get_param_optiongroup("scale");
+ if( method.compare( mod_method) != 0 ) {
+ method = mod_method;
}
- prefs->setBool("/dialogs/import/link_svg", link );
+ prefs->setString("/dialogs/import/method", method );
+ if( scale.compare( mod_scale ) != 0 ) {
+ scale = mod_scale;
+ }
+ prefs->setString("/dialogs/import/scale", scale );
+ prefs->setBool("/dialogs/import/ask", !mod->get_param_bool("do_not_ask") );
}
-
SPDocument * doc = SPDocument::createNewDoc (NULL, TRUE, TRUE);
- if (link && is_import) {
+ if (method.compare("include") != 0 && is_import) {
+ bool embed = ( method.compare( "embed" ) == 0 );
SPDocument * ret = SPDocument::createNewDoc(uri, TRUE);
SPNamedView *nv = sp_document_namedview(doc, NULL);
Glib::ustring display_unit = nv->display_units->abbr;
@@ -251,12 +254,19 @@ Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri)
sp_repr_css_attr_unref( css );
}
// convert filename to uri
- gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
- if(_uri) {
- image_node->setAttribute("xlink:href", _uri);
- g_free(_uri);
+ if (embed) {
+ std::unique_ptr<Inkscape::Pixbuf> pb(Inkscape::Pixbuf::create_from_file(uri));
+ if(pb) {
+ sp_embed_image(image_node, pb.get());
+ }
} else {
- image_node->setAttribute("xlink:href", uri);
+ gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
+ if(_uri) {
+ image_node->setAttribute("xlink:href", _uri);
+ g_free(_uri);
+ } else {
+ image_node->setAttribute("xlink:href", uri);
+ }
}
// Add it to the current layer
Inkscape::XML::Node *layer_node = xml_doc->createElement("svg:g");
diff --git a/src/extension/system.cpp b/src/extension/system.cpp
index f438d84b9..5b039948a 100644
--- a/src/extension/system.cpp
+++ b/src/extension/system.cpp
@@ -95,13 +95,21 @@ SPDocument *open(Extension *key, gchar const *filename)
//g_warning("Extension: %s", imod->get_id());
bool show = true;
- if (strlen(imod->get_id()) > 27) {
+ if (strlen(imod->get_id()) > 21) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool ask = prefs->getBool("/dialogs/import/ask");
- Glib::ustring id = Glib::ustring(imod->get_id(), 28);
- if (!ask && id.compare( "org.inkscape.input.gdkpixbuf") == 0) {
+ Glib::ustring id = Glib::ustring(imod->get_id(), 22);
+ if (id.compare( "org.inkscape.input.svg") == 0 &&
+ (strcmp(prefs->getString("/options/openmethod/value").c_str(), "import") != 0 || !ask))
+ {
show = false;
imod->set_gui(false);
+ } else if(strlen(imod->get_id()) > 27) {
+ id = Glib::ustring(imod->get_id(), 28);
+ if (!ask && id.compare( "org.inkscape.input.gdkpixbuf") == 0) {
+ show = false;
+ imod->set_gui(false);
+ }
}
}
imod->set_state(Extension::STATE_LOADED);
diff --git a/src/object/sp-image.cpp b/src/object/sp-image.cpp
index 6fd9e5c1e..3a76b9633 100644
--- a/src/object/sp-image.cpp
+++ b/src/object/sp-image.cpp
@@ -125,6 +125,7 @@ SPImage::SPImage() : SPItem(), SPViewBox() {
this->color_profile = 0;
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
this->pixbuf = 0;
+ this->on_construct = true;
}
SPImage::~SPImage() {
@@ -327,7 +328,8 @@ void SPImage::update(SPCtx *ctx, unsigned int flags) {
SPItem::update(ctx, flags);
- if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) {
+ if ((flags & SP_IMAGE_HREF_MODIFIED_FLAG) || this->on_construct) {
+ this->on_construct = false;
delete this->pixbuf;
this->pixbuf = NULL;
@@ -510,24 +512,24 @@ gchar* SPImage::description() const {
this->pixbuf->height(),
href_desc) );
- if (this->pixbuf == NULL &&
- this->document)
- {
- Inkscape::Pixbuf * pb = NULL;
- pb = sp_image_repr_read_image (
- this->getRepr()->attribute("xlink:href"),
- this->getRepr()->attribute("sodipodi:absref"),
- this->document->getBase());
-
- if (pb) {
- ret = ( pb == NULL ? g_strdup_printf(_("[bad reference]: %s"), href_desc)
- : g_strdup_printf(_("%d &#215; %d: %s"),
- pb->width(),
- pb->height(),
- href_desc));
- delete pb;
- }
- }
+// if (this->pixbuf == NULL &&
+// this->document)
+// {
+// Inkscape::Pixbuf * pb = NULL;
+// pb = sp_image_repr_read_image (
+// this->getRepr()->attribute("xlink:href"),
+// this->getRepr()->attribute("sodipodi:absref"),
+// this->document->getBase());
+
+// if (pb) {
+// ret = ( pb == NULL ? g_strdup_printf(_("[bad reference]: %s"), href_desc)
+// : g_strdup_printf(_("%d &#215; %d: %s"),
+// pb->width(),
+// pb->height(),
+// href_desc));
+// delete pb;
+// }
+// }
g_free(href_desc);
return ret;
diff --git a/src/object/sp-image.h b/src/object/sp-image.h
index 9cd5faa8b..a5dd84fe2 100644
--- a/src/object/sp-image.h
+++ b/src/object/sp-image.h
@@ -63,6 +63,7 @@ public:
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
void apply_profile(Inkscape::Pixbuf *pixbuf);
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
+ bool on_construct;
};
/* Return duplicate of curve or NULL */