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 ]]--
|
|
|
|
|
2020-07-09 00:02:34 +00:00
|
|
|
local function getDir(isUser)
|
|
|
|
local home = Device.home_dir
|
2021-12-07 11:17:45 +00:00
|
|
|
|
|
|
|
local XDG_DATA_HOME = os.getenv("XDG_DATA_HOME")
|
|
|
|
local LINUX_FONT_PATH = XDG_DATA_HOME and XDG_DATA_HOME .. "/fonts"
|
|
|
|
or home .. "/.local/share/fonts"
|
|
|
|
local LINUX_SYS_FONT_PATH = "/usr/share/fonts"
|
|
|
|
local MACOS_FONT_PATH = "Library/fonts"
|
|
|
|
|
2020-07-09 00:02:34 +00:00
|
|
|
if isUser and not home then return end
|
2021-12-07 11:17:45 +00:00
|
|
|
|
2020-07-09 00:02:34 +00:00
|
|
|
if Device:isAndroid() then
|
2021-12-07 11:17:45 +00:00
|
|
|
return isUser and home .. "/fonts;" .. home .. "/koreader/fonts"
|
|
|
|
or "/system/fonts"
|
2020-08-25 21:13:39 +00:00
|
|
|
elseif Device:isPocketBook() then
|
2021-12-07 11:17:45 +00:00
|
|
|
return isUser and "/mnt/ext1/system/fonts"
|
|
|
|
or "/ebrmain/adobefonts;/ebrmain/fonts"
|
2021-04-19 07:04:31 +00:00
|
|
|
elseif Device:isRemarkable() then
|
2021-12-07 11:17:45 +00:00
|
|
|
return isUser and LINUX_FONT_PATH
|
|
|
|
or LINUX_SYS_FONT_PATH
|
2020-07-09 00:02:34 +00:00
|
|
|
elseif Device:isDesktop() or Device:isEmulator() then
|
|
|
|
if jit.os == "OSX" then
|
2021-12-07 11:17:45 +00:00
|
|
|
return isUser and home .. "/" .. MACOS_FONT_PATH
|
|
|
|
or "/" .. MACOS_FONT_PATH
|
2020-07-09 00:02:34 +00:00
|
|
|
else
|
2021-12-07 11:17:45 +00:00
|
|
|
return isUser and LINUX_FONT_PATH
|
|
|
|
or LINUX_SYS_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")
|
2022-12-03 20:29:13 +00:00
|
|
|
UIManager:askForRestart()
|
2019-12-08 13:54:14 +00:00
|
|
|
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
|