diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 50a999a09..a834d74fe 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -104,9 +104,8 @@ function Document:getNativePageDimensions(pageno) end function Document:_readMetadata() - if self.info.has_pages then - self.info.number_of_pages = self._document:getPages() - else + self.info.number_of_pages = self._document:getPages() + if not self.info.has_pages then self.info.doc_height = self._document:getFullHeight() end return true diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index dcce27f01..892066332 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -2,6 +2,7 @@ require "ui/reader/readerpanning" ReaderRolling = InputContainer:new{ old_doc_height = nil, + old_page = nil, view_mode = "page", current_pos = 0, -- only used for page view mode @@ -85,6 +86,7 @@ function ReaderRolling:init() self.doc_height = self.ui.document.info.doc_height self.old_doc_height = self.doc_height + self.old_page = self.ui.document.info.number_of_pages end function ReaderRolling:onReadSettings(config) @@ -92,10 +94,21 @@ function ReaderRolling:onReadSettings(config) if not soe then self.show_overlap_enable = soe end - self:gotoPercent(config:readSetting("last_percent") or 0) - -- we have to do a real pos change in self.ui.document._document to - -- update status information in CREngine. - self.ui.document:gotoPos(self.current_pos) + -- we read last_percent just for backward compatibility + local last_per = config:readSetting("last_percent") + if last_per then + self:gotoPercent(last_per) + -- we have to do a real pos change in self.ui.document._document to + -- update status information in CREngine. + self.ui.document:gotoPos(self.current_pos) + end + local last_xp = config:readSetting("last_xpointer") + if last_xp then + self:gotoXPointer(last_xp) + -- we have to do a real jump in self.ui.document._document to + -- update status information in CREngine. + self.ui.document:gotoXPointer(last_xp) + end if self.view_mode == "page" then self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getCurrentPage())) end @@ -104,7 +117,9 @@ end function ReaderRolling:onCloseDocument() local cur_xp = self.ui.document:getXPointer() local cur_pos = self.ui.document:getPosFromXPointer(cur_xp) - self.ui.doc_settings:saveSetting("last_percent", 10000 * cur_pos / self.doc_height) + -- remove last_percent config since its deprecated + self.ui.doc_settings:saveSetting("last_percent", nil) + self.ui.doc_settings:saveSetting("last_xpointer", self.ui.document:getXPointer()) self.ui.doc_settings:saveSetting("percent_finished", cur_pos / self.doc_height) end @@ -172,9 +187,12 @@ function ReaderRolling:onUpdatePos() self.ui.document:_readMetadata() -- update self.current_pos if the height of document has been changed. local new_height = self.ui.document.info.doc_height - if self.old_doc_height ~= new_height then + local new_page = self.ui.document.info.number_of_pages + if self.old_doc_height ~= new_height or self.old_page ~= new_page then self:gotoXPointer(self.ui.document:getXPointer()) self.old_doc_height = new_height + self.old_page = new_page + self.ui:handleEvent(Event:new("UpdateToc")) end return true end diff --git a/frontend/ui/reader/readertoc.lua b/frontend/ui/reader/readertoc.lua index 1c7b9407f..4b5e2cee6 100644 --- a/frontend/ui/reader/readertoc.lua +++ b/frontend/ui/reader/readertoc.lua @@ -1,4 +1,5 @@ ReaderToc = InputContainer:new{ + toc = nil, toc_menu_title = "Table of contents", } @@ -21,6 +22,11 @@ function ReaderToc:onSetDimensions(dimen) self.dimen = dimen end +function ReaderToc:onUpdateToc() + self.toc = nil + return true +end + function ReaderToc:fillToc() self.toc = self.ui.document:getToc() end @@ -61,15 +67,19 @@ function ReaderToc:getTocTitleOfCurrentPage() end function ReaderToc:onShowToc() - local items = self.ui.document:getToc() + if not self.toc then + self:fillToc() + end -- build menu items - for _,v in ipairs(items) do - v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title) + if self.toc and not self.toc[1].text then + for _,v in ipairs(self.toc) do + v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title) + end end local toc_menu = Menu:new{ title = "Table of Contents", - item_table = items, + item_table = self.toc, ui = self.ui, width = Screen:getWidth()-20, height = Screen:getHeight(), diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index a49a79898..94d0beb64 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -171,6 +171,7 @@ end function ReaderView:onSetViewMode(new_mode) self.ui.view_mode = new_mode self.ui.document:setViewMode(new_mode) + self.ui:handleEvent(Event:new("UpdatePos")) return true end