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