Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of page turn command and picking of the last commits of the koreader. #156

Merged
merged 7 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_definitions(-DCR3_ANTIWORD_PATCH=1 -DENABLE_ANTIWORD=1)
add_definitions(-DMAX_IMAGE_SCALE_MUL=2)
add_definitions(-DUSE_NANOSVG=1)
add_definitions(-DBUNDLED_FRIBIDI=1)
add_definitions(-DKO_LIBUNIBREAK_PATCH=1) # patch "add_lb_get_char_class.patch" for libunibreak from koreader

#set(LOCAL_CFLAGS "-Wno-psabi -Wno-unused-variable -Wno-sign-compare -Wno-write-strings -Wno-main -Wno-unused-but-set-variable -Wno-unused-function -Wall")
# Option '-Wl,--no-merge-exidx-entries' removed as incompatible with clang.
Expand Down
3 changes: 2 additions & 1 deletion android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CRFLAGS := -DLINUX=1 -D_LINUX=1 -DFOR_ANDROID=1 -DCR3_PATCH \
-DCR3_ANTIWORD_PATCH=1 -DENABLE_ANTIWORD=1 \
-DMAX_IMAGE_SCALE_MUL=2 \
-DUSE_NANOSVG=1 \
-DBUNDLED_FRIBIDI=1
-DBUNDLED_FRIBIDI=1 \
-DKO_LIBUNIBREAK_PATCH=1

CR3_ROOT := $(LOCAL_PATH)/../..

Expand Down
4 changes: 2 additions & 2 deletions android/jni/docview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ JNIEXPORT jobject JNICALL Java_org_coolreader_crengine_DocView_getPositionPropsI
} else {
useCurPos = p->_docview->getViewMode()==DVM_SCROLL;
if ( !useCurPos ) {
bm = p->_docview->getBookmark();
bm = p->_docview->getBookmark(false);
if ( bm.isNull() ) {
CRLog::error("getPositionPropsInternal: Cannot get current position bookmark");
}
Expand All @@ -1725,7 +1725,7 @@ JNIEXPORT jobject JNICALL Java_org_coolreader_crengine_DocView_getPositionPropsI
CRStringField(v,"pageText").set(p->_docview->getPageText(false, -1));
#else
p->_docview->getMutex().lock();
LVRef<ldomXRange> range = p->_docview->getPageDocumentRange(-1);
LVRef<ldomXRange> range = p->_docview->getPageDocumentRange(-1, false);
p->_docview->getMutex().unlock();
lString16 text;
if (!range.isNull())
Expand Down
19 changes: 3 additions & 16 deletions crengine/Tools/Fb2Linux/fb2v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,6 @@ class MyXWindowApp
}
};

void initHyph(const char * fname)
{
HyphMan hyphman;
LVStreamRef stream = LVOpenFileStream( fname, LVOM_READ);
if (!stream)
{
printf("Cannot load hyphenation file %s\n", fname);
return;
}
HyphMan::activateDictionaryFromStream( stream );
}

int main( int argc, const char * argv[] )
{
CRLog::setStdoutLogger();
Expand Down Expand Up @@ -312,10 +300,9 @@ int main( int argc, const char * argv[] )
#endif

// init hyphenation manager
char hyphfn[1024];
sprintf(hyphfn, "%sRussian_EnUS_hyphen_(Alan).pdb", exedir );
initHyph( hyphfn );

HyphMan::initDictionaries(Utf8ToUnicode(exedir));
HyphMan::activateDictionary(L"Russian_EnUS_hyphen_(Alan).pdb");

//LVCHECKPOINT("WinMain start");

LVDocView text_view;
Expand Down
4 changes: 2 additions & 2 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class LVDocView : public CacheLoadingCallback
void updateSelections();
void updateBookMarksRanges();
/// get page document range, -1 for current page
LVRef<ldomXRange> getPageDocumentRange( int pageIndex=-1 );
LVRef<ldomXRange> getPageDocumentRange( int pageIndex=-1, bool precise = true );
/// get page text, -1 for current page
lString16 getPageText( bool wrapWords, int pageIndex=-1 );
/// returns number of non-space characters on current page
Expand Down Expand Up @@ -803,7 +803,7 @@ class LVDocView : public CacheLoadingCallback
LVStreamRef getCoverPageImageStream();

/// returns bookmark
ldomXPointer getBookmark();
ldomXPointer getBookmark( bool precise = true );
/// returns bookmark for specified page
ldomXPointer getPageBookmark( int page );
/// sets current bookmark
Expand Down
6 changes: 4 additions & 2 deletions crengine/include/textlang.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ class TextLangMan
~TextLangMan();
};

#define MAX_NB_LB_PROPS_ITEMS 10 // for our statically sized array (increase if needed)
#define MAX_NB_LB_PROPS_ITEMS 20 // for our statically sized array (increase if needed)

typedef lChar16 (*lb_char_sub_func_t)(const lChar16 * text, int pos, int next_usable);
#if USE_LIBUNIBREAK==1
typedef lChar16 (*lb_char_sub_func_t)(struct LineBreakContext *lbpCtx, const lChar16 * text, int pos, int next_usable);
#endif

