From 8070e6c1b481dcd340810ddc680aaccbf4ef1997 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 12 Mar 2010 09:19:19 +0200 Subject: Cleanup Group all our font names functions in |otfl-font-nms.lua| and make |luaotfload.lua| load it. Now |otfl-font-dum.lua| is an unmodified, we instead override the needed functions in the names module. This decreases the redundancy that we had. --- luaotfload.dtx | 1 + mkluatexfontdb.lua | 2 -- otfl-font-dum.lua | 83 ++++++++++++------------------------------------- otfl-font-nms.lua | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 107 insertions(+), 70 deletions(-) diff --git a/luaotfload.dtx b/luaotfload.dtx index 33b8922..39343d8 100644 --- a/luaotfload.dtx +++ b/luaotfload.dtx @@ -489,6 +489,7 @@ luaotfload.loadmodule('font-otc.lua') luaotfload.loadmodule('font-def.lua') luaotfload.loadmodule('font-xtx.lua') luaotfload.loadmodule('font-dum.lua') +luaotfload.loadmodule('font-nms.lua') luaotfload.loadmodule('font-clr.lua') % \end{macrocode} diff --git a/mkluatexfontdb.lua b/mkluatexfontdb.lua index ef39a4e..e8ce1a5 100644 --- a/mkluatexfontdb.lua +++ b/mkluatexfontdb.lua @@ -26,8 +26,6 @@ local version = '1.07' -- same version number as luaotfload mkluatexfontdb = { } -- just for now, elie is rewriting it anyway local names = fonts.names -names.basename = names.basename or "otfl-names.lua" -names.version = names.version or 2.005 -- the path to add to TEXMFVAR or TEXMFSYSVAR to get the final directory in -- normal cases diff --git a/otfl-font-dum.lua b/otfl-font-dum.lua index 5295e57..8e13b5b 100644 --- a/otfl-font-dum.lua +++ b/otfl-font-dum.lua @@ -48,83 +48,40 @@ end fonts.names = fonts.names or { } -fonts.names.version = 2.005 -- not the same as in context -fonts.names.basename = "otfl-names.lua" -fonts.names.subtexmfvardir = "/scripts/luatexfontdb/" +fonts.names.version = 1.001 -- not the same as in context +fonts.names.basename = "luatex-fonts-names.lua" fonts.names.new_to_old = { } fonts.names.old_to_new = { } local data, loaded = nil, false -local synonyms = { - regular = {"normal", "roman", "plain", "book", "medium"}, - italic = {"regularitalic", "normalitalic", "oblique", "slant"}, - bolditalic = {"boldoblique", "boldslant"}, -} - -local function sanitize(str) - return string.gsub(string.lower(str), "[^%a%d]", "") -end - -function fonts.names.resolve(specification) - local name, style = specification.name, specification.style or "regular" +function fonts.names.resolve(name,sub) if not loaded then local basename = fonts.names.basename - if basename and basename ~= "" and fonts.names.subtexmfvardir then - local foundname = kpse.expand_var("$TEXMFVAR") .. fonts.names.subtexmfvardir .. basename - if not file.isreadable(foundname) then - foundname = kpse.expand_var("$TEXMFSYSVAR") .. fonts.names.subtexmfvardir .. basename - end - if file.isreadable(foundname) then - data = dofile(foundname) - logs.report("load font", "loaded font names database: %s", foundname) + if basename and basename ~= "" then + for _, format in ipairs { "lua", "tex", "other text files" } do + local foundname = resolvers.find_file(basename,format) or "" + if foundname ~= "" then + data = dofile(foundname) + break + end end end loaded = true end if type(data) == "table" and data.version == fonts.names.version then - if data.mappings then - local family = data.families[name] - if family and type(family) == "table" then - for _,v in ipairs(family) do - local face = data.mappings[v] - local subfamily = sanitize(face.names.subfamily) - local rqssize = tonumber(specification.optsize) or specification.size and specification.size / 65536 - local dsnsize = face.size[1] and face.size[1] / 10 - local maxsize = face.size[2] and face.size[2] / 10 - local minsize = face.size[3] and face.size[3] / 10 - local filename = face.filename - if subfamily then - if subfamily == style then - if not dsnsize or dsnsize == rqssize or (rqssize > minsize and rqssize <= maxsize) then - found = filename - logs.report("load font", "font family='%s', subfamily='%s' found: %s", name, style, found) - break - end - else - if synonyms[style] then - for _,v in ipairs(synonyms[style]) do - if subfamily == v then - if not dsnsize or dsnsize == rqssize or (rqssize > minsize and rqssize <= maxsize) then - found = filename - logs.report("load font", "font family='%s', subfamily='%s' found: %s", name, style, found) - break - end - end - end - end - end - end - end - if found then - return found, false - else - return name, false -- fallback to filename - end + local condensed = string.gsub(string.lower(name),"[^%a%d]","") + local found = data.mappings and data.mappings[condensed] + if found then + local fontname, filename, subfont = found[1], found[2], found[3] + if subfont then + return filename, fontname + else + return filename, false end + else + return name, false -- fallback to filename end - else - logs.report("load font", "Font names database version mismatch, found: %s, requested: %s", data.version, fonts.names.version) end end diff --git a/otfl-font-nms.lua b/otfl-font-nms.lua index a45aeb7..ba15f1c 100644 --- a/otfl-font-nms.lua +++ b/otfl-font-nms.lua @@ -6,19 +6,100 @@ if not modules then modules = { } end modules ['font-nms'] = { license = "GPL" } -fonts = fonts or { } -fonts.names = fonts.names or { } +fonts = fonts or { } +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 = { } -local names = fonts.names local splitpath, expandpath, glob, basename = file.split_path, kpse.expand_path, dir.glob, file.basename -local upper, format = string.upper, string.format +local upper, format = string.upper, string.format local trace_progress = true --trackers.register("names.progress", function(v) trace_progress = v end) local trace_search = false --trackers.register("names.search", function(v) trace_search = v end) local trace_loading = false --trackers.register("names.loading", function(v) trace_loading = v end) -function fonts.names.set_log_level(level) +local function sanitize(str) + return string.gsub(string.lower(str), "[^%a%d]", "") +end + +local data, loaded = nil, false +local synonyms = { + regular = {"normal", "roman", "plain", "book", "medium"}, + italic = {"regularitalic", "normalitalic", "oblique", "slant"}, + bolditalic = {"boldoblique", "boldslant"}, +} + +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 + loaded = true + end + if type(data) == "table" and data.version == names.version then + if data.mappings then + local family = data.families[name] + if family and type(family) == "table" then + for _,v in ipairs(family) do + local face = data.mappings[v] + local subfamily = sanitize(face.names.subfamily) + local rqssize = tonumber(specification.optsize) or specification.size and specification.size / 65536 + local dsnsize = face.size[1] and face.size[1] / 10 + local maxsize = face.size[2] and face.size[2] / 10 + local minsize = face.size[3] and face.size[3] / 10 + local filename = face.filename + if subfamily then + if subfamily == style then + if not dsnsize or dsnsize == rqssize or (rqssize > minsize and rqssize <= maxsize) then + found = filename + logs.report("load font", "font family='%s', subfamily='%s' found: %s", name, style, found) + break + end + else + if synonyms[style] then + for _,v in ipairs(synonyms[style]) do + if subfamily == v then + if not dsnsize or dsnsize == rqssize or (rqssize > minsize and rqssize <= maxsize) then + found = filename + logs.report("load font", "font family='%s', subfamily='%s' found: %s", name, style, found) + break + end + end + end + end + end + end + end + if found then + return found, false + else + return name, false -- fallback to filename + end + end + end + else + logs.report("load font", "Font names database version mismatch, found: %s, requested: %s", data.version, names.version) + end +end + +names.resolvespec = names.resolve -- only supported in mkiv + +function names.set_log_level(level) if level == 2 then trace_progress = false trace_loading = true -- cgit v1.2.3