Skip to content

Commit

Permalink
kopt: color support
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Jun 23, 2024
1 parent d1525d2 commit 197a1d3
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 31 deletions.
2 changes: 1 addition & 1 deletion base/ffi/koptcontext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function KOPTContext_mt.__index:getPageDim() return self.page_width, self.page_h
function KOPTContext_mt.__index:getBBox(x0, y0, x1, y1) return self.bbox.x0, self.bbox.y0, self.bbox.x1, self.bbox.y1 end

function KOPTContext_mt.__index:copyDestBMP(src)
if src.dst.bpp == 8 or src.dst.bpp == 32 then
if src.dst.bpp == 8 or src.dst.bpp == 24 or src.dst.bpp == 32 then
k2pdfopt.bmp_copy(self.dst, src.dst)
end
end
Expand Down
10 changes: 0 additions & 10 deletions frontend/document/document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,6 @@ function Document:updateColorRendering()
end
end

function Document:preRenderPage()
return nil
end

function Document:postRenderPage()
return nil
end

function Document:getTileCacheValidity()
return self.tile_cache_validity_ts
end
Expand Down Expand Up @@ -428,7 +420,6 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, h
if hinting then
CanvasContext:enableCPUCores(2)
end
self:preRenderPage()

local page_size = self:getPageDimensions(pageno, zoom, rotation)
-- this will be the size we actually render
Expand Down Expand Up @@ -486,7 +477,6 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, h
page:close()
DocCache:insert(hash, tile)

self:postRenderPage()
if hinting then
CanvasContext:enableCPUCores(1)
end
Expand Down
2 changes: 1 addition & 1 deletion frontend/document/koptinterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ end

function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, render_mode, hinting)
if doc.configurable.text_wrap == 1 then
return self:renderReflowedPage(doc, pageno, rect, zoom, rotation, render_mode, hinting)
return self:renderReflowedPage(doc, pageno, rect, zoom, rotation, render_mode)
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
return self:renderOptimizedPage(doc, pageno, rect, zoom, rotation, render_mode, hinting)
else
Expand Down
14 changes: 1 addition & 13 deletions frontend/document/pdfdocument.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ 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()
pdf.color = self.render_color
self.koptinterface = require("document/koptinterface")
self.koptinterface:setDefaultConfigurable(self.configurable)
local ok
Expand Down Expand Up @@ -81,14 +77,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
Expand Down
5 changes: 0 additions & 5 deletions frontend/ui/widget/htmlboxwidget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,12 @@ function HtmlBoxWidget:_render()
return
end

-- In pdfdocument.lua, color is activated only at the moment of
-- rendering and then immediately disabled, for safety with kopt.
-- We do the same here.
Mupdf.color = Screen:isColorEnabled()

local page = self.document:openPage(self.page_number)
local dc = DrawContext.new()
self.bb = page:draw_new(dc, self.dimen.w, self.dimen.h, 0, 0)
page:close()

Mupdf.color = false
end

function HtmlBoxWidget:getSize()
Expand Down
2 changes: 1 addition & 1 deletion subprojects/libk2pdfopt.wrap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[wrap-git]
directory = libk2pdfopt
url = https://github.com/benoit-pierre/libk2pdfopt.git
revision = 6ec29e1d9217421488d9544e06b59f6836c47a49
revision = 6f2cf43b7e1fa54e370638b92f9e9fed65b1c4ba
depth = 1
patch_directory = libk2pdfopt/overlay

Expand Down

0 comments on commit 197a1d3

Please sign in to comment.