From 853f34b488654e35019286c0ba2f1942935958a4 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 15 Sep 2012 22:19:12 +0100 Subject: [PATCH 1/4] Fix for calculating the current position in the case of TOC containing links to external files: when walking the TOC we should check if the destination page is within the range of the current document. --- unireader.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 31b15959e..5b255e196 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1740,10 +1740,11 @@ end -- corresponding to the current page. function UniReader:findTOCpos() local pos, found_pos = 0, false + local numpages = self.doc:getPages() -- find the index into toc_xview first for k,v in ipairs(self.toc) do - if v.page > self.pageno then + if v.page >= 1 and v.page <= self.doc:getPages() and v.page > self.pageno then pos = k - 1 found_pos = true break From cc5abd3b87cd38912f6f37a16a56cbfd56863a7b Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 15 Sep 2012 22:22:07 +0100 Subject: [PATCH 2/4] Use the value of self.doc:getPages() stored in a local variable instead of calling it for each TOC entry. --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 5b255e196..b7b42619b 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1744,7 +1744,7 @@ function UniReader:findTOCpos() -- find the index into toc_xview first for k,v in ipairs(self.toc) do - if v.page >= 1 and v.page <= self.doc:getPages() and v.page > self.pageno then + if v.page >= 1 and v.page <= numpages and v.page > self.pageno then pos = k - 1 found_pos = true break From 56f4ac42bd2890f47789c2dfe8f71c83117511ab Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 15 Sep 2012 23:26:30 +0100 Subject: [PATCH 3/4] Better fix for the external links in TOC problem: instead of returning to the current page display a message "External links unsupported" and remain in the TOC menu. The reason for this decision is that if the user chose invalid TOC entry she is more likely to wish to stay in the TOC menu and choose another entry rather than return to reading immediately. --- unireader.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/unireader.lua b/unireader.lua index b7b42619b..495ced29e 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1483,8 +1483,6 @@ end -- change current page and cache next page after rendering function UniReader:goto(no, is_ignore_jump) if no < 1 or no > self.doc:getPages() then - -- may be reached by following TOC entry pointing to external file. - self:redrawCurrentPage() return end @@ -1798,7 +1796,14 @@ function UniReader:showToc() } local ret_code, item_no, all = toc_menu:choose(0, fb.bb:getHeight()) if ret_code then -- normal item selection - return self:gotoTocEntry(self.toc[self.toc_curidx_to_x[ret_code]]) + -- check to make sure the destination is local + local pagenum = self.toc[self.toc_curidx_to_x[ret_code]].page + if pagenum < 1 or pagenum > self.doc:getPages() then + showInfoMsgWithDelay("External links unsupported", 1500, 1) + self.toc_curitem = ret_code + else + return self:gotoTocEntry(self.toc[self.toc_curidx_to_x[ret_code]]) + end elseif item_no then -- expand or collapse item local abs_item_no = math.abs(item_no) local xidx = self.toc_curidx_to_x[abs_item_no] From 51ccc20845c3fb60e203fa9d314cfadf52b0fb80 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 15 Sep 2012 23:32:56 +0100 Subject: [PATCH 4/4] Save a few table indexing operations since we already have the page number. --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 495ced29e..17cb343f0 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1802,7 +1802,7 @@ function UniReader:showToc() showInfoMsgWithDelay("External links unsupported", 1500, 1) self.toc_curitem = ret_code else - return self:gotoTocEntry(self.toc[self.toc_curidx_to_x[ret_code]]) + return self:goto(pagenum) end elseif item_no then -- expand or collapse item local abs_item_no = math.abs(item_no)