diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2010-04-01 06:50:11 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2010-04-01 06:50:11 +0200 |
commit | 520eba1ac4dbda9d8c4720824777da5b56353f06 (patch) | |
tree | 32baeae4ed97d06c03dda9fffc8e41bcf0125836 /otfl-luat-dum.lua | |
parent | a3fa5d7b5e84ca6c9d232762961682a5147bcf57 (diff) | |
download | luaotfload-520eba1ac4dbda9d8c4720824777da5b56353f06.tar.gz |
Enable font caching
Update from ConTeXt, changes to save fonts under
TEXMFVAR/luatex-cache/latex/fonts.
Diffstat (limited to 'otfl-luat-dum.lua')
-rw-r--r-- | otfl-luat-dum.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/otfl-luat-dum.lua b/otfl-luat-dum.lua index 832f80d..6e2e1c6 100644 --- a/otfl-luat-dum.lua +++ b/otfl-luat-dum.lua @@ -73,3 +73,56 @@ function resolvers.findbinfile(name,kind) end return resolvers.find_file(name,(kind and remapper[kind]) or kind) end + +-- Caches ... I will make a real stupid version some day when I'm in the +-- mood. After all, the generic code does not need the more advanced +-- ConTeXt features. Cached data is not shared between ConTeXt and other +-- usage as I don't want any dependency at all. Also, ConTeXt might have +-- different needs and tricks added. + +caches = { } + +--~ containers.usecache = true + +function caches.setpath(category,subcategory) +-- local root = kpse.var_value("TEXMFCACHE") or "" +-- if root == "" then +-- root = kpse.var_value("VARTEXMF") or "" +-- end + local var = kpse.var_value("TEXMFVAR") + local root = var and (var .. "/luatex-cache/latex") or "" + if root ~= "" then + root = file.join(root,category) + lfs.mkdir(root) + root = file.join(root,subcategory) + lfs.mkdir(root) + return lfs.isdir(root) and root + end +end + +local function makefullname(path,name) + if path and path ~= "" then + name = "temp-" and name -- clash prevention + return file.addsuffix(file.join(path,name),"lua") + end +end + +function caches.iswritable(path,name) + local fullname = makefullname(path,name) + return fullname and file.iswritable(fullname) +end + +function caches.loaddata(path,name) + local fullname = makefullname(path,name) + if fullname then + local data = loadfile(fullname) + return data and data() + end +end + +function caches.savedata(path,name,data) + local fullname = makefullname(path,name) + if fullname then + table.tofile(fullname,data,'return',false,true,false) + end +end |