credocument: deal with loadDocument() failures (#3570)

cre:loadDocument() may fail in recognizing the document format, and
koreader would previously keep calling other methods on it, which would
make crengine segfaults. We now check loadDocument success at the
various places it is called, and try to deal the best way we can when it fails.
This commit is contained in:
poire-z
2018-01-03 09:43:49 +01:00
committed by GitHub
parent 6f41cecab2
commit 7797c2369e
5 changed files with 139 additions and 78 deletions

View File

@@ -109,6 +109,11 @@ function CreDocument:init()
-- set fallback font face
self._document:setStringProperty("crengine.font.fallback.face", self.fallback_font)
-- 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.
self.is_open = true
self.info.has_pages = false
self:_readMetadata()
@@ -117,9 +122,11 @@ end
function CreDocument:loadDocument()
if not self._loaded then
self._document:loadDocument(self.file)
self._loaded = true
if self._document:loadDocument(self.file) then
self._loaded = true
end
end
return self._loaded
end
function CreDocument:render()
@@ -160,7 +167,9 @@ end
function CreDocument:getCoverPageImage()
-- don't need to render document in order to get cover image
self:loadDocument()
if not self:loadDocument() then
return nil -- not recognized by crengine
end
local data, size = self._document:getCoverPageImageData()
if data and size then
local Mupdf = require("ffi/mupdf")