mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
kopt: color support
Keep colors when reflowing documents.
This commit is contained in:
committed by
Frans de Jonge
parent
cb002f3d1f
commit
0c17941ffb
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user