From 85ac59ae0074c321861d57ccc1c3e52518e1d60e Mon Sep 17 00:00:00 2001 From: poire-z Date: Tue, 20 Nov 2018 21:07:59 +0100 Subject: [PATCH] CreDocument: fix document loading interferences (#4349) When a main document is opened for displaying, some other document openings (for getting metadata or cover image) could affect the main document. Split some code from CreDocument:init() into another new method CreDocument:setupDefaultView(), that will only be called by ReaderUI when opening the main document (and not by these other openings like Book inforation, View cover...) Also speed up some of these other openings (Search, Screensaver) by using doc:loadDocument(false) to load only metadata and avoid parsing the HTML. Details in https://github.com/koreader/koreader/issues/4346#issuecomment-440036496 --- base | 2 +- .../apps/filemanager/filemanagersearch.lua | 3 ++ frontend/apps/reader/readerui.lua | 5 +++ frontend/document/credocument.lua | 40 +++++++++++++------ frontend/ui/screensaver.lua | 3 ++ 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/base b/base index 84299a585..461b75093 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 84299a585587f306230c448f80e4e4811f2f990d +Subproject commit 461b750936897041c115f5de6c94eb9e0309a5ee diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 9600fe5ec..b94512079 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -504,6 +504,9 @@ function Search:onMenuHold(item) local thumbnail local doc = DocumentRegistry:openDocument(item.path) if doc then + if doc.loadDocument then -- CreDocument + doc:loadDocument(false) -- load only metadata + end thumbnail = doc:getCoverPageImage() doc:close() end diff --git a/frontend/apps/reader/readerui.lua b/frontend/apps/reader/readerui.lua index e3f1bf320..67f47787f 100644 --- a/frontend/apps/reader/readerui.lua +++ b/frontend/apps/reader/readerui.lua @@ -263,6 +263,11 @@ function ReaderUI:init() document = self.document, }) else + -- load crengine default settings (from cr3.ini, some of these + -- will be overriden by our settings by some reader modules below) + if self.document.setupDefaultView then + self.document:setupDefaultView() + end -- make sure we render document first before calling any callback self:registerPostInitCallback(function() if not self.document:loadDocument() then diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index c8877c147..515638959 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -124,18 +124,6 @@ function CreDocument:init() error(self._document) -- will contain error message end - -- adjust font sizes according to screen dpi - self._document:adjustFontSizes(Screen:getDPI()) - - if G_reader_settings:readSetting("cre_header_status_font_size") then - self._document:setIntProperty("crengine.page.header.font.size", - G_reader_settings:readSetting("cre_header_status_font_size")) - end - - -- set fallback font face - self._document:setStringProperty("crengine.font.fallback.face", - G_reader_settings:readSetting("fallback_font") or self.fallback_font) - -- We would have liked to call self._document:loadDocument(self.file) -- here, to detect early if file is a supported document, but we -- need to delay it till after some crengine settings are set for a @@ -160,6 +148,34 @@ function CreDocument:requestDomVersion(version) cre.requestDomVersion(version) end +function CreDocument:setupDefaultView() + if self.loaded then + -- Don't apply defaults if the document has already been loaded + -- as this must be done before calling loadDocument() + return + end + -- have crengine load defaults from cr3.ini + self._document:readDefaults() + logger.dbg("CreDocument: applied cr3.ini default settings.") + + -- set fallback font face (this was formerly done in :init(), but it + -- affects crengine calcGlobalSettingsHash() and would invalidate the + -- cache from the main currently being read document when we just + -- loadDocument(only_metadata) another document go get its metadata + -- or cover image, eg. from History hold menu). + self._document:setStringProperty("crengine.font.fallback.face", + G_reader_settings:readSetting("fallback_font") or self.fallback_font) + + -- adjust font sizes according to screen dpi + self._document:adjustFontSizes(Screen:getDPI()) + + -- set top status bar font size + if G_reader_settings:readSetting("cre_header_status_font_size") then + self._document:setIntProperty("crengine.page.header.font.size", + G_reader_settings:readSetting("cre_header_status_font_size")) + end +end + function CreDocument:loadDocument(full_document) if not self._loaded then local only_metadata = full_document == false diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index 4d6747d46..8e3a13857 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -249,6 +249,9 @@ function Screensaver:show(event, fallback_message) if exclude ~= true then if lfs.attributes(lastfile, "mode") == "file" then local doc = DocumentRegistry:openDocument(lastfile) + if doc.loadDocument then -- CreDocument + doc:loadDocument(false) -- load only metadata + end local image = doc:getCoverPageImage() doc:close() if image ~= nil then