diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index aa59ab12d..03269f6f6 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -98,6 +98,12 @@ function ReaderHighlight:addToMainMenu(menu_items) text = _("Highlighting"), sub_item_table = self:genHighlightDrawerMenu(), } + if self.document.info.has_pages then + menu_items.panel_zoom_options = { + text = _("Panel zoom (manga/comic)"), + sub_item_table = self:genPanelZoomMenu(), + } + end menu_items.translation_settings = Translator:genSettingsMenu() end @@ -107,6 +113,41 @@ local highlight_style = { invert = _("Invert"), } +local function getPanelZoomSupportedExt() + local default_supported_ext = { + cbz = true, + cbt = true, + } + return G_reader_settings:readSetting("panel_zoom_ext") or default_supported_ext +end + +local function isPanelZoomSupported(file) + local filetype = util.getFileNameSuffix(file) + local supported_filetypes = getPanelZoomSupportedExt() + return supported_filetypes[filetype] +end + +function ReaderHighlight:genPanelZoomMenu() + return { + { + text = _("Allow panel zoom"), + checked_func = function() + return self.panel_zoom_enabled + end, + callback = function() + self:onTogglePanelZoomSetting() + end, + hold_callback = function() + local ext = util.getFileNameSuffix(self.ui.document.file) + local supported_ext = getPanelZoomSupportedExt() + supported_ext[ext] = not supported_ext[ext] + G_reader_settings:saveSetting("panel_zoom_ext", supported_ext) + end, + separator = true, + }, + } +end + function ReaderHighlight:genHighlightDrawerMenu() local get_highlight_style = function(style) return { @@ -576,7 +617,36 @@ function ReaderHighlight:_resetHoldTimer(clear) end end +function ReaderHighlight:onTogglePanelZoomSetting(arg, ges) + if not self.document.info.has_pages then return end + self.panel_zoom_enabled = not self.panel_zoom_enabled +end + +function ReaderHighlight:onPanelZoom(arg, ges) + self:clear() + local hold_pos = self.view:screenToPageTransform(ges.pos) + if not hold_pos then return false end -- outside page boundary + local rect = self.ui.document:getPanelFromPage(hold_pos.page, hold_pos) + if not rect then return false end -- panel not found, return + local image = self.ui.document:getPagePart(hold_pos.page, rect, 0) + + if image then + local ImageViewer = require("ui/widget/imageviewer") + local imgviewer = ImageViewer:new{ + image = image, + with_title_bar = false, + fullscreen = true, + } + UIManager:show(imgviewer) + end + return true +end + function ReaderHighlight:onHold(arg, ges) + if self.document.info.has_pages and self.panel_zoom_enabled then + return self:onPanelZoom(arg, ges) + end + -- disable hold gesture if highlighting is disabled if self.view.highlight.disabled then return false end self:clear() -- clear previous highlight (delayed clear may not have done it yet) @@ -1298,6 +1368,14 @@ function ReaderHighlight:onReadSettings(config) disable_highlight = G_reader_settings:readSetting("highlight_disabled") or false end self.view.highlight.disabled = disable_highlight + + -- panel zoom settings isn't supported in EPUB + if self.document.info.has_pages then + self.panel_zoom_enabled = config:readSetting("panel_zoom_enabled") + if self.panel_zoom_enabled == nil then + self.panel_zoom_enabled = isPanelZoomSupported(self.ui.document.file) + end + end end function ReaderHighlight:onUpdateHoldPanRate() @@ -1307,6 +1385,7 @@ end function ReaderHighlight:onSaveSettings() self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer) self.ui.doc_settings:saveSetting("highlight_disabled", self.view.highlight.disabled) + self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled) end function ReaderHighlight:onClose() diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index ebf4a66ca..42c8204c5 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -112,10 +112,11 @@ local settingsList = { toggle_bookmark = { category="none", event="ToggleBookmark", title=_("Toggle bookmark"), rolling=true, paging=true,}, toggle_inverse_reading_order = { category="none", event="ToggleReadingOrder", title=_("Toggle page turn direction"), rolling=true, paging=true,}, cycle_highlight_action = { category="none", event="CycleHighlightAction", title=_("Cycle highlight action"), rolling=true, paging=true,}, - cycle_highlight_style = { category="none", event="CycleHighlightStyle", title=_("Cycle highlight style"), rolling=true, paging=true, separator=true,}, + cycle_highlight_style = { category="none", event="CycleHighlightStyle", title=_("Cycle highlight style"), rolling=true, paging=true,}, kosync_push_progress = { category="none", event="KOSyncPushProgress", title=_("Push progress from this device"), rolling=true, paging=true,}, kosync_pull_progress = { category="none", event="KOSyncPullProgress", title=_("Pull progress from other devices"), rolling=true, paging=true, separator=true,}, page_jmp = { category="absolutenumber", event="GotoViewRel", min=-100, max=100, title=_("Go %1 pages"), rolling=true, paging=true,}, + panel_zoom_toggle = { category="none", event="TogglePanelZoomSetting", title=_("Toggle panel zoom"), paging=true, separator=true,}, -- rolling reader settings increase_font = { category="incrementalnumber", event="IncreaseFontSize", min=1, max=255, title=_("Increase font size by %1"), rolling=true,}, @@ -260,6 +261,7 @@ local dispatcher_menu_order = { "zoom", "cycle_highlight_action", "cycle_highlight_style", + "panel_zoom_toggle", "kosync_push_progress", "kosync_pull_progress", diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index cf7e42efb..b4fbc55b0 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -72,6 +72,10 @@ function DjvuDocument:getPageTextBoxes(pageno) return self._document:getPageText(pageno) end +function DjvuDocument:getPanelFromPage(pageno, pos) + return self.koptinterface:getPanelFromPage(self, pageno, pos) +end + function DjvuDocument:getWordFromPosition(spos) return self.koptinterface:getWordFromPosition(self, spos) end diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 931700a5f..6454dff11 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -413,6 +413,13 @@ function Document:getDrawnImagesStatistics() return self._drawn_images_count, self._drawn_images_surface_ratio end +function Document:getPagePart(pageno, rect, rotation) + local tile = self:renderPage(pageno, rect, 1, rotation, 1, 0) + local target = Blitbuffer.new(rect.w, rect.h, self.render_color and self.color_bb_type or nil) + target:blitFrom(tile.bb, 0, 0, rect.x, rect.y, rect.w, rect.h) + return target +end + function Document:getPageText(pageno) -- is this worth caching? not done yet. local page = self._document:openPage(pageno) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 5df4cec1e..7049af3f4 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -539,6 +539,23 @@ function KoptInterface:getReflowedTextBoxesFromScratch(doc, pageno) end end +function KoptInterface:getPanelFromPage(doc, pageno, ges) + local page_size = Document.getNativePageDimensions(doc, pageno) + local bbox = { + x0 = 0, y0 = 0, + x1 = page_size.w, + y1 = page_size.h, + } + local kc = self:createContext(doc, pageno, bbox) + kc:setZoom(1.0) + local page = doc._document:openPage(pageno) + page:getPagePix(kc) + local panel = kc:getPanelFromPage(ges) + page:close() + kc:free() + return panel +end + --[[-- Get text boxes in native page via optical method. diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index c5ec7f667..0e96f482f 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -105,6 +105,10 @@ function PdfDocument:getPageTextBoxes(pageno) return text end +function PdfDocument:getPanelFromPage(pageno, pos) + return self.koptinterface:getPanelFromPage(self, pageno, pos) +end + function PdfDocument:getWordFromPosition(spos) return self.koptinterface:getWordFromPosition(self, spos) end diff --git a/frontend/ui/elements/reader_menu_order.lua b/frontend/ui/elements/reader_menu_order.lua index 500c3516a..61e89f04a 100644 --- a/frontend/ui/elements/reader_menu_order.lua +++ b/frontend/ui/elements/reader_menu_order.lua @@ -37,6 +37,7 @@ local order = { "speed_reading_module_perception_expander", "----------------------------", "highlight_options", + "panel_zoom_options" }, setting = { -- common settings