From 1cbe646d6d26e61bad75a5f748f63f47d484479a Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 12 Mar 2010 21:37:11 +0200 Subject: Isolate database loading code and clean it a bit --- mkluatexfontdb.lua | 12 ++++-------- otfl-font-nms.lua | 31 ++++++++++++++++++------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/mkluatexfontdb.lua b/mkluatexfontdb.lua index d4782ea..ad50996 100644 --- a/mkluatexfontdb.lua +++ b/mkluatexfontdb.lua @@ -27,12 +27,8 @@ local version = '1.07' -- same version number as luaotfload mkluatexfontdb = { } -- just for now, elie is rewriting it anyway local names = fonts.names --- the path to add to TEXMFVAR or TEXMFSYSVAR to get the final directory in --- normal cases -mkluatexfontdb.subtexmfvardir = "/scripts/luatexfontdb/" - -- the directory in which the database will be saved, can be overwritten -mkluatexfontdb.directory = kpse.expand_var("$TEXMFVAR") .. mkluatexfontdb.subtexmfvardir +mkluatexfontdb.directory = names.path.localdir local log = logs.report @@ -134,11 +130,11 @@ local function process_cmdline() elseif v == "fc-cache" then run_fc_cache = 1 elseif v == "sys" then - mkluatexfontdb.directory = kpse.expand_var("$TEXMFSYSVAR") .. mkluatexfontdb.subtexmfvardir + mkluatexfontdb.directory = names.path.systemdir end end if string.match(arg[0], '-sys') then - mkluatexfontdb.directory = kpse.expand_var("$TEXMFSYSVAR") .. mkluatexfontdb.subtexmfvardir + mkluatexfontdb.directory = names.path.systemdir end mkluatexfontdb.directory = fonts.path_normalize(mkluatexfontdb.directory) names.set_log_level(log_level) @@ -166,7 +162,7 @@ local function generate(force, purge) os.exit(1) end end - savepath = savepath .. '/' .. names.basename + savepath = savepath .. '/' .. names.path.basename local fh = io.open(savepath, 'a+') if not fh then texio.write_nl(string.format("Error: cannot write file '%s', exiting.\n", savepath)) diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index 3239f0b..b70b88b 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -11,10 +11,13 @@ fonts.names = fonts.names or { } local names = fonts.names names.version = 2.005 -- not the same as in context -names.basename = "otfl-names.lua" -names.subtexmfvardir = "/scripts/luatexfontdb/" names.new_to_old = { } names.old_to_new = { } +names.path = { + basename = "otfl-names.lua", + localdir = kpse.expand_var("$TEXMFVAR") .. "/scripts/luatexfontdb/", + systemdir = kpse.expand_var("$TEXMFSYSVAR") .. "/scripts/luatexfontdb/", +} local splitpath, expandpath, glob, basename = file.split_path, kpse.expand_path, dir.glob, file.basename @@ -35,20 +38,22 @@ local synonyms = { bolditalic = {"boldoblique", "boldslant"}, } +function names.load() + local localpath = names.path.localdir .. names.path.basename + local systempath = names.path.systemdir .. names.path.basename + local data = dofile(localpath) or dofile(systempath) + if data then + if trace_loading then + logs.report("load font", "loaded font names database: %s", foundname) + end + return data + end +end + function names.resolve(specification) local name, style = specification.name, specification.style or "regular" if not loaded then - local basename = names.basename - if basename and basename ~= "" and names.subtexmfvardir then - local foundname = kpse.expand_var("$TEXMFVAR") .. names.subtexmfvardir .. basename - if not file.isreadable(foundname) then - foundname = kpse.expand_var("$TEXMFSYSVAR") .. names.subtexmfvardir .. basename - end - if file.isreadable(foundname) then - data = dofile(foundname) - logs.report("load font", "loaded font names database: %s", foundname) - end - end + data = names.load() loaded = true end if type(data) == "table" and data.version == names.version then -- cgit v1.2.3