From d6bbf5d1ef0b489bd842ff64bbe6bc091f8c2abb Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 4 Oct 2012 19:30:14 +0200 Subject: [PATCH 1/4] paintRect should support negative x and y without this page, highlights which land outside of page in negative direction will core-dump reader --- blitbuffer.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/blitbuffer.c b/blitbuffer.c index b149923d8..6345025d7 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -332,9 +332,25 @@ static int paintRect(lua_State *L) { uint8_t *dstptr; int cy; - if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { - return 0; + + if(x < 0) { + if (x+w > 0) { + w += x; + x = 0; + } else { + return 0; + } } + + if(y < 0) { + if (y+h > 0) { + h += y; + y = 0; + } else { + return 0; + } + } + if(x + w > dst->w) { w = dst->w - x; } @@ -342,6 +358,10 @@ static int paintRect(lua_State *L) { h = dst->h - y; } + if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { + return 0; + } + if(x & 1) { /* This will render the leftmost column * in the case when x is odd. After this, From cceae8ad0a87064fa06b8a1855dcd6c65195453f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 5 Oct 2012 14:33:24 +0200 Subject: [PATCH 2/4] add negative x,y checking in dimRect --- blitbuffer.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/blitbuffer.c b/blitbuffer.c index 6345025d7..90e2e55d5 100644 --- a/blitbuffer.c +++ b/blitbuffer.c @@ -489,6 +489,27 @@ static int dimRect(lua_State *L) { uint8_t *dstptr; int cy, cx; + + if (x < 0) { + if ( x + w > 0 ) { + w = w + x; + x = 0; + } else { + //printf("## invertRect x out of bound\n"); + return 0; + } + } + + if (y < 0) { + if ( y + h > 0 ) { + h = h + y; + y = 0; + } else { + //printf("## invertRect y out of bound\n"); + return 0; + } + } + if(w <= 0 || h <= 0 || x >= dst->w || y >= dst->h) { return 0; } From 6ab06cb58409ec483481131cea895ee4a784a30d Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 5 Oct 2012 11:56:12 +0200 Subject: [PATCH 3/4] reset screen offsets after pre-cache Code which tried to restore offsets didn't do anything since old and self point to same values --- unireader.lua | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/unireader.lua b/unireader.lua index c839021f5..0074216bf 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1532,12 +1532,37 @@ function UniReader:goto(no, is_ignore_jump) -- TODO: move the following to a more appropriate place -- into the caching section if no < numpages then - if #self.bbox == 0 or not self.bbox.enabled then - -- pre-cache next page, but if we will modify bbox don't! - -- Tigran: I think we should _always_ precache the page - -- because of the benefits of pre-decoding it (for DjVu). - self:drawOrCache(no+1, true) - end + + local old = { + globalzoom = self.globalzoom, + offset_x = self.offset_x, + offset_y = self.offset_y, + dest_x = self.dest_x, + dest_y = self.dest_y, + min_offset_x = self.min_offset_x, + min_offset_y = self.min_offset_y, + pan_x = self.pan_x, + pan_y = self.pan_y + } + + self:drawOrCache(no+1, true) + + -- restore currently visible values, not from preCache page + self.globalzoom = old.globalzoom + self.offset_x = old.offset_x + self.offset_y = old.offset_y + self.dest_x = old.dest_x + self.dest_y = old.dest_y + self.min_offset_x = old.min_offset_x + self.min_offset_y = old.min_offset_y + self.pan_x = old.pan_x + self.pan_y = old.pan_y + + Debug("pre-cached page ", no+1, " and restored offsets") + + + Debug("globalzoom_mode:", self.globalzoom_mode, " globalzoom:", self.globalzoom, " globalrotate:", self.globalrotate, " offset:", self.offset_x, self.offset_y, " pagesize:", self.fullwidth, self.fullheight, " min_offset:", self.min_offset_x, self.min_offset_y) + end end From fea2eea7a4536c381065cfe6d5ca4a2359dbc510 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 5 Oct 2012 15:48:22 +0200 Subject: [PATCH 4/4] create shortcuts just for visible links --- unireader.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/unireader.lua b/unireader.lua index 0074216bf..cabb9bce8 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2960,18 +2960,22 @@ function UniReader:addAllCommands() local face = Font:getFace("rifont", font_size) local page_links = 0 + local visible_links = {} for i, link in ipairs(links) do if link.page then local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - fb.bb:dimRect(x,y,w,h) -- black 50% - fb.bb:dimRect(x,y,w,h) -- black 25% - page_links = page_links + 1 + if x > 0 and y > 0 and x < G_width and y < G_height then + fb.bb:dimRect(x,y,w,h) -- black 50% + fb.bb:dimRect(x,y,w,h) -- black 25% + page_links = page_links + 1 + visible_links[page_links] = link + end end end if page_links == 0 then - InfoMessage:inform("No links on this page ", 2000, 1, MSG_WARN) + InfoMessage:inform("No visible links on this page ", 2000, 1, MSG_WARN) return end @@ -2987,7 +2991,7 @@ function UniReader:addAllCommands() shortcut_map = {} for i = 1, #SelectMenu.item_shortcuts, 1 do - local link = links[ i + shortcut_offset ] + local link = visible_links[ i + shortcut_offset ] if link == nil then break end Debug("link", i, shortcut_offset, link) if link.page then @@ -3032,7 +3036,7 @@ function UniReader:addAllCommands() link = 30 elseif ev.code == KEY_BACK then goto_page = unireader.pageno - elseif ( ev.code == KEY_FW_RIGHT or ev.code == KEY_FW_DOWN ) and shortcut_offset <= #links - 30 then + elseif ( ev.code == KEY_FW_RIGHT or ev.code == KEY_FW_DOWN ) and shortcut_offset <= #visible_links - 30 then shortcut_offset = shortcut_offset + 30 render_shortcuts() elseif ( ev.code == KEY_FW_LEFT or ev.code == KEY_FW_UP ) and shortcut_offset >= 30 then @@ -3043,7 +3047,7 @@ function UniReader:addAllCommands() if link then link = shortcut_map[link] - if links[link] ~= nil and links[link].page ~= nil then + if visible_links[link] ~= nil and visible_links[link].page ~= nil then goto_page = links[link].page + 1 else Debug("missing link", link)