Commit 5835eaa2 authored by Thomas Holder's avatar Thomas Holder

fix clipboard URL rebasing

parent afc23108
Pipeline #35795037 passed with stages
in 55 minutes and 54 seconds
......@@ -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) {}
};
......
......@@ -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();
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
......@@ -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);
......
......@@ -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;
......
......@@ -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.
*
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment