summaryrefslogtreecommitdiff
path: root/src/luaotfload-features.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luaotfload-features.lua')
-rw-r--r--src/luaotfload-features.lua66
1 files changed, 52 insertions, 14 deletions
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index b432022..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
@@ -2068,20 +2100,23 @@ local install_extra_features = function (data, filename, raw)
end
local format = data.format
if not format then
+ --- font not fully loaded, happens with TFM/PFB
logreport ("both", 4, "features",
- "no format info for font “%s”/“%s”; not \z
+ "no format info for font “%s”; not \z
installing extra features.",
- fontname, filename)
- return
+ filename)
+ --return
end
- for feature, specification in next, extrafeatures do
- if not fontname then fontname = "<unknown>" 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 "<unknown>"
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
@@ -2099,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)