|
|
|
@ -9,13 +9,10 @@ local ffi = require("ffi")
|
|
|
|
|
local C = ffi.C
|
|
|
|
|
local pdf = nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local PdfDocument = Document:new{
|
|
|
|
|
_document = false,
|
|
|
|
|
is_pdf = true,
|
|
|
|
|
dc_null = DrawContext.new(),
|
|
|
|
|
epub_font_size = G_reader_settings:readSetting("copt_font_size")
|
|
|
|
|
or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22,
|
|
|
|
|
koptinterface = nil,
|
|
|
|
|
provider = "mupdf",
|
|
|
|
|
provider_name = "MuPDF",
|
|
|
|
@ -36,11 +33,10 @@ function PdfDocument:init()
|
|
|
|
|
if not ok then
|
|
|
|
|
error(self._document) -- will contain error message
|
|
|
|
|
end
|
|
|
|
|
self.is_reflowable = self._document:isDocumentReflowable()
|
|
|
|
|
self.reflowable_font_size = self:convertKoptToReflowableFontSize()
|
|
|
|
|
-- no-op on PDF
|
|
|
|
|
self._document:layoutDocument(
|
|
|
|
|
CanvasContext:getWidth(),
|
|
|
|
|
CanvasContext:getHeight(),
|
|
|
|
|
CanvasContext:scaleBySize(self.epub_font_size))
|
|
|
|
|
self:layoutDocument()
|
|
|
|
|
self.is_open = true
|
|
|
|
|
self.info.has_pages = true
|
|
|
|
|
self.info.configurable = true
|
|
|
|
@ -51,6 +47,37 @@ function PdfDocument:init()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PdfDocument:layoutDocument(font_size)
|
|
|
|
|
if font_size then
|
|
|
|
|
self.reflowable_font_size = font_size
|
|
|
|
|
end
|
|
|
|
|
self._document:layoutDocument(
|
|
|
|
|
CanvasContext:getWidth(),
|
|
|
|
|
CanvasContext:getHeight(),
|
|
|
|
|
CanvasContext:scaleBySize(self.reflowable_font_size))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local default_font_size = 22
|
|
|
|
|
-- the koptreader config goes from 0.1 to 3.0, but we want a regular font size
|
|
|
|
|
function PdfDocument:convertKoptToReflowableFontSize(font_size)
|
|
|
|
|
if font_size then
|
|
|
|
|
return font_size * default_font_size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local docsettings = require("docsettings"):open(self.file)
|
|
|
|
|
local size = docsettings:readSetting("kopt_font_size")
|
|
|
|
|
docsettings:close()
|
|
|
|
|
if size then
|
|
|
|
|
return size * default_font_size
|
|
|
|
|
elseif G_reader_settings:readSetting("kopt_font_size") then
|
|
|
|
|
return G_reader_settings:readSetting("kopt_font_size") * default_font_size
|
|
|
|
|
elseif DKOPTREADER_CONFIG_FONT_SIZE then
|
|
|
|
|
return DKOPTREADER_CONFIG_FONT_SIZE * default_font_size
|
|
|
|
|
else
|
|
|
|
|
return default_font_size
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PdfDocument:preRenderPage()
|
|
|
|
|
pdf.color = self.render_color
|
|
|
|
|
end
|
|
|
|
@ -104,7 +131,7 @@ function PdfDocument:getPageBlock(pageno, x, y)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PdfDocument:getUsedBBox(pageno)
|
|
|
|
|
local hash = "pgubbox|"..self.file.."|"..pageno
|
|
|
|
|
local hash = "pgubbox|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
|
|
|
|
local cached = Cache:check(hash)
|
|
|
|
|
if cached then
|
|
|
|
|
return cached.ubbox
|
|
|
|
@ -127,7 +154,7 @@ function PdfDocument:getUsedBBox(pageno)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PdfDocument:getPageLinks(pageno)
|
|
|
|
|
local hash = "pglinks|"..self.file.."|"..pageno
|
|
|
|
|
local hash = "pgubbox|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
|
|
|
|
local cached = Cache:check(hash)
|
|
|
|
|
if cached then
|
|
|
|
|
return cached.links
|
|
|
|
|