copt deduplicate: render_dpi, margins, rotation_mode (#10880)

reviewable/pr10890/r1
hius07 8 months ago committed by GitHub
parent 73378cd9d7
commit 7d626456a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,14 +13,11 @@ local ReaderCoptListener = EventListener:extend{}
local CRE_HEADER_DEFAULT_SIZE = 20
function ReaderCoptListener:onReadSettings(config)
local view_mode = config:readSetting("copt_view_mode")
or G_reader_settings:readSetting("copt_view_mode")
or 0 -- default to "page" mode
local view_mode_name = view_mode == 0 and "page" or "scroll"
local view_mode_name = self.document.configurable.view_mode == 0 and "page" or "scroll"
-- Let crengine know of the view mode before rendering, as it can
-- cause a rendering change (2-pages would become 1-page in
-- scroll mode).
self.ui.document:setViewMode(view_mode_name)
self.document:setViewMode(view_mode_name)
-- ReaderView is the holder of the view_mode state
self.view.view_mode = view_mode_name
@ -35,20 +32,19 @@ function ReaderCoptListener:onReadSettings(config)
self.battery_percent = G_reader_settings:readSetting("cre_header_battery_percent", 0)
self.chapter_marks = G_reader_settings:readSetting("cre_header_chapter_marks", 1)
self.ui.document._document:setIntProperty("window.status.title", self.title)
self.ui.document._document:setIntProperty("window.status.clock", self.clock)
self.ui.document._document:setIntProperty("window.status.pos.page.number", self.page_number)
self.ui.document._document:setIntProperty("window.status.pos.page.count", self.page_count)
self.ui.document._document:setIntProperty("crengine.page.header.chapter.marks", self.chapter_marks)
self.ui.document._document:setIntProperty("window.status.battery", self.battery)
self.ui.document._document:setIntProperty("window.status.battery.percent", self.battery_percent)
self.ui.document._document:setIntProperty("window.status.pos.percent", self.reading_percent)
self.document._document:setIntProperty("window.status.title", self.title)
self.document._document:setIntProperty("window.status.clock", self.clock)
self.document._document:setIntProperty("window.status.pos.page.number", self.page_number)
self.document._document:setIntProperty("window.status.pos.page.count", self.page_count)
self.document._document:setIntProperty("crengine.page.header.chapter.marks", self.chapter_marks)
self.document._document:setIntProperty("window.status.battery", self.battery)
self.document._document:setIntProperty("window.status.battery.percent", self.battery_percent)
self.document._document:setIntProperty("window.status.pos.percent", self.reading_percent)
self:onTimeFormatChanged()
-- Enable or disable crengine header status line (note that for crengine, 0=header enabled, 1=header disabled)
local status_line = config:readSetting("copt_status_line") or G_reader_settings:readSetting("copt_status_line", 1)
self.ui:handleEvent(Event:new("SetStatusLine", status_line))
self.ui:handleEvent(Event:new("SetStatusLine", self.document.configurable.status_line))
self.old_battery_level = self.ui.rolling:updateBatteryState()
@ -87,7 +83,7 @@ end
ReaderCoptListener.onNotCharging = ReaderCoptListener.onCharging
function ReaderCoptListener:onTimeFormatChanged()
self.ui.document._document:setIntProperty("window.status.clock.12hours", G_reader_settings:isTrue("twelve_hour_clock") and 1 or 0)
self.document._document:setIntProperty("window.status.clock.12hours", G_reader_settings:isTrue("twelve_hour_clock") and 1 or 0)
end
function ReaderCoptListener:shouldHeaderBeRepainted()
@ -107,14 +103,14 @@ end
function ReaderCoptListener:updateHeader()
-- Have crengine display accurate time and battery on its next drawing
self.ui.document:resetBufferCache() -- be sure next repaint is a redrawing
self.document:resetBufferCache() -- be sure next repaint is a redrawing
-- Force a refresh if we're not hidden behind another widget
if self:shouldHeaderBeRepainted() then
UIManager:setDirty(self.view.dialog, "ui",
Geom:new{
x = 0, y = 0,
w = Device.screen:getWidth(),
h = self.ui.document:getHeaderHeight(),
h = self.document:getHeaderHeight(),
}
)
end
@ -176,7 +172,7 @@ ReaderCoptListener.onCloseDocument = ReaderCoptListener.unscheduleHeaderRefresh
ReaderCoptListener.onSuspend = ReaderCoptListener.unscheduleHeaderRefresh
function ReaderCoptListener:setAndSave(setting, property, value)
self.ui.document._document:setIntProperty(property, value)
self.document._document:setIntProperty(property, value)
G_reader_settings:saveSetting(setting, value)
-- Have crengine redraw it (even if hidden by the menu at this time)
self.ui.rolling:updateBatteryState()

@ -52,41 +52,27 @@ function ReaderTypeset:onReadSettings(config)
or 3 -- default to 'web' mode
end
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
self.ui.document.configurable.block_rendering_mode = self.block_rendering_mode
self.configurable.block_rendering_mode = self.block_rendering_mode
end
self:setBlockRenderingMode(self.block_rendering_mode)
-- set render DPI
self.render_dpi = config:readSetting("render_dpi")
or G_reader_settings:readSetting("copt_render_dpi")
or 96
self:setRenderDPI(self.render_dpi)
-- default to 96 dpi
self.ui.document:setRenderDPI(self.configurable.render_dpi)
-- uncomment if we want font size to follow DPI changes
-- self.ui.document:setRenderScaleFontWithDPI(1)
-- set page margins
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or G_defaults:readSetting("DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM")
local t_margin = config:readSetting("copt_t_page_margin")
or G_reader_settings:readSetting("copt_t_page_margin")
or G_defaults:readSetting("DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE")
local b_margin = config:readSetting("copt_b_page_margin")
or G_reader_settings:readSetting("copt_b_page_margin")
or G_defaults:readSetting("DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE")
self.unscaled_margins = { h_margins[1], t_margin, h_margins[2], b_margin }
self.unscaled_margins = { self.configurable.h_page_margins[1], self.configurable.t_page_margin,
self.configurable.h_page_margins[2], self.configurable.b_page_margin }
self:onSetPageMargins(self.unscaled_margins)
self.sync_t_b_page_margins = config:readSetting("copt_sync_t_b_page_margins")
or G_reader_settings:readSetting("copt_sync_t_b_page_margins")
or 0
self.sync_t_b_page_margins = self.sync_t_b_page_margins == 1 and true or false
self.sync_t_b_page_margins = self.configurable.sync_t_b_page_margins == 1 and true or false
-- default to disable TXT formatting as it does more harm than good
-- default to disable TXT formatting as it does more harm than good (the setting is not in UI)
self.txt_preformatted = config:readSetting("txt_preformatted")
or G_reader_settings:readSetting("txt_preformatted")
or 1
self:toggleTxtPreFormatted(self.txt_preformatted)
self.ui.document:setTxtPreFormatted(self.txt_preformatted)
-- default to disable smooth scaling
self.ui.document:setImageScaling(self.configurable.smooth_scaling == 1)
@ -97,7 +83,6 @@ end
function ReaderTypeset:onSaveSettings()
self.ui.doc_settings:saveSetting("css", self.css)
self.ui.doc_settings:saveSetting("render_dpi", self.render_dpi)
end
function ReaderTypeset:onToggleEmbeddedStyleSheet(toggle)
@ -149,7 +134,17 @@ end
function ReaderTypeset:onSetBlockRenderingMode(mode)
self:setBlockRenderingMode(mode)
Notification:notify(T( _("Render mode set to: %1"), optionsutil:getOptionText("SetBlockRenderingMode", mode)))
local text = T(_("Render mode set to: %1"), optionsutil:getOptionText("SetBlockRenderingMode", mode))
Notification:notify(text)
return true
end
function ReaderTypeset:onSetRenderDPI(dpi)
self.configurable.render_dpi = dpi
self.ui.document:setRenderDPI(dpi)
self.ui:handleEvent(Event:new("UpdatePos"))
local text = T(_("Zoom set to: %1"), optionsutil:getOptionText("SetRenderDPI", dpi))
Notification:notify(text)
return true
end
@ -169,12 +164,6 @@ local OBSOLETED_CSS = {
"txt.css",
}
function ReaderTypeset:onSetRenderDPI(dpi)
self:setRenderDPI(dpi)
Notification:notify(T( _("Zoom set to: %1"), optionsutil:getOptionText("SetRenderDPI", dpi)))
return true
end
function ReaderTypeset:genStyleSheetMenu()
local getStyleMenuItem = function(text, css_file, separator)
return {
@ -358,17 +347,6 @@ function ReaderTypeset:ensureSanerBlockRenderingFlags(mode)
self:setBlockRenderingMode(self.block_rendering_mode)
end
function ReaderTypeset:toggleTxtPreFormatted(toggle)
self.ui.document:setTxtPreFormatted(toggle)
self.ui:handleEvent(Event:new("UpdatePos"))
end
function ReaderTypeset:setRenderDPI(dpi)
self.render_dpi = dpi
self.ui.document:setRenderDPI(dpi)
self.ui:handleEvent(Event:new("UpdatePos"))
end
function ReaderTypeset:addToMainMenu(menu_items)
-- insert table to main reader menu
menu_items.set_render_style = {
@ -379,7 +357,7 @@ end
function ReaderTypeset:makeDefaultStyleSheet(css, text, touchmenu_instance)
UIManager:show(ConfirmBox:new{
text = T( _("Set default style to %1?"), BD.filename(text)),
text = T(_("Set default style to %1?"), BD.filename(text)),
ok_callback = function()
G_reader_settings:saveSetting("copt_css", css)
if touchmenu_instance then touchmenu_instance:updateItems() end
@ -397,7 +375,7 @@ function ReaderTypeset:onSetPageTopMargin(t_margin, when_applied_callback)
if self.sync_t_b_page_margins then
self.unscaled_margins[4] = t_margin
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
self.ui.document.configurable.b_page_margin = t_margin
self.configurable.b_page_margin = t_margin
end
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback))
end
@ -407,7 +385,7 @@ function ReaderTypeset:onSetPageBottomMargin(b_margin, when_applied_callback)
if self.sync_t_b_page_margins then
self.unscaled_margins[2] = b_margin
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
self.ui.document.configurable.t_page_margin = b_margin
self.configurable.t_page_margin = b_margin
end
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback))
end
@ -418,7 +396,7 @@ function ReaderTypeset:onSetPageTopAndBottomMargin(t_b_margins, when_applied_cal
if t_margin ~= b_margin then
-- Set Sync T/B Margins toggle to off, as user explicitly made them differ
self.sync_t_b_page_margins = false
self.ui.document.configurable.sync_t_b_page_margins = 0
self.configurable.sync_t_b_page_margins = 0
end
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback))
end
@ -435,8 +413,8 @@ function ReaderTypeset:onSyncPageTopBottomMargins(toggle, when_applied_callback)
-- and later scaled, the end result could still be different.
-- So just take the mean and make them equal.
local mean_margin = Math.round((self.unscaled_margins[2] + self.unscaled_margins[4]) / 2)
self.ui.document.configurable.t_page_margin = mean_margin
self.ui.document.configurable.b_page_margin = mean_margin
self.configurable.t_page_margin = mean_margin
self.configurable.b_page_margin = mean_margin
self.unscaled_margins = { self.unscaled_margins[1], mean_margin, self.unscaled_margins[3], mean_margin }
self.ui:handleEvent(Event:new("SetPageMargins", self.unscaled_margins, when_applied_callback))
when_applied_callback = nil

@ -867,20 +867,12 @@ function ReaderView:onReadSettings(config)
config:delSetting("gamma")
end
end
local rotation_mode = nil
local locked = G_reader_settings:isTrue("lock_rotation")
-- Keep current rotation by doing nothing when sticky rota is enabled.
if not locked then
-- Honor docsettings's rotation
if config:has("rotation_mode") then
rotation_mode = config:readSetting("rotation_mode") -- Doc's
else
-- No doc specific rotation, pickup global defaults for the doc type
local setting_name = self.ui.paging and "kopt_rotation_mode" or "copt_rotation_mode"
rotation_mode = G_reader_settings:readSetting(setting_name) or Screen.DEVICE_ROTATED_UPRIGHT
end
end
if rotation_mode then
if G_reader_settings:nilOrFalse("lock_rotation") then
local setting_name = self.ui.paging and "kopt_rotation_mode" or "copt_rotation_mode"
-- document.configurable.rotation_mode is not ready yet
local rotation_mode = config:readSetting(setting_name)
or G_reader_settings:readSetting(setting_name)
or Screen.DEVICE_ROTATED_UPRIGHT
self:onSetRotationMode(rotation_mode)
end
local full_screen = config:readSetting("kopt_full_screen") or self.document.configurable.full_screen
@ -1078,9 +1070,8 @@ function ReaderView:onSaveSettings()
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
end
-- Don't etch the current rotation in stone when sticky rotation is enabled
local locked = G_reader_settings:isTrue("lock_rotation")
if not locked then
self.ui.doc_settings:saveSetting("rotation_mode", Screen:getRotationMode())
if G_reader_settings:nilOrFalse("lock_rotation") then
self.document.configurable.rotation_mode = Screen:getRotationMode() -- will be saved by ReaderConfig
end
self.ui.doc_settings:saveSetting("highlight", self.highlight.saved)
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)

