From 268309d7aa43dad9796db082b2db5b36053ab05a Mon Sep 17 00:00:00 2001 From: Donkey <15072483565@163.com> Date: Tue, 28 Jul 2020 14:21:35 +0800 Subject: [PATCH] epub file's css style support --- .../fbreader/src/formats/xhtml/XHTMLReader.cpp | 1 + jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp | 5 +---- jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp | 8 ++++++++ jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp index 3aa01f12b..4b97e027b 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -294,6 +294,7 @@ void XHTMLTagLinkAction::doAtStart(XHTMLReader &reader, const char **xmlattribut std::string cssFilePath = reader.myPathPrefix + MiscUtil::decodeHtmlURL(href); //ZLLogger::Instance().registerClass("CSS"); ZLLogger::Instance().println("CSS", "style file: " + cssFilePath); + cssFilePath = ZLStringUtil::replace(cssFilePath, ":", "/"); const ZLFile cssFile(cssFilePath); cssFilePath = cssFile.path(); shared_ptr parser = reader.myFileParsers[cssFilePath]; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp index 6dcb6cd55..04dc32411 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp @@ -37,10 +37,7 @@ ZLFile::ZLFile() : myMimeTypeIsUpToDate(true), myInfoIsFilled(true) { } ZLFile::ZLFile(const std::string &path, const std::string &mimeType) : myPath(path), myMimeType(mimeType), myMimeTypeIsUpToDate(!mimeType.empty()), myInfoIsFilled(false) { - std::string::size_type position = myPath.find(":./"); - if (position != myPath.npos){ - myPath.replace(position, 3, ":"); - } + myPath = ZLStringUtil::replace(myPath, ":./", ":"); ZLFSManager::Instance().normalize(myPath); { std::size_t index = ZLFSManager::Instance().findLastFileNameDelimiter(myPath); diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp index a76177b0c..b0a2c489e 100644 --- a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp @@ -80,6 +80,14 @@ void ZLStringUtil::append(std::string &str, const std::vector &text } } +std::string ZLStringUtil::replace(std::string &str, const std::string &strSrc, const std::string &strDst){ + std::string::size_type position= str.find(strSrc); + if (position != std::string::npos){ + str.replace(position,strSrc.length(),strDst); + } + return str; +} + void ZLStringUtil::stripWhiteSpaces(std::string &str) { std::size_t counter = 0; std::size_t length = str.length(); diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h index fdc22f06b..366a90d6d 100644 --- a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.h @@ -48,6 +48,8 @@ public: static unsigned long parseHex(const std::string &str, int defaultValue); static void asciiToLowerInline(std::string &asciiString); + + static std::string replace(std::string &str, const std::string &strSrc, const std::string &strDst); }; #endif /* __ZLSTRINGUTIL_H__ */