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
|
|
|
|
2013-10-22 15:19:08 +00:00
|
|
|
local PicDocument = Document:new{
|
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
|
|
|
|
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
|
|
|
|
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)
|
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
|