@ -51,7 +51,7 @@ local CreOptions = {
{
icon = "appbar.rotation",
options = {
{
{ -- ReaderView
name = "rotation_mode",
name_text = _("Rotation"),
item_icons_func = function()
@ -99,7 +99,7 @@ local CreOptions = {
event = "SetRotationMode",
name_text_hold_callback = optionsutil.showValues,
},
{
{ -- ReaderRolling
name = "visible_pages",
name_text = _("Two Columns"),
toggle = {_("off"), _("on")},
@ -131,7 +131,7 @@ This is disabled in scroll mode. Switching from page mode with two columns to sc
{
icon = "appbar.crop",
options = {
{
{ -- ReaderTypeset
name = "h_page_margins",
name_text = _("L/R Margins"),
buttonprogress = true,
@ -176,7 +176,7 @@ This is disabled in scroll mode. Switching from page mode with two columns to sc
right_hold_step = 5,
},
},
{
{ -- ReaderTypeset
name = "sync_t_b_page_margins",
name_text = _("Sync T/B Margins"),
toggle = {_("off"), _("on")},
@ -193,7 +193,7 @@ This is disabled in scroll mode. Switching from page mode with two columns to sc
In the top menu Settings Status bar, you can choose whether the bottom margin applies from the bottom of the screen, or from above the status bar.]]),
},
{
{ -- ReaderTypeset
name = "t_page_margin",
name_text = _("Top Margin"),
buttonprogress = true,
@ -247,7 +247,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
right_hold_step = 5,
},
},
{
{ -- ReaderTypeset
name = "b_page_margin",
name_text = _("Bottom Margin"),
buttonprogress = true,
@ -305,7 +305,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
{
icon = "appbar.pageview",
options = {
{
{ -- ReaderView
name = "view_mode",
name_text = _("View Mode"),
toggle = {_("page"), _("continuous")},
@ -318,7 +318,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
help_text = _([[- 'page' mode splits the text into pages, at the most acceptable places (page numbers and the number of pages may change when you change fonts, margins, styles, etc.).
- 'continuous' mode allows you to scroll the text like you would in a web browser (the 'Page Overlap' setting is only available in this mode).]]),
},
{
{ -- ReaderTypeset
name = "block_rendering_mode",
name_text = _("Render Mode"),
toggle = {_("legacy"), _("flat"), _("book"), _("web")},
@ -334,7 +334,7 @@ In the top menu → Settings → Status bar, you can choose whether the bottom m
- 'book' additionally allows floats, but limits style support to avoid blank spaces and overflows.
- 'web' renders as web browsers do, allowing negative margins and possible page overflow.]]),
},
{
{ -- ReaderTypeset
name = "render_dpi",
name_text = _("Zoom (dpi)"),
more_options = true,
@ -363,7 +363,7 @@ Note that your selected font size is not affected by this setting.]]),
end,
},
{
{ -- ReaderFont
name = "line_spacing",
name_text = _("Line Spacing"),
buttonprogress = true,
@ -418,7 +418,7 @@ Note that your selected font size is not affected by this setting.]]),
{
icon = "appbar.textsize",
options = {
{
{ -- ReaderFont
name = "font_size",
alt_name_text = _("Font Size"),
item_text = tableOfNumbersToTableOfStrings(G_defaults:readSetting("DCREREADER_CONFIG_FONT_SIZES")),
@ -430,7 +430,7 @@ Note that your selected font size is not affected by this setting.]]),
args = G_defaults:readSetting("DCREREADER_CONFIG_FONT_SIZES"),
event = "SetFontSize",
},
{
{ -- ReaderFont
name = "font_fine_tune",
name_text = _("Font Size"),
toggle = Device:isTouchDevice() and {_("decrease"), _("increase")} or nil,
@ -458,7 +458,7 @@ Note that your selected font size is not affected by this setting.]]),
optionsutil.showValues(configurable, opt, prefix, nil, "pt")
end,
},
{
{ -- ReaderFont
name = "word_spacing",
name_text = _("Word Spacing"),
more_options = true,
@ -501,7 +501,7 @@ Note that your selected font size is not affected by this setting.]]),
return string.format("%d\u{202F}%%, %d\u{202F}%%", val[1], val[2]) -- use Narrow Now-Break space here
end,
},
{
{ -- ReaderFont
name = "word_expansion",
name_text = _("Word Expansion"),
more_options = true,
@ -540,7 +540,7 @@ Note that your selected font size is not affected by this setting.]]),
return string.format("%d\u{202F}%%", val) -- use Narrow No-Break space here
end,
},
{
{ -- ReaderFont
-- This option is not shown in the bottom menu, but its fine tuning is made
-- available via the other_button in Word Expansion's fine tuning widget.
-- We still need to define it as an option here for it to be known and
@ -572,7 +572,7 @@ Note that your selected font size is not affected by this setting.]]),
{
icon = "appbar.contrast",
options = {
{
{ -- ReaderFont
name = "font_gamma",
name_text = _("Contrast"),
buttonprogress = true,
@ -597,7 +597,7 @@ Note that your selected font size is not affected by this setting.]]),
value_table_shift = 1,
},
},
{
{ -- ReaderFont
name = "font_base_weight",
name_text = _("Font Weight"),
toggle = { "-1", "", "0", "", "+1", "+1½", "+3" },
@ -631,7 +631,7 @@ If a font variation is not available, as well as for fractional adjustments, it
return weightClassToString(400+val*100)
end,
},
{
{ -- ReaderFont
name = "font_hinting",
name_text = _("Font Hinting"),
toggle = {C_("Font hinting", "off"), C_("Font hinting", "native"), C_("Font hinting", "auto")},
@ -646,7 +646,7 @@ If a font variation is not available, as well as for fractional adjustments, it
- native: use the font internal hinting instructions.
- auto: use FreeType's hinting algorithm, ignoring font instructions.]]),
},
{
{ -- ReaderFont
name = "font_kerning",
name_text = _("Font Kerning"),
toggle = {_("off"), _("fast"), _("good"), _("best")},
@ -669,7 +669,7 @@ If a font variation is not available, as well as for fractional adjustments, it
{
icon = "appbar.settings",
options = {
{
{ -- ReaderRolling
name = "status_line",
name_text = _("Alt Status Bar"),
toggle = {_("off"), _("on")},
@ -683,7 +683,7 @@ If a font variation is not available, as well as for fractional adjustments, it
Whether enabled or disabled, KOReader's own status bar at the bottom of the screen can be toggled by tapping.]]),
},
{
{ -- ReaderTypeset
name = "embedded_css",
name_text = _("Embedded Style"),
toggle = {_("off"), _("on")},
@ -696,7 +696,7 @@ Whether enabled or disabled, KOReader's own status bar at the bottom of the scre
help_text = _([[Enable or disable publisher stylesheets embedded in the book.
(Note that less radical changes can be achieved via Style Tweaks in the main menu.)]]),
},
{
{ -- ReaderTypeset
name = "embedded_fonts",
name_text = _("Embedded Fonts"),
toggle = {_("off"), _("on")},
@ -724,7 +724,7 @@ Whether enabled or disabled, KOReader's own status bar at the bottom of the scre
end
end,
},
{
{ -- ReaderTypeset
name = "smooth_scaling",
name_text = _("Image Scaling"),
toggle = {_("fast"), _("best")},
@ -737,7 +737,7 @@ Whether enabled or disabled, KOReader's own status bar at the bottom of the scre
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.]]),
},
{
{ -- ReaderTypeset
name = "nightmode_images",
name_text = _("Invert Images"),
toggle = {_("on"), _("off")},

@ -317,6 +317,7 @@ function Profiles:getProfileFromCurrentDocument(new_name)
"embedded_fonts",
"smooth_scaling",
"nightmode_images",
"status_line",
}
else
document_settings = {

Loading…
Cancel
Save