kopt: option to invert document in night mode (#14954)
This commit is contained in:
1 parent
9b03ee8c6d
commit
a47ecfcdc2
4 files changed
+51
-8
No files matched your search
@@ -299,6 +299,7 @@ local settingsList = {
|
||||
kopt_forced_ocr = {category="configurable", paging=true},
|
||||
kopt_writing_direction = {category="configurable", paging=true},
|
||||
kopt_defect_size = {category="string", paging=true}, -- not shown in the bottom menu
|
||||
kopt_nightmode_document = {category="configurable", paging=true},
|
||||
kopt_max_columns = {category="configurable", paging=true},
|
||||
kopt_auto_straighten = {category="absolutenumber", paging=true},
|
||||
|
||||
@@ -551,6 +552,7 @@ local dispatcher_menu_order = {
|
||||
"kopt_forced_ocr",
|
||||
"kopt_writing_direction",
|
||||
"kopt_defect_size",
|
||||
"kopt_nightmode_document",
|
||||
"kopt_max_columns",
|
||||
"kopt_auto_straighten",
|
||||
}
|
||||
|
||||
@@ -547,6 +547,15 @@ function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
end
|
||||
end
|
||||
|
||||
function Document:drawPageInverted(target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
local tile = self:renderPage(pageno, rect, zoom, rotation, gamma)
|
||||
target:invertblitFrom(tile.bb,
|
||||
x, y,
|
||||
rect.x - tile.excerpt.x,
|
||||
rect.y - tile.excerpt.y,
|
||||
rect.w, rect.h)
|
||||
end
|
||||
|
||||
function Document:getDrawnImagesStatistics()
|
||||
-- For now, only set by CreDocument in CreDocument:drawCurrentView()
|
||||
-- Returns 0, 0 (as per Document:init) otherwise.
|
||||
|
||||
@@ -12,6 +12,7 @@ local FFIUtil = require("ffi/util")
|
||||
local Geom = require("ui/geometry")
|
||||
local KOPTContext = require("ffi/koptcontext")
|
||||
local Persist = require("persist")
|
||||
local Screen = require("device").screen
|
||||
local TileCacheItem = require("document/tilecacheitem")
|
||||
local Utf8Proc = require("ffi/utf8proc")
|
||||
local logger = require("logger")
|
||||
@@ -577,10 +578,13 @@ function KoptInterface:hintReflowedPage(doc, pageno, zoom, rotation, gamma, hint
|
||||
end
|
||||
|
||||
function KoptInterface:drawPage(doc, target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
local nightmode_invert = doc.configurable.nightmode_document == 1 and Screen.night_mode
|
||||
if doc.configurable.text_wrap == 1 then
|
||||
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation)
|
||||
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
|
||||
elseif doc.configurable.page_opt == 1 or doc.configurable.auto_straighten > 0 then
|
||||
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation)
|
||||
self:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
|
||||
elseif nightmode_invert then
|
||||
Document.drawPageInverted(doc, target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
else
|
||||
Document.drawPage(doc, target, x, y, rect, pageno, zoom, rotation, gamma)
|
||||
end
|
||||
@@ -591,13 +595,31 @@ Draw cached tile pixels into target blitbuffer.
|
||||
|
||||
Inherited from common document interface.
|
||||
--]]
|
||||
function KoptInterface:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation)
|
||||
function KoptInterface:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert)
|
||||
local tile = self:renderPage(doc, pageno, rect, zoom, rotation, 1.0)
|
||||
target:blitFrom(tile.bb,
|
||||
x, y,
|
||||
rect.x - tile.excerpt.x,
|
||||
rect.y - tile.excerpt.y,
|
||||
rect.w, rect.h)
|
||||
local offs_x = rect.x - tile.excerpt.x
|
||||
local offs_y = rect.y - tile.excerpt.y
|
||||
if nightmode_invert then
|
||||
if doc.configurable.page_opt == 1 then
|
||||
-- Dewatermark enabled: draw tile, then invert the drawn area
|
||||
target:blitFrom(tile.bb,
|
||||
x, y,
|
||||
offs_x, offs_y,
|
||||
rect.w, rect.h)
|
||||
target:invertRect(x, y, rect.w, rect.h)
|
||||
else
|
||||
-- Dewatermark disabled: invert tile directly
|
||||
target:invertblitFrom(tile.bb,
|
||||
x, y,
|
||||
offs_x, offs_y,
|
||||
rect.w, rect.h)
|
||||
end
|
||||
else
|
||||
target:blitFrom(tile.bb,
|
||||
x, y,
|
||||
offs_x, offs_y,
|
||||
rect.w, rect.h)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
@@ -630,6 +630,16 @@ This can also be used to remove some gray background or to convert a grayscale o
|
||||
end,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
},
|
||||
{
|
||||
name = "nightmode_document",
|
||||
name_text = _("Invert Document"),
|
||||
toggle = {_("off"), _("on")},
|
||||
values = {0, 1},
|
||||
default_value = 0,
|
||||
show_func = function() return Device.screen.night_mode end,
|
||||
name_text_hold_callback = optionsutil.showValues,
|
||||
help_text = _([[Invert document in night mode. Useful for image-heavy documents such as comics or manga.]]),
|
||||
},
|
||||
{
|
||||
name = "max_columns",
|
||||
name_text = _("Document Columns"),
|
||||
|
||||
Reference in new issue
Block a user