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.
reviewable/pr9202/r1
poire-z 2 years ago
parent b9724f1e93
commit cc185bae4e

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

@ -1,9 +1,10 @@
local Device = require("device")
local Screen = Device.screen
local ffiUtil = require("ffi/util")
local optionsutil = require("ui/data/optionsutil")
local _ = require("gettext")
local C_ = _.pgettext
local T = require("ffi/util").template
local T = ffiUtil.template
-- Get font size numbers as a table of strings
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},
default_arg = nil,
event = "ToggleEmbeddedFonts",
enabled_func = function(configurable)
enabled_func = function(configurable, document)
return optionsutil.enableIfEquals(configurable, "embedded_css", 1)
and next(document:getEmbeddedFontList()) ~= nil
end,
name_text_hold_callback = optionsutil.showValues,
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.)]]),
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",

@ -101,7 +101,10 @@ function optionsutil.showValues(configurable, option, prefix, document)
end
if option.help_text_func then
-- 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
local text
local name_text = option.name_text_func

Loading…
Cancel
Save