mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
easier user font paths with Device.home_dir
This commit is contained in:
committed by
Martín Fernández
parent
509ee7bb86
commit
a376a52c3a
@@ -72,6 +72,7 @@ end
|
|||||||
local Device = Generic:new{
|
local Device = Generic:new{
|
||||||
model = "SDL",
|
model = "SDL",
|
||||||
isSDL = yes,
|
isSDL = yes,
|
||||||
|
home_dir = os.getenv("HOME"),
|
||||||
hasKeyboard = yes,
|
hasKeyboard = yes,
|
||||||
hasKeys = yes,
|
hasKeys = yes,
|
||||||
hasDPad = yes,
|
hasDPad = yes,
|
||||||
@@ -115,7 +116,6 @@ local AppImage = Device:new{
|
|||||||
hasMultitouch = no,
|
hasMultitouch = no,
|
||||||
hasOTAUpdates = yes,
|
hasOTAUpdates = yes,
|
||||||
isDesktop = yes,
|
isDesktop = yes,
|
||||||
home_dir = os.getenv("HOME"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local Emulator = Device:new{
|
local Emulator = Device:new{
|
||||||
@@ -133,12 +133,12 @@ local Emulator = Device:new{
|
|||||||
local Linux = Device:new{
|
local Linux = Device:new{
|
||||||
model = "Linux",
|
model = "Linux",
|
||||||
isDesktop = yes,
|
isDesktop = yes,
|
||||||
home_dir = os.getenv("HOME"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local UbuntuTouch = Device:new{
|
local UbuntuTouch = Device:new{
|
||||||
model = "UbuntuTouch",
|
model = "UbuntuTouch",
|
||||||
hasFrontlight = yes,
|
hasFrontlight = yes,
|
||||||
|
home_dir = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
function Device:init()
|
function Device:init()
|
||||||
|
|||||||
@@ -5,54 +5,27 @@ local _ = require("gettext")
|
|||||||
|
|
||||||
--[[ Font settings for desktop linux, mac and android ]]--
|
--[[ Font settings for desktop linux, mac and android ]]--
|
||||||
|
|
||||||
local ANDROID_SYSTEM_FONT_DIR = "/system/fonts"
|
local function getDir(isUser)
|
||||||
local LINUX_SYSTEM_FONT_DIR = "/usr/share/fonts"
|
local home = Device.home_dir
|
||||||
local DESKTOP_USER_FONT_DIR = "/.local/share/fonts"
|
if isUser and not home then return end
|
||||||
|
if Device:isAndroid() then
|
||||||
-- get primary storage on Android
|
if isUser then
|
||||||
local function getAndroidPrimaryStorage()
|
return home .. "/fonts;" .. home .. "/koreader/fonts"
|
||||||
local A, android = pcall(require, "android")
|
|
||||||
if not A then return end
|
|
||||||
local path = android.getExternalStoragePath()
|
|
||||||
if path ~= "Unknown" then
|
|
||||||
-- use the external storage identified by the app
|
|
||||||
return path
|
|
||||||
else
|
else
|
||||||
-- unable to identify external storage. Use defaults
|
return "/system/fonts"
|
||||||
return "/sdcard"
|
end
|
||||||
|
elseif Device:isDesktop() or Device:isEmulator() then
|
||||||
|
if jit.os == "OSX" then
|
||||||
|
return isUser and home .. "/Library/fonts" or "/Library/fonts"
|
||||||
|
else
|
||||||
|
return isUser and home .. "/.local/share/fonts" or "/usr/share/fonts"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- user font path, should be rw. On linux/mac it goes under $HOME.
|
|
||||||
-- on Android it goes in the primary storage (internal/sd)
|
|
||||||
local function getUserDir()
|
|
||||||
if Device:isDesktop() or Device:isEmulator() then
|
|
||||||
local home = os.getenv("HOME")
|
|
||||||
if home then return home..DESKTOP_USER_FONT_DIR end
|
|
||||||
elseif Device:isAndroid() then
|
|
||||||
local p = getAndroidPrimaryStorage()
|
|
||||||
return p.."/koreader/fonts;"..p.."/fonts"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- system (ttf) fonts are available on linux and android but not on mac
|
|
||||||
local function getSystemDir()
|
|
||||||
if Device:isDesktop() or Device:isEmulator() then
|
|
||||||
if util.pathExists(LINUX_SYSTEM_FONT_DIR) then
|
|
||||||
return LINUX_SYSTEM_FONT_DIR
|
|
||||||
else return nil end
|
|
||||||
elseif Device:isAndroid() then
|
|
||||||
return ANDROID_SYSTEM_FONT_DIR
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function usesSystemFonts()
|
|
||||||
return G_reader_settings:isTrue("system_fonts")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function openFontDir()
|
local function openFontDir()
|
||||||
if not Device:canOpenLink() then return end
|
if not Device:canOpenLink() then return end
|
||||||
local user_dir = getUserDir()
|
local user_dir = getDir(true)
|
||||||
local openable = util.pathExists(user_dir)
|
local openable = util.pathExists(user_dir)
|
||||||
if not openable and user_dir then
|
if not openable and user_dir then
|
||||||
logger.info("Font path not found, making one in ", user_dir)
|
logger.info("Font path not found, making one in ", user_dir)
|
||||||
@@ -65,16 +38,22 @@ local function openFontDir()
|
|||||||
Device:openLink(user_dir)
|
Device:openLink(user_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function usesSystemFonts()
|
||||||
|
return G_reader_settings:isTrue("system_fonts")
|
||||||
|
end
|
||||||
|
|
||||||
local FontSettings = {}
|
local FontSettings = {}
|
||||||
|
|
||||||
function FontSettings:getPath()
|
function FontSettings:getPath()
|
||||||
|
local user, system = getDir(true), getDir()
|
||||||
if usesSystemFonts() then
|
if usesSystemFonts() then
|
||||||
local system_path = getSystemDir()
|
if user and system then
|
||||||
if system_path ~= nil then
|
return user .. ";" .. system
|
||||||
return getUserDir()..";"..system_path
|
elseif system then
|
||||||
|
return system
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return getUserDir()
|
return user
|
||||||
end
|
end
|
||||||
|
|
||||||
function FontSettings:getSystemFontMenuItems()
|
function FontSettings:getSystemFontMenuItems()
|
||||||
|
|||||||
Reference in New Issue
Block a user