summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorPeter Moulder <peter.moulder@monash.edu>2009-04-07 05:31:32 +0000
committerpjrm <pjrm@users.sourceforge.net>2009-04-07 05:31:32 +0000
commitc2d8810625892a8bedcaa192df9b4165e46609ee (patch)
tree86bf3792eb9043b59435c17ae9415138d2e81a21 /src/extension
parentfunctional noop: Clarify g_strcanon behaviour by not redundantly reassigning ... (diff)
downloadinkscape-c2d8810625892a8bedcaa192df9b4165e46609ee.tar.gz
inkscape-c2d8810625892a8bedcaa192df9b4165e46609ee.zip
Move Inkscape::IO::fixupHrefs to Inkscape::XML::rebase_hrefs in new file xml/rebase-hrefs.*. Give it the old and new base directory, so that it can change hrefs without relying on sodipodi:absref.
Also create a new function sp_repr_save_rebased_file that changes all xlink:href attributes as it writes them, so that we don't need to modify the owning document. (Especially useful for "Save a copy" or exporting.) extension/system.cpp: (Inkscape::Extension::save): Don't call sp_document_set_uri even temporarily other than at the same time as calling rebase_hrefs. (Otherwise, existing relative hrefs will point nowhere.) When exporting plain SVG, change the relative hrefs according to the destination filename. (bzr r7643)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/implementation/xslt.cpp10
-rw-r--r--src/extension/internal/gdkpixbuf-input.cpp2
-rw-r--r--src/extension/internal/svg.cpp8
-rw-r--r--src/extension/system.cpp17
4 files changed, 19 insertions, 18 deletions
diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp
index c331cac60..f34fea64a 100644
--- a/src/extension/implementation/xslt.cpp
+++ b/src/extension/implementation/xslt.cpp
@@ -184,16 +184,14 @@ XSLT::open(Inkscape::Extension::Input */*module*/, gchar const *filename)
void
XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const *filename)
{
+ /* TODO: Should we assume filename to be in utf8 or to be a raw filename?
+ * See JavaFXOutput::save for discussion. */
g_return_if_fail(doc != NULL);
g_return_if_fail(filename != NULL);
Inkscape::XML::Node *repr = NULL;
repr = sp_document_repr_root (doc);
- gchar *save_path = g_path_get_dirname (filename);
- Inkscape::IO::fixupHrefs( doc, save_path, true );
- g_free(save_path);
-
std::string tempfilename_out;
int tempfd_out = 0;
try {
@@ -203,8 +201,8 @@ XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const
return;
}
- gboolean const s = sp_repr_save_file (repr->document(), tempfilename_out.c_str(), SP_SVG_NS_URI);
- if (s == FALSE) {
+ if (!sp_repr_save_rebased_file(repr->document(), tempfilename_out.c_str(), SP_SVG_NS_URI,
+ doc->base, filename)) {
throw Inkscape::Extension::Output::save_failed();
}
diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp
index e8af0ec9d..f28b017b4 100644
--- a/src/extension/internal/gdkpixbuf-input.cpp
+++ b/src/extension/internal/gdkpixbuf-input.cpp
@@ -54,7 +54,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
// import as <image>
repr = xml_doc->createElement("svg:image");
- // both are the same, as we don't know our base dir here and cannot relativate href (importer will fixupHrefs):
+ // both are the same, as we don't know our base dir here and cannot relativate href (importer will rebase_hrefs):
repr->setAttribute("xlink:href", uri);
repr->setAttribute("sodipodi:absref", uri);
diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp
index 4a323d7d7..a3589e905 100644
--- a/src/extension/internal/svg.cpp
+++ b/src/extension/internal/svg.cpp
@@ -198,7 +198,7 @@ Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena
gchar *save_path = g_path_get_dirname(filename);
- gboolean const spns = (!mod->get_id()
+ bool const spns = ( !mod->get_id()
|| !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE)
|| !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE));
@@ -212,10 +212,8 @@ Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena
repr = sp_document_root (doc)->updateRepr(rdoc, repr, SP_OBJECT_WRITE_BUILD);
}
- Inkscape::IO::fixupHrefs( doc, save_path, spns );
-
- gboolean const s = sp_repr_save_file(repr->document(), filename, SP_SVG_NS_URI);
- if (s == FALSE) {
+ if (!sp_repr_save_rebased_file(repr->document(), filename, SP_SVG_NS_URI,
+ doc->base, filename)) {
throw Inkscape::Extension::Output::save_failed();
}
diff --git a/src/extension/system.cpp b/src/extension/system.cpp
index 6442f2f7e..37b70fec8 100644
--- a/src/extension/system.cpp
+++ b/src/extension/system.cpp
@@ -29,6 +29,7 @@
#include "print.h"
#include "implementation/script.h"
#include "implementation/xslt.h"
+#include "xml/rebase-hrefs.h"
/* #include "implementation/plugin.h" */
namespace Inkscape {
@@ -250,12 +251,20 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
bool saved_modified = false;
gchar *saved_output_extension = NULL;
gchar *saved_dataloss = NULL;
- gchar *saved_uri = NULL;
if (!official) {
saved_modified = doc->isModifiedSinceSave();
saved_output_extension = g_strdup(repr->attribute("inkscape:output_extension"));
saved_dataloss = g_strdup(repr->attribute("inkscape:dataloss"));
- saved_uri = g_strdup(doc->uri);
+ } else {
+ /* The document is changing name/uri. */
+
+ /* TODO: Don't treat URIs and filenames interchangeably.
+ * So call g_filename_to_uri when passing to sp_document_set_uri,
+ * and change rebase_hrefs to accept a base URI/LEIRI instead of dir name. */
+ gchar *const new_base = g_path_get_dirname(fileName);
+ Inkscape::XML::rebase_hrefs(doc, new_base, true);
+ sp_document_set_uri(doc, fileName);
+ g_free(new_base);
}
// Update attributes:
@@ -263,8 +272,6 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
bool const saved = sp_document_get_undo_sensitive(doc);
sp_document_set_undo_sensitive(doc, false);
{
- // save the filename for next use
- sp_document_set_uri(doc, fileName);
// also save the extension for next use
repr->setAttribute("inkscape:output_extension", omod->get_id());
// set the "dataloss" attribute if the chosen extension is lossy
@@ -286,14 +293,12 @@ save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension,
{
repr->setAttribute("inkscape:output_extension", saved_output_extension);
repr->setAttribute("inkscape:dataloss", saved_dataloss);
- sp_document_set_uri(doc, saved_uri);
}
sp_document_set_undo_sensitive(doc, saved);
doc->setModifiedSinceSave(saved_modified);
g_free(saved_output_extension);
g_free(saved_dataloss);
- g_free(saved_uri);
}
g_free(fileName);