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.
pull/1400/head
chrox 9 years ago
parent dfa30f5524
commit 077517be0b

@ -58,8 +58,8 @@ function CreDocument:engineInit()
-- we need to initialize the CRE font list -- we need to initialize the CRE font list
local fonts = Font:getFontList() local fonts = Font:getFontList()
for _k, _v in ipairs(fonts) do for _k, _v in ipairs(fonts) do
if _v:sub(1, 4) ~= "urw/" then if not _v:find("/urw/") then
local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v) local ok, err = pcall(cre.registerFont, _v)
if not ok then if not ok then
DEBUG(err) DEBUG(err)
end end

@ -41,7 +41,7 @@ local Font = {
[4] = "freefont/FreeSans.ttf", [4] = "freefont/FreeSans.ttf",
}, },
fontdir = os.getenv("FONTDIR") or "./fonts", fontdir = "./fonts",
-- face table -- face table
faces = {}, faces = {},
@ -77,23 +77,27 @@ function Font:getFace(font, size)
return { size = size, orig_size = orig_size, ftface = face, hash = font..size } return { size = size, orig_size = orig_size, ftface = face, hash = font..size }
end end
function Font:_readList(target, dir, effective_dir) function Font:_readList(target, dir)
for f in lfs.dir(dir) do for f in lfs.dir(dir) do
if lfs.attributes(dir.."/"..f, "mode") == "directory" and f ~= "." and f ~= ".." then 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 else
local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "")
if file_type == "ttf" or file_type == "ttc" if file_type == "ttf" or file_type == "ttc"
or file_type == "cff" or file_type == "otf" then or file_type == "cff" or file_type == "otf" then
table.insert(target, effective_dir..f) table.insert(target, dir.."/"..f)
end end
end end
end end
end end
function Font:getFontList() function Font:getFontList()
fontlist = {} local fontlist = {}
self:_readList(fontlist, self.fontdir, "") 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) table.sort(fontlist)
return fontlist return fontlist
end end

@ -115,6 +115,9 @@ export TESSDATA_PREFIX="data"
# export dict directory # export dict directory
export STARDICT_DATA_DIR="data/dict" export STARDICT_DATA_DIR="data/dict"
# export font directory
export FONTDIR="/mnt/us/fonts"
logmsg "Setting up IPTables rules . . ." logmsg "Setting up IPTables rules . . ."
# accept input ports for zsync plugin # accept input ports for zsync plugin
iptables -A INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT iptables -A INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT

@ -21,6 +21,9 @@ export TESSDATA_PREFIX="data"
# export dict directory # export dict directory
export STARDICT_DATA_DIR="data/dict" 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 # fast and dirty way of check if we are called from nickel
# through fmon, or from another launcher (KSM or advboot) # through fmon, or from another launcher (KSM or advboot)
from_nickel=`pidof nickel | wc -c` from_nickel=`pidof nickel | wc -c`

@ -21,6 +21,9 @@ export TESSDATA_PREFIX="data"
# export dict directory # export dict directory
export STARDICT_DATA_DIR="data/dict" export STARDICT_DATA_DIR="data/dict"
# export font directory
export FONTDIR="/mnt/ext1/fonts"
if [ `echo $@ | wc -c` -eq 1 ]; then if [ `echo $@ | wc -c` -eq 1 ]; then
args="/mnt/ext1/" args="/mnt/ext1/"
else else

Loading…
Cancel
Save