kopt: color support

Keep colors when reflowing documents.
This commit is contained in:
Benoit Pierre
2024-07-14 22:00:31 +02:00
committed by Frans de Jonge
parent cb002f3d1f
commit 0c17941ffb
5 changed files with 14 additions and 36 deletions

View File

@@ -21,12 +21,6 @@ local PdfDocument = Document:extend{
function PdfDocument:init()
if not pdf then pdf = require("ffi/mupdf") end
-- mupdf.color has to stay false for kopt to work correctly
-- and be accurate (including its job about showing highlight
-- boxes). We will turn it on and off in PdfDocument:preRenderPage()
-- and :postRenderPage() when mupdf is called without kopt involved.
pdf.color = false
self:updateColorRendering()
self.koptinterface = require("document/koptinterface")
self.koptinterface:setDefaultConfigurable(self.configurable)
local ok
@@ -34,6 +28,7 @@ function PdfDocument:init()
if not ok then
error(self._document) -- will contain error message
end
self:updateColorRendering()
self.is_reflowable = self._document:isDocumentReflowable()
self.reflowable_font_size = self:convertKoptToReflowableFontSize()
-- no-op on PDF
@@ -48,6 +43,13 @@ function PdfDocument:init()
end
end
function PdfDocument:updateColorRendering()
Document.updateColorRendering(self) -- will set self.render_color
if self._document then
self._document:setColorRendering(self.render_color)
end
end
function PdfDocument:layoutDocument(font_size)
if font_size then
self.reflowable_font_size = font_size
@@ -81,14 +83,6 @@ function PdfDocument:convertKoptToReflowableFontSize(font_size)
end
end
function PdfDocument:preRenderPage()
pdf.color = self.render_color
end
function PdfDocument:postRenderPage()
pdf.color = false
end
function PdfDocument:unlock(password)
if not self._document:authenticatePassword(password) then
return false