Embedded fonts toggle: disabled if no embedded font

Have the enabled/disabled state of the toggle show the
presence or not of embedded fonts in the current book.
Also show the names of the embedded fonts in the
help_text InfoMessage.
pull/9202/head
poire-z 2 years ago
parent b9724f1e93
commit cc185bae4e

@ -797,6 +797,10 @@ function CreDocument:getFontFace()
return self._document:getFontFace() return self._document:getFontFace()
end end
function CreDocument:getEmbeddedFontList()
return self._document:getEmbeddedFontList()
end
function CreDocument:getCurrentPos() function CreDocument:getCurrentPos()
return self._document:getCurrentPos() return self._document:getCurrentPos()
end end

@ -1,9 +1,10 @@
local Device = require("device") local Device = require("device")
local Screen = Device.screen local Screen = Device.screen
local ffiUtil = require("ffi/util")
local optionsutil = require("ui/data/optionsutil") local optionsutil = require("ui/data/optionsutil")
local _ = require("gettext") local _ = require("gettext")
local C_ = _.pgettext local C_ = _.pgettext
local T = require("ffi/util").template local T = ffiUtil.template
-- Get font size numbers as a table of strings -- Get font size numbers as a table of strings
local tableOfNumbersToTableOfStrings = function(numbers) local tableOfNumbersToTableOfStrings = function(numbers)
@ -700,12 +701,24 @@ Whether enabled or disabled, KOReader's own status bar at the bottom of the scre
args = {false, true}, args = {false, true},
default_arg = nil, default_arg = nil,
event = "ToggleEmbeddedFonts", event = "ToggleEmbeddedFonts",
enabled_func = function(configurable) enabled_func = function(configurable, document)
return optionsutil.enableIfEquals(configurable, "embedded_css", 1) return optionsutil.enableIfEquals(configurable, "embedded_css", 1)
and next(document:getEmbeddedFontList()) ~= nil
end, end,
name_text_hold_callback = optionsutil.showValues, name_text_hold_callback = optionsutil.showValues,
help_text = _([[Enable or disable the use of the fonts embedded in the book. help_text = _([[Enable or disable the use of the fonts embedded in the book.
(Disabling the fonts specified in the publisher stylesheets can also be achieved via Style Tweaks in the main menu.)]]), (Disabling the fonts specified in the publisher stylesheets can also be achieved via Style Tweaks in the main menu.)]]),
help_text_func = function(configurable, document)
local font_list = document:getEmbeddedFontList()
if next(font_list) then
local font_details = {}
table.insert(font_details, _("Embedded fonts provided by the current book:"))
for name in ffiUtil.orderedPairs(font_list) do
table.insert(font_details, name .. (font_list[name] and "" or T(" (%1)", _("not used"))))
end
return table.concat(font_details, "\n")
end
end,
}, },
{ {
name = "smooth_scaling", name = "smooth_scaling",

@ -101,7 +101,10 @@ function optionsutil.showValues(configurable, option, prefix, document)
end end
if option.help_text_func then if option.help_text_func then
-- Allow for concatenating a dynamic help_text_func to a static help_text -- Allow for concatenating a dynamic help_text_func to a static help_text
help_text = T("%1\n%2\n", help_text, option.help_text_func(configurable, document)) local more_text = option.help_text_func(configurable, document)
if more_text and more_text ~= "" then
help_text = T("%1\n%2\n", help_text, more_text)
end
end end
local text local text
local name_text = option.name_text_func local name_text = option.name_text_func

Loading…
Cancel
Save