mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add FONTDIR env variable
to support custom font directory for EPUB documents Now Koreader could find fonts in the "fonts" directory in the USB root directory of kindle, Kobo and PocketBook devices, thus no need to copy fonts to "koreader/fonts" directory.
This commit is contained in:
@@ -58,8 +58,8 @@ function CreDocument:engineInit()
|
||||
-- we need to initialize the CRE font list
|
||||
local fonts = Font:getFontList()
|
||||
for _k, _v in ipairs(fonts) do
|
||||
if _v:sub(1, 4) ~= "urw/" then
|
||||
local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v)
|
||||
if not _v:find("/urw/") then
|
||||
local ok, err = pcall(cre.registerFont, _v)
|
||||
if not ok then
|
||||
DEBUG(err)
|
||||
end
|
||||
|
||||
@@ -41,7 +41,7 @@ local Font = {
|
||||
[4] = "freefont/FreeSans.ttf",
|
||||
},
|
||||
|
||||
fontdir = os.getenv("FONTDIR") or "./fonts",
|
||||
fontdir = "./fonts",
|
||||
|
||||
-- face table
|
||||
faces = {},
|
||||
@@ -77,23 +77,27 @@ function Font:getFace(font, size)
|
||||
return { size = size, orig_size = orig_size, ftface = face, hash = font..size }
|
||||
end
|
||||
|
||||
function Font:_readList(target, dir, effective_dir)
|
||||
function Font:_readList(target, dir)
|
||||
for f in lfs.dir(dir) do
|
||||
if lfs.attributes(dir.."/"..f, "mode") == "directory" and f ~= "." and f ~= ".." then
|
||||
self:_readList(target, dir.."/"..f, effective_dir..f.."/")
|
||||
self:_readList(target, dir.."/"..f)
|
||||
else
|
||||
local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "")
|
||||
if file_type == "ttf" or file_type == "ttc"
|
||||
or file_type == "cff" or file_type == "otf" then
|
||||
table.insert(target, effective_dir..f)
|
||||
table.insert(target, dir.."/"..f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Font:getFontList()
|
||||
fontlist = {}
|
||||
self:_readList(fontlist, self.fontdir, "")
|
||||
local fontlist = {}
|
||||
self:_readList(fontlist, self.fontdir)
|
||||
-- multiple path should be joined with semicolon in FONTDIR env variable
|
||||
for dir in string.gmatch(os.getenv("FONTDIR") or "", "([^;]+)") do
|
||||
self:_readList(fontlist, dir)
|
||||
end
|
||||
table.sort(fontlist)
|
||||
return fontlist
|
||||
end
|
||||
|
||||
@@ -115,6 +115,9 @@ export TESSDATA_PREFIX="data"
|
||||
# export dict directory
|
||||
export STARDICT_DATA_DIR="data/dict"
|
||||
|
||||
# export font directory
|
||||
export FONTDIR="/mnt/us/fonts"
|
||||
|
||||
logmsg "Setting up IPTables rules . . ."
|
||||
# accept input ports for zsync plugin
|
||||
iptables -A INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT
|
||||
|
||||
@@ -21,6 +21,9 @@ export TESSDATA_PREFIX="data"
|
||||
# export dict directory
|
||||
export STARDICT_DATA_DIR="data/dict"
|
||||
|
||||
# export font directory
|
||||
export FONTDIR="/mnt/onboard/fonts"
|
||||
|
||||
# fast and dirty way of check if we are called from nickel
|
||||
# through fmon, or from another launcher (KSM or advboot)
|
||||
from_nickel=`pidof nickel | wc -c`
|
||||
|
||||
@@ -21,6 +21,9 @@ export TESSDATA_PREFIX="data"
|
||||
# export dict directory
|
||||
export STARDICT_DATA_DIR="data/dict"
|
||||
|
||||
# export font directory
|
||||
export FONTDIR="/mnt/ext1/fonts"
|
||||
|
||||
if [ `echo $@ | wc -c` -eq 1 ]; then
|
||||
args="/mnt/ext1/"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user