2013-10-18 20:38:07 +00:00
|
|
|
local CreOptions = require("ui/data/creoptions")
|
|
|
|
local Document = require("document/document")
|
2014-08-14 11:49:42 +00:00
|
|
|
local Configurable = require("configurable")
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2014-01-17 19:05:17 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Screen = require("device").screen
|
2014-08-14 11:49:42 +00:00
|
|
|
local Font = require("ui/font")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2014-08-22 10:24:49 +00:00
|
|
|
local ffi = require("ffi")
|
2012-06-05 07:23:36 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local CreDocument = Document:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
|
|
|
SCROLL_VIEW_MODE = 0,
|
|
|
|
PAGE_VIEW_MODE = 1,
|
|
|
|
|
|
|
|
_document = false,
|
2014-08-28 12:59:42 +00:00
|
|
|
_loaded = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
engine_initilized = false,
|
|
|
|
|
|
|
|
line_space_percent = 100,
|
2014-07-08 00:11:17 +00:00
|
|
|
default_font = G_reader_settings:readSetting("cre_font") or "Noto Serif",
|
|
|
|
header_font = G_reader_settings:readSetting("header_font") or "Noto Sans",
|
2014-08-23 14:46:28 +00:00
|
|
|
fallback_font = G_reader_settings:readSetting("fallback_font") or "Droid Sans Fallback H",
|
2014-03-13 13:52:43 +00:00
|
|
|
default_css = "./data/cr3.css",
|
|
|
|
options = CreOptions,
|
2012-06-05 07:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- NuPogodi, 20.05.12: inspect the zipfile content
|
2014-08-11 12:37:50 +00:00
|
|
|
function CreDocument:zipContentExt(fname)
|
|
|
|
local std_out = io.popen("unzip ".."-qql \""..fname.."\"")
|
|
|
|
if std_out then
|
|
|
|
for line in std_out:lines() do
|
|
|
|
local size, ext = string.match(line, "%s+(%d+)%s+.+%.([^.]+)")
|
|
|
|
-- return the extention
|
|
|
|
if size and ext then return string.lower(ext) end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
end
|
2012-06-05 07:23:36 +00:00
|
|
|
end
|
|
|
|
|
2014-04-30 15:24:44 +00:00
|
|
|
function CreDocument:cacheInit()
|
|
|
|
-- remove legacy cr3cache directory
|
|
|
|
if lfs.attributes("./cr3cache", "mode") == "directory" then
|
|
|
|
os.execute("rm -r ./cr3cache")
|
|
|
|
end
|
|
|
|
cre.initCache("./cache/cr3cache", 1024*1024*32)
|
|
|
|
end
|
|
|
|
|
2012-06-12 06:52:35 +00:00
|
|
|
function CreDocument:engineInit()
|
2014-03-13 13:52:43 +00:00
|
|
|
if not engine_initilized then
|
|
|
|
-- initialize cache
|
2014-04-30 15:24:44 +00:00
|
|
|
self:cacheInit()
|
|
|
|
|
|
|
|
-- initialize hyph dictionaries
|
2014-06-17 13:48:07 +00:00
|
|
|
cre.initHyphDict("./data/hyph/")
|
2013-03-13 02:43:15 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we need to initialize the CRE font list
|
|
|
|
local fonts = Font:getFontList()
|
|
|
|
for _k, _v in ipairs(fonts) do
|
2014-07-02 14:47:24 +00:00
|
|
|
if _v:sub(1, 4) ~= "urw/" then
|
2014-03-13 13:52:43 +00:00
|
|
|
local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v)
|
|
|
|
if not ok then
|
|
|
|
DEBUG(err)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-12 06:52:35 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
engine_initilized = true
|
|
|
|
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()
|
2014-03-13 13:52:43 +00:00
|
|
|
require "libs/libkoreader-cre"
|
|
|
|
self:engineInit()
|
|
|
|
self.configurable:loadDefaults(self.options)
|
|
|
|
|
|
|
|
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
|
2014-08-11 12:37:50 +00:00
|
|
|
file_type = self:zipContentExt(self.file) or "unknown"
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
|
|
|
self.default_css = "./data/"..file_type..".css"
|
|
|
|
|
|
|
|
-- @TODO check the default view_mode to a global user configurable
|
|
|
|
-- variable 22.12 2012 (houqp)
|
2014-08-29 09:17:08 +00:00
|
|
|
local ok
|
2014-03-13 13:52:43 +00:00
|
|
|
ok, self._document = pcall(cre.newDocView,
|
|
|
|
Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE
|
|
|
|
)
|
|
|
|
if not ok then
|
2014-08-29 09:17:08 +00:00
|
|
|
error(self._document) -- will contain error message
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-04-02 20:59:17 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- adjust font sizes according to screen dpi
|
|
|
|
self._document:adjustFontSizes(Screen:getDPI())
|
2014-04-02 20:59:17 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- set fallback font face
|
|
|
|
self._document:setStringProperty("crengine.font.fallback.face", self.fallback_font)
|
2014-04-02 20:59:17 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.is_open = true
|
|
|
|
self.info.has_pages = false
|
|
|
|
self:_readMetadata()
|
|
|
|
self.info.configurable = true
|
2012-06-05 07:23:36 +00:00
|
|
|
end
|
|
|
|
|
2014-08-28 12:59:42 +00:00
|
|
|
function CreDocument:loadDocument()
|
|
|
|
if not self._loaded then
|
|
|
|
self._document:loadDocument(self.file)
|
|
|
|
self._loaded = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-28 05:22:31 +00:00
|
|
|
function CreDocument:render()
|
|
|
|
-- load document before rendering
|
2014-08-28 12:59:42 +00:00
|
|
|
self:loadDocument()
|
2014-10-07 06:05:34 +00:00
|
|
|
-- set visible page count in landscape
|
|
|
|
if math.max(Screen:getWidth(), Screen:getHeight()) / Screen:getDPI()
|
|
|
|
< DCREREADER_TWO_PAGE_THRESHOLD then
|
|
|
|
self:setVisiblePageCount(1)
|
|
|
|
end
|
2014-08-28 05:22:31 +00:00
|
|
|
self._document:renderDocument()
|
2014-03-13 13:52:43 +00:00
|
|
|
if not self.info.has_pages then
|
|
|
|
self.info.doc_height = self._document:getFullHeight()
|
|
|
|
end
|
2013-01-13 02:22:33 +00:00
|
|
|
end
|
|
|
|
|
2013-10-16 15:21:20 +00:00
|
|
|
function CreDocument:close()
|
2014-03-13 13:52:43 +00:00
|
|
|
Document.close(self)
|
2013-10-16 15:21:20 +00:00
|
|
|
end
|
|
|
|
|
2013-10-17 15:53:29 +00:00
|
|
|
function CreDocument:getPageCount()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getPages()
|
2013-10-17 15:53:29 +00:00
|
|
|
end
|
|
|
|
|
2014-08-22 10:24:49 +00:00
|
|
|
function CreDocument:getCoverPageImage()
|
2014-08-28 05:22:31 +00:00
|
|
|
-- don't need to render document in order to get cover image
|
2014-08-28 12:59:42 +00:00
|
|
|
self:loadDocument()
|
2014-08-22 10:24:49 +00:00
|
|
|
local data, size = self._document:getCoverPageImageData()
|
|
|
|
if data and size then
|
2014-10-18 22:22:35 +00:00
|
|
|
local Mupdf = require("ffi/mupdf")
|
2014-10-23 01:01:10 +00:00
|
|
|
local ok, image = pcall(Mupdf.renderImage, data, size)
|
|
|
|
if ok then
|
|
|
|
ffi.C.free(data)
|
|
|
|
return image
|
|
|
|
end
|
2014-08-22 10:24:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-24 17:42:57 +00:00
|
|
|
function CreDocument:getWordFromPosition(pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
local word_box = self._document:getWordFromPosition(pos.x, pos.y)
|
2014-07-02 06:47:05 +00:00
|
|
|
DEBUG("CreDocument: get word box", word_box)
|
2014-03-13 13:52:43 +00:00
|
|
|
local text_range = self._document:getTextFromPositions(pos.x, pos.y, pos.x, pos.y)
|
2014-07-02 06:47:05 +00:00
|
|
|
DEBUG("CreDocument: get text range", text_range)
|
|
|
|
local wordbox = {
|
|
|
|
word = text_range.text == "" and word_box.word or text_range.text,
|
|
|
|
page = self._document:getCurrentPage(),
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
if word_box.word then
|
2014-07-02 06:47:05 +00:00
|
|
|
wordbox.sbox = Geom:new{
|
|
|
|
x = word_box.x0, y = word_box.y0,
|
|
|
|
w = word_box.x1 - word_box.x0,
|
|
|
|
h = word_box.y1 - word_box.y0,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
-- dummy word box
|
|
|
|
wordbox.sbox = Geom:new{
|
|
|
|
x = pos.x, y = pos.y,
|
|
|
|
w = 20, h = 20,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2014-07-02 06:47:05 +00:00
|
|
|
return wordbox
|
2013-12-24 17:42:57 +00:00
|
|
|
end
|
|
|
|
|
2014-01-17 19:05:17 +00:00
|
|
|
function CreDocument:getTextFromPositions(pos0, pos1)
|
2014-03-13 13:52:43 +00:00
|
|
|
local text_range = self._document:getTextFromPositions(pos0.x, pos0.y, pos1.x, pos1.y)
|
|
|
|
DEBUG("CreDocument: get text range", text_range)
|
2014-11-06 03:18:04 +00:00
|
|
|
if text_range then
|
|
|
|
local line_boxes = self:getScreenBoxesFromPositions(text_range.pos0, text_range.pos1)
|
|
|
|
return {
|
|
|
|
text = text_range.text,
|
|
|
|
pos0 = text_range.pos0,
|
|
|
|
pos1 = text_range.pos1,
|
|
|
|
--sboxes = line_boxes, -- boxes on screen
|
|
|
|
}
|
|
|
|
end
|
2014-01-17 19:05:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getScreenBoxesFromPositions(pos0, pos1)
|
2014-03-13 13:52:43 +00:00
|
|
|
local line_boxes = {}
|
|
|
|
if pos0 and pos1 then
|
|
|
|
local word_boxes = self._document:getWordBoxesFromPositions(pos0, pos1)
|
|
|
|
--DEBUG("word boxes", word_boxes)
|
|
|
|
for i = 1, #word_boxes do
|
|
|
|
local line_box = word_boxes[i]
|
|
|
|
table.insert(line_boxes, Geom:new{
|
|
|
|
x = line_box.x0, y = line_box.y0,
|
|
|
|
w = line_box.x1 - line_box.x0,
|
|
|
|
h = line_box.y1 - line_box.y0,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
--DEBUG("line boxes", line_boxes)
|
|
|
|
end
|
|
|
|
return line_boxes
|
2013-12-24 17:42:57 +00:00
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
function CreDocument:drawCurrentView(target, x, y, rect, pos)
|
2014-10-27 14:03:20 +00:00
|
|
|
if self.buffer and (self.buffer.w ~= rect.w or self.buffer.h ~= rect.h) then
|
|
|
|
self.buffer:free()
|
|
|
|
self.buffer = nil
|
|
|
|
end
|
|
|
|
if not self.buffer then
|
|
|
|
self.buffer = Blitbuffer.new(rect.w, rect.h)
|
|
|
|
end
|
|
|
|
self._document:drawCurrentPage(self.buffer)
|
|
|
|
target:blitFrom(self.buffer, x, y, 0, 0, rect.w, rect.h)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:drawCurrentViewByPos(target, x, y, rect, pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:gotoPos(pos)
|
|
|
|
self:drawCurrentView(target, x, y, rect)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:drawCurrentViewByPage(target, x, y, rect, page)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:gotoPage(page)
|
|
|
|
self:drawCurrentView(target, x, y, rect)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
2012-06-05 07:23:36 +00:00
|
|
|
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-12-22 05:27:46 +00:00
|
|
|
function CreDocument:gotoXPointer(xpointer)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: goto xpointer", xpointer)
|
|
|
|
self._document:gotoXPointer(xpointer)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getXPointer()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getXPointer()
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getPosFromXPointer(xp)
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getPosFromXPointer(xp)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getPageFromXPointer(xp)
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getPageFromXPointer(xp)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:getFontFace()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getFontFace()
|
2012-06-12 12:58:15 +00:00
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
function CreDocument:getCurrentPos()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getCurrentPos()
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
2014-01-15 15:34:37 +00:00
|
|
|
function CreDocument:getPageLinks()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getPageLinks()
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
2014-01-20 12:41:01 +00:00
|
|
|
function CreDocument:getLinkFromPosition(pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getLinkFromPosition(pos.x, pos.y)
|
2014-01-20 12:41:01 +00:00
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
function Document:gotoPos(pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: goto position", pos)
|
|
|
|
self._document:gotoPos(pos)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:gotoPage(page)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: goto page", page)
|
|
|
|
self._document:gotoPage(page)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
2014-01-15 15:34:37 +00:00
|
|
|
function CreDocument:gotoLink(link)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: goto link", link)
|
|
|
|
self._document:gotoLink(link)
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:goBack()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: go back")
|
|
|
|
self._document:goBack()
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:goForward(link)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: go forward")
|
|
|
|
self._document:goForward()
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
function CreDocument:getCurrentPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getCurrentPage()
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:setFontFace(new_font_face)
|
2014-03-13 13:52:43 +00:00
|
|
|
if new_font_face then
|
|
|
|
DEBUG("CreDocument: set font face", new_font_face)
|
2014-05-11 12:57:18 +00:00
|
|
|
self._document:setStringProperty("font.face.default", new_font_face)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2012-06-12 09:42:02 +00:00
|
|
|
end
|
|
|
|
|
2014-11-15 11:22:47 +00:00
|
|
|
function CreDocument:setHyphDictionary(new_hyph_dictionary)
|
|
|
|
if new_hyph_dictionary then
|
|
|
|
DEBUG("CreDocument: set hyphenation dictionary", new_hyph_dictionary)
|
|
|
|
self._document:setStringProperty("crengine.hyphenation.directory", new_hyph_dictionary)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-22 09:16:37 +00:00
|
|
|
function CreDocument:clearSelection()
|
2014-11-05 04:28:11 +00:00
|
|
|
DEBUG("clear selection")
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:clearSelection()
|
2014-01-22 09:16:37 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:getFontSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self._document:getFontSize()
|
2012-06-12 12:58:15 +00:00
|
|
|
end
|
|
|
|
|
2012-12-17 06:50:50 +00:00
|
|
|
function CreDocument:setFontSize(new_font_size)
|
2014-03-13 13:52:43 +00:00
|
|
|
if new_font_size then
|
|
|
|
DEBUG("CreDocument: set font size", new_font_size)
|
|
|
|
self._document:setFontSize(new_font_size)
|
|
|
|
end
|
2012-12-17 06:50:50 +00:00
|
|
|
end
|
|
|
|
|
2013-01-07 11:53:35 +00:00
|
|
|
function CreDocument:setViewMode(new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
if new_mode then
|
|
|
|
DEBUG("CreDocument: set view mode", new_mode)
|
|
|
|
if new_mode == "scroll" then
|
|
|
|
self._document:setViewMode(self.SCROLL_VIEW_MODE)
|
|
|
|
else
|
|
|
|
self._document:setViewMode(self.PAGE_VIEW_MODE)
|
|
|
|
end
|
|
|
|
end
|
2013-01-07 11:53:35 +00:00
|
|
|
end
|
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
function CreDocument:setViewDimen(dimen)
|
|
|
|
DEBUG("CreDocument: set view dimen", dimen)
|
|
|
|
self._document:setViewDimen(dimen.w, dimen.h)
|
|
|
|
end
|
|
|
|
|
2013-01-13 03:23:30 +00:00
|
|
|
function CreDocument:setHeaderFont(new_font)
|
2014-03-13 13:52:43 +00:00
|
|
|
if new_font then
|
|
|
|
DEBUG("CreDocument: set header font", new_font)
|
|
|
|
self._document:setHeaderFont(new_font)
|
|
|
|
end
|
2013-01-13 03:23:30 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function CreDocument:zoomFont(delta)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: zoom font", delta)
|
|
|
|
self._document:zoomFont(delta)
|
2012-06-12 12:58:15 +00:00
|
|
|
end
|
2012-06-11 15:50:11 +00:00
|
|
|
|
2012-06-12 13:12:04 +00:00
|
|
|
function CreDocument:setInterlineSpacePercent(percent)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set interline space", percent)
|
|
|
|
self._document:setDefaultInterlineSpace(percent)
|
2012-06-12 13:12:04 +00:00
|
|
|
end
|
|
|
|
|
2014-06-04 13:54:01 +00:00
|
|
|
function CreDocument:toggleFontBolder(toggle)
|
|
|
|
DEBUG("CreDocument: toggle font bolder", toggle)
|
|
|
|
self._document:setIntProperty("font.face.weight.embolden", toggle)
|
2013-01-07 17:16:17 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 03:49:01 +00:00
|
|
|
function CreDocument:setGammaIndex(index)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set gamma index", index)
|
|
|
|
cre.setGammaIndex(index)
|
2013-01-13 03:49:01 +00:00
|
|
|
end
|
|
|
|
|
2013-01-17 21:59:40 +00:00
|
|
|
function CreDocument:setStyleSheet(new_css)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set style sheet", new_css)
|
|
|
|
self._document:setStyleSheet(new_css)
|
2013-01-21 22:27:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:setEmbeddedStyleSheet(toggle)
|
2014-05-12 07:47:11 +00:00
|
|
|
-- FIXME: occasional segmentation fault when switching embedded style sheet
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set embedded style sheet", toggle)
|
2014-05-12 07:47:11 +00:00
|
|
|
self._document:setIntProperty("crengine.doc.embedded.styles.enabled", toggle)
|
2013-01-17 21:59:40 +00:00
|
|
|
end
|
|
|
|
|
2013-06-28 09:12:04 +00:00
|
|
|
function CreDocument:setPageMargins(left, top, right, bottom)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set page margins", left, top, right, bottom)
|
2014-05-12 07:47:11 +00:00
|
|
|
self._document:setIntProperty("crengine.page.margin.left", left)
|
|
|
|
self._document:setIntProperty("crengine.page.margin.top", top)
|
|
|
|
self._document:setIntProperty("crengine.page.margin.right", right)
|
|
|
|
self._document:setIntProperty("crengine.page.margin.bottom", bottom)
|
2013-06-28 09:12:04 +00:00
|
|
|
end
|
|
|
|
|
2014-01-02 17:59:40 +00:00
|
|
|
function CreDocument:setFloatingPunctuation(enabled)
|
2014-07-22 13:54:05 +00:00
|
|
|
-- FIXME: occasional segmentation fault when toggling floating punctuation
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set floating punctuation", enabled)
|
|
|
|
self._document:setIntProperty("crengine.style.floating.punctuation.enabled", enabled)
|
2014-01-02 17:59:40 +00:00
|
|
|
end
|
|
|
|
|
2014-07-03 09:54:30 +00:00
|
|
|
function CreDocument:getVisiblePageCount()
|
|
|
|
return self._document:getVisiblePageCount()
|
|
|
|
end
|
|
|
|
|
2013-07-28 06:35:46 +00:00
|
|
|
function CreDocument:setVisiblePageCount(new_count)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set visible page count", new_count)
|
|
|
|
self._document:setVisiblePageCount(new_count)
|
2013-07-28 06:35:46 +00:00
|
|
|
end
|
|
|
|
|
2014-01-04 14:30:36 +00:00
|
|
|
function CreDocument:setBatteryState(state)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set battery state", state)
|
|
|
|
self._document:setBatteryState(state)
|
2014-01-04 14:30:36 +00:00
|
|
|
end
|
|
|
|
|
2014-01-18 11:18:12 +00:00
|
|
|
function CreDocument:isXPointerInCurrentPage(xp)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: check in page", xp)
|
|
|
|
return self._document:isXPointerInCurrentPage(xp)
|
2014-01-18 11:18:12 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function CreDocument:setStatusLineProp(prop)
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("CreDocument: set status line property", prop)
|
|
|
|
self._document:setStringProperty("window.status.line", prop)
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function CreDocument:findText(pattern, origin, reverse, caseInsensitive)
|
|
|
|
DEBUG("CreDocument: find text", pattern, origin, reverse, caseInsensitive)
|
|
|
|
return self._document:findText(pattern, origin, reverse, caseInsensitive)
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
function CreDocument:register(registry)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("txt", "application/txt", self)
|
2014-11-14 12:25:02 +00:00
|
|
|
registry:addProvider("txt.zip", "application/zip", self)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("epub", "application/epub", self)
|
|
|
|
registry:addProvider("fb2", "application/fb2", self)
|
2014-11-04 18:11:29 +00:00
|
|
|
registry:addProvider("fb2.zip", "application/zip", self)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("html", "application/html", self)
|
2014-11-14 12:25:02 +00:00
|
|
|
registry:addProvider("html.zip", "application/zip", self)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("htm", "application/htm", self)
|
2014-11-14 12:25:02 +00:00
|
|
|
registry:addProvider("htm.zip", "application/zip", self)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("rtf", "application/rtf", self)
|
|
|
|
registry:addProvider("mobi", "application/mobi", self)
|
|
|
|
registry:addProvider("prc", "application/prc", self)
|
|
|
|
registry:addProvider("azw", "application/azw", self)
|
|
|
|
registry:addProvider("chm", "application/chm", self)
|
|
|
|
registry:addProvider("pdb", "application/pdb", self)
|
|
|
|
registry:addProvider("doc", "application/doc", self)
|
|
|
|
registry:addProvider("tcr", "application/tcr", self)
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return CreDocument
|