From 789b5d57e29ec499e1b8052d763b81d99eb09daf Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 9 Jan 2013 16:41:42 +0800 Subject: [PATCH 1/5] read page information for crerengine --- frontend/document/document.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 From 3a65a9ddde7800b9faca3f472a08ab44f08c636c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 9 Jan 2013 16:45:11 +0800 Subject: [PATCH 2/5] also check page changes on UpdatePos event --- frontend/ui/reader/readerrolling.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index dcce27f01..4d920a174 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) @@ -172,9 +174,11 @@ 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 end return true end From 4c6420abba8bf7070e2abb7f7e960a91134a20b9 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 9 Jan 2013 16:53:32 +0800 Subject: [PATCH 3/5] fix: retrieve toc when page or height of document is changed --- frontend/ui/reader/readerrolling.lua | 1 + frontend/ui/reader/readertoc.lua | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index 4d920a174..6904c3b40 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -179,6 +179,7 @@ function ReaderRolling:onUpdatePos() 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(), From 688540c25bbd9b6875602d9d14b866fe2ded798f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 10 Jan 2013 10:06:47 +0800 Subject: [PATCH 4/5] singla UpdatePos event on view mode change this event also force renew toc --- frontend/ui/reader/readerview.lua | 1 + 1 file changed, 1 insertion(+) 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 From e7e6a2be9c3258c452a8329db3c2d56638e99480 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Fri, 11 Jan 2013 13:46:39 +0800 Subject: [PATCH 5/5] use xpointer instead of read percent to mark read progress --- frontend/ui/reader/readerrolling.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index 6904c3b40..892066332 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -94,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 @@ -106,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