Merge remote-tracking branch 'upstream/master'

resolved conflicts with refactored structure
pull/334/head
HW 11 years ago
commit 748a443cd5

@ -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

@ -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)

@ -13,7 +13,6 @@ local DjvuDocument = Document:new{
djvulibre_cache_size = nil,
dc_null = DrawContext.new(),
options = KoptOptions,
configurable = Configurable,
koptinterface = KoptInterface,
}

@ -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)

@ -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

@ -12,7 +12,6 @@ local PdfDocument = Document:new{
mupdf_cache_size = 5 * 1024 * 1024,
dc_null = DrawContext.new(),
options = KoptOptions,
configurable = Configurable,
koptinterface = KoptInterface,
}

@ -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

@ -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)

@ -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

@ -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")

@ -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

@ -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,
}

@ -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()

@ -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{

Loading…
Cancel
Save