2013-10-22 17:19:08 +02:00
|
|
|
local Document = require("document/document")
|
2013-12-31 13:12:56 +08:00
|
|
|
local DrawContext = require("ffi/drawcontext")
|
2019-02-18 08:01:00 -08:00
|
|
|
local CanvasContext = require("document/canvascontext")
|
2014-06-16 02:20:59 -04:00
|
|
|
local pic = nil
|
2013-10-17 17:34:55 -04:00
|
|
|
|
2013-10-22 17:19:08 +02:00
|
|
|
local PicDocument = Document:new{
|
2014-03-13 21:52:43 +08:00
|
|
|
_document = false,
|
2015-09-07 20:06:17 +03: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 20:49:21 +01:00
|
|
|
dc_null = DrawContext.new(),
|
2018-02-02 21:21:52 +01: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 20:49:21 +01:00
|
|
|
provider_name = "Picture Document",
|
2013-10-17 17:34:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function PicDocument:init()
|
2017-10-01 19:23:06 +02:00
|
|
|
self:updateColorRendering()
|
2014-06-16 02:20:59 -04:00
|
|
|
if not pic then pic = require("ffi/pic") end
|
2017-10-01 19:23:06 +02:00
|
|
|
-- pic.color needs to be true before opening document to allow toggling color
|
2019-02-18 08:01:00 -08:00
|
|
|
pic.color = CanvasContext.is_color_rendering_enabled
|
2016-02-14 13:47:36 -08:00
|
|
|
local ok
|
2014-03-13 21:52:43 +08:00
|
|
|
ok, self._document = pcall(pic.openDocument, self.file)
|
|
|
|
|
if not ok then
|
2019-11-15 15:14:32 +01:00
|
|
|
error("Failed to open image:" .. self._document)
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2013-10-17 17:34:55 -04:00
|
|
|
|
2014-03-13 21:52:43 +08:00
|
|
|
self.info.has_pages = true
|
|
|
|
|
self.info.configurable = false
|
2013-10-17 17:34:55 -04:00
|
|
|
|
2014-11-11 22:32:57 +01:00
|
|
|
self:_readMetadata()
|
2013-10-17 17:34:55 -04:00
|
|
|
end
|
|
|
|
|
|
2014-11-11 22:32:57 +01:00
|
|
|
function PicDocument:getUsedBBox(pageno)
|
|
|
|
|
return { x0 = 0, y0 = 0, x1 = self._document.width, y1 = self._document.height }
|
2013-10-17 17:34:55 -04:00
|
|
|
end
|
|
|
|
|
|
2017-08-20 12:43:52 +02: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 22:00:52 +02:00
|
|
|
local first_page = self._document:openPage(1)
|
|
|
|
|
if first_page.image_bb then
|
2019-02-21 08:59:41 +01:00
|
|
|
return first_page.image_bb:copy()
|
2017-08-20 12:43:52 +02:00
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
2013-10-22 17:19:08 +02: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 20:49:21 +01:00
|
|
|
registry:addProvider("gif", "image/gif", self, 100)
|
|
|
|
|
registry:addProvider("jpg", "image/jpeg", self, 100)
|
|
|
|
|
registry:addProvider("jpeg", "image/jpeg", self, 100)
|
|
|
|
|
registry:addProvider("png", "image/png", self, 100)
|
2013-10-22 17:19:08 +02:00
|
|
|
end
|
2013-10-17 17:34:55 -04:00
|
|
|
|
2013-10-22 17:19:08 +02:00
|
|
|
return PicDocument
|