Skip to content

Commit

Permalink
Merge pull request #213 from blchinezu/dev
Browse files Browse the repository at this point in the history
Up version: 0.0.6-17-59
  • Loading branch information
blchinezu committed Oct 30, 2016
2 parents 6365bc4 + 2512528 commit 1229cbb
Show file tree
Hide file tree
Showing 28 changed files with 191 additions and 24 deletions.
Binary file modified builds/360/360/latest.zip
Binary file not shown.
Binary file modified builds/515/pro4/latest.zip
Binary file not shown.
Binary file modified builds/515/pro5/latest.zip
Binary file not shown.
Binary file modified builds/602/pro2/latest.zip
Binary file not shown.
Binary file modified builds/626/pro4/latest.zip
Binary file not shown.
Binary file modified builds/626/pro5/latest.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion builds/current.version
@@ -1 +1 @@
0.0.6-17-58
0.0.6-17-59
60 changes: 59 additions & 1 deletion cr3gui/src/cr3pocketbook.cpp
Expand Up @@ -2650,8 +2650,10 @@ class CRPocketBookDocView : public V3DocViewWin {
_docview->getFlatToc(tocItems);
_tocLength = tocItems.length();

int tocSize;

if (_tocLength) {
int tocSize = (_tocLength + 1) * sizeof(tocentry);
tocSize = (_tocLength + 1) * sizeof(tocentry);
_toc = (tocentry *) malloc(tocSize);
int j = 0;
for (int i = 0; i < tocItems.length(); i++) {
Expand All @@ -2674,6 +2676,62 @@ class CRPocketBookDocView : public V3DocViewWin {
_toc = NULL;
}
}

// If there are no TOC entries try setting the section bounds as TOC
if( _tocLength < 2 ) {
if( _toc != NULL ) {
freeContents();
}
LVArray<int> dummy;
LVArray<int> & sbounds = dummy;
sbounds = main_win->getDocView()->getSectionBoundsPages();

if( sbounds.length() > 1 ) {

_tocLength = sbounds.length()+2;
tocSize = _tocLength * sizeof(tocentry);
_toc = (tocentry *) malloc(tocSize);

int prevPage = 0;
int index = 0;
int page = 1;

// Start
_toc[index].level = 1;
_toc[index].position = page;
_toc[index].page = page;
_toc[index].text = strdup(UnicodeToUtf8(L"Start").c_str());
prevPage = page;

// Content
for( int sbound_index = 0; sbound_index < sbounds.length(); sbound_index++ ) {

page = sbounds[sbound_index]+1;
if( page == prevPage ) {
continue;
}

index++;
_toc[index].level = 1;
_toc[index].position = page;
_toc[index].page = page;
_toc[index].text = strdup(UnicodeToUtf8(L"Section " + lString16::itoa(index)).c_str());
prevPage = page;
}

// End
index++;
page = main_win->getDocView()->getPageCount();
_toc[index].level = 1;
_toc[index].position = page;
_toc[index].page = page;
_toc[index].text = strdup(UnicodeToUtf8(L"End").c_str());

// Set real TOC real length
_tocLength = index+1;
}
}

if ( _tocLength < 2 ) {
Message(ICON_INFORMATION, const_cast<char*>("CoolReader"),
const_cast<char*>("@No_contents"), 2000);
Expand Down
4 changes: 2 additions & 2 deletions cr3gui/src/cr3pocketbook.h
Expand Up @@ -78,8 +78,8 @@ enum CRPbCommands {

#define PB_CR3_CACHE_SIZE (0x100000 * 64)

#define CR_PB_VERSION "0.0.6-17-58"
#define CR_PB_BUILD_DATE "2016-10-11"
#define CR_PB_VERSION "0.0.6-17-59"
#define CR_PB_BUILD_DATE "2016-10-30"

#define PB_ROTATE_MODE_360 0
#define PB_ROTATE_MODE_180 1
Expand Down
5 changes: 5 additions & 0 deletions crengine/include/lvdocview.h
Expand Up @@ -335,6 +335,9 @@ class LVDocView : public CacheLoadingCallback
LVArray<int> m_section_bounds;
bool m_section_bounds_valid;

LVArray<int> m_section_bounds_page;
bool m_section_bounds_page_valid;

LVMutex _mutex;
#if CR_ENABLE_PAGE_IMAGE_CACHE==1
LVDocViewImageCache m_imageCache;
Expand Down Expand Up @@ -385,6 +388,7 @@ class LVDocView : public CacheLoadingCallback
void updateDocStyleSheet();
//serg
void addBounds( ldomNode * lsection, int fh, lUInt16 section_id );
void addBoundsPage( ldomNode * lsection, int fh, lUInt16 section_id );

protected:

Expand Down Expand Up @@ -649,6 +653,7 @@ class LVDocView : public CacheLoadingCallback
bool isDocumentOpened();
/// returns section bounds, in 1/100 of percent
LVArray<int> & getSectionBounds( );
LVArray<int> & getSectionBoundsPages( );
/// sets battery state
virtual bool setBatteryState( int newState );
/// returns battery state
Expand Down
144 changes: 124 additions & 20 deletions crengine/src/lvdocview.cpp
Expand Up @@ -542,7 +542,8 @@ void LVDocView::Clear() {
_posIsSet = false;
m_cursorPos.clear();
m_filename.clear();
m_section_bounds_valid = false;
m_section_bounds_valid = false;
m_section_bounds_page_valid = false;
}
clearImageCache();
_navigationHistory.clear();
Expand All @@ -554,6 +555,7 @@ void LVDocView::clearImageCache() {
m_imageCache.clear();
#endif
m_section_bounds_valid = false;
m_section_bounds_page_valid = false;
if (m_callback != NULL)
m_callback->OnImageCacheClear();
}
Expand Down Expand Up @@ -1481,6 +1483,56 @@ LVArray<int> & LVDocView::getSectionBounds() {
return m_section_bounds;
}

void LVDocView::addBoundsPage( ldomNode * lsection, int fh, lUInt16 section_id )
{
int cnt = lsection->getChildCount();

for ( int i= 0; i < cnt; i++ ) {
ldomNode * l1section = lsection->getChildElementNode( i, section_id );
if ( !l1section )
continue;
lvRect rc;
l1section->getAbsRect(rc);
int p;
if ( getViewMode() == DVM_SCROLL )
p = (int) ( (lInt64) rc.top );
else
p = (int) ( (lInt64) m_pages.FindNearestPage(rc.top, 0) );
m_section_bounds_page.add(p);
addBoundsPage( l1section, fh, section_id );
}
}

/// returns section bounds, in pages
LVArray<int> & LVDocView::getSectionBoundsPages() {
if (m_section_bounds_page_valid)
return m_section_bounds_page;
m_section_bounds_page.clear();
m_section_bounds_page.add(0);
// Get sections from FB2 books
ldomNode * body = m_doc->nodeFromXPath(cs16("/FictionBook/body[1]"));
lUInt16 section_id = m_doc->getElementNameIndex(L"section");
if (body == NULL) {
// Get sections from EPUB books
body = m_doc->nodeFromXPath(cs16("/body[1]"));
section_id = m_doc->getElementNameIndex(L"DocFragment");
}
int fh = GetFullHeight();
if (body && fh > 0) {
if ( getViewMode() == DVM_PAGES ) {
fh = m_pages.length();
int pc = getVisiblePageCount();
if ( ( pc==2 && (fh&1) ) )
fh++;
if ( fh > 1 )
addBoundsPage( body, fh, section_id );
} else
addBoundsPage( body, fh, section_id );
}
m_section_bounds_page_valid = true;
return m_section_bounds_page;
}

int LVDocView::getPosEndPagePercent() {
LVLock lock(getMutex());
checkPos();
Expand Down Expand Up @@ -4259,8 +4311,10 @@ void LVDocView::createEmptyDocument() {
m_markRanges.clear();
m_bmkRanges.clear();
_posBookmark.clear();
m_section_bounds.clear();
m_section_bounds_valid = false;
m_section_bounds.clear();
m_section_bounds_valid = false;
m_section_bounds_page.clear();
m_section_bounds_page_valid = false;
_posIsSet = false;
m_swapDone = false;

Expand Down Expand Up @@ -4989,29 +5043,79 @@ lString16 LVDocView::getCurrentChapterName(int currentPage) {
lString16 chapterName = lString16("");
/// returns pointer to TOC root node
LVPtrVector < LVTocItem, false > items;
if (!getFlatToc(items))
return chapterName;

// show book authors - name if there are less than 3 chapters
// current page
int cp = (currentPage==-2?getCurPage():currentPage)+1;
if( items.length() < 3 ) {
return getPageHeaderTitle(cp);
int page;

// try getting real TOC chapter
if( getFlatToc(items) && items.length() >= 3 ) {
page = -1;
int vcp = getVisiblePageCount();
if (vcp < 1 || vcp > 2)
vcp = 1;
for (int i = 0; i < items.length(); i++) {
LVTocItem * item = items[i];
int p = item->getPage();
if (p < cp && (page == -1 || page < p)) {
page = p;
chapterName = item->getName();
}
}
return chapterName;
}

// get current chapter name
int page = -1;
int vcp = getVisiblePageCount();
if (vcp < 1 || vcp > 2)
vcp = 1;
for (int i = 0; i < items.length(); i++) {
LVTocItem * item = items[i];
int p = item->getPage();
if (p < cp && (page == -1 || page < p)) {
page = p;
chapterName = item->getName();
// show book authors - name if there are less than 3 chapters
chapterName = getPageHeaderTitle(cp);

// try getting sections
LVArray<int> dummy;
LVArray<int> & sbounds = dummy;
sbounds = getSectionBoundsPages();
if( sbounds.length() > 1 ) {

int prevPage = 0;
int index = 0;
page = 1;

lString16 plus = L"";

// Start
if( cp >= 1 ) {
plus = L" - Start";
}
}
prevPage = page;

// Content
for( int sbound_index = 0; sbound_index < sbounds.length(); sbound_index++ ) {

page = sbounds[sbound_index]+1;
if( page == prevPage ) {
continue;
}

index++;
if( cp >= page ) {
plus = L" - Section " + lString16::itoa(index);
}
else {
break;
}
prevPage = page;
}

// End
if( cp == getPageCount() ) {
plus = L" - End";
}

// Return if got value
if( !plus.empty() ) {
return chapterName + plus;
}
}

// return authors + title
return chapterName;
}

Expand Down
Binary file modified data/common/system/share/cr3/i18n/bg.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/ca.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/cs.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/de.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/es.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/fr.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/he.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/hu.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/it.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/lt.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/nl.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/pl.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/ro.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/ru.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/tr.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/uk.mo
Binary file not shown.
Binary file modified data/common/system/share/cr3/i18n/zh.mo
Binary file not shown.

0 comments on commit 1229cbb

Please sign in to comment.