diff --git a/fbreader/fbreader/fbreader/src/bookmodel/BookReader.cpp b/fbreader/fbreader/fbreader/src/bookmodel/BookReader.cpp index 6679258..590ba74 100644 --- a/fbreader/fbreader/fbreader/src/bookmodel/BookReader.cpp +++ b/fbreader/fbreader/fbreader/src/bookmodel/BookReader.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004-2010 Geometer Plus - * Copyright (C) 2016 Slava Monich + * Copyright (C) 2016-2019 Slava Monich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,8 @@ BookReader::BookReader(BookModel &model) : myModel(model) { myTextParagraphExists = false; myContentsParagraphExists = false; + myBookTextParagraphExists = false; + myBookContentsParagraphExists = false; myInsideTitle = false; mySectionContainsRegularContents = false; @@ -41,10 +43,20 @@ BookReader::~BookReader() { } void BookReader::setMainTextModel() { - myCurrentTextModel = myModel.myBookTextModel; + if (myCurrentTextModel != myModel.myBookTextModel) { + myCurrentTextModel = myModel.myBookTextModel; + myTextParagraphExists = myBookTextParagraphExists; + myContentsParagraphExists = myBookContentsParagraphExists; + } } void BookReader::setFootnoteTextModel(const std::string &id) { + if (myCurrentTextModel == myModel.myBookTextModel) { + myBookTextParagraphExists = myTextParagraphExists; + myBookContentsParagraphExists = myContentsParagraphExists; + } + myTextParagraphExists = false; + myContentsParagraphExists = false; std::map >::iterator it = myModel.myFootnotes.find(id); if (it != myModel.myFootnotes.end()) { myCurrentTextModel = (*it).second; @@ -54,6 +66,14 @@ void BookReader::setFootnoteTextModel(const std::string &id) { } } +void BookReader::setFootnoteTextModel(const std::string &id, const std::string &alt) +{ + setFootnoteTextModel(id); + if (!alt.empty() && myModel.myFootnotes.find(alt) == myModel.myFootnotes.end()) { + myModel.myFootnotes.insert(std::make_pair(alt, myCurrentTextModel)); + } +} + void BookReader::unsetTextModel() { myCurrentTextModel = 0; } diff --git a/fbreader/fbreader/fbreader/src/bookmodel/BookReader.h b/fbreader/fbreader/fbreader/src/bookmodel/BookReader.h index dce9403..a03a76c 100644 --- a/fbreader/fbreader/fbreader/src/bookmodel/BookReader.h +++ b/fbreader/fbreader/fbreader/src/bookmodel/BookReader.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2004-2010 Geometer Plus + * Copyright (C) 2016-2019 Slava Monich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,6 +41,7 @@ public: void setMainTextModel(); void setFootnoteTextModel(const std::string &id); + void setFootnoteTextModel(const std::string &id, const std::string &alt); void unsetTextModel(); void insertEndOfSectionParagraph(); @@ -91,6 +93,8 @@ private: bool myTextParagraphExists; bool myContentsParagraphExists; + bool myBookTextParagraphExists; + bool myBookContentsParagraphExists; std::stack myTOCStack; bool myLastTOCParagraphIsEmpty; diff --git a/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.cpp b/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.cpp index 9606ec0..254ee25 100644 --- a/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004-2010 Geometer Plus - * Copyright (C) 2016-2018 Slava Monich + * Copyright (C) 2016-2019 Slava Monich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -394,7 +394,7 @@ XHTMLTagFootnoteAction::XHTMLTagFootnoteAction() { void XHTMLTagFootnoteAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) { const char *id = reader.attributeValue(xmlattributes, "id"); if (id) { - bookReader(reader).setFootnoteTextModel(id); + bookReader(reader).setFootnoteTextModel(id, reader.myReferenceName + "#" + id); } } diff --git a/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.h b/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.h index e3522d6..33bb936 100644 --- a/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.h +++ b/fbreader/fbreader/fbreader/src/formats/xhtml/XHTMLReader.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2004-2010 Geometer Plus - * Copyright (C) 2016-2018 Slava Monich + * Copyright (C) 2016-2019 Slava Monich * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,9 +41,9 @@ class XHTMLTagAction { public: virtual ~XHTMLTagAction(); - - virtual void doAtStart(XHTMLReader &reader, const char **xmlattributes); - virtual void doAtEnd(XHTMLReader &reader); + + virtual void doAtStart(XHTMLReader &reader, const char **xmlattributes); + virtual void doAtEnd(XHTMLReader &reader); protected: static BookReader &bookReader(XHTMLReader &reader); @@ -87,28 +87,28 @@ private: bool processNamespaces() const; - void haveContent(); - void beginParagraph(); + void haveContent(); + void beginParagraph(); void endParagraph(); - void applyStyles(ParseContext &context); - void addStyleParagraph(const ZLTextStyleEntry &style); - void addBottomMargin(short size, ZLTextStyleEntry::SizeUnit unit); - bool elementHasTopMargin(const ParseContext &context) const; - bool elementHasBottomMargin(const ParseContext &context) const; - void applyBottomMargins(); - void addPageBreak(); + void applyStyles(ParseContext &context); + void addStyleParagraph(const ZLTextStyleEntry &style); + void addBottomMargin(short size, ZLTextStyleEntry::SizeUnit unit); + bool elementHasTopMargin(const ParseContext &context) const; + bool elementHasBottomMargin(const ParseContext &context) const; + void applyBottomMargins(); + void addPageBreak(); private: BookReader &myModelReader; std::string myPathPrefix; std::string myReferenceName; std::string myReferenceDirName; - int myPreformatted; + int myPreformatted; StyleSheetTable myStyleSheetTable; - StyleSheetTable::ElementList myElementStack; - StyleSheetTable::StyleList myStyleStack; - std::vector myParseStack; - std::vector myBottomMargins; + StyleSheetTable::ElementList myElementStack; + StyleSheetTable::StyleList myStyleStack; + std::vector myParseStack; + std::vector myBottomMargins; StyleSheetSingleStyleParser myStyleParser; shared_ptr myTableParser; enum { @@ -118,14 +118,15 @@ private: } myReadState; friend class XHTMLTagAction; - friend class XHTMLTagStyleAction; - friend class XHTMLTagLinkAction; - friend class XHTMLTagHyperlinkAction; - friend class XHTMLTagPreAction; - friend class XHTMLTagControlAction; - friend class XHTMLTagParagraphWithControlAction; - friend class XHTMLTagBodyAction; - friend class XHTMLTagImageAction; + friend class XHTMLTagStyleAction; + friend class XHTMLTagLinkAction; + friend class XHTMLTagHyperlinkAction; + friend class XHTMLTagPreAction; + friend class XHTMLTagControlAction; + friend class XHTMLTagParagraphWithControlAction; + friend class XHTMLTagBodyAction; + friend class XHTMLTagImageAction; + friend class XHTMLTagFootnoteAction; }; #endif /* __XHTMLREADER_H__ */