From 24d649c9d17a115ddcd699044b74a66b9db19b4c Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Fri, 11 May 2012 19:45:05 +0100 Subject: [PATCH] XHTMLReader reused --- TODO.1.5 | 1 + .../fbreader/src/formats/css/StyleSheetTable.cpp | 6 ++++++ .../fbreader/src/formats/css/StyleSheetTable.h | 2 ++ .../fbreader/src/formats/oeb/OEBBookReader.cpp | 2 +- .../fbreader/src/formats/xhtml/XHTMLReader.cpp | 8 +++++++- .../fbreader/src/formats/xhtml/XHTMLReader.h | 2 +- 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/TODO.1.5 b/TODO.1.5 index b61d8e7dc..52644d516 100644 --- a/TODO.1.5 +++ b/TODO.1.5 @@ -5,6 +5,7 @@ Larger icon on the site litres: top/hot lists (what's happen?) litres: author photos +* Hyperlinks in the SJ book * Network library initialization in ProcessHyperlinkAction :( * "Use embedded fonts" option * "Scan hidden directories" option diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp index 4e095a9a4..8255c844c 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.cpp @@ -248,3 +248,9 @@ shared_ptr StyleSheetTable::createControl(const AttributeMap & return entry; } + +void StyleSheetTable::clear() { + myControlMap.clear(); + myPageBreakBeforeMap.clear(); + myPageBreakAfterMap.clear(); +} diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h index 6d88c482c..54236fb22 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetTable.h @@ -47,6 +47,8 @@ public: bool doBreakAfter(const std::string &tag, const std::string &aClass) const; shared_ptr control(const std::string &tag, const std::string &aClass) const; + void clear(); + private: struct Key { Key(const std::string &tag, const std::string &aClass); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp index 34ace4ba2..daa61a420 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp @@ -153,6 +153,7 @@ bool OEBBookReader::readBook(const ZLFile &file) { myModelReader.setMainTextModel(); myModelReader.pushKind(REGULAR); + XHTMLReader xhtmlReader(myModelReader); bool firstFile = true; for (std::vector::const_iterator it = myHtmlFileNames.begin(); it != myHtmlFileNames.end(); ++it) { const ZLFile xhtmlFile(myFilePrefix + *it); @@ -162,7 +163,6 @@ bool OEBBookReader::readBook(const ZLFile &file) { if (!firstFile) { myModelReader.insertEndOfSectionParagraph(); } - XHTMLReader xhtmlReader(myModelReader); xhtmlReader.readFile(xhtmlFile, *it); firstFile = false; } diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp index 4e1847ae6..908c68746 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -500,11 +500,17 @@ bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName) myPreformatted = false; myNewParagraphInProgress = false; myReadState = READ_NOTHING; + myCurrentParagraphIsEmpty = true; + myStyleSheetTable.clear(); myCSSStack.clear(); myStyleEntryStack.clear(); myStylesToRemove = 0; + myDoPageBreakAfterStack.clear(); + myStyleParser = new StyleSheetSingleStyleParser(); + myTableParser.reset(); + return readDocument(file); } @@ -547,7 +553,7 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes) const char *style = attributeValue(attributes, "style"); if (style != 0) { ZLLogger::Instance().println("CSS", std::string("parsing style attribute: ") + style); - shared_ptr entry = myStyleParser.parseString(style); + shared_ptr entry = myStyleParser->parseString(style); myModelReader.addStyleEntry(*entry); myStyleEntryStack.push_back(entry); } else { diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h index 44f017af6..717d8356e 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h @@ -88,7 +88,7 @@ private: int myStylesToRemove; std::vector myDoPageBreakAfterStack; bool myCurrentParagraphIsEmpty; - StyleSheetSingleStyleParser myStyleParser; + shared_ptr myStyleParser; shared_ptr myTableParser; enum { READ_NOTHING,