Allow disabling automagic image inversion in Nightmode in CRe (#5095)

* Allow disabling automagic image inversion in NightMode

Fix #4986
pull/5097/head
NiLuJe 5 years ago committed by GitHub
parent fca51757af
commit 4ccb1f3dd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,6 +96,14 @@ function ReaderTypeset:onReadSettings(config)
self.smooth_scaling = (global == nil or global == 0) and 0 or 1
end
self:toggleImageScaling(self.smooth_scaling)
-- default to automagic nightmode-friendly handling of images
self.nightmode_images = config:readSetting("nightmode_images")
if self.nightmode_images == nil then
local global = G_reader_settings:readSetting("copt_nightmode_images")
self.nightmode_images = (global == nil or global == 1) and 1 or 0
end
self:toggleNightmodeImages(self.nightmode_images)
end
function ReaderTypeset:onSaveSettings()
@ -105,6 +113,7 @@ function ReaderTypeset:onSaveSettings()
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)
@ -122,6 +131,11 @@ function ReaderTypeset:onToggleImageScaling(toggle)
return true
end
function ReaderTypeset:onToggleNightmodeImages(toggle)
self:toggleNightmodeImages(toggle)
return true
end
-- June 2018: epub.css has been cleaned to be more conforming to HTML specs
-- and to not include class name based styles (with conditional compatiblity
-- styles for previously opened documents). It should be usable on all
@ -286,6 +300,17 @@ function ReaderTypeset:toggleImageScaling(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:handleEvent(Event:new("UpdatePos"))
end
function ReaderTypeset:toggleFloatingPunctuation(toggle)
-- for some reason the toggle value read from history files may stay boolean
-- and there seems no more elegant way to convert boolean values to numbers

@ -23,6 +23,7 @@ local CreDocument = Document:new{
_loaded = false,
_view_mode = nil,
_smooth_scaling = false,
_nightmode_images = true,
line_space_percent = 100,
default_font = "Noto Serif",
@ -378,7 +379,7 @@ function CreDocument:drawCurrentView(target, x, y, rect, pos)
-- local start_clock = os.clock()
self._drawn_images_count, self._drawn_images_surface_ratio =
self._document:drawCurrentPage(self.buffer, self.render_color, Screen.night_mode, self._smooth_scaling, Screen.sw_dithering)
self._document:drawCurrentPage(self.buffer, self.render_color, Screen.night_mode and self._nightmode_images, self._smooth_scaling, Screen.sw_dithering)
-- print(string.format("CreDocument:drawCurrentView: Rendering took %9.3f ms", (os.clock() - start_clock) * 1000))
-- start_clock = os.clock()
@ -736,6 +737,11 @@ function CreDocument:setImageScaling(toggle)
self._smooth_scaling = toggle
end
function CreDocument:setNightmodeImages(toggle)
logger.dbg("CreDocument: set nightmode images", toggle)
self._nightmode_images = toggle
end
function CreDocument:setFloatingPunctuation(enabled)
-- FIXME: occasional segmentation fault when toggling floating punctuation
logger.dbg("CreDocument: set floating punctuation", enabled)

@ -427,6 +427,19 @@ Note that your selected font size is not affected by this setting.]]),
help_text = _([[- 'fast' uses a fast but inaccurate scaling algorithm when scaling images.
- 'best' switches to a more costly but vastly more pleasing and accurate algorithm.]]),
},
{
name = "nightmode_images",
name_text = S.NIGHTMODE_IMAGES,
toggle = {S.ON, S.OFF},
values = {1, 0},
default_value = 1,
args = {true, false},
default_arg = nil,
event = "ToggleNightmodeImages",
show_func = function() return Device.screen.night_mode end,
name_text_hold_callback = optionsutil.showValues,
help_text = _([[Disable the automagic inversion of images when nightmode is enabled. Useful if your book contains mainly inlined mathematical content or scene break art.]]),
},
},
},
}

@ -40,6 +40,7 @@ S.FORCED_OCR = _("Forced OCR")
S.HW_DITHERING = _("Dithering")
S.INVERSE_READING_ORDER = _("Inverse Order")
S.IMAGE_SCALING = _("Image Scaling")
S.NIGHTMODE_IMAGES = _("Invert Images")
S.ON = _("on")
S.OFF = _("off")

@ -196,7 +196,12 @@ function ConfigOption:init()
for c = 1, #self.options do
-- Ignore names of options that won't be shown
local show_default = not self.options[c].advanced or show_advanced
if self.options[c].show ~= false and show_default then
local show = self.options[c].show
-- Prefer show_func over show if there's one
if self.options[c].show_func then
show = self.options[c].show_func()
end
if show ~= false and show_default then
local name_font_face = self.options[c].name_font_face and self.options[c].name_font_face or "cfont"
local name_font_size = self.options[c].name_font_size and self.options[c].name_font_size or default_name_font_size
local text = self.options[c].name_text
@ -225,7 +230,12 @@ function ConfigOption:init()
for c = 1, #self.options do
local show_default = not self.options[c].advanced or show_advanced
if self.options[c].show ~= false and show_default then
local show = self.options[c].show
-- Prefer show_func over show if there's one
if self.options[c].show_func then
show = self.options[c].show_func()
end
if show ~= false and show_default then
local name_align = self.options[c].name_align_right and self.options[c].name_align_right or default_name_align_right
local item_align = self.options[c].item_align_center and self.options[c].item_align_center or default_item_align_center
local name_font_face = self.options[c].name_font_face and self.options[c].name_font_face or "cfont"
@ -574,7 +584,7 @@ function ConfigOption:init()
table.insert(self.config.layout, #self.config.layout,self:_itemGroupToLayoutLine(option_items_group))
table.insert(horizontal_group, option_items_container)
table.insert(vertical_group, horizontal_group)
end -- if self.options[c].show ~= false
end -- if show ~= false
end -- for c = 1, #self.options
table.insert(vertical_group, VerticalSpan:new{ width = default_option_vpadding })

Loading…
Cancel
Save