From d37cfaf8b6bd3e82c8220d385e5da53793f332e1 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 27 Jul 2016 23:55:25 +0200 Subject: [features,fontloader] fix adding features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes our own features work with otf.addfeature(). However, for TFM it’s still not functional out of the box since the enhancer is installed at a time when it has not been defined yet. An answer from Hans is pending. In the meantime, we put a crude hack into our font-tfm.lua to allow injecting the enhancer retroactively on Luaotfload init. --- src/fontloader/misc/fontloader-font-tfm.lua | 6 +++ src/luaotfload-features.lua | 59 +++++++++++++++++++++++------ src/luaotfload-resolvers.lua | 1 + 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/fontloader/misc/fontloader-font-tfm.lua b/src/fontloader/misc/fontloader-font-tfm.lua index d9b0523..6565a0e 100644 --- a/src/fontloader/misc/fontloader-font-tfm.lua +++ b/src/fontloader/misc/fontloader-font-tfm.lua @@ -85,6 +85,12 @@ local steps = { enhancers["check extra features"] = otf.enhancers.enhance +--[[ PHG: begin hack for Luaotfload ]]-- +luaotfload_tfm_enhancers_reregister = function () + enhancers["check extra features"]=otf.enhancers.enhance +end +--[[ PHG: end hack for Luaotfload ]]-- + local function applyenhancers(data,filename) for i=1,#steps do local step = steps[i] diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua index 0af59fb..5905c19 100644 --- a/src/luaotfload-features.lua +++ b/src/luaotfload-features.lua @@ -2035,29 +2035,61 @@ local rot13_specification = { prepend = true, } -local extrafeatures = { - tlig = { tlig_specification, "tex ligatures and substitutions" }, - anum = { anum_specification, "arabic numerals" }, - rot13 = { rot13_specification, "rot13" }, -} + +local extrafeatures = { } +local knownfeatures = { } function add_otf_feature (name, specification) if type (name) == "table" then specification = name - name = specification.name end + specification, name = validspecification (specification, name) if type (specification) ~= "table" then logreport ("both", 0, "features", "invalid feature specification “%s”", tostring (name)) return end + specification.name = name if name and specification then - extrafeatures[name] = specification + if knownfeatures [name] then + logreport ("both", 0, "features", + "prevent redefinition of extra feature “%s”", name) + else + extrafeatures [#extrafeatures + 1] = specification + knownfeatures [name] = true + end end end otf.addfeature = add_otf_feature +local autofeatures = { + --- always present with Luaotfload + { "tlig" , tlig_specification , "tex ligatures and substitutions" }, + { "anum" , anum_specification , "arabic numerals" }, + { "rot13", rot13_specification, "rot13" }, +} + +local add_auto_features = function () + local nfeats = #autofeatures + logreport ("both", 5, "features", + "auto-installing %d feature definitions", nfeats) + for i = 1, nfeats do + local name, spec, desc = unpack (autofeatures [i]) + spec.description = desc + add_otf_feature (name, spec) + end +end + +local function enhance(data,filename,raw) + for slot=1,#extrafeatures do + local specification = extrafeatures[slot] + addfeature(data,specification.name,specification) + end +end + +otf.enhancers.enhance = enhance + local install_extra_features = function (data, filename, raw) local metadata = data and data.metadata if not metadata then @@ -2075,14 +2107,16 @@ local install_extra_features = function (data, filename, raw) filename) --return end - for feature, specification in next, extrafeatures do - if not fontname then fontname = "" end - if not subfont then subfont = -1 end + for i = 1, #extrafeatures do + local specification = extrafeatures [i] + local feature = specification.name local fontname = tostring (data.metadata.fontname) or "" local subfont = tonumber (metadata.subfontindex) or -1 + if not fontname then fontname = filename end + if not subfont then subfont = -1 end logreport ("both", 3, "features", "register synthetic feature “%s” for %s font “%s”(%d)", - feature, format, fontname, subfont) + feature, format or "tfm", filename, subfont) otf.features.register { name = feature, description = specification[2] } otf.enhancers.addfeature (data, feature, specification[1]) end @@ -2100,8 +2134,11 @@ return { return false end + add_auto_features () + otf = fonts.handlers.otf otf.enhancers.addfeature = addfeature + luaotfload_tfm_enhancers_reregister () otf.enhancers.register ("check extra features", install_extra_features) diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua index a1e702b..983d3fc 100644 --- a/src/luaotfload-resolvers.lua +++ b/src/luaotfload-resolvers.lua @@ -173,6 +173,7 @@ local resolve_tex_format = function (specification) local usename = suffix == format and fileremovesuffix (name) or name specification.forcedname = file.addsuffix (usename, format) specification.forced = format +---- specification.resolved = name return true end end -- cgit v1.2.3