mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
CRE: add "CJK width scaling" option
The setting is handled like all other bottom menu options but, as it's really not useful and its target audience is very limited, make it not shown in the bottom menu, but available via another button in the (also quite not useful) Word Expansion fine tuning widget.
This commit is contained in:
@@ -145,6 +145,11 @@ function ReaderFont:onReadSettings(config)
|
||||
or 0
|
||||
self.ui.document:setWordExpansion(self.word_expansion)
|
||||
|
||||
self.cjk_width_scaling = config:readSetting("cjk_width_scaling")
|
||||
or G_reader_settings:readSetting("copt_cjk_width_scaling")
|
||||
or 100
|
||||
self.ui.document:setCJKWidthScaling(self.cjk_width_scaling)
|
||||
|
||||
self.line_space_percent = config:readSetting("line_space_percent")
|
||||
or G_reader_settings:readSetting("copt_line_spacing")
|
||||
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
|
||||
@@ -261,6 +266,14 @@ function ReaderFont:onSetWordExpansion(value)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderFont:onSetCJKWidthScaling(value)
|
||||
self.cjk_width_scaling = value
|
||||
self.ui.document:setCJKWidthScaling(value)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
Notification:notify(T(_("CJK width scaling set to: %1%."), value))
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderFont:onSetFontGamma(gamma)
|
||||
self.gamma_index = gamma
|
||||
self.ui.document:setGammaIndex(self.gamma_index)
|
||||
@@ -279,6 +292,7 @@ function ReaderFont:onSaveSettings()
|
||||
self.ui.doc_settings:saveSetting("font_kerning", self.font_kerning)
|
||||
self.ui.doc_settings:saveSetting("word_spacing", self.word_spacing)
|
||||
self.ui.doc_settings:saveSetting("word_expansion", self.word_expansion)
|
||||
self.ui.doc_settings:saveSetting("cjk_width_scaling", self.cjk_width_scaling)
|
||||
self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent)
|
||||
self.ui.doc_settings:saveSetting("gamma_index", self.gamma_index)
|
||||
end
|
||||
|
||||
@@ -1124,6 +1124,11 @@ function CreDocument:setWordExpansion(value)
|
||||
self._document:setIntProperty("crengine.style.max.added.letter.spacing.percent", value or 0)
|
||||
end
|
||||
|
||||
function CreDocument:setCJKWidthScaling(value)
|
||||
logger.dbg("CreDocument: set cjk width scaling", value)
|
||||
self._document:setIntProperty("crengine.style.cjk.width.scale.percent", value or 100)
|
||||
end
|
||||
|
||||
function CreDocument:setStyleSheet(new_css_file, appended_css_content )
|
||||
logger.dbg("CreDocument: set style sheet:",
|
||||
new_css_file and new_css_file or "no file",
|
||||
|
||||
@@ -510,6 +510,10 @@ Note that your selected font size is not affected by this setting.]]),
|
||||
name_text = _("Max word expansion"),
|
||||
info_text = _([[Set max word expansion as a percentage of the font size.]]),
|
||||
event = "SetWordExpansion",
|
||||
other_button = { -- allow fine tuning the hidden cjk_width_scaling option (defined below)
|
||||
text = _("CJK scaling"),
|
||||
other_option = "cjk_width_scaling",
|
||||
}
|
||||
},
|
||||
toggle = {C_("Word expansion", "none"), C_("Word expansion", "some"), C_("Word expansion", "more")},
|
||||
values = {
|
||||
@@ -531,6 +535,33 @@ Note that your selected font size is not affected by this setting.]]),
|
||||
return string.format("%d\xE2\x80\xAF%%", val) -- use Narrow No-Break space here
|
||||
end,
|
||||
},
|
||||
{
|
||||
-- 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
|
||||
-- handled as any other one - we just make it hidden.
|
||||
show = false,
|
||||
name = "cjk_width_scaling",
|
||||
default_value = 100,
|
||||
values = { 100, 105, 110 }, -- (not shown)
|
||||
event = "SetCJKWidthScaling",
|
||||
more_options = true,
|
||||
more_options_param = {
|
||||
value_min = 100,
|
||||
value_max = 150,
|
||||
value_step = 1,
|
||||
value_hold_step = 5,
|
||||
unit = "%",
|
||||
name = "cjk_width_scaling",
|
||||
name_text = _("CJK width scaling"),
|
||||
info_text = _([[Increase the width of all CJK (Chinese, Japanese, Korean) chararacters by this percentage. This has the effect of adding space between these glyphs, and might make them easier to distinguish to some readers.]]),
|
||||
event = "SetCJKWidthScaling",
|
||||
other_button = {
|
||||
text = _("Word expansion"),
|
||||
other_option = "word_expansion",
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1337,6 +1337,13 @@ function ConfigDialog:onConfigMoreChoose(values, name, event, args, name_text, m
|
||||
end,
|
||||
})
|
||||
end,
|
||||
option_text = more_options_param.other_button and more_options_param.other_button.text,
|
||||
option_callback = more_options_param.other_button and function()
|
||||
when_applied_callback = nil -- prevent bottom menu from being shown (before being hidden again)
|
||||
widget:onClose()
|
||||
local option = self:findOptionByName(more_options_param.other_button.other_option)
|
||||
self:onConfigMoreChoose(option.values, option.name, option.event, nil, option.name_text, option.more_options_param)
|
||||
end,
|
||||
}
|
||||
end
|
||||
UIManager:show(widget)
|
||||
@@ -1421,6 +1428,23 @@ function ConfigDialog:onMakeFineTuneDefault(name, name_text, values, labels, dir
|
||||
})
|
||||
end
|
||||
|
||||
function ConfigDialog:findOptionByName(name)
|
||||
local option
|
||||
for i=1, #self.config_options do
|
||||
local options = self.config_options[i].options
|
||||
for j=1, #options do
|
||||
if options[j].name == name then
|
||||
option = options[j]
|
||||
break
|
||||
end
|
||||
end
|
||||
if option then
|
||||
break
|
||||
end
|
||||
end
|
||||
return option
|
||||
end
|
||||
|
||||
function ConfigDialog:closeDialog()
|
||||
UIManager:close(self)
|
||||
if self.close_callback then
|
||||
|
||||
Reference in New Issue
Block a user