mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
ContentsTree instead of ZLTextTreeModel
This commit is contained in:
parent
b783fa99b9
commit
9b22b0743a
13 changed files with 79 additions and 260 deletions
|
@ -211,33 +211,19 @@ static jobject createTextModel(JNIEnv *env, jobject javaModel, ZLTextModel &mode
|
|||
return env->PopLocalFrame(textModel);
|
||||
}
|
||||
|
||||
static bool initTOC(JNIEnv *env, jobject javaModel, BookModel &model) {
|
||||
ContentsModel &contentsModel = (ContentsModel&)*model.contentsModel();
|
||||
static void initTOC(JNIEnv *env, jobject javaModel, const ContentsTree &tree) {
|
||||
const std::vector<shared_ptr<ContentsTree> > &children = tree.children();
|
||||
for (std::vector<shared_ptr<ContentsTree> >::const_iterator it = children.begin(); it != children.end(); ++it) {
|
||||
const ContentsTree &child = **it;
|
||||
jstring text = AndroidUtil::createJavaString(env, child.text());
|
||||
const int ref = child.reference();
|
||||
AndroidUtil::Method_NativeBookModel_addTOCItem->call(javaModel, text, ref);
|
||||
env->DeleteLocalRef(text);
|
||||
|
||||
jobject javaTextModel = createTextModel(env, javaModel, contentsModel);
|
||||
if (javaTextModel == 0) {
|
||||
return false;
|
||||
initTOC(env, javaModel, child);
|
||||
|
||||
AndroidUtil::Method_NativeBookModel_leaveTOCItem->call(javaModel);
|
||||
}
|
||||
|
||||
std::vector<jint> childrenNumbers;
|
||||
std::vector<jint> referenceNumbers;
|
||||
const size_t size = contentsModel.paragraphsNumber();
|
||||
childrenNumbers.reserve(size);
|
||||
referenceNumbers.reserve(size);
|
||||
for (size_t pos = 0; pos < size; ++pos) {
|
||||
ZLTextTreeParagraph *par = (ZLTextTreeParagraph*)contentsModel[pos];
|
||||
childrenNumbers.push_back(par->children().size());
|
||||
referenceNumbers.push_back(contentsModel.reference(par));
|
||||
}
|
||||
jintArray javaChildrenNumbers = AndroidUtil::createJavaIntArray(env, childrenNumbers);
|
||||
jintArray javaReferenceNumbers = AndroidUtil::createJavaIntArray(env, referenceNumbers);
|
||||
|
||||
AndroidUtil::Method_NativeBookModel_initTOC->call(javaModel, javaTextModel, javaChildrenNumbers, javaReferenceNumbers);
|
||||
|
||||
env->DeleteLocalRef(javaTextModel);
|
||||
env->DeleteLocalRef(javaChildrenNumbers);
|
||||
env->DeleteLocalRef(javaReferenceNumbers);
|
||||
return !env->ExceptionCheck();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
@ -259,10 +245,12 @@ JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPl
|
|||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (!initInternalHyperlinks(env, javaModel, *model) || !initTOC(env, javaModel, *model)) {
|
||||
if (!initInternalHyperlinks(env, javaModel, *model)) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
initTOC(env, javaModel, *model->contentsTree());
|
||||
|
||||
shared_ptr<ZLTextModel> textModel = model->bookTextModel();
|
||||
jobject javaTextModel = createTextModel(env, javaModel, *textModel);
|
||||
if (javaTextModel == 0) {
|
||||
|
|
|
@ -34,7 +34,7 @@ BookModel::BookModel(const shared_ptr<Book> book, jobject javaModel) : myBook(bo
|
|||
|
||||
const std::string cacheDirectory = Library::Instance().cacheDirectory();
|
||||
myBookTextModel = new ZLTextPlainModel(std::string(), book->language(), 131072, cacheDirectory, "ncache");
|
||||
myContentsModel = new ContentsModel(book->language(), cacheDirectory, "ncontents");
|
||||
myContentsTree = new ContentsTree();
|
||||
/*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false);
|
||||
if (!plugin.isNull()) {
|
||||
plugin->readModel(*this);
|
||||
|
@ -58,20 +58,6 @@ BookModel::Label BookModel::label(const std::string &id) const {
|
|||
return (it != myInternalHyperlinks.end()) ? it->second : Label(0, -1);
|
||||
}
|
||||
|
||||
ContentsModel::ContentsModel(const std::string &language,
|
||||
const std::string &directoryName, const std::string &fileExtension) :
|
||||
ZLTextTreeModel(std::string(), language, directoryName, fileExtension) {
|
||||
}
|
||||
|
||||
void ContentsModel::setReference(const ZLTextTreeParagraph *paragraph, int reference) {
|
||||
myReferenceByParagraph[paragraph] = reference;
|
||||
}
|
||||
|
||||
int ContentsModel::reference(const ZLTextTreeParagraph *paragraph) const {
|
||||
std::map<const ZLTextTreeParagraph*,int>::const_iterator it = myReferenceByParagraph.find(paragraph);
|
||||
return (it != myReferenceByParagraph.end()) ? it->second : -1;
|
||||
}
|
||||
|
||||
const shared_ptr<Book> BookModel::book() const {
|
||||
return myBook;
|
||||
}
|
||||
|
@ -81,7 +67,6 @@ bool BookModel::flush() {
|
|||
if (myBookTextModel->allocator().failed()) {
|
||||
return false;
|
||||
}
|
||||
myContentsModel->flush();
|
||||
|
||||
std::map<std::string,shared_ptr<ZLTextModel> >::const_iterator it = myFootnotes.begin();
|
||||
for (; it != myFootnotes.end(); ++it) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <jni.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <ZLTextModel.h>
|
||||
|
@ -31,15 +32,21 @@
|
|||
class ZLImage;
|
||||
class Book;
|
||||
|
||||
class ContentsModel : public ZLTextTreeModel {
|
||||
class ContentsTree {
|
||||
|
||||
public:
|
||||
ContentsModel(const std::string &language, const std::string &directoryName, const std::string &fileExtension);
|
||||
void setReference(const ZLTextTreeParagraph *paragraph, int reference);
|
||||
int reference(const ZLTextTreeParagraph *paragraph) const;
|
||||
ContentsTree();
|
||||
ContentsTree(ContentsTree &parent, int reference);
|
||||
void addText(const std::string &buffer);
|
||||
|
||||
const std::string &text() const;
|
||||
int reference() const;
|
||||
const std::vector<shared_ptr<ContentsTree> > &children() const;
|
||||
|
||||
private:
|
||||
std::map<const ZLTextTreeParagraph*,int> myReferenceByParagraph;
|
||||
std::string myText;
|
||||
const int myReference;
|
||||
std::vector<shared_ptr<ContentsTree> > myChildren;
|
||||
};
|
||||
|
||||
class BookModel {
|
||||
|
@ -66,7 +73,7 @@ public:
|
|||
void setHyperlinkMatcher(shared_ptr<HyperlinkMatcher> matcher);
|
||||
|
||||
shared_ptr<ZLTextModel> bookTextModel() const;
|
||||
shared_ptr<ZLTextModel> contentsModel() const;
|
||||
shared_ptr<ContentsTree> contentsTree() const;
|
||||
const std::map<std::string,shared_ptr<ZLTextModel> > &footnotes() const;
|
||||
|
||||
Label label(const std::string &id) const;
|
||||
|
@ -80,7 +87,7 @@ private:
|
|||
const shared_ptr<Book> myBook;
|
||||
jobject myJavaModel;
|
||||
shared_ptr<ZLTextModel> myBookTextModel;
|
||||
shared_ptr<ZLTextModel> myContentsModel;
|
||||
shared_ptr<ContentsTree> myContentsTree;
|
||||
std::map<std::string,shared_ptr<ZLTextModel> > myFootnotes;
|
||||
std::map<std::string,Label> myInternalHyperlinks;
|
||||
shared_ptr<HyperlinkMatcher> myHyperlinkMatcher;
|
||||
|
@ -89,8 +96,20 @@ friend class BookReader;
|
|||
};
|
||||
|
||||
inline shared_ptr<ZLTextModel> BookModel::bookTextModel() const { return myBookTextModel; }
|
||||
inline shared_ptr<ZLTextModel> BookModel::contentsModel() const { return myContentsModel; }
|
||||
inline shared_ptr<ContentsTree> BookModel::contentsTree() const { return myContentsTree; }
|
||||
inline const std::map<std::string,shared_ptr<ZLTextModel> > &BookModel::footnotes() const { return myFootnotes; }
|
||||
inline const std::map<std::string,BookModel::Label> &BookModel::internalHyperlinks() const { return myInternalHyperlinks; }
|
||||
|
||||
inline ContentsTree::ContentsTree() : myReference(-1) {}
|
||||
inline ContentsTree::ContentsTree(ContentsTree &parent, int reference) : myReference(reference) {
|
||||
parent.myChildren.push_back(this);
|
||||
}
|
||||
inline void ContentsTree::addText(const std::string &buffer) {
|
||||
myText += buffer;
|
||||
}
|
||||
|
||||
inline const std::string &ContentsTree::text() const { return myText; }
|
||||
inline int ContentsTree::reference() const { return myReference; }
|
||||
inline const std::vector<shared_ptr<ContentsTree> > &ContentsTree::children() const { return myChildren; }
|
||||
|
||||
#endif /* __BOOKMODEL_H__ */
|
||||
|
|
|
@ -34,10 +34,8 @@
|
|||
|
||||
BookReader::BookReader(BookModel &model) : myModel(model) {
|
||||
myCurrentTextModel = 0;
|
||||
myLastTOCParagraphIsEmpty = false;
|
||||
|
||||
myTextParagraphExists = false;
|
||||
myContentsParagraphExists = false;
|
||||
|
||||
myInsideTitle = false;
|
||||
mySectionContainsRegularContents = false;
|
||||
|
@ -195,8 +193,8 @@ void BookReader::addData(const std::string &data) {
|
|||
}
|
||||
|
||||
void BookReader::addContentsData(const std::string &data) {
|
||||
if (!data.empty() && !myTOCStack.empty()) {
|
||||
myContentsBuffer.push_back(data);
|
||||
if (!data.empty() && !myContentsTreeStack.empty()) {
|
||||
myContentsTreeStack.top()->addText(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,45 +254,33 @@ void BookReader::addImageReference(const std::string &id, short vOffset, bool is
|
|||
|
||||
void BookReader::beginContentsParagraph(int referenceNumber) {
|
||||
if (myCurrentTextModel == myModel.myBookTextModel) {
|
||||
ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel;
|
||||
if (referenceNumber == -1) {
|
||||
referenceNumber = myCurrentTextModel->paragraphsNumber();
|
||||
}
|
||||
ZLTextTreeParagraph *peek = myTOCStack.empty() ? 0 : myTOCStack.top();
|
||||
if (!myContentsBuffer.empty()) {
|
||||
contentsModel.addText(myContentsBuffer);
|
||||
myContentsBuffer.clear();
|
||||
myLastTOCParagraphIsEmpty = false;
|
||||
shared_ptr<ContentsTree> parent =
|
||||
myContentsTreeStack.empty() ? myModel.contentsTree() : myContentsTreeStack.top();
|
||||
if (parent->text().empty()) {
|
||||
parent->addText("...");
|
||||
}
|
||||
if (myLastTOCParagraphIsEmpty) {
|
||||
contentsModel.addText("...");
|
||||
}
|
||||
ZLTextTreeParagraph *para = contentsModel.createParagraph(peek);
|
||||
contentsModel.addControl(CONTENTS_TABLE_ENTRY, true);
|
||||
contentsModel.setReference(para, referenceNumber);
|
||||
myTOCStack.push(para);
|
||||
myLastTOCParagraphIsEmpty = true;
|
||||
new ContentsTree(*parent, referenceNumber);
|
||||
const std::vector<shared_ptr<ContentsTree> > &children = parent->children();
|
||||
myContentsTreeStack.push(children[children.size() - 1]);
|
||||
myContentsParagraphExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BookReader::endContentsParagraph() {
|
||||
if (!myTOCStack.empty()) {
|
||||
ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel;
|
||||
if (!myContentsBuffer.empty()) {
|
||||
contentsModel.addText(myContentsBuffer);
|
||||
myContentsBuffer.clear();
|
||||
myLastTOCParagraphIsEmpty = false;
|
||||
if (!myContentsTreeStack.empty()) {
|
||||
shared_ptr<ContentsTree> tree = myContentsTreeStack.top();
|
||||
if (tree->text().empty()) {
|
||||
tree->addText("...");
|
||||
}
|
||||
if (myLastTOCParagraphIsEmpty) {
|
||||
contentsModel.addText("...");
|
||||
myLastTOCParagraphIsEmpty = false;
|
||||
}
|
||||
myTOCStack.pop();
|
||||
myContentsTreeStack.pop();
|
||||
}
|
||||
myContentsParagraphExists = false;
|
||||
}
|
||||
|
||||
/*
|
||||
void BookReader::setReference(size_t contentsParagraphNumber, int referenceNumber) {
|
||||
ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel;
|
||||
if (contentsParagraphNumber >= contentsModel.paragraphsNumber()) {
|
||||
|
@ -302,6 +288,7 @@ void BookReader::setReference(size_t contentsParagraphNumber, int referenceNumbe
|
|||
}
|
||||
contentsModel.setReference((const ZLTextTreeParagraph*)contentsModel[contentsParagraphNumber], referenceNumber);
|
||||
}
|
||||
*/
|
||||
|
||||
void BookReader::reset() {
|
||||
myKindStack.clear();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "FBTextKind.h"
|
||||
|
||||
class BookModel;
|
||||
class ContentsTree;
|
||||
class ZLTextModel;
|
||||
class ZLInputStream;
|
||||
class ZLCachedMemoryAllocator;
|
||||
|
@ -69,7 +70,7 @@ public:
|
|||
void beginContentsParagraph(int referenceNumber = -1);
|
||||
void endContentsParagraph();
|
||||
bool contentsParagraphIsOpen() const;
|
||||
void setReference(size_t contentsParagraphNumber, int referenceNumber);
|
||||
//void setReference(size_t contentsParagraphNumber, int referenceNumber);
|
||||
|
||||
void addData(const std::string &data);
|
||||
void addContentsData(const std::string &data);
|
||||
|
@ -93,14 +94,12 @@ private:
|
|||
|
||||
bool myTextParagraphExists;
|
||||
bool myContentsParagraphExists;
|
||||
std::stack<ZLTextTreeParagraph*> myTOCStack;
|
||||
bool myLastTOCParagraphIsEmpty;
|
||||
std::stack<shared_ptr<ContentsTree> > myContentsTreeStack;
|
||||
|
||||
bool mySectionContainsRegularContents;
|
||||
bool myInsideTitle;
|
||||
|
||||
std::vector<std::string> myBuffer;
|
||||
std::vector<std::string> myContentsBuffer;
|
||||
|
||||
std::string myHyperlinkReference;
|
||||
FBHyperlinkType myHyperlinkType;
|
||||
|
|
|
@ -110,7 +110,8 @@ shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Tag_getTag;
|
|||
|
||||
shared_ptr<ObjectField> AndroidUtil::Field_NativeBookModel_Book;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initInternalHyperlinks;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_initTOC;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_addTOCItem;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_leaveTOCItem;
|
||||
shared_ptr<ObjectMethod> AndroidUtil::Method_NativeBookModel_createTextModel;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setBookTextModel;
|
||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_setFootnoteModel;
|
||||
|
@ -185,7 +186,8 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
|
||||
Field_NativeBookModel_Book = new ObjectField(Class_NativeBookModel, "Book", Class_Book);
|
||||
Method_NativeBookModel_initInternalHyperlinks = new VoidMethod(Class_NativeBookModel, "initInternalHyperlinks", "(Ljava/lang/String;Ljava/lang/String;I)");
|
||||
Method_NativeBookModel_initTOC = new VoidMethod(Class_NativeBookModel, "initTOC", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;[I[I)");
|
||||
Method_NativeBookModel_addTOCItem = new VoidMethod(Class_NativeBookModel, "addTOCItem", "(Ljava/lang/String;I)");
|
||||
Method_NativeBookModel_leaveTOCItem = new VoidMethod(Class_NativeBookModel, "leaveTOCItem", "()");
|
||||
Method_NativeBookModel_createTextModel = new ObjectMethod(Class_NativeBookModel, "createTextModel", Class_ZLTextModel, "(Ljava/lang/String;Ljava/lang/String;I[I[I[I[I[BLjava/lang/String;Ljava/lang/String;I)");
|
||||
Method_NativeBookModel_setBookTextModel = new VoidMethod(Class_NativeBookModel, "setBookTextModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)");
|
||||
Method_NativeBookModel_setFootnoteModel = new VoidMethod(Class_NativeBookModel, "setFootnoteModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)");
|
||||
|
|
|
@ -132,7 +132,8 @@ public:
|
|||
|
||||
static shared_ptr<ObjectField> Field_NativeBookModel_Book;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_initInternalHyperlinks;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_initTOC;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_addTOCItem;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_leaveTOCItem;
|
||||
static shared_ptr<ObjectMethod> Method_NativeBookModel_createTextModel;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_setBookTextModel;
|
||||
static shared_ptr<VoidMethod> Method_NativeBookModel_setFootnoteModel;
|
||||
|
|
|
@ -133,42 +133,6 @@ void ZLTextModel::addParagraphInternal(ZLTextParagraph *paragraph) {
|
|||
myLastEntryStart = 0;
|
||||
}
|
||||
|
||||
ZLTextTreeModel::ZLTextTreeModel(const std::string &id, const std::string &language,
|
||||
const std::string &directoryName, const std::string &fileExtension) :
|
||||
ZLTextModel(id, language, 8192, directoryName, fileExtension) {
|
||||
myRoot = new ZLTextTreeParagraph();
|
||||
myRoot->open(true);
|
||||
}
|
||||
|
||||
ZLTextTreeModel::~ZLTextTreeModel() {
|
||||
delete myRoot;
|
||||
}
|
||||
|
||||
ZLTextTreeParagraph *ZLTextTreeModel::createParagraph(ZLTextTreeParagraph *parent) {
|
||||
if (parent == 0) {
|
||||
parent = myRoot;
|
||||
}
|
||||
ZLTextTreeParagraph *tp = new ZLTextTreeParagraph(parent);
|
||||
addParagraphInternal(tp);
|
||||
return tp;
|
||||
}
|
||||
|
||||
/*
|
||||
void ZLTextTreeModel::search(const std::string &text, size_t startIndex, size_t endIndex, bool ignoreCase) const {
|
||||
ZLTextModel::search(text, startIndex, endIndex, ignoreCase);
|
||||
for (std::vector<ZLTextMark>::const_iterator it = marks().begin(); it != marks().end(); ++it) {
|
||||
((ZLTextTreeParagraph*)(*this)[it->ParagraphIndex])->openTree();
|
||||
}
|
||||
}
|
||||
|
||||
void ZLTextTreeModel::selectParagraph(size_t index) const {
|
||||
if (index < paragraphsNumber()) {
|
||||
ZLTextModel::selectParagraph(index);
|
||||
((ZLTextTreeParagraph*)(*this)[index])->openTree();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, const size_t rowSize,
|
||||
const std::string &directoryName, const std::string &fileExtension) :
|
||||
ZLTextModel(id, language, rowSize, directoryName, fileExtension) {
|
||||
|
|
|
@ -36,12 +36,6 @@ class ZLTextStyleEntry;
|
|||
|
||||
class ZLTextModel {
|
||||
|
||||
public:
|
||||
enum Kind {
|
||||
PLAIN_TEXT_MODEL,
|
||||
TREE_MODEL,
|
||||
};
|
||||
|
||||
protected:
|
||||
ZLTextModel(const std::string &id, const std::string &language, const size_t rowSize,
|
||||
const std::string &directoryName, const std::string &fileExtension);
|
||||
|
@ -50,7 +44,6 @@ protected:
|
|||
|
||||
public:
|
||||
virtual ~ZLTextModel();
|
||||
virtual Kind kind() const = 0;
|
||||
|
||||
const std::string &id() const;
|
||||
const std::string &language() const;
|
||||
|
@ -121,27 +114,9 @@ public:
|
|||
const std::string &directoryName, const std::string &fileExtension);
|
||||
ZLTextPlainModel(const std::string &id, const std::string &language,
|
||||
shared_ptr<ZLCachedMemoryAllocator> allocator);
|
||||
Kind kind() const;
|
||||
void createParagraph(ZLTextParagraph::Kind kind);
|
||||
};
|
||||
|
||||
class ZLTextTreeModel : public ZLTextModel {
|
||||
|
||||
public:
|
||||
ZLTextTreeModel(const std::string &id, const std::string &language,
|
||||
const std::string &directoryName, const std::string &fileExtension);
|
||||
~ZLTextTreeModel();
|
||||
Kind kind() const;
|
||||
|
||||
ZLTextTreeParagraph *createParagraph(ZLTextTreeParagraph *parent = 0);
|
||||
|
||||
void search(const std::string &text, size_t startIndex, size_t endIndex, bool ignoreCase) const;
|
||||
void selectParagraph(size_t index) const;
|
||||
|
||||
private:
|
||||
ZLTextTreeParagraph *myRoot;
|
||||
};
|
||||
|
||||
inline const std::string &ZLTextModel::id() const { return myId; }
|
||||
inline const std::string &ZLTextModel::language() const { return myLanguage; }
|
||||
inline size_t ZLTextModel::paragraphsNumber() const { return myParagraphs.size(); }
|
||||
|
@ -162,8 +137,4 @@ inline const ZLTextParagraph *ZLTextModel::operator [] (size_t index) const {
|
|||
return myParagraphs[std::min(myParagraphs.size() - 1, index)];
|
||||
}
|
||||
|
||||
inline ZLTextModel::Kind ZLTextPlainModel::kind() const { return PLAIN_TEXT_MODEL; }
|
||||
|
||||
inline ZLTextModel::Kind ZLTextTreeModel::kind() const { return TREE_MODEL; }
|
||||
|
||||
#endif /* __ZLTEXTMODEL_H__ */
|
||||
|
|
|
@ -239,32 +239,3 @@ size_t ZLTextParagraph::characterNumber() const {
|
|||
return len;
|
||||
}
|
||||
*/
|
||||
|
||||
ZLTextTreeParagraph::ZLTextTreeParagraph(ZLTextTreeParagraph *parent) : myIsOpen(false), myParent(parent) {
|
||||
if (parent != 0) {
|
||||
parent->addChild(this);
|
||||
myDepth = parent->myDepth + 1;
|
||||
} else {
|
||||
myDepth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ZLTextTreeParagraph::openTree() {
|
||||
for (ZLTextTreeParagraph *p = parent(); p != 0; p = p->parent()) {
|
||||
p->open(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ZLTextTreeParagraph::removeFromParent() {
|
||||
if (myParent != 0) {
|
||||
myParent->myChildren.erase(std::find(myParent->myChildren.begin(), myParent->myChildren.end(), this));
|
||||
}
|
||||
}
|
||||
|
||||
int ZLTextTreeParagraph::fullSize() const {
|
||||
int size = 1;
|
||||
for (std::vector<ZLTextTreeParagraph*>::const_iterator it = myChildren.begin(); it != myChildren.end(); ++it) {
|
||||
size += (*it)->fullSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -222,34 +222,6 @@ private:
|
|||
friend class ZLTextPlainModel;
|
||||
};
|
||||
|
||||
class ZLTextTreeParagraph : public ZLTextParagraph {
|
||||
|
||||
public:
|
||||
ZLTextTreeParagraph(ZLTextTreeParagraph *parent = 0);
|
||||
~ZLTextTreeParagraph();
|
||||
Kind kind() const;
|
||||
|
||||
bool isOpen() const;
|
||||
void open(bool o);
|
||||
void openTree();
|
||||
int depth() const;
|
||||
ZLTextTreeParagraph *parent();
|
||||
const ZLTextTreeParagraph *parent() const;
|
||||
const std::vector<ZLTextTreeParagraph*> &children() const;
|
||||
int fullSize() const;
|
||||
|
||||
void removeFromParent();
|
||||
|
||||
private:
|
||||
void addChild(ZLTextTreeParagraph *child);
|
||||
|
||||
private:
|
||||
bool myIsOpen;
|
||||
int myDepth;
|
||||
ZLTextTreeParagraph *myParent;
|
||||
std::vector<ZLTextTreeParagraph*> myChildren;
|
||||
};
|
||||
|
||||
inline ZLTextParagraphEntry::ZLTextParagraphEntry() {}
|
||||
inline ZLTextParagraphEntry::~ZLTextParagraphEntry() {}
|
||||
|
||||
|
@ -295,14 +267,4 @@ inline ZLTextSpecialParagraph::ZLTextSpecialParagraph(Kind kind) : myKind(kind)
|
|||
inline ZLTextSpecialParagraph::~ZLTextSpecialParagraph() {}
|
||||
inline ZLTextParagraph::Kind ZLTextSpecialParagraph::kind() const { return myKind; }
|
||||
|
||||
inline ZLTextTreeParagraph::~ZLTextTreeParagraph() {}
|
||||
inline ZLTextParagraph::Kind ZLTextTreeParagraph::kind() const { return TREE_PARAGRAPH; }
|
||||
inline bool ZLTextTreeParagraph::isOpen() const { return myIsOpen; }
|
||||
inline void ZLTextTreeParagraph::open(bool o) { myIsOpen = o; }
|
||||
inline int ZLTextTreeParagraph::depth() const { return myDepth; }
|
||||
inline ZLTextTreeParagraph *ZLTextTreeParagraph::parent() { return myParent; }
|
||||
inline const ZLTextTreeParagraph *ZLTextTreeParagraph::parent() const { return myParent; }
|
||||
inline const std::vector<ZLTextTreeParagraph*> &ZLTextTreeParagraph::children() const { return myChildren; }
|
||||
inline void ZLTextTreeParagraph::addChild(ZLTextTreeParagraph *child) { myChildren.push_back(child); }
|
||||
|
||||
#endif /* __ZLTEXTPARAGRAPH_H__ */
|
||||
|
|
|
@ -90,7 +90,8 @@
|
|||
-keepclassmembers class org.geometerplus.fbreader.bookmodel.NativeBookModel {
|
||||
public ** Book;
|
||||
public void initInternalHyperlinks(**,**,int);
|
||||
public void initTOC(**,int[],int[]);
|
||||
public void addTOCItem(**,int);
|
||||
public void leaveTOCItem();
|
||||
public ** createTextModel(**,**,int,int[],int[],int[],int[],byte[],**,**,int);
|
||||
public void setBookTextModel(**);
|
||||
public void setFootnoteModel(**);
|
||||
|
|
|
@ -36,49 +36,18 @@ public class NativeBookModel extends BookModelImpl {
|
|||
myInternalHyperlinks = new CachedCharStorageRO(directoryName, fileExtension, blocksNumber);
|
||||
}
|
||||
|
||||
public void initTOC(ZLTextModel contentsModel, int[] childrenNumbers, int[] referenceNumbers) {
|
||||
try {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
private TOCTree myCurrentTree = TOCTree;
|
||||
|
||||
final ArrayList<Integer> positions = new ArrayList<Integer>();
|
||||
TOCTree tree = TOCTree;
|
||||
|
||||
final int size = contentsModel.getParagraphsNumber();
|
||||
for (int pos = 0; pos < size; ++pos) {
|
||||
positions.add(pos);
|
||||
ZLTextParagraph par = contentsModel.getParagraph(pos);
|
||||
|
||||
buffer.delete(0, buffer.length());
|
||||
ZLTextParagraph.EntryIterator it = par.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.getType() == ZLTextParagraph.Entry.TEXT) {
|
||||
buffer.append(it.getTextData(), it.getTextOffset(), it.getTextLength());
|
||||
}
|
||||
public void addTOCItem(String text, int reference) {
|
||||
myCurrentTree = new TOCTree(myCurrentTree);
|
||||
myCurrentTree.setText(text);
|
||||
myCurrentTree.setReference(myBookTextModel, reference);
|
||||
}
|
||||
|
||||
tree = new TOCTree(tree);
|
||||
tree.setText(buffer.toString());
|
||||
tree.setReference(myBookTextModel, referenceNumbers[pos]);
|
||||
|
||||
while (positions.size() > 0 && tree != TOCTree) {
|
||||
final int lastIndex = positions.size() - 1;
|
||||
final int treePos = positions.get(lastIndex);
|
||||
if (tree.subTrees().size() < childrenNumbers[treePos]) {
|
||||
break;
|
||||
}
|
||||
tree = tree.Parent;
|
||||
positions.remove(lastIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (tree != TOCTree || positions.size() > 0) {
|
||||
throw new RuntimeException("Invalid state after TOC building:\n"
|
||||
+ "tree.Level = " + tree.Level + "\n"
|
||||
+ "positions.size() = " + positions.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
public void leaveTOCItem() {
|
||||
myCurrentTree = myCurrentTree.Parent;
|
||||
if (myCurrentTree == null) {
|
||||
myCurrentTree = TOCTree;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue