2012-06-05 07:23:36 +00:00
|
|
|
require "ui/geometry"
|
|
|
|
|
|
|
|
CreDocument = Document:new{
|
|
|
|
_document = false,
|
2012-06-12 06:52:35 +00:00
|
|
|
engine_initilized = false,
|
|
|
|
|
2012-06-05 07:23:36 +00:00
|
|
|
line_space_percent = 100,
|
2012-06-12 06:52:35 +00:00
|
|
|
default_font = "Droid Sans Fallback",
|
2012-06-05 07:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2012-06-12 06:52:35 +00:00
|
|
|
function CreDocument:engineInit()
|
|
|
|
if not engine_initilized then
|
|
|
|
-- 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
|
2012-06-05 07:23:36 +00:00
|
|
|
end
|
2012-06-12 06:52:35 +00:00
|
|
|
|
|
|
|
engine_initilized = true
|
2012-06-05 07:23:36 +00:00
|
|
|
end
|
2012-06-12 06:52:35 +00:00
|
|
|
end
|
2012-06-05 07:23:36 +00:00
|
|
|
|
2012-06-12 06:52:35 +00:00
|
|
|
function CreDocument:init()
|
|
|
|
self:engineInit()
|
2012-06-05 07:23:36 +00:00
|
|
|
|
|
|
|
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,
|
2012-06-10 15:36:19 +00:00
|
|
|
Screen:getWidth(), Screen:getHeight())
|
2012-06-05 07:23:36 +00:00
|
|
|
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()
|
|
|
|
|
2012-06-12 13:12:04 +00:00
|
|
|
-- @TODO read line_space_percent from setting file 12.06 2012 (houqp)
|
|
|
|
--self._document:setDefaultInterlineSpace(self.line_space_percent)
|
2012-06-05 07:23:36 +00:00
|
|
|
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
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:getFontFace()
|
|
|
|
return self._document:getFontFace()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:setFontFace(new_font_face)
|
|
|
|
if new_font_face then
|
2012-06-12 09:42:02 +00:00
|
|
|
self._document:setFontFace(new_font_face)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:getFontSize()
|
|
|
|
return self._document:getFontSize()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:zoomFont(delta)
|
|
|
|
self._document:zoomFont(delta)
|
|
|
|
end
|
2012-06-11 15:50:11 +00:00
|
|
|
|
2012-06-12 13:12:04 +00:00
|
|
|
function CreDocument:setInterlineSpacePercent(percent)
|
|
|
|
self._document:setDefaultInterlineSpace(percent)
|
|
|
|
end
|
|
|
|
|
2012-06-05 07:23:36 +00:00
|
|
|
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
2012-06-11 15:50:11 +00:00
|
|
|
DocumentRegistry:addProvider("epub", "application/epub", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("html", "application/html", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("htm", "application/htm", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("zip", "application/zip", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("rtf", "application/rtf", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("mobi", "application/mobi", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("prc", "application/prc", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("azw", "application/azw", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("chm", "application/chm", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("pdb", "application/pdb", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("doc", "application/doc", CreDocument)
|
|
|
|
DocumentRegistry:addProvider("tcr", "application/tcr", CreDocument)
|