diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2018-12-09 14:56:40 +0000 |
|---|---|---|
| committer | Thomas Holder <thomas@thomas-holder.de> | 2018-12-09 20:50:04 +0000 |
| commit | 34d2e296a45845f9241cedeafff7b23e06d8f5cf (patch) | |
| tree | dea6c03ac9504dfbeebbd3671c5dd632671efcca /src | |
| parent | Fix license in new files (diff) | |
| download | inkscape-34d2e296a45845f9241cedeafff7b23e06d8f5cf.tar.gz inkscape-34d2e296a45845f9241cedeafff7b23e06d8f5cf.zip | |
remove Inkscape::URI::getFullPath
Diffstat (limited to 'src')
| -rw-r--r-- | src/object/color-profile.cpp | 25 | ||||
| -rw-r--r-- | src/object/uri-references.cpp | 12 | ||||
| -rw-r--r-- | src/object/uri.cpp | 46 | ||||
| -rw-r--r-- | src/object/uri.h | 9 |
4 files changed, 28 insertions, 64 deletions
diff --git a/src/object/color-profile.cpp b/src/object/color-profile.cpp index 8e4e8978b..9cfac23cf 100644 --- a/src/object/color-profile.cpp +++ b/src/object/color-profile.cpp @@ -352,33 +352,26 @@ void ColorProfile::set(SPAttributeEnum key, gchar const *value) { //# 1. Get complete URI of document gchar const *docbase = doc->getURI(); - gchar* escaped = g_uri_escape_string(this->href, "!*'();@=+$,/?#", TRUE); - - //g_message("docbase:%s\n", docbase); - //org::w3c::dom::URI docUri(docbase); Inkscape::URI docUri(""); if (docbase) { // The file has already been saved docUri = Inkscape::URI::from_native_filename(docbase); } - //# 2. Get href of icc file. we don't care if it's rel or abs - //org::w3c::dom::URI hrefUri(escaped); - Inkscape::URI hrefUri(escaped); - //# 3. Resolve the href according the docBase. This follows - // the w3c specs. All absolute and relative issues are considered - std::string fullpath = hrefUri.getFullPath(docUri.getFullPath("")); - - gchar* fullname = g_uri_unescape_string(fullpath.c_str(), ""); this->impl->_clearProfile(); - this->impl->_profHandle = cmsOpenProfileFromFile( fullname, "r" ); + + try { + auto hrefUri = Inkscape::URI(this->href, docUri); + auto contents = hrefUri.getContents(); + this->impl->_profHandle = cmsOpenProfileFromMem(contents.data(), contents.size()); + } catch (...) { + g_warning("Failed to open CMS profile URI '%.100s'", this->href); + } + if ( this->impl->_profHandle ) { this->impl->_profileSpace = cmsGetColorSpace( this->impl->_profHandle ); this->impl->_profileClass = cmsGetDeviceClass( this->impl->_profHandle ); } DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)this->impl->_profHandle ); - g_free(escaped); - escaped = nullptr; - g_free(fullname); #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) } } diff --git a/src/object/uri-references.cpp b/src/object/uri-references.cpp index 21b90c950..3e11cd26c 100644 --- a/src/object/uri-references.cpp +++ b/src/object/uri-references.cpp @@ -130,8 +130,16 @@ void URIReference::attach(const URI &uri) // The path contains references to separate document files to load. if (document && uri.getPath() && !skip) { - std::string base = document->getBase() ? document->getBase() : ""; - std::string path = uri.getFullPath(base); + char const *base = document->getBase(); + auto absuri = URI::from_href_and_basedir(uri.str().c_str(), base); + std::string path; + + try { + path = absuri.toNativeFilename(); + } catch (const Glib::Error &e) { + g_warning("%s", e.what().c_str()); + } + if (!path.empty()) { document = document->createChildDoc(path); } else { diff --git a/src/object/uri.cpp b/src/object/uri.cpp index 5f9a38c5f..f6d044a6e 100644 --- a/src/object/uri.cpp +++ b/src/object/uri.cpp @@ -216,48 +216,16 @@ const gchar *URI::Impl::getOpaque() const { return nullptr; } -/* - * Returns the absolute path to an existing file referenced in this URI, - * if the uri is data, the path is empty or the file doesn't exist, then - * an empty string is returned. - * - * Does not check if the returned path is the local document's path (local) - * and thus redundent. Caller is expected to check against the document's path. - * - * @param base directory name to use as base if this is not an absolute URL - */ -const std::string URI::getFullPath(std::string const &base) const { - if (!_impl->getPath()) { - return ""; - } - - URI url; - - if (!base.empty() && !getScheme()) { - url = Inkscape::URI::from_href_and_basedir(str().c_str(), base.c_str()); - } else { - url = *this; - } - - if (!url.hasScheme("file")) { - return ""; - } - - auto path = Glib::filename_from_uri(url.str()); +std::string URI::toNativeFilename() const +{ // + auto uristr = str(); - // Check the existence of the file - if(! g_file_test(path.c_str(), G_FILE_TEST_EXISTS) - || g_file_test(path.c_str(), G_FILE_TEST_IS_DIR) ) { - path.clear(); + // remove fragment identifier + if (getFragment() != nullptr) { + uristr.resize(uristr.find('#')); } - return path; -} - -/* TODO !!! proper error handling */ -std::string URI::toNativeFilename() const -{ // - return Glib::filename_from_uri(str()); + return Glib::filename_from_uri(uristr); } URI URI::fromUtf8( gchar const* path ) { diff --git a/src/object/uri.h b/src/object/uri.h index f8a28726b..04c4fabe6 100644 --- a/src/object/uri.h +++ b/src/object/uri.h @@ -157,15 +157,10 @@ public: static URI from_href_and_basedir(char const *href, char const *basedir); /** - * @deprecated Use ::toNativeFilename() instead - * - * @todo remove - */ - const std::string getFullPath(std::string const &base) const; - - /** * Convert this URI to a native filename. * + * Discards the fragment identifier. + * * @throw Glib::ConvertError If this is not a "file" URI */ std::string toNativeFilename() const; |
