From f79ae48de8deaeca7d4dc101b040c2cb3a1c3770 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 18:16:46 +0800 Subject: [PATCH 1/2] add: UniReader:initGlobalSettings() Use this method to read settings that may shared among all readers. For instance, pan_overlap_vertical --- reader.lua | 2 ++ unireader.lua | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/reader.lua b/reader.lua index e2d9db1e3..da64c633c 100755 --- a/reader.lua +++ b/reader.lua @@ -119,6 +119,8 @@ if r_cfont ~=nil then FontChooser.cfont = r_cfont end +-- initialize global settings shared among all readers +UniReader:initGlobalSettings(reader_settings) -- initialize specific readers PDFReader:init() DJVUReader:init() diff --git a/unireader.lua b/unireader.lua index bb18797c8..9d5dd9107 100644 --- a/unireader.lua +++ b/unireader.lua @@ -117,6 +117,13 @@ function UniReader:loadSettings(filename) return false end +function UniReader:initGlobalSettings(settings) + local pan_overlap_vertical = settings:readsetting("pan_overlap_vertical") + if pan_overlap_vertical then + self.pan_overlap_vertical = pan_overlap_vertical + end +end + -- guarantee that we have enough memory in cache function UniReader:cacheclaim(size) if(size > self.cache_max_memsize) then From bf267ef0ef37e2d33a66b7ddc6c16e2f216cabb8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 21:44:59 +0800 Subject: [PATCH 2/2] mod: add ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode This mode is used with ZOOM_FIT_TO_CONTENT_WIDTH, so when press KEY_PGFWD, you jump to lower part of current page. When hit page bottom, you do a real page turn. It now behaviors the same like the native reader as I mentioned in issue #41. The first time you set to ZOOM_FIT_TO_CONTENT_WIDTH mode, the reader will setup proper zoom factor and offset, then switch to ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode. When you hit the page bottom, the reader will set the mode back to ZOOM_FIT_TO_CONTENT_WIDTH mode and do a real page turn. --- unireader.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/unireader.lua b/unireader.lua index 9d5dd9107..7c1c65069 100644 --- a/unireader.lua +++ b/unireader.lua @@ -11,8 +11,10 @@ UniReader = { ZOOM_FIT_TO_CONTENT = -4, ZOOM_FIT_TO_CONTENT_WIDTH = -5, ZOOM_FIT_TO_CONTENT_HEIGHT = -6, - ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -7, - ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -8, + ZOOM_FIT_TO_CONTENT_WIDTH_PAN = -7, + --ZOOM_FIT_TO_CONTENT_HEIGHT_PAN = -8, + ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -9, + ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -10, GAMMA_NO_GAMMA = 1.0, @@ -37,6 +39,7 @@ UniReader = { offset_y = 0, min_offset_x = 0, min_offset_y = 0, + content_top = 0, -- for ZOOM_FIT_TO_CONTENT_WIDTH_PAN (prevView) -- set panning distance shift_x = 100, @@ -252,6 +255,21 @@ function UniReader:setzoom(page) end self.offset_x = -1 * x0 * self.globalzoom self.offset_y = -1 * y0 * self.globalzoom + self.content_top = self.offset_y + -- enable pan mode in ZOOM_FIT_TO_CONTENT_WIDTH + self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN + elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.content_top == -2012 then + -- We must handle previous page turn as a special cases, + -- because we want to arrive at the bottom of previous page. + -- Since this a real page turn, we need to recalcunate stuff. + if (x1 - x0) < pwidth then + self.globalzoom = width / (x1 - x0) + end + self.offset_x = -1 * x0 * self.globalzoom + self.content_top = -1 * y0 * self.globalzoom + self.offset_y = fb.bb:getHeight() - self.fullheight + end elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then if (y1 - y0) < pheight then self.globalzoom = height / (y1 - y0) @@ -398,6 +416,57 @@ function UniReader:goto(no) end end +function UniReader:nextView() + local pageno = self.pageno + + if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.offset_y <= self.min_offset_y then + -- hit content bottom, turn to next page + self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH + pageno = pageno + 1 + else + -- goto next view of current page + self.offset_y = self.offset_y - height + self.pan_overlap_vertical + end + else + -- not in fit to content width pan mode, just do a page turn + pageno = pageno + 1 + if self.pan_by_page then + -- we are in two column mode + self.offset_x = self.pan_x + self.offset_y = self.pan_y + end + end + + return pageno +end + +function UniReader:prevView() + local pageno = self.pageno + + if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.offset_y >= self.content_top then + -- hit content top, turn to previous page + -- set self.content_top with magic num to signal self:setzoom + self.content_top = -2012 + pageno = pageno - 1 + else + -- goto previous view of current page + self.offset_y = self.offset_y + height - self.pan_overlap_vertical + end + else + -- not in fit to content width pan mode, just do a page turn + pageno = pageno - 1 + if self.pan_by_page then + -- we are in two column mode + self.offset_x = self.pan_x + self.offset_y = self.pan_y + end + end + + return pageno +end + -- adjust global gamma setting function UniReader:modify_gamma(factor) print("modify_gamma, gamma="..self.globalgamma.." factor="..factor) @@ -514,11 +583,9 @@ function UniReader:inputloop() elseif Keys.altmode then self:setglobalzoom(self.globalzoom+self.globalzoom_orig*0.1) else - if self.pan_by_page then - self.offset_x = self.pan_x - self.offset_y = self.pan_y - end - self:goto(self.pageno + 1) + -- turn page forward + local pageno = self:nextView() + self:goto(pageno) end elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then if Keys.shiftmode then @@ -526,11 +593,9 @@ function UniReader:inputloop() elseif Keys.altmode then self:setglobalzoom(self.globalzoom-self.globalzoom_orig*0.1) else - if self.pan_by_page then - self.offset_x = self.pan_x - self.offset_y = self.pan_y - end - self:goto(self.pageno - 1) + -- turn page back + local pageno = self:prevView() + self:goto(pageno) end elseif ev.code == KEY_BACK then if Keys.altmode then