From cc81d49cc952355d390a6527fba831a6712bad46 Mon Sep 17 00:00:00 2001 From: WS64 Date: Thu, 3 Jul 2014 18:19:28 +0200 Subject: [PATCH] New function to count the actual page of the current chapter --- frontend/apps/reader/modules/readertoc.lua | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readertoc.lua b/frontend/apps/reader/modules/readertoc.lua index fb368843b..edd9c0904 100644 --- a/frontend/apps/reader/modules/readertoc.lua +++ b/frontend/apps/reader/modules/readertoc.lua @@ -111,7 +111,7 @@ function ReaderToc:_getChapterPagesLeft(pageno,pages) j=0 if #self.toc > 0 then - for i=1, #self.toc do + for i = 1, #self.toc do v = self.toc[i] if v.page > pageno then j = v.page @@ -119,13 +119,45 @@ function ReaderToc:_getChapterPagesLeft(pageno,pages) end end end - if j==0 then - return pages-pageno + if j == 0 then + if pages > 0 then + return pages-pageno + else + return "" + end else return j-pageno-1 end end +function ReaderToc:_getChapterPagesDone(pageno) + if not self.toc then + -- build toc when needed. + self:fillToc() + end + + -- no table of content + if #self.toc == 0 then + return "" + end + + j=0 + if #self.toc > 0 then + for i = 1, #self.toc do + v = self.toc[i] + if v.page >= pageno then + break + end + j = v.page + end + end + if j < 2 then + return "" + else + return j-pageno + end +end + function ReaderToc:onShowToc() if not self.toc then