|
|
|
@ -49,11 +49,15 @@ function ReaderFont:init()
|
|
|
|
|
event = "ChangeLineSpace", args = "decrease" },
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
-- build face_table for menu
|
|
|
|
|
-- Build face_table for menu
|
|
|
|
|
self.face_table = {}
|
|
|
|
|
if Device:isAndroid() or Device:isDesktop() or Device:isEmulator() then
|
|
|
|
|
table.insert(self.face_table, require("ui/elements/font_settings"):getMenuTable())
|
|
|
|
|
end
|
|
|
|
|
-- Font settings
|
|
|
|
|
table.insert(self.face_table, {
|
|
|
|
|
text = _("Font settings"),
|
|
|
|
|
sub_item_table = self:getFontSettingsTable(),
|
|
|
|
|
separator = true,
|
|
|
|
|
})
|
|
|
|
|
-- Font list
|
|
|
|
|
local face_list = cre.getFontFaces()
|
|
|
|
|
for k,v in ipairs(face_list) do
|
|
|
|
|
table.insert(self.face_table, {
|
|
|
|
@ -82,20 +86,6 @@ function ReaderFont:init()
|
|
|
|
|
})
|
|
|
|
|
face_list[k] = {text = v}
|
|
|
|
|
end
|
|
|
|
|
if self:hasFontsTestSample() then
|
|
|
|
|
self.face_table[#self.face_table].separator = true
|
|
|
|
|
table.insert(self.face_table, {
|
|
|
|
|
text = _("Generate fonts test HTML document"),
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
|
text = _("Would you like to generate an HTML document showing some sample text rendered with each available font?");
|
|
|
|
|
ok_callback = function()
|
|
|
|
|
self:buildFontsTestDocument()
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -346,24 +336,79 @@ function ReaderFont:onAdjustFontSize(ges, direction)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderFont:hasFontsTestSample()
|
|
|
|
|
local font_test_sample = require("datastorage"):getSettingsDir() .. "/fonts-test-sample.html"
|
|
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
|
|
|
|
return lfs.attributes(font_test_sample, "mode") == "file"
|
|
|
|
|
function ReaderFont:getFontSettingsTable()
|
|
|
|
|
local settings_table = {}
|
|
|
|
|
|
|
|
|
|
if Device:isAndroid() or Device:isDesktop() or Device:isEmulator() then
|
|
|
|
|
for _, item in ipairs(require("ui/elements/font_settings"):getSystemFontMenuItems()) do
|
|
|
|
|
table.insert(settings_table, item)
|
|
|
|
|
end
|
|
|
|
|
settings_table[#settings_table].separator = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
table.insert(settings_table, {
|
|
|
|
|
text = _("Use additional fallback fonts"),
|
|
|
|
|
checked_func = function()
|
|
|
|
|
return G_reader_settings:nilOrTrue("additional_fallback_fonts")
|
|
|
|
|
end,
|
|
|
|
|
callback = function()
|
|
|
|
|
G_reader_settings:flipNilOrTrue("additional_fallback_fonts")
|
|
|
|
|
self.ui.document:setupFallbackFontFaces()
|
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
|
end,
|
|
|
|
|
help_text = T(_([[
|
|
|
|
|
Enable additional fallback fonts, for the most complete script and language coverage.
|
|
|
|
|
These fonts will be used in this order:
|
|
|
|
|
|
|
|
|
|
%1
|
|
|
|
|
|
|
|
|
|
You can set a preferred fallback font with a long-press on a font name, and it will be used before these.
|
|
|
|
|
If that font happens to be part of this list already, it will be used first.]]),
|
|
|
|
|
table.concat(self.ui.document.fallback_fonts, "\n")),
|
|
|
|
|
separator = true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
table.insert(settings_table, {
|
|
|
|
|
text = _("Generate font test document"),
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
|
text = _("Would you like to generate an HTML document showing some sample text rendered with each available font?");
|
|
|
|
|
ok_callback = function()
|
|
|
|
|
self:buildFontsTestDocument()
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
return settings_table
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Default sample file
|
|
|
|
|
local FONT_TEST_DEFAULT_SAMPLE_PATH = "frontend/ui/elements/font-test-sample-default.html"
|
|
|
|
|
-- Users can set their own sample file, that will be used if found
|
|
|
|
|
local FONT_TEST_USER_SAMPLE_PATH = require("datastorage"):getSettingsDir() .. "/font-test-sample.html"
|
|
|
|
|
-- This document will be generated in the home or default directory
|
|
|
|
|
local FONT_TEST_FINAL_FILENAME = "font-test.html"
|
|
|
|
|
|
|
|
|
|
function ReaderFont:buildFontsTestDocument()
|
|
|
|
|
local font_test_sample = require("datastorage"):getSettingsDir() .. "/fonts-test-sample.html"
|
|
|
|
|
local f = io.open(font_test_sample, "r")
|
|
|
|
|
if not f then return nil end
|
|
|
|
|
local html_sample = f:read("*all")
|
|
|
|
|
f:close()
|
|
|
|
|
local html_sample
|
|
|
|
|
local f = io.open(FONT_TEST_USER_SAMPLE_PATH, "r")
|
|
|
|
|
if f then
|
|
|
|
|
html_sample = f:read("*all")
|
|
|
|
|
f:close()
|
|
|
|
|
end
|
|
|
|
|
if not html_sample then
|
|
|
|
|
f = io.open(FONT_TEST_DEFAULT_SAMPLE_PATH, "r")
|
|
|
|
|
if not f then return nil end
|
|
|
|
|
html_sample = f:read("*all")
|
|
|
|
|
f:close()
|
|
|
|
|
end
|
|
|
|
|
local dir = G_reader_settings:readSetting("home_dir")
|
|
|
|
|
if not dir then dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end
|
|
|
|
|
if not dir then dir = "." end
|
|
|
|
|
local fonts_test_path = dir .. "/fonts-test-all.html"
|
|
|
|
|
f = io.open(fonts_test_path, "w")
|
|
|
|
|
-- Using <section><title>...</title></section> allows for a TOC to be built
|
|
|
|
|
local font_test_final_path = dir .. "/" .. FONT_TEST_FINAL_FILENAME
|
|
|
|
|
f = io.open(font_test_final_path, "w")
|
|
|
|
|
if not f then return end
|
|
|
|
|
-- Using <section><title>...</title></section> allows for a TOC to be built by crengine
|
|
|
|
|
f:write(string.format([[
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<html>
|
|
|
|
@ -400,10 +445,10 @@ a { color: black; }
|
|
|
|
|
f:write("</body></html>\n")
|
|
|
|
|
f:close()
|
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
|
text = T(_("Document created as:\n%1\n\nWould you like to read it now?"), BD.filepath(fonts_test_path)),
|
|
|
|
|
text = T(_("Document created as:\n%1\n\nWould you like to read it now?"), BD.filepath(font_test_final_path)),
|
|
|
|
|
ok_callback = function()
|
|
|
|
|
UIManager:scheduleIn(1.0, function()
|
|
|
|
|
self.ui:switchDocument(fonts_test_path)
|
|
|
|
|
self.ui:switchDocument(font_test_final_path)
|
|
|
|
|
end)
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|