summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2018-11-06 10:18:22 +0000
committerThomas Holder <thomas@thomas-holder.de>2018-11-07 20:58:07 +0000
commit5835eaa282065fe8f44fb071a467f10c0adcb76a (patch)
treee9f07e0514b6ccdfaf52619b0a93044cefe19907
parentRefactor rebase_hrefs with new URI API (diff)
downloadinkscape-5835eaa282065fe8f44fb071a467f10c0adcb76a.tar.gz
inkscape-5835eaa282065fe8f44fb071a467f10c0adcb76a.zip
fix clipboard URL rebasing
-rw-r--r--src/extension/implementation/implementation.h5
-rw-r--r--src/extension/internal/svg.cpp3
-rw-r--r--src/extension/internal/svg.h3
-rw-r--r--src/extension/output.cpp3
-rw-r--r--src/extension/output.h3
-rw-r--r--src/ui/clipboard.cpp7
-rw-r--r--src/xml/rebase-hrefs.cpp41
-rw-r--r--src/xml/rebase-hrefs.h2
-rw-r--r--src/xml/repr-io.cpp10
9 files changed, 34 insertions, 43 deletions
diff --git a/src/extension/implementation/implementation.h b/src/extension/implementation/implementation.h
index 7658e5a83..88afa0d27 100644
--- a/src/extension/implementation/implementation.h
+++ b/src/extension/implementation/implementation.h
@@ -178,6 +178,11 @@ public:
Geom::Point const & /*p*/,
SPStyle const * /*style*/) { return 0; }
virtual void processPath(Inkscape::XML::Node * /*node*/) {}
+
+ /**
+ * If detach = true, when saving to a file, don't store URIs realtive to the filename
+ */
+ virtual void setDetachBase(bool detach) {}
};
diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp
index 8fb1e61b9..4d6a24b40 100644
--- a/src/extension/internal/svg.cpp
+++ b/src/extension/internal/svg.cpp
@@ -397,7 +397,8 @@ Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena
}
if (!sp_repr_save_rebased_file(rdoc, filename, SP_SVG_NS_URI,
- doc->getBase(), filename)) {
+ doc->getBase(), //
+ m_detachbase ? nullptr : filename)) {
throw Inkscape::Extension::Output::save_failed();
}
diff --git a/src/extension/internal/svg.h b/src/extension/internal/svg.h
index cba0ebf3d..17f3f7bb2 100644
--- a/src/extension/internal/svg.h
+++ b/src/extension/internal/svg.h
@@ -22,8 +22,11 @@ namespace Extension {
namespace Internal {
class Svg : public Inkscape::Extension::Implementation::Implementation {
+ bool m_detachbase = false;
public:
+ void setDetachBase(bool detach) override { m_detachbase = detach; }
+
void save( Inkscape::Extension::Output *mod,
SPDocument *doc,
gchar const *filename ) override;
diff --git a/src/extension/output.cpp b/src/extension/output.cpp
index 5a39a2403..e863c77fc 100644
--- a/src/extension/output.cpp
+++ b/src/extension/output.cpp
@@ -211,8 +211,9 @@ Output::prefs ()
could be changed, and old files will still work properly.
*/
void
-Output::save(SPDocument *doc, gchar const *filename)
+Output::save(SPDocument *doc, gchar const *filename, bool detachbase)
{
+ imp->setDetachBase(detachbase);
imp->save(this, doc, filename);
return;
diff --git a/src/extension/output.h b/src/extension/output.h
index de1ce4503..a67a3cc30 100644
--- a/src/extension/output.h
+++ b/src/extension/output.h
@@ -42,7 +42,8 @@ public:
~Output () override;
bool check () override;
void save (SPDocument *doc,
- gchar const *uri);
+ gchar const *filename,
+ bool detachbase = false);
bool prefs ();
gchar * get_mimetype();
gchar * get_extension();
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index a18df5675..b57179725 100644
--- a/src/ui/clipboard.cpp
+++ b/src/ui/clipboard.cpp
@@ -1279,7 +1279,12 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/)
// Need to load the extension.
(*out)->set_state(Inkscape::Extension::Extension::STATE_LOADED);
}
- (*out)->save(_clipboardSPDoc, filename);
+
+ if (SP_ACTIVE_DOCUMENT) {
+ _clipboardSPDoc->setBase(SP_ACTIVE_DOCUMENT->getBase());
+ }
+
+ (*out)->save(_clipboardSPDoc, filename, true);
}
g_file_get_contents(filename, &data, &len, nullptr);
diff --git a/src/xml/rebase-hrefs.cpp b/src/xml/rebase-hrefs.cpp
index e484ee7a1..c6276a610 100644
--- a/src/xml/rebase-hrefs.cpp
+++ b/src/xml/rebase-hrefs.cpp
@@ -103,7 +103,12 @@ Inkscape::XML::rebase_href_attrs(gchar const *const old_abs_base,
uri = URI::from_native_filename(sp_absref);
}
- auto new_href = uri.str(URI::from_dirname(new_abs_base).str().c_str());
+ std::string baseuri;
+ if (new_abs_base) {
+ baseuri = URI::from_dirname(new_abs_base).str();
+ }
+
+ auto new_href = uri.str(baseuri.c_str());
ret = cons(AttributeRecord(href_key, share_string(new_href.c_str())), ret); // Check if this is safe/copied or if it is only held.
if (sp_absref) {
@@ -118,40 +123,6 @@ Inkscape::XML::rebase_href_attrs(gchar const *const old_abs_base,
return ret;
}
-// std::string Inkscape::XML::rebase_href_attrs( std::string const &oldAbsBase, std::string const &newAbsBase, gchar const * /*href*/, gchar const */*absref*/ )
-// {
-// std::string ret;
-// //g_message( "XX need to flip from [%s] to [%s]", oldAbsBase.c_str(), newAbsBase.c_str() );
-
-// if ( oldAbsBase != newAbsBase ) {
-// }
-
-// return ret;
-// }
-
-std::string Inkscape::XML::calc_abs_doc_base(gchar const *doc_base)
-{
- /* Note that we don't currently try to handle the case of doc_base containing
- * `..' or `.' path components. This non-handling means that sometimes
- * sp_relative_path_from_path will needlessly give an absolute path.
- *
- * It's probably not worth trying to address this until we're using proper
- * relative URL/IRI href processing (with liburiparser).
- *
- * (Note that one possible difficulty with `..' is symlinks.) */
- std::string ret;
-
- if (!doc_base) {
- ret = Glib::get_current_dir();
- } else if (Glib::path_is_absolute(doc_base)) {
- ret = doc_base;
- } else {
- ret = Glib::build_filename( Glib::get_current_dir(), doc_base );
- }
-
- return ret;
-}
-
void Inkscape::XML::rebase_hrefs(SPDocument *const doc, gchar const *const new_base, bool const spns)
{
using Inkscape::URI;
diff --git a/src/xml/rebase-hrefs.h b/src/xml/rebase-hrefs.h
index 79778d537..12e521dea 100644
--- a/src/xml/rebase-hrefs.h
+++ b/src/xml/rebase-hrefs.h
@@ -8,8 +8,6 @@ class SPDocument;
namespace Inkscape {
namespace XML {
-std::string calc_abs_doc_base(char const *doc_base);
-
/**
* Change relative hrefs in doc to be relative to \a new_base instead of doc.base.
*
diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp
index 35a2e3793..258f50fe5 100644
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
@@ -43,7 +43,6 @@ using Inkscape::XML::Document;
using Inkscape::XML::SimpleDocument;
using Inkscape::XML::Node;
using Inkscape::XML::AttributeRecord;
-using Inkscape::XML::calc_abs_doc_base;
using Inkscape::XML::rebase_href_attrs;
Document *sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns);
@@ -709,8 +708,15 @@ bool sp_repr_save_rebased_file(Document *doc, gchar const *const filename, gchar
Glib::ustring old_href_abs_base;
Glib::ustring new_href_abs_base;
+
+ if (old_base) {
+ old_href_abs_base = old_base;
+ if (!Glib::path_is_absolute(old_href_abs_base)) {
+ old_href_abs_base = Glib::build_filename(Glib::get_current_dir(), old_href_abs_base);
+ }
+ }
+
if (for_filename) {
- old_href_abs_base = calc_abs_doc_base(old_base);
if (Glib::path_is_absolute(for_filename)) {
new_href_abs_base = Glib::path_get_dirname(for_filename);
} else {