2014-05-15 08:07:38 +00:00
|
|
|
describe("PDF document module", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local DocumentRegistry
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
end)
|
|
|
|
|
2015-03-03 10:00:38 +00:00
|
|
|
local doc
|
2014-05-15 08:07:38 +00:00
|
|
|
it("should open document", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
2014-05-15 08:07:38 +00:00
|
|
|
doc = DocumentRegistry:openDocument(sample_pdf)
|
|
|
|
assert.truthy(doc)
|
|
|
|
end)
|
|
|
|
it("should get page dimensions", function()
|
|
|
|
local dimen = doc:getPageDimensions(1, 1, 0)
|
|
|
|
assert.are.same(dimen.w, 567)
|
|
|
|
assert.are.same(dimen.h, 1418)
|
|
|
|
end)
|
2015-10-07 14:42:12 +00:00
|
|
|
it("should get cover image", function()
|
|
|
|
local image = doc:getCoverPageImage()
|
|
|
|
assert.truthy(image)
|
|
|
|
assert.are.same(320, image:getWidth())
|
|
|
|
assert.are.same(800, image:getHeight())
|
|
|
|
end)
|
2014-05-15 08:07:38 +00:00
|
|
|
local pos0 = {page = 1, x = 0, y = 20}
|
|
|
|
local pos1 = {page = 1, x = 300, y = 120}
|
|
|
|
local pboxes = {
|
|
|
|
{x = 26, y = 42, w = 240, h = 22},
|
|
|
|
{x = 48, y = 82, w = 185, h = 22},
|
|
|
|
}
|
|
|
|
it("should clip page rect to PNG file", function()
|
|
|
|
doc:clipPagePNGFile(pos0, pos1, nil, nil, "/tmp/clip0.png")
|
|
|
|
doc:clipPagePNGFile(pos0, pos1, pboxes, "lighten", "/tmp/clip1.png")
|
|
|
|
end)
|
|
|
|
it("should clip page rect to PNG string", function()
|
|
|
|
local clip0 = doc:clipPagePNGString(pos0, pos1, nil, nil)
|
|
|
|
assert.truthy(clip0)
|
|
|
|
local clip1 = doc:clipPagePNGString(pos0, pos1, pboxes, "lighten")
|
|
|
|
assert.truthy(clip1)
|
|
|
|
end)
|
2015-02-19 14:15:31 +00:00
|
|
|
it("should calculate fast digest", function()
|
|
|
|
assert.is_equal(doc:fastDigest(), "41cce710f34e5ec21315e19c99821415")
|
|
|
|
end)
|
2014-05-15 08:07:38 +00:00
|
|
|
it("should close document", function()
|
|
|
|
doc:close()
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe("EPUB document module", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local DocumentRegistry
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
end)
|
|
|
|
|
2015-03-03 10:00:38 +00:00
|
|
|
local doc
|
2014-05-15 08:07:38 +00:00
|
|
|
it("should open document", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local sample_epub = "spec/front/unit/data/leaves.epub"
|
2014-05-15 08:07:38 +00:00
|
|
|
doc = DocumentRegistry:openDocument(sample_epub)
|
|
|
|
assert.truthy(doc)
|
|
|
|
end)
|
2014-08-22 10:24:49 +00:00
|
|
|
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)
|
2015-02-19 14:15:31 +00:00
|
|
|
it("should calculate fast digest", function()
|
|
|
|
assert.is_equal(doc:fastDigest(), "59d481d168cca6267322f150c5f6a2a3")
|
|
|
|
end)
|
2015-06-02 04:29:54 +00:00
|
|
|
it("should register droid sans fallback", function()
|
|
|
|
local fonts_registry = {
|
|
|
|
"Droid Sans Mono",
|
|
|
|
"FreeSans",
|
|
|
|
"FreeSerif",
|
|
|
|
"Noto Sans",
|
2019-10-27 04:22:17 +00:00
|
|
|
"Noto Sans Arabic UI",
|
2015-09-05 09:32:34 +00:00
|
|
|
"Noto Sans CJK SC",
|
2020-01-31 16:25:13 +00:00
|
|
|
"Noto Sans Devanagari UI",
|
2015-06-02 04:29:54 +00:00
|
|
|
"Noto Serif",
|
|
|
|
}
|
|
|
|
local face_list = cre.getFontFaces()
|
|
|
|
assert.are.same(fonts_registry, face_list)
|
|
|
|
end)
|
2014-05-15 08:07:38 +00:00
|
|
|
it("should close document", function()
|
|
|
|
doc:close()
|
|
|
|
end)
|
|
|
|
end)
|