From b31224a81f04f0ff9b412983f2f35fa63c0e7e41 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 16 Jan 2014 12:20:34 -0500 Subject: Add the ability to load external documents in xlink:hrefs such as the use element. See bug #1269880 Fixed bugs: - https://launchpad.net/bugs/1269880 (bzr r12939) --- src/uri-references.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 2c09695d4..718b2d451 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -12,6 +12,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include #include @@ -21,6 +22,7 @@ #include "uri-references.h" #include "extract-uri.h" +#include #include namespace Inkscape { @@ -45,15 +47,31 @@ URIReference::~URIReference() void URIReference::attach(const URI &uri) throw(BadURIException) { - SPDocument *document; + SPDocument *document = NULL; + + // Attempt to get the document that contains the URI if (_owner) { document = _owner->document; } else if (_owner_document) { document = _owner_document; - } else { - g_assert_not_reached(); } + // The path contains references to seperate document files to load. + const char *path = uri.getPath(); + if(path) { + if(document != NULL) { + // Calculate the absolute path from an available document + std::string basePath = std::string( document->getBase() ); + std::string absPath = Glib::build_filename(basePath, std::string( path ) ); + path = absPath.c_str(); + } + // TODO: This is inefficient because it will load the same svg file + // many times if it's used many times. A global list of documents would + // be useful for tracking linked items. + document = SPDocument::createNewDoc(path, FALSE); + } + g_return_if_fail(document != NULL); + gchar const *fragment = uri.getFragment(); if ( !uri.isRelative() || uri.getQuery() || !fragment ) { throw UnsupportedURIException(); -- cgit v1.2.3