2013-10-22 15:19:08 +00:00
|
|
|
local Document = require("document/document")
|
2013-12-31 05:12:56 +00:00
|
|
|
local DrawContext = require("ffi/drawcontext")
|
2019-02-18 16:01:00 +00:00
|
|
|
local CanvasContext = require("document/canvascontext")
|
2014-06-16 06:20:59 +00:00
|
|
|
local pic = nil
|
2013-10-17 21:34:55 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local PicDocument = Document:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
_document = false,
|
2015-09-07 17:06:17 +00:00
|
|
|
is_pic = true,
|
[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
|
|
|
dc_null = DrawContext.new(),
|
2018-02-02 20:21:52 +00:00
|
|
|
provider = "picdocument",
|
[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 = "Picture Document",
|
2013-10-17 21:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function PicDocument:init()
|
2017-10-01 17:23:06 +00:00
|
|
|
self:updateColorRendering()
|
2014-06-16 06:20:59 +00:00
|
|
|
if not pic then pic = require("ffi/pic") end
|
2017-10-01 17:23:06 +00:00
|
|
|
-- pic.color needs to be true before opening document to allow toggling color
|
2019-02-18 16:01:00 +00:00
|
|
|
pic.color = CanvasContext.is_color_rendering_enabled
|
2016-02-14 21:47:36 +00:00
|
|
|
local ok
|
2014-03-13 13:52:43 +00:00
|
|
|
ok, self._document = pcall(pic.openDocument, self.file)
|
|
|
|
if not ok then
|
2019-11-15 14:14:32 +00:00
|
|
|
error("Failed to open image:" .. self._document)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-10-17 21:34:55 +00:00
|
|
|
|
2021-05-20 17:09:54 +00:00
|
|
|
self.is_open = true
|
2014-03-13 13:52:43 +00:00
|
|
|
self.info.has_pages = true
|
|
|
|
self.info.configurable = false
|
2013-10-17 21:34:55 +00:00
|
|
|
|
2022-02-06 17:01:45 +00:00
|
|
|
-- Enforce dithering in PicDocument
|
|
|
|
if CanvasContext:hasEinkScreen() then
|
|
|
|
if CanvasContext:canHWDither() then
|
|
|
|
self.hw_dithering = true
|
|
|
|
elseif CanvasContext.fb_bpp == 8 then
|
|
|
|
self.sw_dithering = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-11 21:32:57 +00:00
|
|
|
self:_readMetadata()
|
2013-10-17 21:34:55 +00:00
|
|
|
end
|
|
|
|
|
2014-11-11 21:32:57 +00:00
|
|
|
function PicDocument:getUsedBBox(pageno)
|
|
|
|
return { x0 = 0, y0 = 0, x1 = self._document.width, y1 = self._document.height }
|
2013-10-17 21:34:55 +00:00
|
|
|
end
|
|
|
|
|
2017-08-20 10:43:52 +00:00
|
|
|
function PicDocument:getProps()
|
|
|
|
local _, _, docname = self.file:find(".*/(.*)")
|
|
|
|
docname = docname or self.file
|
|
|
|
return {
|
|
|
|
title = docname:match("(.*)%."),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function PicDocument:getCoverPageImage()
|
2018-04-21 20:00:52 +00:00
|
|
|
local first_page = self._document:openPage(1)
|
|
|
|
if first_page.image_bb then
|
2019-02-21 07:59:41 +00:00
|
|
|
return first_page.image_bb:copy()
|
2017-08-20 10:43:52 +00:00
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2013-10-22 15:19:08 +00:00
|
|
|
function PicDocument: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("gif", "image/gif", self, 100)
|
2020-12-04 18:10:50 +00:00
|
|
|
registry:addProvider("jpg", "image/jpeg", self, 80)
|
|
|
|
registry:addProvider("jpeg", "image/jpeg", self, 80)
|
|
|
|
registry:addProvider("png", "image/png", self, 80)
|
2022-08-03 21:19:31 +00:00
|
|
|
registry:addProvider("webp", "image/webp", self, 80)
|
2013-10-22 15:19:08 +00:00
|
|
|
end
|
2013-10-17 21:34:55 +00:00
|
|
|
|
2013-10-22 15:19:08 +00:00
|
|
|
return PicDocument
|