From 734f94da898b15a6fbd0459b26a015bb4a8667a0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 13 Mar 2012 15:37:45 +0800 Subject: [PATCH 1/4] fix: handle positive self.offset in draworcache method --- unireader.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/unireader.lua b/unireader.lua index 9def0d545..85e2df6d2 100644 --- a/unireader.lua +++ b/unireader.lua @@ -182,15 +182,24 @@ function UniReader:draworcache(no, preCache) local page = self.doc:openPage(no) local dc = self:setzoom(page) + -- offset_x_in_page & offset_y_in_page is the offset within zoomed page + -- they are always positive. + -- you can see self.offset_x_& self.offset_y as the offset within + -- draw space, which includes the page. So it can be negative and positive. + local offset_x_in_page = -self.offset_x + local offset_y_in_page = -self.offset_y + if offset_x_in_page < 0 then offset_x_in_page = 0 end + if offset_x_in_page < 0 then offset_y_in_page = 0 end + -- check if we have relevant cache contents local pagehash = no..'_'..self.globalzoom..'_'..self.globalrotate..'_'..self.globalgamma if self.cache[pagehash] ~= nil then -- we have something in cache, check if it contains the requested part - if self.cache[pagehash].x <= (-self.offset_x) - and self.cache[pagehash].y <= (-self.offset_y) - and ( self.cache[pagehash].x + self.cache[pagehash].w >= (-self.offset_x) + width + if self.cache[pagehash].x <= offset_x_in_page + and self.cache[pagehash].y <= offset_y_in_page + and ( self.cache[pagehash].x + self.cache[pagehash].w >= offset_x_in_page + width or self.cache[pagehash].w >= self.fullwidth - 1) - and ( self.cache[pagehash].y + self.cache[pagehash].h >= (-self.offset_y) + height + and ( self.cache[pagehash].y + self.cache[pagehash].h >= offset_y_in_page + height or self.cache[pagehash].h >= self.fullheight - 1) then -- requested part is within cached tile @@ -202,14 +211,15 @@ function UniReader:draworcache(no, preCache) end -- ...and return blitbuffer plus offset into it return pagehash, - (-self.offset_x) - self.cache[pagehash].x, - (-self.offset_y) - self.cache[pagehash].y + offset_x_in_page - self.cache[pagehash].x, + offset_y_in_page - self.cache[pagehash].y end end -- okay, we do not have it in cache yet. -- so render now. -- start off with the requested area - local tile = { x = (-self.offset_x), y = (-self.offset_y), w = width, h = heigth } + local tile = { x = offset_x_in_page, y = offset_y_in_page, + w = width, h = heigth } -- can we cache the full page? local max_cache = self.cache_max_memsize if preCache then @@ -256,14 +266,15 @@ function UniReader:draworcache(no, preCache) size = tile.w * tile.h / 2, bb = Blitbuffer.new(tile.w, tile.h) } + --print ("# new biltbuffer:"..dump(self.cache[pagehash])) dc:setOffset(-tile.x, -tile.y) print("# rendering: page="..no) page:draw(dc, self.cache[pagehash].bb, 0, 0) page:close() return pagehash, - (-self.offset_x) - tile.x, - (-self.offset_y) - tile.y + offset_x_in_page - tile.x, + offset_y_in_page - tile.y end -- blank the cache From 8c31dd3c5fce39251b3d5e705f8d45040de57ceb Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 13 Mar 2012 16:21:16 +0800 Subject: [PATCH 2/4] fix: hanlde offset in ZOOM_FIT_TO_WIDTH_PAN mode ZOOM_FIT_TO_WIDTH_PAN mode must be handled differently. Because not like other zoom mode, its offset is not set to middle of the screen or page. --- unireader.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/unireader.lua b/unireader.lua index 85e2df6d2..1cb4ea516 100644 --- a/unireader.lua +++ b/unireader.lua @@ -189,7 +189,7 @@ function UniReader:draworcache(no, preCache) local offset_x_in_page = -self.offset_x local offset_y_in_page = -self.offset_y if offset_x_in_page < 0 then offset_x_in_page = 0 end - if offset_x_in_page < 0 then offset_y_in_page = 0 end + if offset_y_in_page < 0 then offset_y_in_page = 0 end -- check if we have relevant cache contents local pagehash = no..'_'..self.globalzoom..'_'..self.globalrotate..'_'..self.globalgamma @@ -272,6 +272,9 @@ function UniReader:draworcache(no, preCache) page:draw(dc, self.cache[pagehash].bb, 0, 0) page:close() + print("offset_x_in_page", offset_x_in_page) + print("offset_y_in_page", offset_y_in_page) + -- return hash and offset within blitbuffer return pagehash, offset_x_in_page - tile.x, offset_y_in_page - tile.y @@ -441,16 +444,27 @@ function UniReader:show(no) local dest_x = 0 local dest_y = 0 if bb:getWidth() - offset_x < width then - -- we can't fill the whole output width + -- we can't fill the whole output width, center the content dest_x = (width - (bb:getWidth() - offset_x)) / 2 end - if bb:getHeight() - offset_y < height then - -- we can't fill the whole output heigth + if bb:getHeight() - offset_y < height and + self.globalzoommode ~= self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + -- we can't fill the whole output height and not in + -- ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode, center the content dest_y = (height - (bb:getHeight() - offset_y)) / 2 + elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN and + self.offset_y > 0 then + -- if we are in ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode and turning to + -- the top of the page, we might leave an empty space between the + -- page top and screen top. + dest_y = self.offset_y end if dest_x or dest_y then fb.bb:paintRect(0, 0, width, height, 8) end + print("# blitFrom dest_off:("..dest_x..", "..dest_y.. + "), src_off:("..offset_x..", "..offset_y.."), ".. + "width:"..width..", height:"..height) fb.bb:blitFrom(bb, dest_x, dest_y, offset_x, offset_y, width, height) if self.rcount == self.rcountmax then print("full refresh") From 46cfd950c79abf1a602017911730c640d6f6e7c0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 13 Mar 2012 17:07:55 +0800 Subject: [PATCH 3/4] fix: typo --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 1cb4ea516..192d81727 100644 --- a/unireader.lua +++ b/unireader.lua @@ -219,7 +219,7 @@ function UniReader:draworcache(no, preCache) -- so render now. -- start off with the requested area local tile = { x = offset_x_in_page, y = offset_y_in_page, - w = width, h = heigth } + w = width, h = height } -- can we cache the full page? local max_cache = self.cache_max_memsize if preCache then From 56a00d79a0888adf1db41c7ce847c9cb74037026 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 13 Mar 2012 17:16:05 +0800 Subject: [PATCH 4/4] mod: delete debug print --- unireader.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index 192d81727..61fd3e26a 100644 --- a/unireader.lua +++ b/unireader.lua @@ -272,8 +272,6 @@ function UniReader:draworcache(no, preCache) page:draw(dc, self.cache[pagehash].bb, 0, 0) page:close() - print("offset_x_in_page", offset_x_in_page) - print("offset_y_in_page", offset_y_in_page) -- return hash and offset within blitbuffer return pagehash, offset_x_in_page - tile.x,