mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
copt deduplicate: smooth_scaling, nightmode_images (#10801)
Main discussion in #10763.
This commit is contained in:
@@ -110,23 +110,11 @@ function ReaderTypeset:onReadSettings(config)
|
||||
or 1
|
||||
self:toggleTxtPreFormatted(self.txt_preformatted)
|
||||
|
||||
-- default to disable smooth scaling for now.
|
||||
if config:has("smooth_scaling") then
|
||||
self.smooth_scaling = config:isTrue("smooth_scaling")
|
||||
else
|
||||
local global = G_reader_settings:readSetting("copt_smooth_scaling")
|
||||
self.smooth_scaling = global == 1 and true or false
|
||||
end
|
||||
self:toggleImageScaling(self.smooth_scaling)
|
||||
-- default to disable smooth scaling
|
||||
self:toggleImageScaling(self.configurable.smooth_scaling == 1)
|
||||
|
||||
-- default to automagic nightmode-friendly handling of images
|
||||
if config:has("nightmode_images") then
|
||||
self.nightmode_images = config:isTrue("nightmode_images")
|
||||
else
|
||||
local global = G_reader_settings:readSetting("copt_nightmode_images")
|
||||
self.nightmode_images = (global == nil or global == 1) and true or false
|
||||
end
|
||||
self:toggleNightmodeImages(self.nightmode_images)
|
||||
self:toggleNightmodeImages(self.configurable.nightmode_images == 1)
|
||||
end
|
||||
|
||||
function ReaderTypeset:onSaveSettings()
|
||||
@@ -134,8 +122,6 @@ function ReaderTypeset:onSaveSettings()
|
||||
self.ui.doc_settings:saveSetting("embedded_css", self.embedded_css)
|
||||
self.ui.doc_settings:saveSetting("embedded_fonts", self.embedded_fonts)
|
||||
self.ui.doc_settings:saveSetting("render_dpi", self.render_dpi)
|
||||
self.ui.doc_settings:saveSetting("smooth_scaling", self.smooth_scaling)
|
||||
self.ui.doc_settings:saveSetting("nightmode_images", self.nightmode_images)
|
||||
end
|
||||
|
||||
function ReaderTypeset:onToggleEmbeddedStyleSheet(toggle)
|
||||
@@ -159,12 +145,14 @@ function ReaderTypeset:onToggleEmbeddedFonts(toggle)
|
||||
end
|
||||
|
||||
function ReaderTypeset:onToggleImageScaling(toggle)
|
||||
self.configurable.smooth_scaling = toggle and 1 or 0
|
||||
self:toggleImageScaling(toggle)
|
||||
Notification:notify(T( _("Image scaling set to: %1"), optionsutil:getOptionText("ToggleImageScaling", toggle)))
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderTypeset:onToggleNightmodeImages(toggle)
|
||||
self.configurable.nightmode_images = toggle and 1 or 0
|
||||
self:toggleNightmodeImages(toggle)
|
||||
return true
|
||||
end
|
||||
@@ -405,24 +393,12 @@ function ReaderTypeset:ensureSanerBlockRenderingFlags(mode)
|
||||
end
|
||||
|
||||
function ReaderTypeset:toggleImageScaling(toggle)
|
||||
if toggle and (toggle == true or toggle == 1) then
|
||||
self.smooth_scaling = true
|
||||
self.ui.document:setImageScaling(true)
|
||||
else
|
||||
self.smooth_scaling = false
|
||||
self.ui.document:setImageScaling(false)
|
||||
end
|
||||
self.ui.document:setImageScaling(toggle)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
end
|
||||
|
||||
function ReaderTypeset:toggleNightmodeImages(toggle)
|
||||
if toggle and (toggle == true or toggle == 1) then
|
||||
self.nightmode_images = true
|
||||
self.ui.document:setNightmodeImages(true)
|
||||
else
|
||||
self.nightmode_images = false
|
||||
self.ui.document:setNightmodeImages(false)
|
||||
end
|
||||
self.ui.document:setNightmodeImages(toggle)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
end
|
||||
|
||||
|
||||
@@ -318,6 +318,7 @@ function ReaderUI:init()
|
||||
})
|
||||
-- typeset controller
|
||||
self:registerModule("typeset", ReaderTypeset:new{
|
||||
configurable = self.document.configurable,
|
||||
dialog = self.dialog,
|
||||
view = self.view,
|
||||
ui = self
|
||||
|
||||
@@ -316,6 +316,7 @@ function Profiles:getProfileFromCurrentDocument(new_name)
|
||||
"embedded_css",
|
||||
"embedded_fonts",
|
||||
"smooth_scaling",
|
||||
"nightmode_images",
|
||||
}
|
||||
else
|
||||
document_settings = {
|
||||
@@ -338,11 +339,16 @@ function Profiles:getProfileFromCurrentDocument(new_name)
|
||||
}
|
||||
end
|
||||
local setting_needs_arg = {
|
||||
["view_mode"] = true,
|
||||
["kopt_trim_page"] = true,
|
||||
["kopt_zoom_mode_genus"] = true,
|
||||
["kopt_zoom_mode_type"] = true,
|
||||
["kopt_page_scroll"] = true,
|
||||
["sync_t_b_page_margins"] = true,
|
||||
["view_mode"] = true,
|
||||
["embedded_css"] = true,
|
||||
["embedded_fonts"] = true,
|
||||
["smooth_scaling"] = true,
|
||||
["nightmode_images"] = true,
|
||||
["kopt_trim_page"] = true,
|
||||
["kopt_zoom_mode_genus"] = true,
|
||||
["kopt_zoom_mode_type"] = true,
|
||||
["kopt_page_scroll"] = true,
|
||||
}
|
||||
|
||||
local profile = { settings = { name = new_name, order = document_settings } }
|
||||
@@ -355,11 +361,7 @@ function Profiles:getProfileFromCurrentDocument(new_name)
|
||||
profile[v] = value
|
||||
end
|
||||
if self.ui.rolling then
|
||||
profile["set_font"] = self.ui.font.font_face
|
||||
profile["sync_t_b_page_margins"] = self.ui.typeset.sync_t_b_page_margins
|
||||
profile["embedded_css"] = self.ui.typeset.embedded_css
|
||||
profile["embedded_fonts"] = self.ui.typeset.embedded_fonts
|
||||
profile["smooth_scaling"] = self.ui.typeset.smooth_scaling
|
||||
profile["set_font"] = self.ui.font.font_face -- not in configurable settings
|
||||
end
|
||||
return profile
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user