Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kopt: color support #1836

Merged
merged 1 commit into from
Jun 24, 2024
Merged

Conversation

benoit-pierre
Copy link
Contributor

@benoit-pierre benoit-pierre commented Jun 22, 2024

Use with:

--- i/frontend/document/document.lua
+++ w/frontend/document/document.lua
@@ -387,14 +387,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
@@ -435,7 +427,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
@@ -493,7 +484,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
--- i/frontend/document/pdfdocument.lua
+++ w/frontend/document/pdfdocument.lua
@@ -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
@@ -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
--- i/frontend/ui/widget/htmlboxwidget.lua
+++ w/frontend/ui/widget/htmlboxwidget.lua
@@ -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()

This change is Reviewable

Note: libk2pdfopt has already been bumped with the necessary changes in a7b40a4.
@benoit-pierre benoit-pierre marked this pull request as ready for review June 24, 2024 19:24
@Frenzie Frenzie merged commit c75e0e5 into koreader:master Jun 24, 2024
3 checks passed
@benoit-pierre benoit-pierre deleted the pr/k2pdfopt_color_support branch June 24, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants