From 077517be0b46204c99cb258c2b38cb35cf71d849 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 25 Jan 2015 16:52:01 +0800 Subject: [PATCH] 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. --- frontend/document/credocument.lua | 4 ++-- frontend/ui/font.lua | 16 ++++++++++------ platform/kindle/koreader.sh | 3 +++ platform/kobo/koreader.sh | 3 +++ platform/pocketbook/koreader.app | 3 +++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 6810e8178..0b5467ba2 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -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 diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index 69835e275..fb1b8af3e 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -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 diff --git a/platform/kindle/koreader.sh b/platform/kindle/koreader.sh index e80a1bbf6..53fe36c76 100755 --- a/platform/kindle/koreader.sh +++ b/platform/kindle/koreader.sh @@ -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 diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index b9f49d34f..796917b24 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -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` diff --git a/platform/pocketbook/koreader.app b/platform/pocketbook/koreader.app index 60e09e8b1..877f7b462 100755 --- a/platform/pocketbook/koreader.app +++ b/platform/pocketbook/koreader.app @@ -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