From a767ad44db5a22c6d14c505241e8698fa3113c69 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sat, 2 Sep 2023 09:41:27 +0300 Subject: [PATCH] PDF contrast: incorrect set by a gesture (#10798) --- frontend/apps/reader/modules/readerkoptlistener.lua | 5 +---- frontend/apps/reader/modules/readerview.lua | 8 +++++--- frontend/dispatcher.lua | 2 +- frontend/document/koptinterface.lua | 3 ++- frontend/ui/data/koptoptions.lua | 8 +++++++- frontend/ui/data/onetime_migration.lua | 12 +++++++++++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/frontend/apps/reader/modules/readerkoptlistener.lua b/frontend/apps/reader/modules/readerkoptlistener.lua index 935ea4623..2a09a9e30 100644 --- a/frontend/apps/reader/modules/readerkoptlistener.lua +++ b/frontend/apps/reader/modules/readerkoptlistener.lua @@ -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 diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index d76f45992..11184d5f3 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -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") diff --git a/frontend/dispatcher.lua b/frontend/dispatcher.lua index ddae58e00..cee7d1709 100644 --- a/frontend/dispatcher.lua +++ b/frontend/dispatcher.lua @@ -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}, diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 133d93017..4f17b264e 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -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) diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index daaa7b608..da3ebe7f0 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -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", diff --git a/frontend/ui/data/onetime_migration.lua b/frontend/ui/data/onetime_migration.lua index 9381a3ef9..fa47164ae 100644 --- a/frontend/ui/data/onetime_migration.lua +++ b/frontend/ui/data/onetime_migration.lua @@ -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)