From 6d7296bde4c6cbf64a4a60af51af9a211c8eb85e Mon Sep 17 00:00:00 2001 From: zwim <36999612+zwim@users.noreply.github.com> Date: Sun, 5 May 2024 11:32:44 +0200 Subject: [PATCH 1/2] Recreate a new cache entry if rotation changes --- plugins/coverimage.koplugin/main.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/coverimage.koplugin/main.lua b/plugins/coverimage.koplugin/main.lua index 91301acc5..b0fbc01e6 100644 --- a/plugins/coverimage.koplugin/main.lua +++ b/plugins/coverimage.koplugin/main.lua @@ -113,14 +113,15 @@ function CoverImage:createCoverImage(doc_settings) if self:coverEnabled() and doc_settings:nilOrFalse("exclude_cover_image") then local cover_image, custom_cover = FileManagerBookInfo:getCoverImage(self.ui.document) if cover_image then - local cache_file = self:getCacheFile(custom_cover) + local s_w, s_h = Screen:getWidth(), Screen:getHeight() + local cache_file = self:getCacheFile(custom_cover, s_w, s_h) if lfs.attributes(cache_file, "mode") == "file" then + logger.dbg("CoverImage: cache file already exists") ffiutil.copyFile(cache_file, self.cover_image_path) lfs.touch(cache_file) -- update date return end - local s_w, s_h = Screen:getWidth(), Screen:getHeight() local i_w, i_h = cover_image:getWidth(), cover_image:getHeight() local scale_factor = math.min(s_w / i_w, s_h / i_h) @@ -199,6 +200,11 @@ function CoverImage:onReaderReady(doc_settings) self:createCoverImage(doc_settings) end +function CoverImage:onRotationUpdate() + logger.dbg("CoverImage: onRotationUpdate") + self.createCoverImage(self.ui.doc_settings) +end + function CoverImage:fallbackEnabled() return self.fallback and isFileOk(self.cover_image_fallback_path) end @@ -211,12 +217,13 @@ end -- cache handling functions --------------------------- -function CoverImage:getCacheFile(custom_cover) +function CoverImage:getCacheFile(custom_cover, s_w, s_h) local custom_cover_mtime = custom_cover and lfs.attributes(custom_cover, "modification") or "" local dummy, document_name = util.splitFilePathName(self.ui.document.file) -- use document_name here. Title may contain characters not allowed on every filesystem (esp. vfat on /sdcard) local key = document_name .. custom_cover_mtime .. self.cover_image_quality .. self.cover_image_stretch_limit .. self.cover_image_background .. self.cover_image_format .. tostring(self.cover_image_grayscale) + .. s_w .. s_h return self.cover_image_cache_path .. self.cover_image_cache_prefix .. md5(key) .. "." .. getExtension(self.cover_image_path) end From 32c7779da2b5669ed425c7a72331e888ae3c00ea Mon Sep 17 00:00:00 2001 From: zwim <36999612+zwim@users.noreply.github.com> Date: Sun, 5 May 2024 19:45:08 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Almost=20ready;=20rotating=20by=20180=C2=B0?= =?UTF-8?q?=20does=20now=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/apps/reader/modules/readerview.lua | 6 +++--- plugins/coverimage.koplugin/main.lua | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 37deb112f..61d57da92 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -781,7 +781,7 @@ function ReaderView:onSetRotationMode(rotation) if rotation ~= nil then local old_rotation = Screen:getRotationMode() if rotation == old_rotation then - return true + return end -- NOTE: We cannot rely on getScreenMode, as it actually checks the screen dimensions, instead of the rotation mode. @@ -798,7 +798,7 @@ function ReaderView:onSetRotationMode(rotation) Screen:setRotationMode(rotation) UIManager:setDirty(self.dialog, "full") Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation))) - return true + return end Screen:setRotationMode(rotation) @@ -810,7 +810,7 @@ function ReaderView:onSetRotationMode(rotation) self.ui:onScreenResize(new_screen_size) self.ui:handleEvent(Event:new("InitScrollPageStates")) Notification:notify(T(_("Rotation mode set to: %1"), optionsutil:getOptionText("SetRotationMode", rotation))) - return true + return end function ReaderView:onSetDimensions(dimensions) diff --git a/plugins/coverimage.koplugin/main.lua b/plugins/coverimage.koplugin/main.lua index b0fbc01e6..6665e3145 100644 --- a/plugins/coverimage.koplugin/main.lua +++ b/plugins/coverimage.koplugin/main.lua @@ -113,8 +113,7 @@ function CoverImage:createCoverImage(doc_settings) if self:coverEnabled() and doc_settings:nilOrFalse("exclude_cover_image") then local cover_image, custom_cover = FileManagerBookInfo:getCoverImage(self.ui.document) if cover_image then - local s_w, s_h = Screen:getWidth(), Screen:getHeight() - local cache_file = self:getCacheFile(custom_cover, s_w, s_h) + local cache_file = self:getCacheFile(custom_cover) if lfs.attributes(cache_file, "mode") == "file" then logger.dbg("CoverImage: cache file already exists") ffiutil.copyFile(cache_file, self.cover_image_path) @@ -122,9 +121,17 @@ function CoverImage:createCoverImage(doc_settings) return end + local s_w, s_h = Screen:getWidth(), Screen:getHeight() local i_w, i_h = cover_image:getWidth(), cover_image:getHeight() local scale_factor = math.min(s_w / i_w, s_h / i_h) + if Screen:getRotationMode() == Screen.DEVICE_ROTATED_UPSIDE_DOWN + or Screen:getRotationMode() == Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE then + print("xxxxx rotating") + cover_image:rotate(180) -- this does not work ???? + end + + if self.cover_image_background == "none" or scale_factor == 1 then local act_format = self.cover_image_format == "auto" and getExtension(self.cover_image_path) or self.cover_image_format if not cover_image:writeToFile(self.cover_image_path, act_format, self.cover_image_quality, self.cover_image_grayscale) then @@ -200,9 +207,9 @@ function CoverImage:onReaderReady(doc_settings) self:createCoverImage(doc_settings) end -function CoverImage:onRotationUpdate() - logger.dbg("CoverImage: onRotationUpdate") - self.createCoverImage(self.ui.doc_settings) +function CoverImage:onSetRotationMode(rotation) + logger.dbg("CoverImage: onSetRotationMode", rotation) + self:createCoverImage(self.ui.doc_settings) end function CoverImage:fallbackEnabled() @@ -217,13 +224,13 @@ end -- cache handling functions --------------------------- -function CoverImage:getCacheFile(custom_cover, s_w, s_h) +function CoverImage:getCacheFile(custom_cover) local custom_cover_mtime = custom_cover and lfs.attributes(custom_cover, "modification") or "" local dummy, document_name = util.splitFilePathName(self.ui.document.file) -- use document_name here. Title may contain characters not allowed on every filesystem (esp. vfat on /sdcard) local key = document_name .. custom_cover_mtime .. self.cover_image_quality .. self.cover_image_stretch_limit .. self.cover_image_background .. self.cover_image_format .. tostring(self.cover_image_grayscale) - .. s_w .. s_h + .. Screen:getRotationMode() return self.cover_image_cache_path .. self.cover_image_cache_prefix .. md5(key) .. "." .. getExtension(self.cover_image_path) end