mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add getCoverPageImage api for CreDocument
This commit is contained in:
@@ -3,11 +3,13 @@ local Document = require("document/document")
|
||||
local Configurable = require("configurable")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local Image = require("ffi/mupdfimg")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("ui/device")
|
||||
local Screen = require("ui/screen")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local ffi = require("ffi")
|
||||
|
||||
local CreDocument = Document:new{
|
||||
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
||||
@@ -130,6 +132,16 @@ function CreDocument:getPageCount()
|
||||
return self._document:getPages()
|
||||
end
|
||||
|
||||
function CreDocument:getCoverPageImage()
|
||||
self._document:loadDocument(self.file)
|
||||
local data, size = self._document:getCoverPageImageData()
|
||||
if data and size then
|
||||
local image = Image:fromData(data, size)
|
||||
ffi.C.free(data)
|
||||
return image
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:getWordFromPosition(pos)
|
||||
local word_box = self._document:getWordFromPosition(pos.x, pos.y)
|
||||
DEBUG("CreDocument: get word box", word_box)
|
||||
|
||||
@@ -54,6 +54,12 @@ describe("EPUB document module", function()
|
||||
doc = DocumentRegistry:openDocument(sample_epub)
|
||||
assert.truthy(doc)
|
||||
end)
|
||||
it("should get cover image", function()
|
||||
local image = doc:getCoverPageImage()
|
||||
assert.truthy(image)
|
||||
assert.are.same(image:getWidth(), 442)
|
||||
assert.are.same(image:getHeight(), 616)
|
||||
end)
|
||||
it("should close document", function()
|
||||
doc:close()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user