2019-08-20 16:38:02 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local logger = require("logger")
|
|
|
|
local util = require("util")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
2021-04-19 07:04:31 +00:00
|
|
|
--[[ Font settings for systems with multiple font dirs ]]--
|
|
|
|
|
|
|
|
local LINUX_FONT_PATH = "share/fonts"
|
|
|
|
local MACOS_FONT_PATH = "Library/fonts"
|
2019-08-20 16:38:02 +00:00
|
|
|
|
2020-07-09 00:02:34 +00:00
|
|
|
local function getDir(isUser)
|
|
|
|
local home = Device.home_dir
|
|
|
|
if isUser and not home then return end
|
|
|
|
if Device:isAndroid() then
|
|
|
|
if isUser then
|
|
|
|
return home .. "/fonts;" .. home .. "/koreader/fonts"
|
|
|
|
else
|
|
|
|
return "/system/fonts"
|
|
|
|
end
|
2020-08-25 21:13:39 +00:00
|
|
|
elseif Device:isPocketBook() then
|
|
|
|
if isUser then
|
|
|
|
return "/mnt/ext1/system/fonts"
|
|
|
|
else
|
|
|
|
return "/ebrmain/adobefonts;/ebrmain/fonts"
|
|
|
|
end
|
2021-04-19 07:04:31 +00:00
|
|
|
elseif Device:isRemarkable() then
|
|
|
|
return isUser and string.format("%s/.local/%s", home, LINUX_FONT_PATH)
|
|
|
|
or string.format("/usr/%s", LINUX_FONT_PATH)
|
2020-07-09 00:02:34 +00:00
|
|
|
elseif Device:isDesktop() or Device:isEmulator() then
|
|
|
|
if jit.os == "OSX" then
|
2021-04-19 07:04:31 +00:00
|
|
|
return isUser and string.format("%s/%s", home, MACOS_FONT_PATH)
|
|
|
|
or string.format("/%s", MACOS_FONT_PATH)
|
2020-07-09 00:02:34 +00:00
|
|
|
else
|
2021-04-19 07:04:31 +00:00
|
|
|
return isUser and string.format("%s/.local/%s", home, LINUX_FONT_PATH)
|
|
|
|
or string.format("/usr/%s", LINUX_FONT_PATH)
|
2020-07-09 00:02:34 +00:00
|
|
|
end
|
2019-08-20 16:38:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function openFontDir()
|
2019-08-24 09:38:37 +00:00
|
|
|
if not Device:canOpenLink() then return end
|
2020-07-09 00:02:34 +00:00
|
|
|
local user_dir = getDir(true)
|
2019-08-20 16:38:02 +00:00
|
|
|
local openable = util.pathExists(user_dir)
|
2019-08-24 09:38:37 +00:00
|
|
|
if not openable and user_dir then
|
2019-08-20 16:38:02 +00:00
|
|
|
logger.info("Font path not found, making one in ", user_dir)
|
|
|
|
openable = util.makePath(user_dir)
|
|
|
|
end
|
|
|
|
if not openable then
|
|
|
|
logger.warn("Unable to create the folder ", user_dir)
|
|
|
|
return
|
|
|
|
end
|
2019-08-24 09:38:37 +00:00
|
|
|
Device:openLink(user_dir)
|
2019-08-20 16:38:02 +00:00
|
|
|
end
|
|
|
|
|
2020-07-09 00:02:34 +00:00
|
|
|
local function usesSystemFonts()
|
|
|
|
return G_reader_settings:isTrue("system_fonts")
|
|
|
|
end
|
|
|
|
|
2019-08-20 16:38:02 +00:00
|
|
|
local FontSettings = {}
|
|
|
|
|
|
|
|
function FontSettings:getPath()
|
2020-07-09 00:02:34 +00:00
|
|
|
local user, system = getDir(true), getDir()
|
2019-08-20 16:38:02 +00:00
|
|
|
if usesSystemFonts() then
|
2020-07-09 00:02:34 +00:00
|
|
|
if user and system then
|
|
|
|
return user .. ";" .. system
|
|
|
|
elseif system then
|
|
|
|
return system
|
2019-08-20 16:38:02 +00:00
|
|
|
end
|
|
|
|
end
|
2020-07-09 00:02:34 +00:00
|
|
|
return user
|
2019-08-20 16:38:02 +00:00
|
|
|
end
|
|
|
|
|
2020-04-28 21:57:10 +00:00
|
|
|
function FontSettings:getSystemFontMenuItems()
|
2019-12-08 13:54:14 +00:00
|
|
|
local t = {{
|
|
|
|
text = _("Enable system fonts"),
|
|
|
|
checked_func = usesSystemFonts,
|
|
|
|
callback = function()
|
|
|
|
G_reader_settings:saveSetting("system_fonts", not usesSystemFonts())
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("This will take effect on next restart.")
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}}
|
|
|
|
|
2020-04-11 15:45:37 +00:00
|
|
|
if Device:isDesktop() or Device:isEmulator() then table.insert(t, 2, {
|
2019-12-08 13:54:14 +00:00
|
|
|
text = _("Open fonts folder"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = openFontDir,
|
|
|
|
})
|
2019-10-13 23:24:46 +00:00
|
|
|
end
|
|
|
|
|
2020-04-28 21:57:10 +00:00
|
|
|
return t
|
2019-08-20 16:38:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return FontSettings
|