summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/font-otd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-otd.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/font-otd.lua157
1 files changed, 92 insertions, 65 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-otd.lua b/Master/texmf-dist/tex/context/base/font-otd.lua
index ebd4879599d..a9d093d6d35 100644
--- a/Master/texmf-dist/tex/context/base/font-otd.lua
+++ b/Master/texmf-dist/tex/context/base/font-otd.lua
@@ -6,6 +6,7 @@ if not modules then modules = { } end modules ['font-otd'] = {
license = "see context related readme files"
}
+local type = type
local match = string.match
local sequenced = table.sequenced
@@ -15,6 +16,8 @@ local trace_applied = false trackers.register("otf.applied", function(v)
local report_otf = logs.reporter("fonts","otf loading")
local report_process = logs.reporter("fonts","otf process")
+local allocate = utilities.storage.allocate
+
local fonts = fonts
local otf = fonts.handlers.otf
local hashes = fonts.hashes
@@ -22,8 +25,10 @@ local definers = fonts.definers
local constructors = fonts.constructors
local specifiers = fonts.specifiers
-local fontdata = hashes.identifiers
------ fontresources = hashes.resources -- not yet defined
+local fontidentifiers = hashes.identifiers
+local fontresources = hashes.resources
+local fontproperties = hashes.properties
+local fontdynamics = hashes.dynamics
local contextsetups = specifiers.contextsetups
local contextnumbers = specifiers.contextnumbers
@@ -34,27 +39,28 @@ local setmetatableindex = table.setmetatableindex
local otffeatures = fonts.constructors.newfeatures("otf")
local registerotffeature = otffeatures.register
-local fontdynamics = { }
-hashes.dynamics = fontdynamics
-
local a_to_script = { }
local a_to_language = { }
-setmetatableindex(fontdynamics, function(t,font)
- local d = fontdata[font].shared.dynamics or false
- t[font] = d
- return d
-end)
+-- we can have a scripts hash in fonts.hashes
function otf.setdynamics(font,attribute)
- local features = contextsetups[contextnumbers[attribute]] -- can be moved to caller
+ -- local features = contextsetups[contextnumbers[attribute]] -- can be moved to caller
+ local features = contextsetups[attribute]
if features then
local dynamics = fontdynamics[font]
- local script = features.script or 'dflt'
- local language = features.language or 'dflt'
+ dynamic = contextmerged[attribute] or 0
+ local script, language
+ if dynamic == 2 then -- merge
+ language = features.language or fontproperties[font].language or "dflt"
+ script = features.script or fontproperties[font].script or "dflt"
+ else -- if dynamic == 1 then -- replace
+ language = features.language or "dflt"
+ script = features.script or "dflt"
+ end
if script == "auto" then
- -- checkedscript and resources are defined later so we cannot shortcut them
- script = definers.checkedscript(fontdata[font],hashes.resources[font],features)
+ -- checkedscript and resources are defined later so we cannot shortcut them -- todo: make installer
+ script = definers.checkedscript(fontidentifiers[font],fontresources[font],features)
end
local ds = dynamics[script] -- can be metatable magic (less testing)
if not ds then
@@ -68,10 +74,10 @@ function otf.setdynamics(font,attribute)
end
local dsla = dsl[attribute]
if not dsla then
- local tfmdata = fontdata[font]
+ local tfmdata = fontidentifiers[font]
a_to_script [attribute] = script
a_to_language[attribute] = language
- -- we need to save some values
+ -- we need to save some values .. quite messy
local properties = tfmdata.properties
local shared = tfmdata.shared
local s_script = properties.script
@@ -88,7 +94,7 @@ function otf.setdynamics(font,attribute)
set.mode = "node" -- really needed
dsla = otf.setfeatures(tfmdata,set)
if trace_dynamics then
- report_otf("setting dynamics %s: attribute %s, script %s, language %s, set: %s",contextnumbers[attribute],attribute,script,language,sequenced(set))
+ report_otf("setting dynamics %s: attribute %a, script %a, language %a, set %a",contextnumbers[attribute],attribute,script,language,set)
end
-- we need to restore some values
properties.script = s_script
@@ -98,7 +104,7 @@ function otf.setdynamics(font,attribute)
-- end of restore
dynamics[script][language][attribute] = dsla -- cache
elseif trace_dynamics then
- -- report_otf("using dynamics %s: attribute %s, script %s, language %s",contextnumbers[attribute],attribute,script,language)
+ -- report_otf("using dynamics %s: attribute %a, script %a, language %a",contextnumbers[attribute],attribute,script,language)
end
return dsla
end
@@ -115,51 +121,58 @@ end
-- we reimplement the dataset resolver
-local special_attributes = {
- init = 1,
- medi = 2,
- fina = 3,
- isol = 4
-}
+local autofeatures = fonts.analyzers.features -- was: constants
+
+local resolved = { } -- we only resolve a font,script,language,attribute pair once
+local wildcard = "*"
+local default = "dflt"
-local resolved = { } -- we only resolve a font,script,language,attribute pair once
-local wildcard = "*"
-local default = "dflt"
+-- what about analyze in local and not in font
local function initialize(sequence,script,language,s_enabled,a_enabled,font,attr,dynamic)
local features = sequence.features
if features then
for kind, scripts in next, features do
- local s_e = s_enabled and s_enabled[kind] -- the value
- local a_e = a_enabled and a_enabled[kind] -- the value
- local e_e = s_e or a_e -- todo: when one of them is true and the other is a value
+ local e_e
+ local a_e = a_enabled and a_enabled[kind] -- the value (location)
+ if a_e ~= nil then
+ e_e = a_e
+ else
+ e_e = s_enabled and s_enabled[kind] -- the value (font)
+ end
if e_e then
local languages = scripts[script] or scripts[wildcard]
if languages then
- local valid, what = false
+ -- local valid, what = false
+ local valid = false
-- not languages[language] or languages[default] or languages[wildcard] because we want tracing
-- only first attribute match check, so we assume simple fina's
-- default can become a font feature itself
if languages[language] then
valid = e_e -- was true
- what = language
+ -- what = language
-- elseif languages[default] then
-- valid = true
-- what = default
elseif languages[wildcard] then
valid = e_e -- was true
- what = wildcard
+ -- what = wildcard
end
if valid then
- local attribute = special_attributes[kind] or false
- if a_e and dynamic < 0 then
- valid = false
- end
+ local attribute = autofeatures[kind] or false
+ -- if a_e and dynamic < 0 then
+ -- valid = false
+ -- end
+ -- if trace_applied then
+ -- local typ, action = match(sequence.type,"(.*)_(.*)") -- brrr
+ -- report_process(
+ -- "%s font: %03i, dynamic: %03i, kind: %s, script: %-4s, language: %-4s (%-4s), type: %s, action: %s, name: %s",
+ -- (valid and "+") or "-",font,attr or 0,kind,script,language,what,typ,action,sequence.name)
+ -- end
if trace_applied then
- local typ, action = match(sequence.type,"(.*)_(.*)") -- brrr
report_process(
- "%s font: %03i, dynamic: %03i, kind: %s, script: %-4s, language: %-4s (%-4s), type: %s, action: %s, name: %s",
- (valid and "+") or "-",font,attr or 0,kind,script,language,what,typ,action,sequence.name)
+ "font %s, dynamic %a (%a), feature %a, script %a, language %a, lookup %a, value %a",
+ font,attr or 0,dynamic,kind,script,language,sequence.name,valid)
end
return { valid, attribute, sequence.chain or 0, kind, sequence }
end
@@ -172,28 +185,32 @@ local function initialize(sequence,script,language,s_enabled,a_enabled,font,attr
end
end
--- local contextresolved = { }
---
--- setmetatableindex(contextresolved, function(t,k)
--- local v = contextsetups[contextnumbers[k]]
--- t[k] = v
--- return v
--- end)
+-- there is some fuzzy language/script state stuff in properties (temporary)
-function otf.dataset(tfmdata,sequences,font,attr) -- attr only when explicit (as in special parbuilder)
+function otf.dataset(tfmdata,font,attr) -- attr only when explicit (as in special parbuilder)
local script, language, s_enabled, a_enabled, dynamic
if attr and attr ~= 0 then
- local features = contextsetups[contextnumbers[attr]] -- could be a direct list
- -- local features = contextresolved[attr]
- language = features.language or "dflt"
- script = features.script or "dflt"
- a_enabled = features
- dynamic = contextmerged[attr] or 0
- if dynamic == 2 or dynamic == -2 then
- -- font based
- s_enabled = tfmdata.shared.features
+ dynamic = contextmerged[attr] or 0
+ -- local features = contextsetups[contextnumbers[attr]] -- could be a direct list
+ local features = contextsetups[attr]
+ a_enabled = features -- location based
+ if dynamic == 1 then -- or dynamic == -1 then
+ -- replace
+ language = features.language or "dflt"
+ script = features.script or "dflt"
+ elseif dynamic == 2 then -- or dynamic == -2 then
+ -- merge
+ local properties = tfmdata.properties
+ s_enabled = tfmdata.shared.features -- font based
+ language = features.language or properties.language or "dflt"
+ script = features.script or properties.script or "dflt"
+ else
+ -- error
+ local properties = tfmdata.properties
+ language = properties.language or "dflt"
+ script = properties.script or "dflt"
end
else
local properties = tfmdata.properties
@@ -220,15 +237,25 @@ function otf.dataset(tfmdata,sequences,font,attr) -- attr only when explicit (as
end
local ra = rl[attr]
if ra == nil then -- attr can be false
- ra = { }
+ ra = {
+ -- indexed but we can also add specific data by key in:
+ }
rl[attr] = ra
- setmetatableindex(ra, function(t,k)
- local v = initialize(sequences[k],script,language,s_enabled,a_enabled,font,attr,dynamic)
- t[k] = v or false
- return v
- end)
+ local sequences = tfmdata.resources.sequences
+-- setmetatableindex(ra, function(t,k)
+-- if type(k) == "number" then
+-- local v = initialize(sequences[k],script,language,s_enabled,a_enabled,font,attr,dynamic)
+-- t[k] = v or false
+-- return v
+-- end
+-- end)
+for s=1,#sequences do
+ local v = initialize(sequences[s],script,language,s_enabled,a_enabled,font,attr,dynamic)
+ if v then
+ ra[#ra+1] = v
+ end
+end
end
-
return ra
end