From b783fa99b9d1ff291db5f138c21f7aa5265fb14c Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Sun, 13 May 2012 05:31:24 +0100 Subject: [PATCH] reference shortening in ePubs; updated TODO --- TODO.1.5 | 5 ++-- .../src/formats/xhtml/XHTMLReader.cpp | 24 ++++++++++++------- .../fbreader/src/formats/xhtml/XHTMLReader.h | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/TODO.1.5 b/TODO.1.5 index aacfaece2..768f65fa3 100644 --- a/TODO.1.5 +++ b/TODO.1.5 @@ -8,13 +8,14 @@ litres: author photos *
tag * the SJ book: ** empty pages at start (in emulator) - ** hyperlinks (including button image) + DONE hyperlinks (including button image) + ** TOC!!! * Network library initialization in ProcessHyperlinkAction :( * "Use embedded fonts" option * "Scan hidden directories" option * ePub: DONE reference resolver (Имя розы) - ** reference shortening in native code (like java code shortening) + DONE reference shortening in native code (like java code shortening) DONE large covers (cover mark for images in native code) * "modes" for wallpapers: tile, fullscreen, etc. * zip: re-use open files diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp index 7d5d99bba..1da5d3140 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -346,10 +346,16 @@ void XHTMLTagHyperlinkAction::doAtStart(XHTMLReader &reader, const char **xmlatt const FBTextKind hyperlinkType = MiscUtil::referenceType(href); std::string link = MiscUtil::decodeHtmlURL(href); if (hyperlinkType == INTERNAL_HYPERLINK) { - link = (link[0] == '#') ? - reader.myReferenceName + link : - reader.myReferenceDirName + link; - link = ZLFileUtil::normalizeUnixPath(link); + if (link[0] == '#') { + link = reader.myReferenceAlias + link; + } else { + const size_t index = link.find('#'); + if (index == std::string::npos) { + link = reader.fileAlias(reader.myReferenceDirName + link); + } else { + link = reader.fileAlias(reader.myReferenceDirName + link.substr(0, index)) + link.substr(index); + } + } } myHyperlinkStack.push(hyperlinkType); bookReader(reader).addHyperlinkControl(hyperlinkType, link); @@ -359,7 +365,7 @@ void XHTMLTagHyperlinkAction::doAtStart(XHTMLReader &reader, const char **xmlatt const char *name = reader.attributeValue(xmlattributes, "name"); if (name != 0) { bookReader(reader).addHyperlinkLabel( - reader.myReferenceName + "#" + MiscUtil::decodeHtmlURL(name) + reader.myReferenceAlias + "#" + MiscUtil::decodeHtmlURL(name) ); } } @@ -488,12 +494,12 @@ XHTMLReader::XHTMLReader(BookReader &modelReader) : myModelReader(modelReader) { } bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName) { - myModelReader.addHyperlinkLabel(referenceName); - fillTagTable(); myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path()); - myReferenceName = referenceName; + myReferenceAlias = fileAlias(referenceName); + myModelReader.addHyperlinkLabel(myReferenceAlias); + const int index = referenceName.rfind('/', referenceName.length() - 1); myReferenceDirName = referenceName.substr(0, index + 1); @@ -528,7 +534,7 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes) static const std::string HASH = "#"; const char *id = attributeValue(attributes, "id"); if (id != 0) { - myModelReader.addHyperlinkLabel(myReferenceName + HASH + id); + myModelReader.addHyperlinkLabel(myReferenceAlias + HASH + id); } const std::string sTag = ZLUnicodeUtil::toLower(tag); diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h index 6a7814059..1c66e869d 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h @@ -82,7 +82,7 @@ private: BookReader &myModelReader; std::string myPathPrefix; - std::string myReferenceName; + std::string myReferenceAlias; std::string myReferenceDirName; bool myPreformatted; bool myNewParagraphInProgress;