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 diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 687ba9986..9cd29ed33 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -20,7 +20,6 @@ local 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 @@ -123,6 +122,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/djvudocument.lua b/frontend/document/djvudocument.lua index e8d141229..ab2260c7e 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -13,7 +13,6 @@ local 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 34662ffc0..19fbbf99b 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -26,24 +26,26 @@ local 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) @@ -92,6 +94,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() @@ -189,7 +195,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, @@ -210,7 +216,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) @@ -256,7 +262,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) diff --git a/frontend/document/documentregistry.lua b/frontend/document/documentregistry.lua index 2a5437cff..21ae9969a 100644 --- a/frontend/document/documentregistry.lua +++ b/frontend/document/documentregistry.lua @@ -31,5 +31,6 @@ end require("document/pdfdocument"):register(DocumentRegistry) require("document/djvudocument"):register(DocumentRegistry) require("document/credocument"):register(DocumentRegistry) +require("document/picdocument"):register(DocumentRegistry) return DocumentRegistry diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index bd9977fee..ece5944b4 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -12,7 +12,6 @@ local PdfDocument = Document:new{ mupdf_cache_size = 5 * 1024 * 1024, dc_null = DrawContext.new(), options = KoptOptions, - configurable = Configurable, koptinterface = KoptInterface, } diff --git a/frontend/document/picdocument.lua b/frontend/document/picdocument.lua new file mode 100644 index 000000000..fa0d329ed --- /dev/null +++ b/frontend/document/picdocument.lua @@ -0,0 +1,31 @@ +local Document = require("document/document") +-- DrawContext + +local 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 + +function PicDocument:register(registry) + registry:addProvider("jpeg", "application/jpeg", self) + registry:addProvider("jpg", "application/jpeg", self) +end + +return PicDocument diff --git a/frontend/ui/reader/readerdictionary.lua b/frontend/ui/reader/readerdictionary.lua index 75de3e792..719c6ff46 100644 --- a/frontend/ui/reader/readerdictionary.lua +++ b/frontend/ui/reader/readerdictionary.lua @@ -18,7 +18,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) diff --git a/frontend/ui/reader/readergoto.lua b/frontend/ui/reader/readergoto.lua index 38e8070a6..ce58115a2 100644 --- a/frontend/ui/reader/readergoto.lua +++ b/frontend/ui/reader/readergoto.lua @@ -28,7 +28,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 = { { { @@ -55,6 +55,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, } @@ -77,8 +80,12 @@ 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 return ReaderGoto diff --git a/frontend/ui/reader/readerhighlight.lua b/frontend/ui/reader/readerhighlight.lua index edd7e9838..9f5ad7506 100644 --- a/frontend/ui/reader/readerhighlight.lua +++ b/frontend/ui/reader/readerhighlight.lua @@ -331,7 +331,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") diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index a89e2b35e..9b8f373a6 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -333,4 +333,9 @@ function ReaderRolling:gotoPercent(new_percent) self:gotoPos(new_percent * self.doc_height / 10000) end +function ReaderRolling:onGotoPage(number) + self:gotoPage(number) + return true +end + return ReaderRolling diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index a534dbbae..b564dff07 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -17,6 +17,7 @@ local InputDialog = InputContainer:new{ input_hint = "", buttons = nil, input_type = nil, + enter_callback = nil, width = nil, height = nil, @@ -48,6 +49,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 e46603eac..7e4258424 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -98,6 +98,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() diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 0e715f61c..a728a5f63 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -83,12 +83,12 @@ local 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{