use koptinterface to reflow text in pdf/djvu readers

This commit is contained in:
chrox
2013-01-03 22:24:38 +08:00
parent e525264b01
commit 349bcb996e
7 changed files with 236 additions and 260 deletions

View File

@@ -1,14 +1,23 @@
require "cache"
require "ui/geometry"
require "ui/screen"
require "ui/device"
require "ui/reader/readerconfig"
require "document/koptinterface"
PdfDocument = Document:new{
_document = false,
-- muPDF manages its own additional cache
mupdf_cache_size = 5 * 1024 * 1024,
dc_null = DrawContext.new()
dc_null = DrawContext.new(),
screen_size = Screen:getSize(),
screen_dpi = Device:getModel() == "KindlePaperWhite" and 212 or 167,
configurable = Configurable,
koptinterface = KoptInterface,
}
function PdfDocument:init()
self.configurable:loadDefaults()
local ok
ok, self._document = pcall(pdf.openDocument, self.file, self.mupdf_cache_size)
if not ok then
@@ -17,6 +26,7 @@ function PdfDocument:init()
end
self.is_open = true
self.info.has_pages = true
self.info.configurable = true
if self._document:needsPassword() then
self.is_locked = true
else
@@ -50,4 +60,28 @@ function PdfDocument:getUsedBBox(pageno)
return used
end
function PdfDocument:getPageDimensions(pageno, zoom, rotation)
if self.configurable.text_wrap == 1 then
return self.koptinterface:getPageDimensions(self, pageno, zoom, rotation)
else
return Document.getPageDimensions(self, pageno, zoom, rotation)
end
end
function PdfDocument:renderPage(pageno, rect, zoom, rotation, render_mode)
if self.configurable.text_wrap == 1 then
return self.koptinterface:renderPage(self, pageno, rect, zoom, rotation, render_mode)
else
return Document.renderPage(self, pageno, rect, zoom, rotation, render_mode)
end
end
function PdfDocument:drawPage(target, x, y, rect, pageno, zoom, rotation, render_mode)
if self.configurable.text_wrap == 1 then
self.koptinterface:drawPage(self, target, x, y, rect, pageno, zoom, rotation, render_mode)
else
Document.drawPage(self, target, x, y, rect, pageno, zoom, rotation, render_mode)
end
end
DocumentRegistry:addProvider("pdf", "application/pdf", PdfDocument)