2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/document/picdocument.lua
chrox 2f2d9f1bf7 issue error directly when doc is malformated
This should popup a message saying "No reader engine for this file"
instead of a crash when document file is malformated.

This should fix #868.
2014-08-29 17:17:12 +08:00

33 lines
762 B
Lua

local Document = require("document/document")
local DrawContext = require("ffi/drawcontext")
local pic = nil
local PicDocument = Document:new{
_document = false,
dc_null = DrawContext.new()
}
function PicDocument:init()
if not pic then pic = require("ffi/pic") end
ok, self._document = pcall(pic.openDocument, self.file)
if not ok then
error("Failed to open jpeg image")
end
self.info.has_pages = true
self.info.configurable = false
self:readMetadata()
end
function PicDocument:readMetadata()
self.info.number_of_pages = 1
end
function PicDocument:register(registry)
registry:addProvider("jpeg", "application/jpeg", self)
registry:addProvider("jpg", "application/jpeg", self)
end
return PicDocument