2012-03-05 01:46:16 +00:00
|
|
|
require "unireader"
|
|
|
|
|
2012-03-19 17:59:36 +00:00
|
|
|
DJVUReader = UniReader:new{}
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- open a DJVU file and its settings store
|
2012-03-05 01:58:19 +00:00
|
|
|
-- DJVU does not support password yet
|
2012-03-05 01:46:16 +00:00
|
|
|
function DJVUReader:open(filename)
|
2012-03-19 23:10:19 +00:00
|
|
|
local ok
|
2012-03-31 12:36:10 +00:00
|
|
|
ok, self.doc = pcall(djvu.openDocument, filename, self.cache_document_size)
|
2012-03-19 23:10:19 +00:00
|
|
|
if not ok then
|
|
|
|
return ok, self.doc -- this will be the error message instead
|
|
|
|
end
|
|
|
|
return ok
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-19 03:05:23 +00:00
|
|
|
|
2012-04-06 12:13:46 +00:00
|
|
|
function DJVUReader:init()
|
|
|
|
self:addAllCommands()
|
|
|
|
self:adjustDjvuReaderCommand()
|
|
|
|
end
|
|
|
|
|
|
|
|
function DJVUReader:adjustDjvuReaderCommand()
|
2012-04-10 12:45:22 +00:00
|
|
|
self.commands:del(KEY_J, MOD_SHIFT, "J")
|
|
|
|
self.commands:del(KEY_K, MOD_SHIFT, "K")
|
2012-04-06 12:13:46 +00:00
|
|
|
end
|
2012-03-23 09:20:51 +00:00
|
|
|
|
|
|
|
|
2012-04-12 03:23:22 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- highlight support
|
|
|
|
----------------------------------------------------
|
|
|
|
function DJVUReader:getText(pageno)
|
|
|
|
return self.doc:getPageText(pageno)
|
|
|
|
end
|
2012-03-23 09:20:51 +00:00
|
|
|
|
2012-05-23 05:04:05 +00:00
|
|
|
-- for incompatible API fixing
|
|
|
|
function DJVUReader:invertTextYAxel(pageno, text_table)
|
|
|
|
local _, height = self.doc:getOriginalPageSize(pageno)
|
|
|
|
for _,text in pairs(text_table) do
|
|
|
|
for _,line in ipairs(text) do
|
|
|
|
line.y0, line.y1 = (height - line.y1), (height - line.y0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return text_table
|
|
|
|
end
|
|
|
|
|