2014-08-14 11:49:42 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2019-03-03 02:50:05 +00:00
|
|
|
local CanvasContext = require("document/canvascontext")
|
2015-10-03 06:18:47 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2017-04-01 15:55:15 +00:00
|
|
|
local Document = require("document/document")
|
2019-03-03 02:50:05 +00:00
|
|
|
local FontList = require("fontlist")
|
2014-01-17 19:05:17 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2018-04-21 20:03:04 +00:00
|
|
|
local RenderImage = require("ui/renderimage")
|
2019-04-18 21:26:53 +00:00
|
|
|
local Screen = require("device").screen
|
2014-08-22 10:24:49 +00:00
|
|
|
local ffi = require("ffi")
|
2018-06-02 16:10:55 +00:00
|
|
|
local C = ffi.C
|
2017-04-01 15:55:15 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
|
|
|
local logger = require("logger")
|
2012-06-05 07:23:36 +00:00
|
|
|
|
2017-04-26 19:46:46 +00:00
|
|
|
-- engine can be initialized only once, on first document opened
|
|
|
|
local engine_initialized = false
|
|
|
|
|
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,
|
2019-02-03 08:58:48 +00:00
|
|
|
_view_mode = nil,
|
2019-04-18 21:26:53 +00:00
|
|
|
_smooth_scaling = false,
|
2019-06-25 22:23:41 +00:00
|
|
|
_nightmode_images = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
|
|
|
|
line_space_percent = 100,
|
2018-05-11 15:48:26 +00:00
|
|
|
default_font = "Noto Serif",
|
|
|
|
header_font = "Noto Sans",
|
|
|
|
fallback_font = "Noto Sans CJK SC",
|
2014-03-13 13:52:43 +00:00
|
|
|
default_css = "./data/cr3.css",
|
2018-02-02 20:21:52 +00:00
|
|
|
provider = "crengine",
|
[feat] DocumentRegistry: add getProviders() and preferred by weight (#3651)
This is step one toward "open with".
References https://github.com/koreader/koreader/issues/3345
* Fix up some mimetypes
* Add XHTML to supported filetypes
* Add a few image files to MuPDF
* ".bmp",
* ".gif",
* ".hdp",
* ".j2k",
* ".jp2",
* ".jpeg",
* ".jpg",
* ".jpx",
* ".jxr",
* ".pam",
* ".pbm",
* ".pgm",
* ".png",
* ".pnm",
* ".ppm",
* ".tif",
* ".tiff",
* ".wdp",
2018-01-31 19:49:21 +00:00
|
|
|
provider_name = "Cool Reader Engine",
|
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
|
2018-03-15 13:09:24 +00:00
|
|
|
-- crengine saves caches on disk for faster re-openings, and cleans
|
|
|
|
-- the less recently used ones when this limit is reached
|
|
|
|
local default_cre_disk_cache_max_size = 64 -- in MB units
|
2018-03-08 20:23:52 +00:00
|
|
|
-- crengine various in-memory caches max-sizes are rather small
|
|
|
|
-- (2.5 / 4.5 / 1.5 / 1 MB), and we can avoid some bugs if we
|
|
|
|
-- increase them. Let's multiply them by 20 (each cache would
|
|
|
|
-- grow only when needed, depending on book characteristics).
|
|
|
|
-- People who would get out of memory crashes with big books on
|
|
|
|
-- older devices can decrease that with setting:
|
|
|
|
-- "cre_storage_size_factor"=1 (or 2, or 5)
|
|
|
|
local default_cre_storage_size_factor = 20
|
2018-03-15 13:09:24 +00:00
|
|
|
cre.initCache(DataStorage:getDataDir() .. "/cache/cr3cache",
|
|
|
|
(G_reader_settings:readSetting("cre_disk_cache_max_size") or default_cre_disk_cache_max_size)*1024*1024,
|
2018-03-01 20:55:05 +00:00
|
|
|
G_reader_settings:nilOrTrue("cre_compress_cached_data"),
|
2018-03-08 20:23:52 +00:00
|
|
|
G_reader_settings:readSetting("cre_storage_size_factor") or default_cre_storage_size_factor)
|
2014-04-30 15:24:44 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 06:52:35 +00:00
|
|
|
function CreDocument:engineInit()
|
2017-04-26 19:46:46 +00:00
|
|
|
if not engine_initialized then
|
2016-03-19 06:22:17 +00:00
|
|
|
require "libs/libkoreader-cre"
|
2014-03-13 13:52:43 +00:00
|
|
|
-- 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
|
2019-03-03 02:50:05 +00:00
|
|
|
local fonts = FontList:getFontList()
|
2014-03-13 13:52:43 +00:00
|
|
|
for _k, _v in ipairs(fonts) do
|
2015-01-25 08:52:01 +00:00
|
|
|
if not _v:find("/urw/") then
|
|
|
|
local ok, err = pcall(cre.registerFont, _v)
|
2014-03-13 13:52:43 +00:00
|
|
|
if not ok then
|
2018-07-01 15:35:12 +00:00
|
|
|
logger.err("failed to register crengine font:", err)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-12 06:52:35 +00:00
|
|
|
|
2017-04-26 19:46:46 +00:00
|
|
|
engine_initialized = true
|
2014-03-13 13:52:43 +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()
|
2017-10-01 17:23:06 +00:00
|
|
|
self:updateColorRendering()
|
2014-03-13 13:52:43 +00:00
|
|
|
self:engineInit()
|
|
|
|
|
|
|
|
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
|
2018-06-06 11:18:29 +00:00
|
|
|
|
|
|
|
-- June 2018: epub.css has been cleaned to be more conforming to HTML specs
|
|
|
|
-- and to not include class name based styles (with conditional compatiblity
|
|
|
|
-- styles for previously opened documents). It should be usable on all
|
|
|
|
-- HTML based documents, except FB2 which has some incompatible specs.
|
|
|
|
-- The other css files (htm.css, rtf.css...) have not been updated in the
|
|
|
|
-- same way, and are kept as-is for when a previously opened document
|
|
|
|
-- requests one of them.
|
|
|
|
self.default_css = "./data/epub.css"
|
|
|
|
if file_type == "fb2" then
|
|
|
|
self.default_css = "./data/fb2.css"
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
2019-02-03 08:58:48 +00:00
|
|
|
-- This mode must be the same as the default one set as ReaderView.view_mode
|
|
|
|
self._view_mode = DCREREADER_VIEW_MODE == "scroll" and self.SCROLL_VIEW_MODE or self.PAGE_VIEW_MODE
|
|
|
|
|
2014-08-29 09:17:08 +00:00
|
|
|
local ok
|
2019-02-18 16:01:00 +00:00
|
|
|
ok, self._document = pcall(cre.newDocView, CanvasContext:getWidth(), CanvasContext:getHeight(), self._view_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
|
|
|
2018-01-03 08:43:49 +00:00
|
|
|
-- We would have liked to call self._document:loadDocument(self.file)
|
|
|
|
-- here, to detect early if file is a supported document, but we
|
|
|
|
-- need to delay it till after some crengine settings are set for a
|
|
|
|
-- consistent behaviour.
|
|
|
|
|
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
|
|
|
|
|
2018-05-04 22:38:50 +00:00
|
|
|
function CreDocument:getLatestDomVersion()
|
2018-05-24 22:22:08 +00:00
|
|
|
return cre.getLatestDomVersion()
|
2018-05-04 22:38:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getOldestDomVersion()
|
|
|
|
return 20171225 -- arbitrary day in the past
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:requestDomVersion(version)
|
2018-05-24 22:22:08 +00:00
|
|
|
logger.dbg("CreDocument: requesting DOM version:", version)
|
|
|
|
cre.requestDomVersion(version)
|
2018-05-04 22:38:50 +00:00
|
|
|
end
|
|
|
|
|
2018-11-20 20:07:59 +00:00
|
|
|
function CreDocument:setupDefaultView()
|
|
|
|
if self.loaded then
|
|
|
|
-- Don't apply defaults if the document has already been loaded
|
|
|
|
-- as this must be done before calling loadDocument()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- have crengine load defaults from cr3.ini
|
|
|
|
self._document:readDefaults()
|
|
|
|
logger.dbg("CreDocument: applied cr3.ini default settings.")
|
|
|
|
|
|
|
|
-- set fallback font face (this was formerly done in :init(), but it
|
|
|
|
-- affects crengine calcGlobalSettingsHash() and would invalidate the
|
|
|
|
-- cache from the main currently being read document when we just
|
|
|
|
-- loadDocument(only_metadata) another document go get its metadata
|
|
|
|
-- or cover image, eg. from History hold menu).
|
|
|
|
self._document:setStringProperty("crengine.font.fallback.face",
|
|
|
|
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
|
|
|
|
|
2019-02-18 16:01:00 +00:00
|
|
|
-- adjust font sizes according to dpi set in canvas context
|
|
|
|
self._document:adjustFontSizes(CanvasContext:getDPI())
|
2018-11-20 20:07:59 +00:00
|
|
|
|
|
|
|
-- set top status bar font size
|
|
|
|
if G_reader_settings:readSetting("cre_header_status_font_size") then
|
|
|
|
self._document:setIntProperty("crengine.page.header.font.size",
|
|
|
|
G_reader_settings:readSetting("cre_header_status_font_size"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-10 21:20:54 +00:00
|
|
|
function CreDocument:loadDocument(full_document)
|
2014-08-28 12:59:42 +00:00
|
|
|
if not self._loaded then
|
2018-03-10 21:20:54 +00:00
|
|
|
local only_metadata = full_document == false
|
2018-08-07 16:37:52 +00:00
|
|
|
logger.dbg("CreDocument: loading document...")
|
2019-03-14 12:59:32 +00:00
|
|
|
if only_metadata then
|
|
|
|
-- Setting a default font before loading document
|
|
|
|
-- actually do prevent some crashes
|
|
|
|
self:setFontFace(self.default_font)
|
|
|
|
end
|
2018-03-10 21:20:54 +00:00
|
|
|
if self._document:loadDocument(self.file, only_metadata) then
|
2018-01-03 08:43:49 +00:00
|
|
|
self._loaded = true
|
2018-08-07 16:37:52 +00:00
|
|
|
logger.dbg("CreDocument: loading done.")
|
|
|
|
else
|
|
|
|
logger.dbg("CreDocument: loading failed.")
|
2018-01-03 08:43:49 +00:00
|
|
|
end
|
2014-08-28 12:59:42 +00:00
|
|
|
end
|
2018-01-03 08:43:49 +00:00
|
|
|
return self._loaded
|
2014-08-28 12:59:42 +00:00
|
|
|
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()
|
2019-03-13 12:07:30 +00:00
|
|
|
-- This is now configurable and done by ReaderRolling:
|
|
|
|
-- -- set visible page count in landscape
|
|
|
|
-- if math.max(CanvasContext:getWidth(), CanvasContext:getHeight()) / CanvasContext:getDPI()
|
|
|
|
-- < DCREREADER_TWO_PAGE_THRESHOLD then
|
|
|
|
-- self:setVisiblePageCount(1)
|
|
|
|
-- end
|
2018-08-07 16:37:52 +00:00
|
|
|
logger.dbg("CreDocument: rendering document...")
|
2014-08-28 05:22:31 +00:00
|
|
|
self._document:renderDocument()
|
2019-02-26 06:19:55 +00:00
|
|
|
self.info.doc_height = self._document:getFullHeight()
|
|
|
|
self.been_rendered = true
|
|
|
|
logger.dbg("CreDocument: rendering done.")
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:_readMetadata()
|
|
|
|
Document._readMetadata(self) -- will grab/update self.info.number_of_pages
|
|
|
|
if self.been_rendered then
|
|
|
|
-- getFullHeight() would crash if the document is not
|
|
|
|
-- yet rendered
|
2014-03-13 13:52:43 +00:00
|
|
|
self.info.doc_height = self._document:getFullHeight()
|
|
|
|
end
|
2019-02-26 06:19:55 +00:00
|
|
|
return true
|
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)
|
2017-10-01 17:23:06 +00:00
|
|
|
if self.buffer then
|
|
|
|
self.buffer:free()
|
|
|
|
self.buffer = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:updateColorRendering()
|
|
|
|
Document.updateColorRendering(self) -- will set self.render_color
|
|
|
|
-- Delete current buffer, a new one will be created according
|
|
|
|
-- to self.render_color
|
|
|
|
if self.buffer then
|
|
|
|
self.buffer:free()
|
|
|
|
self.buffer = nil
|
|
|
|
end
|
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()
|
2018-04-21 20:03:04 +00:00
|
|
|
-- no need to render document in order to get cover image
|
2018-01-03 08:43:49 +00:00
|
|
|
if not self:loadDocument() then
|
|
|
|
return nil -- not recognized by crengine
|
|
|
|
end
|
2014-08-22 10:24:49 +00:00
|
|
|
local data, size = self._document:getCoverPageImageData()
|
|
|
|
if data and size then
|
2018-04-21 20:03:04 +00:00
|
|
|
local image = RenderImage:renderImageData(data, size)
|
2018-06-02 16:10:55 +00:00
|
|
|
C.free(data) -- free the userdata we got from crengine
|
2018-04-21 20:03:04 +00:00
|
|
|
return image
|
2017-01-15 20:42:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-21 20:03:04 +00:00
|
|
|
function CreDocument:getImageFromPosition(pos, want_frames)
|
2017-01-15 20:42:04 +00:00
|
|
|
local data, size = self._document:getImageDataFromPosition(pos.x, pos.y)
|
|
|
|
if data and size then
|
|
|
|
logger.dbg("CreDocument: got image data from position", data, size)
|
2018-04-21 20:03:04 +00:00
|
|
|
local image = RenderImage:renderImageData(data, size, want_frames)
|
2018-06-02 16:10:55 +00:00
|
|
|
C.free(data) -- free the userdata we got from crengine
|
2018-04-21 20:03:04 +00:00
|
|
|
return image
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: get text range", text_range)
|
2014-07-02 06:47:05 +00:00
|
|
|
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
|
2019-03-13 12:10:32 +00:00
|
|
|
if text_range then
|
|
|
|
-- add xpointers if found, might be useful for across pages highlighting
|
|
|
|
wordbox.pos0 = text_range.pos0
|
|
|
|
wordbox.pos1 = text_range.pos1
|
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: get text range", text_range)
|
2014-11-06 03:18:04 +00:00
|
|
|
if text_range then
|
2016-02-15 09:33:48 +00:00
|
|
|
-- local line_boxes = self:getScreenBoxesFromPositions(text_range.pos0, text_range.pos1)
|
2014-11-06 03:18:04 +00:00
|
|
|
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
|
|
|
|
|
2018-10-08 16:57:59 +00:00
|
|
|
function CreDocument:getScreenBoxesFromPositions(pos0, pos1, get_segments)
|
2014-03-13 13:52:43 +00:00
|
|
|
local line_boxes = {}
|
|
|
|
if pos0 and pos1 then
|
2018-10-08 16:57:59 +00:00
|
|
|
local word_boxes = self._document:getWordBoxesFromPositions(pos0, pos1, get_segments)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
return line_boxes
|
2013-12-24 17:42:57 +00:00
|
|
|
end
|
|
|
|
|
2019-02-17 15:15:32 +00:00
|
|
|
function CreDocument:compareXPointers(xp1, xp2)
|
|
|
|
-- Returns 1 if XPointers are ordered (if xp2 is after xp1), -1 if not, 0 if same
|
|
|
|
return self._document:compareXPointers(xp1, xp2)
|
|
|
|
end
|
|
|
|
|
2019-02-15 23:42:27 +00:00
|
|
|
function CreDocument:getNextVisibleWordStart(xp)
|
|
|
|
return self._document:getNextVisibleWordStart(xp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getNextVisibleWordEnd(xp)
|
|
|
|
return self._document:getNextVisibleWordEnd(xp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getPrevVisibleWordStart(xp)
|
|
|
|
return self._document:getPrevVisibleWordStart(xp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getPrevVisibleWordEnd(xp)
|
|
|
|
return self._document:getPrevVisibleWordEnd(xp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getPrevVisibleChar(xp)
|
|
|
|
return self._document:getPrevVisibleChar(xp)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getNextVisibleChar(xp)
|
|
|
|
return self._document:getNextVisibleChar(xp)
|
|
|
|
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
|
2017-10-01 17:23:06 +00:00
|
|
|
-- Note about color rendering:
|
2019-03-27 21:50:44 +00:00
|
|
|
-- We use TYPE_BBRGB32 (and LVColorDrawBuf drawBuf(..., 32) in cre.cpp),
|
|
|
|
-- to match the screen's BB type, allowing us to take shortcuts when blitting.
|
|
|
|
self.buffer = Blitbuffer.new(rect.w, rect.h, self.render_color and Blitbuffer.TYPE_BBRGB32 or nil)
|
2014-10-27 14:03:20 +00:00
|
|
|
end
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @todo self.buffer could be re-used when no page/layout/highlights
|
2018-10-08 16:57:59 +00:00
|
|
|
-- change has been made, to avoid having crengine redraw the exact
|
2019-03-29 23:04:38 +00:00
|
|
|
-- same buffer. And it could only change when some other methods
|
|
|
|
-- from here are called
|
|
|
|
|
2019-04-18 21:26:53 +00:00
|
|
|
-- If in night mode, we ask crengine to invert all images, so they
|
2019-03-29 23:04:38 +00:00
|
|
|
-- get displayed in their original colors when the whole screen
|
|
|
|
-- is inverted by night mode
|
2019-04-18 21:26:53 +00:00
|
|
|
-- We also honor the current smooth scaling setting,
|
|
|
|
-- as well as the global SW dithering setting.
|
2019-03-29 23:04:38 +00:00
|
|
|
|
|
|
|
-- local start_clock = os.clock()
|
|
|
|
self._drawn_images_count, self._drawn_images_surface_ratio =
|
2019-06-25 22:23:41 +00:00
|
|
|
self._document:drawCurrentPage(self.buffer, self.render_color, Screen.night_mode and self._nightmode_images, self._smooth_scaling, Screen.sw_dithering)
|
2019-03-29 23:04:38 +00:00
|
|
|
-- print(string.format("CreDocument:drawCurrentView: Rendering took %9.3f ms", (os.clock() - start_clock) * 1000))
|
|
|
|
|
|
|
|
-- start_clock = os.clock()
|
2014-10-27 14:03:20 +00:00
|
|
|
target:blitFrom(self.buffer, x, y, 0, 0, rect.w, rect.h)
|
2019-03-29 23:04:38 +00:00
|
|
|
-- print(string.format("CreDocument:drawCurrentView: Blitting took %9.3f ms", (os.clock() - start_clock) * 1000))
|
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
|
|
|
|
|
2018-10-12 15:51:58 +00:00
|
|
|
function CreDocument:getPageMargins()
|
|
|
|
return self._document:getPageMargins()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getHeaderHeight()
|
|
|
|
return self._document:getHeaderHeight()
|
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
function CreDocument:gotoXPointer(xpointer)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: goto xpointer", xpointer)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
|
|
|
|
2017-01-15 20:42:04 +00:00
|
|
|
function CreDocument:isXPointerInDocument(xp)
|
|
|
|
return self._document:isXPointerInDocument(xp)
|
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
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
|
|
|
|
|
2019-02-03 08:58:48 +00:00
|
|
|
function CreDocument:getScreenPositionFromXPointer(xp)
|
|
|
|
-- We do not ensure xp is in the current page: we may return
|
|
|
|
-- a negative screen_y, which could be useful in some contexts
|
|
|
|
local doc_margins = self:getPageMargins()
|
|
|
|
local doc_y, doc_x = self:getPosFromXPointer(xp)
|
|
|
|
local top_y = self:getCurrentPos()
|
|
|
|
local screen_y = doc_y - top_y
|
2019-03-13 12:09:44 +00:00
|
|
|
local screen_x = doc_x + doc_margins["left"]
|
2019-02-03 08:58:48 +00:00
|
|
|
if self._view_mode == self.PAGE_VIEW_MODE then
|
2019-03-13 12:09:44 +00:00
|
|
|
if self:getVisiblePageCount() > 1 then
|
|
|
|
-- Correct coordinates if on the 2nd page in 2-pages mode
|
|
|
|
local next_page = self:getCurrentPage() + 1
|
|
|
|
if next_page <= self:getPageCount() then
|
|
|
|
local next_top_y = self._document:getPageStartY(next_page)
|
|
|
|
if doc_y >= next_top_y then
|
|
|
|
screen_y = doc_y - next_top_y
|
|
|
|
screen_x = screen_x + self._document:getPageOffsetX(next_page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-03 08:58:48 +00:00
|
|
|
screen_y = screen_y + doc_margins["top"] + self:getHeaderHeight()
|
|
|
|
end
|
|
|
|
-- Just as getPosFromXPointer() does, we return y first and x second,
|
|
|
|
-- as callers most often just need the y
|
|
|
|
return screen_y, screen_x
|
|
|
|
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
|
|
|
|
|
2018-10-10 16:50:24 +00:00
|
|
|
function CreDocument:getPageLinks(internal_links_only)
|
|
|
|
return self._document:getPageLinks(internal_links_only)
|
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
|
|
|
|
|
2018-10-10 16:50:24 +00:00
|
|
|
function CreDocument:isLinkToFootnote(source_xpointer, target_xpointer, flags, max_text_size)
|
|
|
|
return self._document:isLinkToFootnote(source_xpointer, target_xpointer, flags, max_text_size)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:highlightXPointer(xp)
|
|
|
|
-- with xp=nil, clears previous highlight(s)
|
|
|
|
return self._document:highlightXPointer(xp)
|
|
|
|
end
|
|
|
|
|
2018-10-08 16:58:43 +00:00
|
|
|
function CreDocument:getDocumentFileContent(filepath)
|
|
|
|
if filepath then
|
|
|
|
return self._document:getDocumentFileContent(filepath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getTextFromXPointer(xp)
|
|
|
|
if xp then
|
|
|
|
return self._document:getTextFromXPointer(xp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 23:42:27 +00:00
|
|
|
function CreDocument:getTextFromXPointers(pos0, pos1)
|
|
|
|
return self._document:getTextFromXPointers(pos0, pos1)
|
|
|
|
end
|
|
|
|
|
2018-10-08 16:58:43 +00:00
|
|
|
function CreDocument:getHTMLFromXPointer(xp, flags, from_final_parent)
|
|
|
|
if xp then
|
|
|
|
return self._document:getHTMLFromXPointer(xp, flags, from_final_parent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getHTMLFromXPointers(xp0, xp1, flags, from_root_node)
|
|
|
|
if xp0 and xp1 then
|
|
|
|
return self._document:getHTMLFromXPointers(xp0, xp1, flags, from_root_node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-01 17:23:06 +00:00
|
|
|
function CreDocument:gotoPos(pos)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: goto position", pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:gotoPos(pos)
|
2012-12-22 05:27:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:gotoPage(page)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: goto page", page)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: goto link", link)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:gotoLink(link)
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:goBack()
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: go back")
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:goBack()
|
2014-01-15 15:34:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:goForward(link)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: go forward")
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set font face", new_font_face)
|
2014-05-11 12:57:18 +00:00
|
|
|
self._document:setStringProperty("font.face.default", new_font_face)
|
2017-09-01 19:49:10 +00:00
|
|
|
|
|
|
|
-- The following makes FontManager prefer this font in its match
|
|
|
|
-- algorithm, with the bias given (applies only to rendering of
|
|
|
|
-- elements with css font-family)
|
|
|
|
-- See: crengine/src/lvfntman.cpp LVFontDef::CalcMatch():
|
|
|
|
-- it will compute a score for each font, where it adds:
|
|
|
|
-- + 25600 if standard font family matches (inherit serif sans-serif
|
|
|
|
-- cursive fantasy monospace) (note that crengine registers all fonts as
|
|
|
|
-- "sans-serif", except if their name is "Times" or "Times New Roman")
|
|
|
|
-- + 6400 if they don't and none are monospace (ie:serif vs sans-serif,
|
|
|
|
-- prefer a sans-serif to a monospace if looking for a serif)
|
|
|
|
-- +256000 if font names match
|
|
|
|
-- So, here, we can bump the score of our default font, and we could use:
|
|
|
|
-- +1: uses existing real font-family, but use our font for
|
|
|
|
-- font-family: serif, sans-serif..., and fonts not found (or
|
|
|
|
-- embedded fonts disabled)
|
|
|
|
-- +25601: uses existing real font-family, but use our font even
|
|
|
|
-- for font-family: monospace
|
|
|
|
-- +256001: prefer our font to any existing font-family font
|
|
|
|
self._document:setAsPreferredFontWithBias(new_font_face, 1)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2012-06-12 09:42:02 +00:00
|
|
|
end
|
|
|
|
|
2018-05-11 15:48:26 +00:00
|
|
|
function CreDocument:setFallbackFontFace(new_fallback_font_face)
|
|
|
|
if new_fallback_font_face then
|
|
|
|
logger.dbg("CreDocument: set fallback font face", new_fallback_font_face)
|
|
|
|
self._document:setStringProperty("crengine.font.fallback.face", new_fallback_font_face)
|
|
|
|
-- crengine may not accept our fallback font, we need to check
|
|
|
|
local set_fallback_font_face = self._document:getStringProperty("crengine.font.fallback.face")
|
|
|
|
logger.dbg("CreDocument: crengine fallback font face", set_fallback_font_face)
|
|
|
|
if set_fallback_font_face ~= new_fallback_font_face then
|
|
|
|
logger.info("CreDocument:", new_fallback_font_face, "is not usable as a fallback font")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
self.fallback_font = new_fallback_font_face
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-15 11:22:47 +00:00
|
|
|
function CreDocument:setHyphDictionary(new_hyph_dictionary)
|
|
|
|
if new_hyph_dictionary then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set hyphenation dictionary", new_hyph_dictionary)
|
2014-11-15 11:22:47 +00:00
|
|
|
self._document:setStringProperty("crengine.hyphenation.directory", new_hyph_dictionary)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-19 12:24:04 +00:00
|
|
|
function CreDocument:setHyphLeftHyphenMin(value)
|
|
|
|
-- default crengine value is 2: reset it if no value provided
|
|
|
|
logger.dbg("CreDocument: set hyphenation left hyphen min", value or 2)
|
|
|
|
self._document:setIntProperty("crengine.hyphenation.left.hyphen.min", value or 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:setHyphRightHyphenMin(value)
|
|
|
|
logger.dbg("CreDocument: set hyphenation right hyphen min", value or 2)
|
|
|
|
self._document:setIntProperty("crengine.hyphenation.right.hyphen.min", value or 2)
|
|
|
|
end
|
|
|
|
|
2018-06-28 21:27:03 +00:00
|
|
|
function CreDocument:setTrustSoftHyphens(toggle)
|
|
|
|
logger.dbg("CreDocument: set hyphenation trust soft hyphens", toggle and 1 or 0)
|
|
|
|
self._document:setIntProperty("crengine.hyphenation.trust.soft.hyphens", toggle and 1 or 0)
|
|
|
|
end
|
|
|
|
|
2018-07-03 05:05:57 +00:00
|
|
|
function CreDocument:setRenderDPI(value)
|
|
|
|
-- set DPI used for scaling css units (with 96, 1 css px = 1 screen px)
|
|
|
|
-- it can be different from KOReader screen DPI
|
|
|
|
-- it has no relation to the default fontsize (which is already
|
|
|
|
-- scaleBySize()'d when provided to crengine)
|
|
|
|
logger.dbg("CreDocument: set render dpi", value or 96)
|
|
|
|
self._document:setIntProperty("crengine.render.dpi", value or 96)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:setRenderScaleFontWithDPI(toggle)
|
|
|
|
-- wheter to scale font with DPI, or keep the current size
|
|
|
|
logger.dbg("CreDocument: set render scale font with dpi", toggle)
|
|
|
|
self._document:setIntProperty("crengine.render.scale.font.with.dpi", toggle)
|
|
|
|
end
|
|
|
|
|
2014-01-22 09:16:37 +00:00
|
|
|
function CreDocument:clearSelection()
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("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
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set font size", new_font_size)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set view mode", new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
if new_mode == "scroll" then
|
2019-02-03 08:58:48 +00:00
|
|
|
self._view_mode = self.SCROLL_VIEW_MODE
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2019-02-03 08:58:48 +00:00
|
|
|
self._view_mode = self.PAGE_VIEW_MODE
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2019-02-03 08:58:48 +00:00
|
|
|
self._document:setViewMode(self._view_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-01-07 11:53:35 +00:00
|
|
|
end
|
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
function CreDocument:setViewDimen(dimen)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set view dimen", dimen)
|
2014-10-10 10:12:25 +00:00
|
|
|
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
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set header font", new_font)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: zoom font", delta)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set interline space", percent)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: toggle font bolder", toggle)
|
2014-06-04 13:54:01 +00:00
|
|
|
self._document:setIntProperty("font.face.weight.embolden", toggle)
|
2013-01-07 17:16:17 +00:00
|
|
|
end
|
|
|
|
|
2018-03-11 13:54:17 +00:00
|
|
|
function CreDocument:getGammaLevel()
|
|
|
|
return cre.getGammaLevel()
|
|
|
|
end
|
|
|
|
|
2013-01-13 03:49:01 +00:00
|
|
|
function CreDocument:setGammaIndex(index)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set gamma index", index)
|
2014-03-13 13:52:43 +00:00
|
|
|
cre.setGammaIndex(index)
|
2013-01-13 03:49:01 +00:00
|
|
|
end
|
|
|
|
|
2017-09-08 15:38:51 +00:00
|
|
|
function CreDocument:setFontHinting(mode)
|
|
|
|
logger.dbg("CreDocument: set font hinting mode", mode)
|
|
|
|
self._document:setIntProperty("font.hinting.mode", mode)
|
|
|
|
end
|
|
|
|
|
2018-08-17 21:08:21 +00:00
|
|
|
function CreDocument:setFontKerning(mode)
|
|
|
|
logger.dbg("CreDocument: set font kerning mode", mode)
|
|
|
|
self._document:setIntProperty("font.kerning.mode", mode)
|
|
|
|
end
|
|
|
|
|
2018-06-30 14:55:43 +00:00
|
|
|
-- min space condensing percent (how much we can decrease a space width to
|
|
|
|
-- make text fit on a line) 25...100%
|
|
|
|
function CreDocument:setSpaceCondensing(value)
|
|
|
|
logger.dbg("CreDocument: set space condensing", value)
|
|
|
|
self._document:setIntProperty("crengine.style.space.condensing.percent", value)
|
|
|
|
end
|
|
|
|
|
2018-05-12 21:24:43 +00:00
|
|
|
function CreDocument:setStyleSheet(new_css_file, appended_css_content )
|
|
|
|
logger.dbg("CreDocument: set style sheet:",
|
|
|
|
new_css_file and new_css_file or "no file",
|
|
|
|
appended_css_content and "and appended content ("..#appended_css_content.." bytes)" or "(no appended content)")
|
|
|
|
self._document:setStyleSheet(new_css_file, appended_css_content)
|
2013-01-21 22:27:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:setEmbeddedStyleSheet(toggle)
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme occasional segmentation fault when switching embedded style sheet
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("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
|
|
|
|
|
2017-08-30 07:04:04 +00:00
|
|
|
function CreDocument:setEmbeddedFonts(toggle)
|
|
|
|
logger.dbg("CreDocument: set embedded fonts", toggle)
|
|
|
|
self._document:setIntProperty("crengine.doc.embedded.fonts.enabled", toggle)
|
|
|
|
end
|
|
|
|
|
2013-06-28 09:12:04 +00:00
|
|
|
function CreDocument:setPageMargins(left, top, right, bottom)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("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
|
|
|
|
|
2019-07-14 20:13:05 +00:00
|
|
|
function CreDocument:setBlockRenderingFlags(flags)
|
|
|
|
logger.dbg("CreDocument: set block rendering flags", string.format("0x%x", flags))
|
|
|
|
self._document:setIntProperty("crengine.render.block.rendering.flags", flags)
|
|
|
|
end
|
|
|
|
|
2019-04-18 21:26:53 +00:00
|
|
|
function CreDocument:setImageScaling(toggle)
|
|
|
|
logger.dbg("CreDocument: set smooth scaling", toggle)
|
|
|
|
self._smooth_scaling = toggle
|
|
|
|
end
|
|
|
|
|
2019-06-25 22:23:41 +00:00
|
|
|
function CreDocument:setNightmodeImages(toggle)
|
|
|
|
logger.dbg("CreDocument: set nightmode images", toggle)
|
|
|
|
self._nightmode_images = toggle
|
|
|
|
end
|
|
|
|
|
2014-01-02 17:59:40 +00:00
|
|
|
function CreDocument:setFloatingPunctuation(enabled)
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme occasional segmentation fault when toggling floating punctuation
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set floating punctuation", enabled)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:setIntProperty("crengine.style.floating.punctuation.enabled", enabled)
|
2014-01-02 17:59:40 +00:00
|
|
|
end
|
|
|
|
|
2017-04-01 14:34:00 +00:00
|
|
|
function CreDocument:setTxtPreFormatted(enabled)
|
|
|
|
logger.dbg("CreDocument: set txt preformatted", enabled)
|
|
|
|
self._document:setIntProperty("crengine.file.txt.preformatted", enabled)
|
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set visible page count", new_count)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set battery state", state)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: check xpointer in current page", xp)
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: set status line property", prop)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._document:setStringProperty("window.status.line", prop)
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2019-08-17 17:10:54 +00:00
|
|
|
function CreDocument:setBackgroundImage(img_path) -- use nil to unset
|
|
|
|
logger.dbg("CreDocument: set background image", img_path)
|
|
|
|
self._document:setBackgroundImage(img_path)
|
|
|
|
end
|
|
|
|
|
2014-11-05 04:28:11 +00:00
|
|
|
function CreDocument:findText(pattern, origin, reverse, caseInsensitive)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("CreDocument: find text", pattern, origin, reverse, caseInsensitive)
|
2016-04-19 06:50:36 +00:00
|
|
|
return self._document:findText(
|
|
|
|
pattern, origin, reverse, caseInsensitive and 1 or 0)
|
2014-11-05 04:28:11 +00:00
|
|
|
end
|
|
|
|
|
2018-03-12 19:46:40 +00:00
|
|
|
function CreDocument:enableInternalHistory(toggle)
|
|
|
|
-- Setting this to 0 unsets crengine internal bookmarks highlighting,
|
|
|
|
-- and as a side effect, disable internal history and the need to build
|
|
|
|
-- a bookmark at each page turn: this speeds up a lot page turning
|
|
|
|
-- and menu opening on big books.
|
|
|
|
-- It has to be called late in the document opening process, and setting
|
|
|
|
-- it to false needs to be followed by a redraw.
|
|
|
|
-- It needs to be temporarily re-enabled on page resize for crengine to
|
|
|
|
-- keep track of position in page and restore it after resize.
|
|
|
|
logger.dbg("CreDocument: set bookmarks highlight and internal history", toggle)
|
|
|
|
self._document:setIntProperty("crengine.highlight.bookmarks", toggle and 2 or 0)
|
|
|
|
end
|
|
|
|
|
2018-05-20 23:19:36 +00:00
|
|
|
function CreDocument:isBuiltDomStale()
|
|
|
|
return self._document:isBuiltDomStale()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:hasCacheFile()
|
|
|
|
return self._document:hasCacheFile()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:invalidateCacheFile()
|
|
|
|
self._document:invalidateCacheFile()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:getCacheFilePath()
|
|
|
|
return self._document:getCacheFilePath()
|
|
|
|
end
|
|
|
|
|
2018-06-13 22:46:52 +00:00
|
|
|
function CreDocument:canHaveAlternativeToc()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:isTocAlternativeToc()
|
|
|
|
return self._document:isTocAlternativeToc()
|
|
|
|
end
|
|
|
|
|
|
|
|
function CreDocument:buildAlternativeToc()
|
|
|
|
self._document:buildAlternativeToc()
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
function CreDocument:register(registry)
|
[feat] DocumentRegistry: add getProviders() and preferred by weight (#3651)
This is step one toward "open with".
References https://github.com/koreader/koreader/issues/3345
* Fix up some mimetypes
* Add XHTML to supported filetypes
* Add a few image files to MuPDF
* ".bmp",
* ".gif",
* ".hdp",
* ".j2k",
* ".jp2",
* ".jpeg",
* ".jpg",
* ".jpx",
* ".jxr",
* ".pam",
* ".pbm",
* ".pgm",
* ".png",
* ".pnm",
* ".ppm",
* ".tif",
* ".tiff",
* ".wdp",
2018-01-31 19:49:21 +00:00
|
|
|
registry:addProvider("azw", "application/vnd.amazon.mobi8-ebook", self, 90)
|
|
|
|
registry:addProvider("chm", "application/vnd.ms-htmlhelp", self, 90)
|
|
|
|
registry:addProvider("doc", "application/msword", self, 90)
|
|
|
|
registry:addProvider("epub", "application/epub+zip", self, 100)
|
|
|
|
registry:addProvider("fb2", "application/fb2", self, 90)
|
|
|
|
registry:addProvider("fb2.zip", "application/zip", self, 90)
|
|
|
|
registry:addProvider("htm", "text/html", self, 100)
|
|
|
|
registry:addProvider("html", "text/html", self, 100)
|
|
|
|
registry:addProvider("htm.zip", "application/zip", self, 100)
|
|
|
|
registry:addProvider("html.zip", "application/zip", self, 100)
|
2017-04-02 13:11:16 +00:00
|
|
|
registry:addProvider("log", "text/plain", self)
|
|
|
|
registry:addProvider("log.zip", "application/zip", self)
|
|
|
|
registry:addProvider("md", "text/plain", self)
|
|
|
|
registry:addProvider("md.zip", "application/zip", self)
|
[feat] DocumentRegistry: add getProviders() and preferred by weight (#3651)
This is step one toward "open with".
References https://github.com/koreader/koreader/issues/3345
* Fix up some mimetypes
* Add XHTML to supported filetypes
* Add a few image files to MuPDF
* ".bmp",
* ".gif",
* ".hdp",
* ".j2k",
* ".jp2",
* ".jpeg",
* ".jpg",
* ".jpx",
* ".jxr",
* ".pam",
* ".pbm",
* ".pgm",
* ".png",
* ".pnm",
* ".ppm",
* ".tif",
* ".tiff",
* ".wdp",
2018-01-31 19:49:21 +00:00
|
|
|
registry:addProvider("mobi", "application/x-mobipocket-ebook", self, 90)
|
|
|
|
-- Palmpilot Document File
|
|
|
|
registry:addProvider("pdb", "application/vnd.palm", self, 90)
|
|
|
|
-- Palmpilot Resource File
|
|
|
|
registry:addProvider("prc", "application/vnd.palm", self)
|
2014-03-13 13:52:43 +00:00
|
|
|
registry:addProvider("tcr", "application/tcr", self)
|
[feat] DocumentRegistry: add getProviders() and preferred by weight (#3651)
This is step one toward "open with".
References https://github.com/koreader/koreader/issues/3345
* Fix up some mimetypes
* Add XHTML to supported filetypes
* Add a few image files to MuPDF
* ".bmp",
* ".gif",
* ".hdp",
* ".j2k",
* ".jp2",
* ".jpeg",
* ".jpg",
* ".jpx",
* ".jxr",
* ".pam",
* ".pbm",
* ".pgm",
* ".png",
* ".pnm",
* ".ppm",
* ".tif",
* ".tiff",
* ".wdp",
2018-01-31 19:49:21 +00:00
|
|
|
registry:addProvider("txt", "text/plain", self, 90)
|
|
|
|
registry:addProvider("txt.zip", "application/zip", self, 90)
|
|
|
|
registry:addProvider("rtf", "application/rtf", self, 90)
|
|
|
|
registry:addProvider("xhtml", "application/xhtml+xml", self, 90)
|
|
|
|
registry:addProvider("zip", "application/zip", self, 10)
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return CreDocument
|