From df692bfe85b73328412b34ba08ee88fd06c6cbf5 Mon Sep 17 00:00:00 2001 From: Alexander Egorov Date: Tue, 11 Mar 2008 00:39:08 +0100 Subject: [PATCH] TOC --- fbreader/src/bookmodel/BookReader.cpp | 26 ++ .../ui/src/nanox/application-desktop/Viewer.cpp | 288 ++++++++++++++++++--- 2 files changed, 275 insertions(+), 39 deletions(-) diff --git a/fbreader/src/bookmodel/BookReader.cpp b/fbreader/src/bookmodel/BookReader.cpp index 6dd6f35..0313581 100644 --- a/fbreader/src/bookmodel/BookReader.cpp +++ b/fbreader/src/bookmodel/BookReader.cpp @@ -22,6 +22,16 @@ #include "BookReader.h" #include "BookModel.h" +struct xxx_toc_entry { + int paragraph; + std::string text; +}; + +extern std::vector xxx_myTOC; +int xxx_paragraph; +std::string xxx_paragraph_data; + + BookReader::BookReader(BookModel &model) : myModel(model) { myCurrentTextModel = 0; myLastTOCParagraphIsEmpty = false; @@ -146,12 +156,16 @@ void BookReader::addData(const std::string &data) { mySectionContainsRegularContents = true; } myBuffer.push_back(data); + + } } void BookReader::addContentsData(const std::string &data) { if (!data.empty() && !myTOCStack.empty()) { myContentsBuffer.push_back(data); + + xxx_paragraph_data += " " + data; } } @@ -209,7 +223,9 @@ void BookReader::beginContentsParagraph(int referenceNumber) { contentsModel.addText(myContentsBuffer); myContentsBuffer.clear(); myLastTOCParagraphIsEmpty = false; + } + if (myLastTOCParagraphIsEmpty) { contentsModel.addText("..."); } @@ -219,6 +235,16 @@ void BookReader::beginContentsParagraph(int referenceNumber) { myTOCStack.push(para); myLastTOCParagraphIsEmpty = true; myContentsParagraphExists = true; + + if(xxx_paragraph >= 0 && !xxx_paragraph_data.empty()) { + struct xxx_toc_entry x; + x.paragraph = xxx_paragraph; + x.text = xxx_paragraph_data; + xxx_myTOC.push_back(x); + } + + xxx_paragraph = referenceNumber; + xxx_paragraph_data = ""; } } diff --git a/zlibrary/ui/src/nanox/application-desktop/Viewer.cpp b/zlibrary/ui/src/nanox/application-desktop/Viewer.cpp index 9a58b9b..b52a6da 100644 --- a/zlibrary/ui/src/nanox/application-desktop/Viewer.cpp +++ b/zlibrary/ui/src/nanox/application-desktop/Viewer.cpp @@ -31,11 +31,25 @@ #include "Viewer.h" #include +#include + #include +#define _DEBUG 1 + int glb_page; bool init; +//std::map xxx_myTOC; + +struct xxx_toc_entry { + int paragraph; + std::string text; +}; + +std::vector xxx_myTOC; + +bool toc_jump; #define ALLOW_RUN_EXE 1 @@ -45,8 +59,6 @@ unsigned char *buf; int InitDoc(char *fileName) { - printf("InitDoc\n"); - init = true; #ifdef ALLOW_RUN_EXE @@ -81,9 +93,9 @@ int InitDoc(char *fileName) file = fileName; - printf("plugin init\n"); glb_page = 0; + toc_jump = false; buf = (unsigned char *)malloc(800*600/4); @@ -95,43 +107,77 @@ int InitDoc(char *fileName) ZLibrary::run(new FBReader(file)); - printf("plugin init end\n"); return 1; } void GetPageData(void **data) { + printf("getpagedata\n"); *data = (void *)buf; } -void vSetDisplayState(Apollo_State *state) {printf("1\n");} +void vSetDisplayState(Apollo_State *state) { +#ifdef _DEBUG + printf("1\n"); +#endif +} extern "C"{ void vSetCurPage(int p) { printf("vSetCurPage: %d\n", p); if(init) return; - if(p == 0) - mainApplication->doAction(ActionCode::SCROLL_TO_START_OF_TEXT); - else if((p + 1) == ((FBReader *)mainApplication)->bookTextView().pageNumber()) - mainApplication->doAction(ActionCode::SCROLL_TO_END_OF_TEXT); + if(toc_jump) { + printf("toc_jump\n"); + ((FBReader *)mainApplication)->bookTextView().gotoParagraph(p); + mainApplication->refreshWindow(); + + toc_jump = false; + return; + } + + if(p <= 0) { +// ((FBReader *)mainApplication)->bookTextView().gotoPage(p + 1); +// mainApplication->refreshWindow(); +// + //mainApplication->doAction(ActionCode::SCROLL_TO_START_OF_TEXT); + ((FBReader *)mainApplication)->bookTextView().scrollToStartOfText(); +// ((FBReader *)mainApplication)->bookTextView().gotoParagraph(0); +// mainApplication->refreshWindow(); + } else if((p + 1) == ((FBReader *)mainApplication)->bookTextView().pageNumber()) + //mainApplication->doAction(ActionCode::SCROLL_TO_END_OF_TEXT); + ((FBReader *)mainApplication)->bookTextView().scrollToEndOfText(); else { ((FBReader *)mainApplication)->bookTextView().gotoPage(p + 1); mainApplication->refreshWindow(); } } -int bGetRotate() {printf("GetRotate\n"); return 0;} -void vSetRotate(int rot) { printf("vSetRotate: %d\n", rot); } +int bGetRotate() { +#ifdef _DEBUG + printf("GetRotate\n"); +#endif + + return 0; +} + +void vSetRotate(int rot) { +#ifdef _DEBUG + printf("vSetRotate: %d\n", rot); +#endif +} void vGetTotalPage(int *iTotalPage) { *iTotalPage = ((FBReader *)mainApplication)->bookTextView().pageNumber(); } int GetPageIndex() { + printf("getpageindex >%d\n", glb_page-1); return glb_page - 1; } -int Origin() {printf("6\n");} +int Origin() { + //printf("6\n"); +} void vFontBigger() { ZLIntegerRangeOption &option = ZLTextStyleCollection::instance().baseStyle().FontSizeOption; @@ -148,10 +194,15 @@ void vFontBigger() { ((FBReader *)mainApplication)->clearTextCaches(); mainApplication->refreshWindow(); } -int Bigger() {printf("8\n");} -int Smaller() {printf("9\n");} -int Rotate() {printf("10\n");} -int Fit() {printf("11\n");} +int Bigger() { + //printf("8\n"); +} +int Smaller() {//printf("9\n"); +} +int Rotate() {//printf("10\n"); +} +int Fit() {//printf("11\n"); +} int Prev() { mainApplication->doAction(ActionCode::LARGE_SCROLL_BACKWARD); @@ -165,13 +216,35 @@ int Next() int IsStandardStatusBarVisible() { return 0; } int GotoPage(int index) { +#ifdef _DEBUG printf("GotoPage: %d\n", index); +#endif + if(index < 0 || index > ((FBReader *)mainApplication)->bookTextView().pageNumber()) + return 0; + + return 1; +} +void Release() { +#ifdef _DEBUG + printf("13\n"); +#endif } -void Release() {printf("13\n");} void GetPageDimension(int *width, int *height) { *width = 600; *height = 800; } -void SetPageDimension(int width, int height) {printf("setpagedimension: %dx%d\n", width, height);} -double dGetResizePro() {printf("15\n");} -void vSetResizePro(double dSetPro) {printf("16\n");} +void SetPageDimension(int width, int height) { +#ifdef _DEBUG + printf("setpagedimension: %dx%d\n", width, height); +#endif +} +double dGetResizePro() { +#ifdef _DEBUG + printf("15\n"); +#endif +} +void vSetResizePro(double dSetPro) { +#ifdef _DEBUG + printf("16\n"); +#endif +} int GetPageNum() { return ((FBReader *)mainApplication)->bookTextView().pageNumber(); } @@ -185,11 +258,23 @@ void bGetUserData(void **vUserData, int *iUserDataLength) { // WTF? vEndDoc(); } -void vSetUserData(void *vUserData, int iUserDataLength){printf("18\n");} +void vSetUserData(void *vUserData, int iUserDataLength){ +#ifdef _DEBUG + printf("18\n"); +#endif +} int iGetDocPageWidth(){ return 600;} int iGetDocPageHeight(){ return 800;} -unsigned short usGetLeftBarFlag(){printf("21\n");} -void vEndInit(int iEndStyle) { printf("vEndInit: %d\n", iEndStyle); } +unsigned short usGetLeftBarFlag(){ +#ifdef _DEBUG + printf("21\n"); +#endif +} +void vEndInit(int iEndStyle) { +#ifdef _DEBUG + printf("vEndInit: %d\n", iEndStyle); +#endif +} void vEndDoc() { free(buf); @@ -197,21 +282,146 @@ void vEndDoc() delete mainApplication; ZLibrary::shutdown(); } -int iInitDocF(char *filename,int pageNo, int flag) { init = false; printf("iInitDocF: %c %d %d\n", filename, pageNo, flag); return 0;} -void vFirstBmp(char *fileName, int pageNo){printf("25\n");} -int iGetCurDirPage(int idx, int level){printf("26\n");} +int iInitDocF(char *filename,int pageNo, int flag) { + init = false; +#ifdef _DEBUG + printf("iInitDocF: %c %d %d\n", filename, pageNo, flag); +#endif + return 0; +} +void vFirstBmp(char *fileName, int pageNo){ +#ifdef _DEBUG + printf("25\n"); +#endif +} +int iGetCurDirPage(int idx, int level){ +// printf("26\n"); + + int index = level * 8 + idx; + + toc_jump = true; + return xxx_myTOC[index].paragraph; + +} int iCreateDirList() { - mainApplication->doAction(ActionCode::SHOW_CONTENTS); - - return 0;} -int iGetDirNumber(){printf("27\n");} -unsigned short* usGetCurDirNameAndLen(int pos, int * len){printf("28\n");} -unsigned short* usGetCurDirName(int level, int index){printf("29\n");} -int iGetCurDirLen(int level, int index){printf("30\n");} -void vClearAllDirList(){printf("31\n");} -int OpenLeaf( int pos ){printf("32\n");} -int bCurItemIsLeaf(int pos){printf("33\n");} -void vEnterChildDir(int pos){printf("34\n");} -void vReturnParentDir(){printf("35\n");} -void vFreeDir(){printf("36\n");} + if(xxx_myTOC.empty()) + return 0; + else + return 1; +} +int iGetDirNumber(){ + return xxx_myTOC.size(); +} +unsigned short* usGetCurDirNameAndLen(int pos, int * len){ + unsigned short codepoint; + unsigned char in_code; + int expect; + + int index = pos & 7; + static unsigned short str[8][64] = {0}; + + const char *p = xxx_myTOC[pos].text.c_str(); + int plen = xxx_myTOC[pos].text.size(); + + int j=0; + + while (j < 60 && *p && plen) + { + in_code = *p++ ; + + if ( in_code >= 0xC0 ) + { + if ( in_code < 0xE0 ) /* U+0080 - U+07FF */ + { + expect = 1; + codepoint = in_code & 0x1F; + } + else if ( in_code < 0xF0 ) /* U+0800 - U+FFFF */ + { + expect = 2; + codepoint = in_code & 0x0F; + } + else if ( in_code < 0xF8 ) /* U+10000 - U+10FFFF */ + { + expect = 3; + codepoint = in_code & 0x07; + } + continue; + } + else if ( in_code >= 0x80 ) + { + --expect; + + if ( expect >= 0 ) + { + codepoint <<= 6; + codepoint += in_code & 0x3F; + } + if ( expect > 0 ) + continue; + + expect = 0; + } + else /* ASCII, U+0000 - U+007F */ + codepoint = in_code; + + plen--; + str[index][j++] = codepoint; + } + str[index][j] = 0; + + *len = j; + return str[index]; +} +unsigned short* usGetCurDirName(int level, int index){ +#ifdef _DEBUG + printf("29\n"); +#endif +} +int iGetCurDirLen(int level, int index){ +#ifdef _DEBUG + printf("30\n"); +#endif + return 11; +} +void vClearAllDirList(){ +#ifdef _DEBUG + printf("31\n"); +#endif +} +int OpenLeaf( int pos ){ +// ((FBReader *)mainApplication)->bookTextView().gotoParagraph(xxx_myTOC[pos-1].paragraph); +// mainApplication->refreshWindow(); + + return 1; +} + +int bCurItemIsLeaf(int pos){ +#ifdef _DEBUG + printf("33\n"); +#endif + return 1; +} +void vEnterChildDir(int pos){ +#ifdef _DEBUG + printf("34\n"); +#endif +} +void vReturnParentDir(){ +#ifdef _DEBUG + printf("35\n"); +#endif +} +void vFreeDir(){ +#ifdef _DEBUG + printf("36\n"); +#endif +} + + +/*int OnKeyPressed(int keyId, int state) +{ +} +*/ + }; //extern "C" -- 2.11.4.GIT