diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index 55d52ad26..fc58352d8 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -25,7 +25,6 @@ local function validDjvuFile(filename) end function DjvuDocument:init() - self:updateColorRendering() local djvu = require("libs/libkoreader-djvu") self.koptinterface = require("document/koptinterface") self.koptinterface:setDefaultConfigurable(self.configurable) @@ -38,6 +37,7 @@ function DjvuDocument:init() if not ok then error(self._document) -- will contain error message end + self:updateColorRendering() self.is_open = true self.info.has_pages = true self.info.configurable = true diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 687f1c976..70649c5b9 100644 --- a/frontend/document/document.lua +++ b/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 @@ -407,15 +399,15 @@ function Document:resetTileCacheValidity() self.tile_cache_validity_ts = os.time() end -function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, color) +function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode) return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|" - ..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(color and "|color" or "") + ..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(self.render_color and "|color" or "|bw") ..(self.reflowable_font_size and "|"..self.reflowable_font_size or "") end function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, hinting) local hash_excerpt - local hash = self:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, self.render_color) + local hash = self:getFullPageHash(pageno, zoom, rotation, gamma, render_mode) local tile = DocCache:check(hash, TileCacheItem) if not tile then hash_excerpt = hash.."|"..tostring(rect) @@ -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 diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index d79ff8f4d..ad774721a 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -169,6 +169,7 @@ function KoptInterface:getContextHash(doc, pageno, bbox, hash_list) local canvas_size = CanvasContext:getSize() table.insert(hash_list, doc.file) table.insert(hash_list, doc.mod_time) + table.insert(hash_list, doc.render_color and 'color' or 'bw') table.insert(hash_list, pageno) doc.configurable:hash(hash_list) table.insert(hash_list, bbox.x0) diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index 35e13f01c..72bc73230 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -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 diff --git a/frontend/ui/widget/htmlboxwidget.lua b/frontend/ui/widget/htmlboxwidget.lua index 447d89472..3b4b36291 100644 --- a/frontend/ui/widget/htmlboxwidget.lua +++ b/frontend/ui/widget/htmlboxwidget.lua @@ -84,18 +84,11 @@ function HtmlBoxWidget:_render() if self.bb then 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) + self.document:setColorRendering(Screen:isColorEnabled()) 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()