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 From e01eb5907b04fdc194551741be6c6dbf5ee6f7e5 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 21 Jan 2014 22:20:23 -0500 Subject: Improve use tag logic by recording the loaded documents in a list. (bzr r12969) --- src/uri-references.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 718b2d451..adf948c7b 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -58,17 +58,36 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // 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(); + if(path && 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(); + + // We look at existing children and parents + SPDocument *parent = document; + SPDocument *original = document; + document = NULL; + + while(parent != NULL) { + boost::ptr_list::iterator iter; + for (iter = parent->child_documents.begin(); + iter != parent->child_documents.end(); ++iter) { + if(strcmp(iter->getURI(), path)==0) + document = &*iter; + } + parent = parent->parent_document; + } + // Load a fresh document from the svg source. + if(!document) { + document = SPDocument::createNewDoc(path, FALSE); + if(document) { + document->parent_document = original; + original->child_documents.push_back(document); + } else { + g_warning("Could not load svg file: %s", path); + } } - // 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); -- cgit v1.2.3 From 9a0c54cb8bc9b0bfc0c6af95f4b156fd717179a8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 22 Jan 2014 14:58:15 -0500 Subject: Protect against infinate looping of new included hrefs (bzr r12970) --- src/uri-references.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index adf948c7b..30e832c04 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -64,25 +64,32 @@ void URIReference::attach(const URI &uri) throw(BadURIException) std::string absPath = Glib::build_filename(basePath, std::string( path ) ); path = absPath.c_str(); - // We look at existing children and parents SPDocument *parent = document; SPDocument *original = document; document = NULL; - while(parent != NULL) { + while(parent != NULL && document == NULL) { + // Check myself and any parents int he chain + if(strcmp(parent->getURI(), path)==0) { + document = parent; + break; + } + // Then check children of those. boost::ptr_list::iterator iter; for (iter = parent->child_documents.begin(); iter != parent->child_documents.end(); ++iter) { - if(strcmp(iter->getURI(), path)==0) + if(strcmp(iter->getURI(), path)==0) { document = &*iter; + break; + } } parent = parent->parent_document; } + // Load a fresh document from the svg source. if(!document) { - document = SPDocument::createNewDoc(path, FALSE); + document = SPDocument::createNewDoc(path, false, false, original); if(document) { - document->parent_document = original; original->child_documents.push_back(document); } else { g_warning("Could not load svg file: %s", path); -- cgit v1.2.3 From 423ea7c0373e77a83c8a9ef62df9a786b4feb7ac Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 22 Jan 2014 17:58:40 -0500 Subject: Move sub-document reference creation code from uri-reference to document.cpp as createChildDoc(path) (bzr r12971) --- src/uri-references.cpp | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 30e832c04..1684c6ade 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -59,42 +59,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // The path contains references to seperate document files to load. const char *path = uri.getPath(); if(path && 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(); - - SPDocument *parent = document; - SPDocument *original = document; - document = NULL; - - while(parent != NULL && document == NULL) { - // Check myself and any parents int he chain - if(strcmp(parent->getURI(), path)==0) { - document = parent; - break; - } - // Then check children of those. - boost::ptr_list::iterator iter; - for (iter = parent->child_documents.begin(); - iter != parent->child_documents.end(); ++iter) { - if(strcmp(iter->getURI(), path)==0) { - document = &*iter; - break; - } - } - parent = parent->parent_document; - } - - // Load a fresh document from the svg source. - if(!document) { - document = SPDocument::createNewDoc(path, false, false, original); - if(document) { - original->child_documents.push_back(document); - } else { - g_warning("Could not load svg file: %s", path); - } - } + document = document->createChildDoc(path); } g_return_if_fail(document != NULL); -- cgit v1.2.3 From ae7f7f7449a2da248ff13119e802a104de297c3d Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 22 Jan 2014 18:06:39 -0500 Subject: Improve warnings for missing files. Don't just assert bolocks to the user. (bzr r12972) --- src/uri-references.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 1684c6ade..f2df55213 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -61,7 +61,10 @@ void URIReference::attach(const URI &uri) throw(BadURIException) if(path && document != NULL) { document = document->createChildDoc(path); } - g_return_if_fail(document != NULL); + if(!document) { + g_warning("Can't get document for referenced URI: %s", uri.toString()); + return; + } gchar const *fragment = uri.getFragment(); if ( !uri.isRelative() || uri.getQuery() || !fragment ) { -- cgit v1.2.3 From ddb8af8009f151c7107daf0c2127f0ba2d882649 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 24 Jan 2014 20:05:26 -0500 Subject: Move absolute path generator to URI and use std::strings (bzr r12977) --- src/uri-references.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index f2df55213..dc0101024 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -57,9 +57,11 @@ void URIReference::attach(const URI &uri) throw(BadURIException) } // The path contains references to seperate document files to load. - const char *path = uri.getPath(); - if(path && document != NULL) { - document = document->createChildDoc(path); + if(document && uri.getPath()) { + std::string base = std::string(g_strdup(document->getBase())); + std::string path = uri.getFullPath(base); + if(!path.empty()) + document = document->createChildDoc(path); } if(!document) { g_warning("Can't get document for referenced URI: %s", uri.toString()); -- cgit v1.2.3 From 7455f1a259ce28ee56866b5cde06e79be4cfaf97 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 26 Jan 2014 12:19:47 -0500 Subject: Check file existance and clean up memory issues thanks to KK and Johan (bzr r12979) --- src/uri-references.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index dc0101024..abe16ec9d 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -58,10 +58,12 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // The path contains references to seperate document files to load. if(document && uri.getPath()) { - std::string base = std::string(g_strdup(document->getBase())); + std::string base = std::string(document->getBase()); std::string path = uri.getFullPath(base); if(!path.empty()) document = document->createChildDoc(path); + else + document = NULL; } if(!document) { g_warning("Can't get document for referenced URI: %s", uri.toString()); -- cgit v1.2.3 From 9dc9db77232e264edcfec1e6ba6437130ac4c0eb Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 7 Feb 2014 13:27:42 +0100 Subject: Prevent attempt to initialize/compare std::string with/to null pointer. (bzr r13004) --- src/uri-references.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index abe16ec9d..de293716b 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -58,7 +58,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // The path contains references to seperate document files to load. if(document && uri.getPath()) { - std::string base = std::string(document->getBase()); + std::string base = std::string(document->getBase() ? document->getBase() : ""); std::string path = uri.getFullPath(base); if(!path.empty()) document = document->createChildDoc(path); @@ -184,3 +184,14 @@ sp_uri_reference_resolve (SPDocument *document, const gchar *uri) return ref; } + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From f11d3869c683c6aeb40ca7ff84d3a721f8e86ba2 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 7 Feb 2014 13:38:46 +0100 Subject: Slightly improved fix to previous check-in. (bzr r13005) --- src/uri-references.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index de293716b..ea8078b28 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -58,7 +58,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException) // The path contains references to seperate document files to load. if(document && uri.getPath()) { - std::string base = std::string(document->getBase() ? document->getBase() : ""); + std::string base = document->getBase() ? document->getBase() : ""; std::string path = uri.getFullPath(base); if(!path.empty()) document = document->createChildDoc(path); -- cgit v1.2.3 From bcb34494fe93d057210bc7e4048da66ce455c953 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 3 Mar 2014 11:31:09 +0100 Subject: Don't try to load JPG and PNG files with createChildDoc(). (bzr r13099) --- src/uri-references.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index ea8078b28..5cdf132fa 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -56,8 +56,19 @@ void URIReference::attach(const URI &uri) throw(BadURIException) document = _owner_document; } + // createChildDoc() assumes that the referenced file is an SVG. + // PNG and JPG files are allowed (in the case of feImage). + gchar *filename = uri.toString(); + bool skip = false; + if( g_str_has_suffix( filename, ".jpg" ) || + g_str_has_suffix( filename, ".JPG" ) || + g_str_has_suffix( filename, ".png" ) || + g_str_has_suffix( filename, ".PNG" ) ) { + skip = true; + } + // The path contains references to seperate document files to load. - if(document && uri.getPath()) { + if(document && uri.getPath() && !skip ) { std::string base = document->getBase() ? document->getBase() : ""; std::string path = uri.getFullPath(base); if(!path.empty()) @@ -66,9 +77,10 @@ void URIReference::attach(const URI &uri) throw(BadURIException) document = NULL; } if(!document) { - g_warning("Can't get document for referenced URI: %s", uri.toString()); + g_warning("Can't get document for referenced URI: %s", filename); return; } + g_free( filename ); gchar const *fragment = uri.getFragment(); if ( !uri.isRelative() || uri.getQuery() || !fragment ) { -- cgit v1.2.3 From cb9756402b60be2b2ed8d058c1de4133ae3c0300 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 3 Mar 2014 22:08:39 +0100 Subject: - fix memleak - fix { } usage - delete NULL is guaranteed to be OK - fix initialization (all paths will eventually init the var, but let the compiler figure that out, instead of a future programmer trying to locate a bug) (bzr r13101) --- src/uri-references.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 5cdf132fa..8edafb0b0 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -71,13 +71,15 @@ void URIReference::attach(const URI &uri) throw(BadURIException) if(document && uri.getPath() && !skip ) { std::string base = document->getBase() ? document->getBase() : ""; std::string path = uri.getFullPath(base); - if(!path.empty()) + if(!path.empty()) { document = document->createChildDoc(path); - else + } else { document = NULL; + } } if(!document) { g_warning("Can't get document for referenced URI: %s", filename); + g_free( filename ); return; } g_free( filename ); @@ -91,7 +93,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException) /* for now this handles the minimal xpointer form that SVG 1.0 * requires of us */ - gchar *id; + gchar *id = NULL; if (!strncmp(fragment, "xpointer(", 9)) { /* FIXME !!! this is wasteful */ /* FIXME: It looks as though this is including "))" in the id. I suggest moving @@ -113,9 +115,7 @@ void URIReference::attach(const URI &uri) throw(BadURIException) /* FIXME !!! validate id as an NCName somewhere */ - if (_uri) { - delete _uri; - } + delete _uri; _uri = new URI(uri); _connection.disconnect(); -- cgit v1.2.3 From 7c4b51c7574844efd991df787e9be4c96fb031b3 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 3 Mar 2014 22:21:55 +0100 Subject: change 0 to NULL for pointers (bzr r13102) --- src/uri-references.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 8edafb0b0..1da890c56 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -172,7 +172,7 @@ void URIReference::_release(SPObject *obj) SPObject* sp_css_uri_reference_resolve( SPDocument *document, const gchar *uri ) { - SPObject* ref = 0; + SPObject* ref = NULL; if ( document && uri && ( strncmp(uri, "url(", 4) == 0 ) ) { gchar *trimmed = extract_uri( uri ); @@ -188,7 +188,7 @@ SPObject* sp_css_uri_reference_resolve( SPDocument *document, const gchar *uri ) SPObject * sp_uri_reference_resolve (SPDocument *document, const gchar *uri) { - SPObject* ref = 0; + SPObject* ref = NULL; if ( uri && (*uri == '#') ) { ref = document->getObjectById( uri + 1 ); -- cgit v1.2.3 From da0a34bdba9070b53f02e09b74d70b822899f554 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 13 Mar 2014 00:35:43 +0100 Subject: Disconnect before destroying URI (bzr r13140) --- src/uri-references.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/uri-references.cpp') diff --git a/src/uri-references.cpp b/src/uri-references.cpp index 1da890c56..6db2ed21f 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -115,10 +115,10 @@ void URIReference::attach(const URI &uri) throw(BadURIException) /* FIXME !!! validate id as an NCName somewhere */ + _connection.disconnect(); delete _uri; _uri = new URI(uri); - _connection.disconnect(); _setObject(document->getObjectById(id)); _connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject)); -- cgit v1.2.3