Skip to content

Commit

Permalink
bump crengine: support min/max-width/height, 2-pages tweaks (#1295)
Browse files Browse the repository at this point in the history
Includes:
- EPUB ncx TOC: allow items with an empty title
- resizeImage(): restore original scaling options code
- CSS: parse and store min/max-width/height
- Add getStyledImageSize() ensuring min/max-width/height
- renderBlockElementEnhanced(): ensure min/max-width/height
- 2-pages mode: add option twoVisiblePagesAsOnePageNumber
- TOC, PageMap: save the visible pages number they were build for
- 2-pages mode: tweak header drawing
- Header: add option to display time as 12-hours clock
- 2-pages mode: decrease min middle margin from 1.2 to 0.8em
- Add LVDocView::getDocumentRenderingHash()
- (Upstream) Text: don't remove trailing space on last word if pre
- (Upstream) Font: replace notfound glyphs only on last fallback font
- (Upstream) Add a few lString8 methods
  • Loading branch information
poire-z committed Jan 28, 2021
1 parent d347b46 commit a40812c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
54 changes: 47 additions & 7 deletions cre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ static int readDefaults(lua_State *L) {
props->setInt(PROP_FONT_KERNING, 3); // harfbuzz (slower than freetype kerning, but needed for proper arabic)
// props->setInt(PROP_FONT_KERNING_ENABLED, 1);
props->setString("styles.pre.font-face", "font-family: \"Droid Sans Mono\"");
// Disable crengine image scaling options (we prefer scaling them via crengine.render.dpi)
props->setInt(PROP_IMG_SCALING_ZOOMIN_INLINE_MODE, 0);
props->setInt(PROP_IMG_SCALING_ZOOMIN_INLINE_SCALE, 1);
props->setInt(PROP_IMG_SCALING_ZOOMOUT_INLINE_MODE, 0);
props->setInt(PROP_IMG_SCALING_ZOOMOUT_INLINE_SCALE, 1);
props->setInt(PROP_IMG_SCALING_ZOOMIN_BLOCK_MODE, 0);
props->setInt(PROP_IMG_SCALING_ZOOMIN_BLOCK_SCALE, 1);
props->setInt(PROP_IMG_SCALING_ZOOMOUT_BLOCK_MODE, 0);
props->setInt(PROP_IMG_SCALING_ZOOMOUT_BLOCK_SCALE, 1);

stream = LVOpenFileStream("data/cr3.ini", LVOM_WRITE);
props->saveToStream(stream.get());
Expand Down Expand Up @@ -776,19 +785,35 @@ static int getDocumentProps(lua_State *L) {
return 1;
}

static int getDocumentRenderingHash(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");

lua_pushinteger(L, doc->text_view->getDocumentRenderingHash());

return 1;
}

static int getNumberOfPages(lua_State *L) {
static int getPages(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
bool internal = false;
if (lua_isboolean(L, 2)) {
internal = lua_toboolean(L, 2);
}

lua_pushinteger(L, doc->text_view->getPageCount());
lua_pushinteger(L, doc->text_view->getPageCount(internal));

return 1;
}

static int getCurrentPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
bool internal = false;
if (lua_isboolean(L, 2)) {
internal = lua_toboolean(L, 2);
}

lua_pushinteger(L, doc->text_view->getCurPage()+1);
int page = doc->text_view->getCurPage(internal);
lua_pushinteger(L, page+1);

return 1;
}
Expand Down Expand Up @@ -1224,9 +1249,10 @@ static int getPageMapVisiblePageLabels(lua_State *L) {
int min_y = rc.top;
int max_y = rc.bottom;
int page2_y = -1;
// We must work with internal page numbers
if ( tv->getVisiblePageCount() == 2 ) {
int next_page = tv->getCurPage() + 1;
if ( next_page < tv->getPageCount() ) {
int next_page = tv->getCurPage(true) + 1;
if ( next_page < tv->getPageCount(true) ) {
page2_y = tv->getPageStartY( next_page );
}
}
Expand Down Expand Up @@ -1441,8 +1467,12 @@ static int setAsPreferredFontWithBias(lua_State *L) {
static int gotoPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pageno = luaL_checkint(L, 2);
bool internal = false;
if (lua_isboolean(L, 3)) {
internal = lua_toboolean(L, 3);
}

doc->text_view->goToPage(pageno-1, true, false); // regulateTwoPages=false
doc->text_view->goToPage(pageno-1, internal, true, false); // regulateTwoPages=false
// In 2-pages mode, we will ensure from frontend the first page displayed
// is an even one: we don't need crengine to ensure that.

Expand Down Expand Up @@ -1593,6 +1623,14 @@ static int setVisiblePageCount(lua_State *L) {
return 0;
}

static int getVisiblePageNumberCount(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");

lua_pushinteger(L, doc->text_view->getVisiblePageNumberCount());

return 1;
}

static int adjustFontSizes(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int dpi = luaL_checkint(L, 2);
Expand Down Expand Up @@ -3464,7 +3502,8 @@ static const struct luaL_Reg credocument_meth[] = {
{"getStringProperty", getStringProperty},
{"getDocumentFormat", getDocumentFormat},
{"getDocumentProps", getDocumentProps},
{"getPages", getNumberOfPages},
{"getDocumentRenderingHash", getDocumentRenderingHash},
{"getPages", getPages},
{"getCurrentPage", getCurrentPage},
{"getPageFlow", getPageFlow},
{"getPageFromXPointer", getPageFromXPointer},
Expand All @@ -3482,6 +3521,7 @@ static const struct luaL_Reg credocument_meth[] = {
{"getHeaderHeight", getHeaderHeight},
{"getToc", getTableOfContent},
{"getVisiblePageCount", getVisiblePageCount},
{"getVisiblePageNumberCount", getVisiblePageNumberCount},
{"getNextVisibleWordStart", getNextVisibleWordStart},
{"getNextVisibleWordEnd", getNextVisibleWordEnd},
{"getPrevVisibleWordStart", getPrevVisibleWordStart},
Expand Down

0 comments on commit a40812c

Please sign in to comment.