mirror of https://github.com/koreader/koreader
first demo for credocument
parent
75ee86b2cb
commit
e7d16de4e2
@ -0,0 +1,79 @@
|
||||
require "cache"
|
||||
require "ui/geometry"
|
||||
|
||||
CreDocument = Document:new{
|
||||
_document = false,
|
||||
line_space_percent = 100,
|
||||
--dc_null = DrawContext.new()
|
||||
}
|
||||
|
||||
-- NuPogodi, 20.05.12: inspect the zipfile content
|
||||
function CreDocument:zipContentExt(fname)
|
||||
local outfile = "./data/zip_content"
|
||||
local s = ""
|
||||
os.execute("unzip ".."-l \""..fname.."\" > "..outfile)
|
||||
local i = 1
|
||||
if io.open(outfile,"r") then
|
||||
for lines in io.lines(outfile) do
|
||||
if i == 4 then s = lines break else i = i + 1 end
|
||||
end
|
||||
end
|
||||
-- return the extention
|
||||
return string.lower(string.match(s, ".+%.([^.]+)"))
|
||||
end
|
||||
|
||||
function CreDocument:init()
|
||||
-- we need to initialize the CRE font list
|
||||
local fonts = Font:getFontList()
|
||||
for _k, _v in ipairs(fonts) do
|
||||
local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v)
|
||||
if not ok then
|
||||
DEBUG(err)
|
||||
end
|
||||
end
|
||||
|
||||
--local default_font = G_reader_settings:readSetting("cre_font")
|
||||
--if default_font then
|
||||
--self.default_font = default_font
|
||||
--end
|
||||
|
||||
local ok
|
||||
local file_type = string.lower(string.match(self.file, ".+%.([^.]+)"))
|
||||
if file_type == "zip" then
|
||||
-- NuPogodi, 20.05.12: read the content of zip-file
|
||||
-- and return extention of the 1st file
|
||||
file_type = self:zipContentExt(filename)
|
||||
end
|
||||
-- these two format use the same css file
|
||||
if file_type == "html" then
|
||||
file_type = "htm"
|
||||
end
|
||||
-- if native css-file doesn't exist, one needs to use default cr3.css
|
||||
if not io.open("./data/"..file_type..".css") then
|
||||
file_type = "cr3"
|
||||
end
|
||||
local style_sheet = "./data/"..file_type..".css"
|
||||
|
||||
ok, self._document = pcall(cre.openDocument, self.file, style_sheet,
|
||||
G_width, G_height)
|
||||
if not ok then
|
||||
self.error_message = self.doc -- will contain error message
|
||||
return
|
||||
end
|
||||
self.is_open = true
|
||||
self.info.has_pages = false
|
||||
self:_readMetadata()
|
||||
|
||||
self._document:setDefaultInterlineSpace(self.line_space_percent)
|
||||
end
|
||||
|
||||
function CreDocument:hintPage(pageno, zoom, rotation)
|
||||
end
|
||||
|
||||
function CreDocument:drawPage(target, x, y, rect, pageno, zoom, rotation)
|
||||
end
|
||||
|
||||
function CreDocument:renderPage(pageno, rect, zoom, rotation)
|
||||
end
|
||||
|
||||
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
@ -0,0 +1,50 @@
|
||||
ReaderRolling = InputContainer:new{
|
||||
key_events = {
|
||||
GotoNextView = { {Input.group.PgFwd}, doc = "go to next view", event = "GotoViewRel", args = 1 },
|
||||
GotoPrevView = { {Input.group.PgBack}, doc = "go to previous view", event = "GotoViewRel", args = -1 },
|
||||
|
||||
GotoFirst = { {"1"}, doc = "go to start", event = "GotoPercent", args = 0},
|
||||
Goto11 = { {"2"}, doc = "go to 11%", event = "GotoPercent", args = 11},
|
||||
Goto22 = { {"3"}, doc = "go to 22%", event = "GotoPercent", args = 22},
|
||||
Goto33 = { {"4"}, doc = "go to 33%", event = "GotoPercent", args = 33},
|
||||
Goto44 = { {"5"}, doc = "go to 44%", event = "GotoPercent", args = 44},
|
||||
Goto55 = { {"6"}, doc = "go to 55%", event = "GotoPercent", args = 55},
|
||||
Goto66 = { {"7"}, doc = "go to 66%", event = "GotoPercent", args = 66},
|
||||
Goto77 = { {"8"}, doc = "go to 77%", event = "GotoPercent", args = 77},
|
||||
Goto88 = { {"9"}, doc = "go to 88%", event = "GotoPercent", args = 88},
|
||||
GotoLast = { {"0"}, doc = "go to end", event = "GotoPercent", args = 100},
|
||||
},
|
||||
current_pos = 0,
|
||||
length = nil,
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
self.length = self.ui.document.info.length
|
||||
end
|
||||
|
||||
function ReaderRolling:onPosUpdate(new_pos)
|
||||
self.current_pos = new_pos
|
||||
end
|
||||
|
||||
function ReaderRolling:gotoPos(new_pos)
|
||||
if new_pos == self.current_pos then return end
|
||||
if new_pos < 0 then new_pos = 0 end
|
||||
if new_pos > self.length then new_pos = self.length end
|
||||
self.ui:handleEvent(Event:new("PosUpdate", new_pos))
|
||||
end
|
||||
|
||||
function ReaderRolling:onGotoPercent(percent)
|
||||
DEBUG("goto document offset in percent:", percent)
|
||||
self:gotoPos(percent * self.length / 10000)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderRolling:onGotoViewRel(diff)
|
||||
DEBUG("goto relative screen:", diff)
|
||||
self:gotoPos(self.current_pos + diff * self.ui.dimen.h)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderRolling:onZoom()
|
||||
--@TODO re-read length info after font or lineheight changes 05.06 2012 (houqp)
|
||||
end
|
Loading…
Reference in New Issue