class TextLangCfg
{
Expand Down
100 changes: 67 additions & 33 deletions crengine/src/lvdocview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,15 +1007,17 @@ LVStreamRef LVDocView::getCoverPageImageStream() {
// FB2 coverpage
//CRLog::trace("LVDocView::getCoverPageImage()");
//m_doc->dumpStatistics();
lUInt16 path[] = { el_FictionBook, el_description, el_title_info,
el_coverpage, 0 };
lUInt16 path[] = { el_FictionBook, el_description, el_title_info, el_coverpage, 0 };
//lUInt16 path[] = { el_FictionBook, el_description, el_title_info, el_coverpage, el_image, 0 };
ldomNode * rootNode = m_doc->getRootNode();
ldomNode * cover_el = 0;
if (rootNode)
if (rootNode) {
cover_el = rootNode->findChildElement(path);
//ldomNode * cover_img_el = m_doc->getRootNode()->findChildElement( path );

if (!cover_el) { // might otherwise be found inside <src-title-info>
lUInt16 path2[] = { el_FictionBook, el_description, el_src_title_info, el_coverpage, 0 };
cover_el = rootNode->findChildElement(path2);
}
}
if (cover_el) {
ldomNode * cover_img_el = cover_el->findChildElement(LXML_NS_ANY,
el_image, 0);
Expand All @@ -1034,15 +1036,17 @@ LVImageSourceRef LVDocView::getCoverPageImage() {
// CRLog::trace("Image stream size is %d", (int)stream->GetSize() );
//CRLog::trace("LVDocView::getCoverPageImage()");
//m_doc->dumpStatistics();
lUInt16 path[] = { el_FictionBook, el_description, el_title_info,
el_coverpage, 0 };
lUInt16 path[] = { el_FictionBook, el_description, el_title_info, el_coverpage, 0 };
//lUInt16 path[] = { el_FictionBook, el_description, el_title_info, el_coverpage, el_image, 0 };
ldomNode * cover_el = 0;
ldomNode * rootNode = m_doc->getRootNode();
if (rootNode)
if (rootNode) {
cover_el = rootNode->findChildElement(path);
//ldomNode * cover_img_el = m_doc->getRootNode()->findChildElement( path );

if (!cover_el) { // might otherwise be found inside <src-title-info>
lUInt16 path2[] = { el_FictionBook, el_description, el_src_title_info, el_coverpage, 0 };
cover_el = rootNode->findChildElement(path2);
}
}
if (cover_el) {
ldomNode * cover_img_el = cover_el->findChildElement(LXML_NS_ANY,
el_image, 0);
Expand Down Expand Up @@ -1125,7 +1129,9 @@ void LVDocView::drawCoverTo(LVDrawBuf * drawBuf, lvRect & rc) {
if (dst_dy > rc.height() * 6 / 8)
dst_dy = imgrc.height();
//CRLog::trace("drawCoverTo() - drawing image");
LVColorDrawBuf buf2(src_dx, src_dy, 32);
// It's best to use a 16bpp LVColorDrawBuf as the intermediate buffer,
// as using 32bpp would mess colors up when drawBuf is itself 32bpp.
LVColorDrawBuf buf2(src_dx, src_dy, 16);
buf2.Draw(imgsrc, 0, 0, src_dx, src_dy, true);
drawBuf->DrawRescaled(&buf2, imgrc.left + (imgrc.width() - dst_dx) / 2,
imgrc.top + (imgrc.height() - dst_dy) / 2, dst_dx, dst_dy, 0);
Expand Down Expand Up @@ -2610,40 +2616,59 @@ void LVDocView::setHeaderIcons(LVRefVec<LVImageSource> icons) {
}

/// get page document range, -1 for current page
LVRef<ldomXRange> LVDocView::getPageDocumentRange(int pageIndex) {
LVRef<ldomXRange> LVDocView::getPageDocumentRange(int pageIndex, bool precise) {
LVLock lock(getMutex());
CHECK_RENDER("getPageDocRange()")
// On some pages (eg: that ends with some padding between an
// image on this page, and some text on next page), there may
// be some area which is rendered "final" without any content,
// thus holding no node. We could then get a null 'start' or
// 'end' below by looking only at start_y or end_y.
// So, in all cases, loop while increasing or decrasing y
// So, in all cases, loop while increasing or decreasing y
// to get more chances of finding a valid XPointer.
LVRef < ldomXRange > res(NULL);
int start_y;
int end_y;
if (isScrollMode()) { // SCROLL mode
if (isScrollMode()) {
// SCROLL mode
start_y = _pos;
end_y = _pos + m_dy;
int fh = GetFullHeight();
if (end_y >= fh)
end_y = fh - 1;
if (!precise) {
ldomXPointer start = m_doc->createXPointer(lvPoint(0, start_y));
ldomXPointer end = m_doc->createXPointer(lvPoint(0, end_y));
if (start.isNull() || end.isNull())
return res;
res = LVRef<ldomXRange> (new ldomXRange(start, end));
}
}
else { // PAGES mode
else {
// PAGES mode
if (pageIndex < 0 || pageIndex >= m_pages.length())
pageIndex = getCurPage();
if (pageIndex >= 0 && pageIndex < m_pages.length()) {
LVRendPageInfo * page = m_pages[pageIndex];
if (page->flags & RN_PAGE_TYPE_COVER)
return res;
start_y = page->start;
end_y = page->start + page->height;
if (!precise) {
ldomXPointer start = m_doc->createXPointer(lvPoint(0, page->start));
ldomXPointer end = m_doc->createXPointer(lvPoint(0, page->start + page->height), 1);
if (start.isNull() || end.isNull())
return res;
res = LVRef<ldomXRange>(new ldomXRange(start, end));
} else {
start_y = page->start;
end_y = page->start + page->height;
}
}
else {
return res;
}
}
if (!res.isNull())
return res;
int height = end_y - start_y;
if (height < 0)
return res;
Expand Down Expand Up @@ -4982,7 +5007,7 @@ ldomXPointer LVDocView::getCurrentPageMiddleParagraph() {
}

/// returns bookmark
ldomXPointer LVDocView::getBookmark() {
ldomXPointer LVDocView::getBookmark( bool precise ) {
LVLock lock(getMutex());
checkPos();
ldomXPointer ptr;
Expand All @@ -4996,18 +5021,24 @@ ldomXPointer LVDocView::getBookmark() {
LVRendPageInfo * page = m_pages[_page];
bool found = false;
ldomXPointer fallback_ptr;
for (int y = page->start; y < page->start + page->height; y++) {
ptr = m_doc->createXPointer(lvPoint(0, y), PT_DIR_SCAN_FORWARD_LOGICAL_FIRST);
lvPoint pt = ptr.toPoint();
if (pt.y >= page->start) {
if (!fallback_ptr)
fallback_ptr = ptr;
if ( pt.y < page->start + page->height ) {
// valid, resolves back to same page
found = true;
break;
if (precise) {
for (int y = page->start; y < page->start + page->height; y++) {
ptr = m_doc->createXPointer(lvPoint(0, y),
PT_DIR_SCAN_FORWARD_LOGICAL_FIRST);
lvPoint pt = ptr.toPoint();
if (pt.y >= page->start) {
if (!fallback_ptr)
fallback_ptr = ptr;
if (pt.y < page->start + page->height) {
// valid, resolves back to same page
found = true;
break;
}
}
}
} else {
ptr = m_doc->createXPointer(lvPoint(0, page->start));
found = true;
}
if (!found) {
// None looking forward resolved to that same page, we
Expand All @@ -5030,7 +5061,6 @@ ldomXPointer LVDocView::getBookmark() {
}
}
} else {
// ptr = m_doc->createXPointer(lvPoint(0, _pos));
// In scroll mode, the y position may not resolve to any xpointer
// (because of margins, empty elements...)
// When inside an image (top of page being the middle of an image),
Expand All @@ -5039,10 +5069,14 @@ ldomXPointer LVDocView::getBookmark() {
// scrolling a bit up.
// Let's do the same in that case: get the previous text node
// position
for (int y = _pos; y >= 0; y--) {
ptr = m_doc->createXPointer(lvPoint(0, y), PT_DIR_SCAN_BACKWARD_LOGICAL_FIRST);
if (!ptr.isNull())
break;
if (precise) {
for (int y = _pos; y >= 0; y--) {
ptr = m_doc->createXPointer(lvPoint(0, y), PT_DIR_SCAN_BACKWARD_LOGICAL_FIRST);
if (!ptr.isNull())
break;
}
} else {
ptr = m_doc->createXPointer(lvPoint(0, _pos));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crengine/src/lvrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10095,7 +10095,7 @@ void getRenderedWidths(ldomNode * node, int &maxWidth, int &minWidth, int direct
lChar16 c = *(txt + start + i);
lChar16 next_c = *(txt + start + i + 1); // might be 0 at end of string
if ( lang_cfg->hasLBCharSubFunc() ) {
next_c = lang_cfg->getLBCharSubFunc()(txt+start, i+1, len-1 - (i+1));
next_c = lang_cfg->getLBCharSubFunc()(&lbCtx, txt+start, i+1, len-1 - (i+1));
}
int brk = lb_process_next_char(&lbCtx, (utf32_t)next_c);
// We don't really need to bother with consecutive spaces (that
Expand Down
2 changes: 1 addition & 1 deletion crengine/src/lvtextfm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ class LVFormatter {
if ( src->lang_cfg->hasLBCharSubFunc() ) {
// Lang specific function may want to substitute char (for
// libunibreak only) to tweak line breaking around it
ch = src->lang_cfg->getLBCharSubFunc()(m_text, pos, len-1 - k);
ch = src->lang_cfg->getLBCharSubFunc()(&lbCtx, m_text, pos, len-1 - k);
}
int brk = lb_process_next_char(&lbCtx, (utf32_t)ch);
if ( pos > 0 ) {
Expand Down
Loading