From c86bb46ef7cf33aab730d5f5f91fd28996fb7dff Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 17 Oct 2013 23:53:29 +0800 Subject: [PATCH 1/9] add gotoLocation for credocument --- frontend/document/credocument.lua | 4 ++++ frontend/document/document.lua | 4 ++++ frontend/ui/reader/readerrolling.lua | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index a2a33b8b8..3f0288699 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -119,6 +119,10 @@ function CreDocument:close() Document.close(self) end +function CreDocument:getPageCount() + return self._document:getPages() +end + function CreDocument:drawCurrentView(target, x, y, rect, pos) tile_bb = Blitbuffer.new(rect.w, rect.h) self._document:drawCurrentPage(tile_bb) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index eeadb287f..a5b15a913 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -126,6 +126,10 @@ function Document:_readMetadata() return true end +function Document:getPageCount() + return self.info.number_of_pages +end + -- calculates page dimensions function Document:getPageDimensions(pageno, zoom, rotation) local native_dimen = self:getNativePageDimensions(pageno):copy() diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index 34eebc387..8edf074e9 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -325,4 +325,7 @@ function ReaderRolling:gotoPercent(new_percent) self:gotoPos(new_percent * self.doc_height / 10000) end - +function ReaderRolling:onGotoPage(number) + self:gotoPage(number) + return true +end From d7d2b9a20bc2b62ced31fd8033f41dba9b12bed7 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 17 Oct 2013 23:56:03 +0800 Subject: [PATCH 2/9] press Enter in Goto Dialog will goto page/location directly --- frontend/ui/reader/readergoto.lua | 11 +++++++++-- frontend/ui/widget/inputdialog.lua | 2 ++ frontend/ui/widget/inputtext.lua | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/ui/reader/readergoto.lua b/frontend/ui/reader/readergoto.lua index e0a59dfd4..f6f32d536 100644 --- a/frontend/ui/reader/readergoto.lua +++ b/frontend/ui/reader/readergoto.lua @@ -25,7 +25,7 @@ function ReaderGoto:onShowGotoDialog() DEBUG("show goto dialog") self.goto_dialog = InputDialog:new{ title = self.goto_dialog_title, - input_hint = "(1 - "..self.document.info.number_of_pages..")", + input_hint = "(1 - "..self.document:getPageCount()..")", buttons = { { { @@ -52,6 +52,9 @@ function ReaderGoto:onShowGotoDialog() }, }, input_type = "number", + enter_callback = self.document.info.has_pages + and function() self:gotoPage() end + or function() self:gotoLocation() end, width = Screen:getWidth() * 0.8, height = Screen:getHeight() * 0.2, } @@ -74,6 +77,10 @@ function ReaderGoto:gotoPage() end function ReaderGoto:gotoLocation() - -- TODO: implement go to location + local number = tonumber(self.goto_dialog:getInputText()) + if number then + self.ui:handleEvent(Event:new("GotoPage", number)) + end self:close() + return true end diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index 90859e0a2..bc033635e 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -7,6 +7,7 @@ InputDialog = InputContainer:new{ input_hint = "", buttons = nil, input_type = nil, + enter_callback = nil, width = nil, height = nil, @@ -38,6 +39,7 @@ function InputDialog:init() face = self.input_face, width = self.width * 0.9, input_type = self.input_type, + enter_callback = self.enter_callback, scroll = false, parent = self, } diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 7a69cc65f..e47bfa86f 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -94,6 +94,10 @@ function InputText:getKeyboardDimen() end function InputText:addChar(char) + if self.enter_callback and char == '\n' then + UIManager:scheduleIn(0.1, function() self.enter_callback() end) + return + end table.insert(self.charlist, self.charpos, char) self.charpos = self.charpos + 1 self.text = self:CharlistToString() From 1ccba6ce39a39890d17706ebe8b240c02277f550 Mon Sep 17 00:00:00 2001 From: chrox Date: Fri, 18 Oct 2013 00:02:55 +0800 Subject: [PATCH 3/9] use --utf8-input and --utf8-out params when calling sdcv This will prevent string encoding conversion in Kobo in which it has problem to doing so. This patch should fix #252 and #272. --- frontend/ui/reader/readerdictionary.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ui/reader/readerdictionary.lua b/frontend/ui/reader/readerdictionary.lua index 17e3f7769..ef3f512c9 100644 --- a/frontend/ui/reader/readerdictionary.lua +++ b/frontend/ui/reader/readerdictionary.lua @@ -19,7 +19,7 @@ function ReaderDictionary:stardictLookup(word) word = string.gsub(word, "%p+$", '') DEBUG("stripped word:", word) -- escape quotes and other funny characters in word - local std_out = io.popen("./sdcv -nj "..("%q"):format(word), "r") + local std_out = io.popen("./sdcv --utf8-input --utf8-output -nj "..("%q"):format(word), "r") local results_str = std_out:read("*all") if results_str then --DEBUG("result str:", word, results_str) From 957cfdbb1b1df37cc64346eebfd812fd65864c04 Mon Sep 17 00:00:00 2001 From: chrox Date: Fri, 18 Oct 2013 00:06:34 +0800 Subject: [PATCH 4/9] revert JSON hack since the unusual utf8 representation is fixed --- frontend/JSON.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/JSON.lua b/frontend/JSON.lua index d507d950e..4be1d95a9 100644 --- a/frontend/JSON.lua +++ b/frontend/JSON.lua @@ -326,8 +326,6 @@ local function grok_string(self, text, start, etc) elseif text:match('^\\t', i) then VALUE = VALUE .. "\t" i = i + 2 - elseif text:match('^\\\\', i) then - i = i + 1 else local hex = text:match('^\\u([0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF])', i) if hex then From 10bf048d770ebd9b886bb89beb924d369c6c2549 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 17 Oct 2013 17:28:20 -0400 Subject: [PATCH 5/9] move configurable to Document class since every document type is depend on it now --- frontend/document/credocument.lua | 1 - frontend/document/djvudocument.lua | 1 - frontend/document/document.lua | 10 ++++++---- frontend/document/pdfdocument.lua | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 3f0288699..e2afaaae5 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -16,7 +16,6 @@ CreDocument = Document:new{ fallback_font = "Droid Sans Fallback", default_css = "./data/cr3.css", options = CreOptions, - configurable = Configurable, } -- NuPogodi, 20.05.12: inspect the zipfile content diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index c8f71af8c..005abfd76 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -10,7 +10,6 @@ DjvuDocument = Document:new{ djvulibre_cache_size = nil, dc_null = DrawContext.new(), options = KoptOptions, - configurable = Configurable, koptinterface = KoptInterface, } diff --git a/frontend/document/document.lua b/frontend/document/document.lua index a5b15a913..6eb2a528e 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -60,24 +60,26 @@ Document = { number_of_pages = 0, -- if not pageable, length of the document in pixels doc_height = 0, - + -- other metadata title = "", author = "", date = "" }, - + GAMMA_NO_GAMMA = 1.0, - + -- override bbox from orignal page's getUsedBBox bbox = {}, - + -- flag to show whether the document was opened successfully is_open = false, error_message = nil, -- flag to show that the document needs to be unlocked by a password is_locked = false, + + configurable = Configurable, } function Document:new(o) diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index 1a376c826..dc6274b0b 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -10,7 +10,6 @@ PdfDocument = Document:new{ mupdf_cache_size = 5 * 1024 * 1024, dc_null = DrawContext.new(), options = KoptOptions, - configurable = Configurable, koptinterface = KoptInterface, } From a59723c053d7eda35e7c864445fce8931983868b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 17 Oct 2013 17:34:55 -0400 Subject: [PATCH 6/9] add pic document type --- frontend/document/document.lua | 1 + frontend/document/picdocument.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 frontend/document/picdocument.lua diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 6eb2a528e..47bc12166 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -315,3 +315,4 @@ end require "document/pdfdocument" require "document/djvudocument" require "document/credocument" +require "document/picdocument" diff --git a/frontend/document/picdocument.lua b/frontend/document/picdocument.lua new file mode 100644 index 000000000..19330750f --- /dev/null +++ b/frontend/document/picdocument.lua @@ -0,0 +1,26 @@ + +PicDocument = Document:new{ + _document = false, + dc_null = DrawContext.new(), +} + +function PicDocument:init() + ok, self._document = pcall(pic.openDocument, self.file) + if not ok then + self.error_message = "failed to open jpeg image" + return + end + + self.info.has_pages = true + self.info.configurable = false + + self:readMetadata() +end + +function PicDocument:readMetadata() + self.info.number_of_pages = 1 +end + + +DocumentRegistry:addProvider("jpeg", "application/jpeg", PicDocument) +DocumentRegistry:addProvider("jpg", "application/jpeg", PicDocument) From bc91b932d12f47ff1ef5601415bf8a89ed6bc347 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 17 Oct 2013 17:37:53 -0400 Subject: [PATCH 7/9] style cleanup in document.lua --- frontend/document/document.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 47bc12166..b2dfd9f9a 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -229,7 +229,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) size = rect end - -- prepare cache item with contained blitbuffer + -- prepare cache item with contained blitbuffer local tile = TileCacheItem:new{ size = size.w * size.h / 2 + 64, -- estimation excerpt = size, @@ -250,7 +250,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) dc:setOffset(0, page_size.h) end dc:setZoom(zoom) - + if gamma ~= self.GAMMA_NO_GAMMA then --DEBUG("gamma correction: ", gamma) dc:setGamma(gamma) @@ -296,7 +296,7 @@ function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma, re end DEBUG("now painting", tile, rect) target:blitFrom(tile.bb, - x, y, + x, y, rect.x - tile.excerpt.x, rect.y - tile.excerpt.y, rect.w, rect.h) From a7d545632aa4f936d7d84e52c6b58cf5ae746396 Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Fri, 18 Oct 2013 21:03:28 +0200 Subject: [PATCH 8/9] Nicer close button, solves #321. --- frontend/ui/widget/menu.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index fd713cf10..48e616b6b 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -68,12 +68,12 @@ MenuCloseButton = InputContainer:new{ function MenuCloseButton:init() self[1] = TextWidget:new{ - text = " X ", - face = Font:getFace("cfont", 42), + text = "×", + face = Font:getFace("cfont", 32), } local text_size = self[1]:getSize() - self.dimen.w, self.dimen.h = text_size.w, text_size.h + self.dimen.w, self.dimen.h = text_size.w*2, text_size.h*2 self.ges_events.Close = { GestureRange:new{ From 8b6bf2e72b1beadc6fe2e42f1374c77634c854d6 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 20 Oct 2013 12:32:35 +0800 Subject: [PATCH 9/9] export highlights only if highlighted text is not nil --- frontend/ui/reader/readerhighlight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ui/reader/readerhighlight.lua b/frontend/ui/reader/readerhighlight.lua index 3fcf5605b..db98334f6 100644 --- a/frontend/ui/reader/readerhighlight.lua +++ b/frontend/ui/reader/readerhighlight.lua @@ -320,7 +320,7 @@ end function ReaderHighlight:exportToClippings(page, item) DEBUG("export highlight to My Clippings") local clippings = io.open("/mnt/us/documents/My Clippings.txt", "a+") - if clippings then + if clippings and item.text then local current_locale = os.setlocale() os.setlocale("C") clippings:write(self.document.file:gsub("(.*/)(.*)", "%2").."\n")