From cea0a73556679b2d36fe9b8e9370b3377d785117 Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 14 Feb 2023 20:39:43 +0100 Subject: [PATCH] bump crengine: support for partial rerenderings Includes: - Cache: minor simplifications - Cache: improve cache file reproducibility - CHM: minor cleanup - LVStream: minor cleanups - LVStream: fix and improve `LVZipDecodeStream` implementation - LVStream: disable CRC checks for ZIP streams - CSS: optimize :nth-child/of-type() and :nth-last-child/of-type() - Page splitting: fix oversight in flags handling - Update _doc_rendering_hash also when loading from cache - getDocumentRenderingHash(extended): add parameter - Toggable support for partial rerenderings of individual DocFragments cre.cpp: add methods for partial rerenderings --- cre.cpp | 72 +++++++++++++++++++++++++++++++++++- thirdparty/kpvcrlib/crengine | 2 +- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/cre.cpp b/cre.cpp index bedc00233..1efba7664 100644 --- a/cre.cpp +++ b/cre.cpp @@ -741,6 +741,12 @@ static int hasCacheFile(lua_State *L) { return 1; } +static int isCacheFileStale(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + lua_pushboolean(L, doc->dom_doc->isCacheFileStale()); + return 1; +} + static int invalidateCacheFile(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); doc->dom_doc->invalidateCacheFile(); @@ -812,12 +818,60 @@ static int getDocumentProps(lua_State *L) { static int getDocumentRenderingHash(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + bool extended = false; + if (lua_isboolean(L, 2)) { + extended = lua_toboolean(L, 2); + } - lua_pushinteger(L, doc->text_view->getDocumentRenderingHash()); + lua_pushinteger(L, doc->text_view->getDocumentRenderingHash(extended)); return 1; } +// Partial rerendering support +static int canBePartiallyRerendered(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + if (doc->dom_doc) { + lua_pushboolean(L, doc->dom_doc->canBePartiallyRerendered()); + return 1; + } + return 0; +} +static int isPartialRerenderingEnabled(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + if (doc->dom_doc) { + lua_pushboolean(L, doc->dom_doc->isPartialRerenderingEnabled()); + return 1; + } + return 0; +} +static int enablePartialRerendering(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + bool enable = lua_toboolean(L, 2); + if (doc->dom_doc) { + bool ret = doc->dom_doc->enablePartialRerendering(enable); + lua_pushboolean(L, ret); + return 1; + } + return 0; +} +static int getPartialRerenderingsCount(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + if (doc->dom_doc) { + lua_pushinteger(L, doc->dom_doc->getPartialRerenderingsCount()); + return 1; + } + return 0; +} +static int isRerenderingDelayed(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + if (doc->dom_doc) { + lua_pushboolean(L, doc->dom_doc->isRerenderingDelayed(lua_toboolean(L, 2))); + return 1; + } + return 0; +} + static int getPages(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); bool internal = false; @@ -1114,6 +1168,15 @@ static int buildAlternativeToc(lua_State *L) { return 0; } +// To be used only after background rerendering to update ToC +// and PageMap page numbers before saving cache. +static int updateTocAndPageMap(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + doc->text_view->getToc(); + doc->text_view->getPageMap(); + return 0; +} + static int buildSyntheticPageMapIfNoneDocumentProvided(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); int chars_per_synthetic_page = luaL_checkint(L, 2); @@ -3870,6 +3933,11 @@ static const struct luaL_Reg credocument_meth[] = { {"getDocumentFormat", getDocumentFormat}, {"getDocumentProps", getDocumentProps}, {"getDocumentRenderingHash", getDocumentRenderingHash}, + {"canBePartiallyRerendered", canBePartiallyRerendered}, + {"isPartialRerenderingEnabled", isPartialRerenderingEnabled}, + {"enablePartialRerendering", enablePartialRerendering}, + {"getPartialRerenderingsCount", getPartialRerenderingsCount}, + {"isRerenderingDelayed", isRerenderingDelayed}, {"getPages", getPages}, {"getCurrentPage", getCurrentPage}, {"getPageFlow", getPageFlow}, @@ -3922,8 +3990,10 @@ static const struct luaL_Reg credocument_meth[] = { /* --- control methods ---*/ {"isBuiltDomStale", isBuiltDomStale}, {"hasCacheFile", hasCacheFile}, + {"isCacheFileStale", isCacheFileStale}, {"invalidateCacheFile", invalidateCacheFile}, {"getCacheFilePath", getCacheFilePath}, + {"updateTocAndPageMap", updateTocAndPageMap}, {"getStatistics", getStatistics}, {"getUnknownEntities", getUnknownEntities}, {"buildAlternativeToc", buildAlternativeToc}, diff --git a/thirdparty/kpvcrlib/crengine b/thirdparty/kpvcrlib/crengine index dd3cb231b..dde2e98a8 160000 --- a/thirdparty/kpvcrlib/crengine +++ b/thirdparty/kpvcrlib/crengine @@ -1 +1 @@ -Subproject commit dd3cb231b9abc9132af33a5a1c837e189b66878d +Subproject commit dde2e98a8ea167fc35df62d586bbea0589c6bcd3