PDF contrast: incorrect set by a gesture (#10798)

reviewable/pr10874/r1
hius07 8 months ago committed by GitHub
parent 4cc620b702
commit a767ad44db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,10 +21,7 @@ function ReaderKoptListener:onReadSettings(config)
normal_zoom_mode = ReaderZooming.zoom_mode_label[normal_zoom_mode] and normal_zoom_mode or ReaderZooming.DEFAULT_ZOOM_MODE
self.normal_zoom_mode = normal_zoom_mode
self:setZoomMode(normal_zoom_mode)
self.document.configurable.contrast = config:readSetting("kopt_contrast")
or G_reader_settings:readSetting("kopt_contrast")
or 1.0
self.ui:handleEvent(Event:new("GammaUpdate", 1/self.document.configurable.contrast))
self.ui:handleEvent(Event:new("GammaUpdate", self.document.configurable.contrast))
-- since K2pdfopt v2.21 negative value of word spacing is also used, for config
-- compatability we should manually change previous -1 to a more reasonable -0.2
if self.document.configurable.word_spacing == -1 then

@ -862,7 +862,10 @@ function ReaderView:onReadSettings(config)
if self.ui.paging then
self.document:setTileCacheValidity(config:readSetting("tile_cache_validity_ts"))
self.render_mode = config:readSetting("render_mode") or 0
self.state.gamma = config:readSetting("gamma") or 1.0
if config:has("gamma") then -- old doc contrast setting
config:saveSetting("kopt_contrast", config:readSetting("gamma"))
config:delSetting("gamma")
end
end
local rotation_mode = nil
local locked = G_reader_settings:isTrue("lock_rotation")
@ -996,7 +999,7 @@ function ReaderView:onGammaUpdate(gamma)
if self.page_scroll then
self.ui:handleEvent(Event:new("UpdateScrollPageGamma", gamma))
end
Notification:notify(T(_("Font gamma set to: %1."), gamma))
Notification:notify(T(_("Contrast set to: %1."), gamma))
end
-- For ReaderKOptListener
@ -1073,7 +1076,6 @@ function ReaderView:onSaveSettings()
end
self.ui.doc_settings:saveSetting("tile_cache_validity_ts", self.document:getTileCacheValidity())
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
self.ui.doc_settings:saveSetting("gamma", self.state.gamma)
end
-- Don't etch the current rotation in stone when sticky rotation is enabled
local locked = G_reader_settings:isTrue("lock_rotation")

@ -226,7 +226,7 @@ local settingsList = {
kopt_font_fine_tune = {category="string", paging=true},
kopt_word_spacing = {category="configurable", paging=true},
kopt_text_wrap = {category="string", paging=true},
kopt_contrast = {category="absolutenumber", paging=true},
kopt_contrast = {category="string", paging=true},
kopt_page_opt = {category="configurable", paging=true},
kopt_hw_dithering = {category="configurable", paging=true, condition=Device:hasEinkScreen() and Device:canHWDither()},
kopt_sw_dithering = {category="configurable", paging=true, condition=Device:hasEinkScreen() and not Device:canHWDither() and Device.screen.fb_bpp == 8},

@ -144,7 +144,8 @@ function KoptInterface:createContext(doc, pageno, bbox)
kc:setZoom(doc.configurable.font_size)
kc:setMargin(doc.configurable.page_margin)
kc:setQuality(doc.configurable.quality)
kc:setContrast(doc.configurable.contrast)
-- k2pdfopt (for reflowing) and mupdf use different algorithms to apply gamma when rendering
kc:setContrast(1 / doc.configurable.contrast)
kc:setDefectSize(doc.configurable.defect_size)
kc:setLineSpacing(doc.configurable.line_spacing)
kc:setWordSpacing(doc.configurable.word_spacing)

@ -483,7 +483,7 @@ Some of the other settings are only available when reflow mode is enabled.]]),
buttonprogress = true,
-- See https://github.com/koreader/koreader/issues/1299#issuecomment-65183895
-- For pdf reflowing mode (kopt_contrast):
values = {1/0.8, 1/1.0, 1/1.5, 1/2.0, 1/4.0, 1/6.0, 1/10.0, 1/50.0},
values = {0.8, 1.0, 1.5, 2.0, 4.0, 6.0, 10.0, 50.0},
default_pos = 2,
default_value = G_defaults:readSetting("DKOPTREADER_CONFIG_CONTRAST"),
event = "GammaUpdate",
@ -491,6 +491,12 @@ Some of the other settings are only available when reflow mode is enabled.]]),
args = {0.8, 1.0, 1.5, 2.0, 4.0, 6.0, 10.0, 50.0},
labels = {0.8, 1.0, 1.5, 2.0, 4.0, 6.0, 10.0, 50.0},
name_text_hold_callback = optionsutil.showValues,
more_options = true,
more_options_param = {
value_step = 0.1, value_hold_step = 1,
value_min = 0.8, value_max = 50,
precision = "%.1f",
},
},
{
name = "page_opt",

@ -10,7 +10,7 @@ local util = require("util")
local _ = require("gettext")
-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20230802
local CURRENT_MIGRATION_DATE = 20230901
-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
@ -622,5 +622,15 @@ if last_migration_date < 20230802 then
end
end
-- 20230901, new handling of the pdf contrast ("gamma") setting
if last_migration_date < 20230901 then
logger.info("Performing one-time migration for 20230901")
local contrast = G_reader_settings:readSetting("kopt_contrast")
if contrast then
G_reader_settings:saveSetting("kopt_contrast", 1 / contrast)
end
end
-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)

Loading…
Cancel
Save