summaryrefslogtreecommitdiff
path: root/tex/context/base/font-ctx.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2012-01-05 19:27:39 +0100
committerHans Hagen <pragma@wxs.nl>2012-01-05 19:27:39 +0100
commit598c44b5523a78a5bf481ad93c88e42dec995482 (patch)
treec04bf4c023cc0e5105e340ad1275732bcea4a53a /tex/context/base/font-ctx.lua
parent3ebffee90ab738221306b6642480dce1ad96cac4 (diff)
downloadcontext-598c44b5523a78a5bf481ad93c88e42dec995482.tar.gz
beta 2011.12.13 15:17
Diffstat (limited to 'tex/context/base/font-ctx.lua')
-rw-r--r--tex/context/base/font-ctx.lua224
1 files changed, 164 insertions, 60 deletions
diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua
index f58893c7d..6a7e0f5d3 100644
--- a/tex/context/base/font-ctx.lua
+++ b/tex/context/base/font-ctx.lua
@@ -112,10 +112,13 @@ commands.resetnullfont = definers.resetnullfont
setmetatableindex(fontdata, function(t,k) return nulldata end)
+-- we might make an font-hsh.lua
+
local chardata = allocate() -- chardata
local descriptions = allocate()
local parameters = allocate()
local properties = allocate()
+local resources = allocate()
local quaddata = allocate()
local markdata = allocate()
local xheightdata = allocate()
@@ -126,6 +129,7 @@ hashes.characters = chardata
hashes.descriptions = descriptions
hashes.parameters = parameters
hashes.properties = properties
+hashes.resources = resources
hashes.quads = quaddata
hashes.marks = markdata
hashes.xheights = xheightdata
@@ -156,6 +160,14 @@ setmetatableindex(properties, function(t,k)
return properties
end)
+setmetatableindex(resources, function(t,k)
+ local shared = fontdata[k].shared
+ local rawdata = shared and shared.rawdata
+ local resources = rawdata and rawdata.resources
+ t[k] = resources or false -- better than resolving each time
+ return resources
+end)
+
setmetatableindex(quaddata, function(t,k)
local parameters = parameters[k]
local quad = parameters and parameters.quad or 0
@@ -207,68 +219,138 @@ local privatefeatures = {
anum = true,
}
-local function modechecker(tfmdata,features,mode) -- we cannot adapt features as they are shared!
- if trace_features then
- report_features(serialize(features,"used"))
- end
- local rawdata = tfmdata.shared.rawdata
- local resources = rawdata and rawdata.resources
- local script = features.script
- if script == "auto" then
- local latn = false
- for g, list in next, resources.features do
- for f, scripts in next, list do
- if privatefeatures[f] then
- -- skip
- elseif scripts.dflt then
- script = "dflt"
- break
- elseif scripts.latn then
- latn = true
- end
+-- local function modechecker(tfmdata,features,mode) -- we cannot adapt features as they are shared!
+-- if trace_features then
+-- report_features(serialize(features,"used"))
+-- end
+-- local rawdata = tfmdata.shared.rawdata
+-- local resources = rawdata and rawdata.resources
+-- local script = features.script
+-- if script == "auto" then
+-- local latn = false
+-- for g, list in next, resources.features do
+-- for f, scripts in next, list do
+-- if privatefeatures[f] then
+-- -- skip
+-- elseif scripts.dflt then
+-- script = "dflt"
+-- break
+-- elseif scripts.latn then
+-- latn = true
+-- end
+-- end
+-- end
+-- if script == "auto" then
+-- script = latn and "latn" or "dflt"
+-- end
+-- features.script = script
+-- if trace_automode then
+-- report_defining("auto script mode: using script '%s' in font '%s'",script,file.basename(tfmdata.properties.name))
+-- end
+-- end
+-- if mode == "auto" then
+-- local sequences = resources.sequences
+-- if sequences and #sequences > 0 then
+-- local script = features.script or "dflt"
+-- local language = features.language or "dflt"
+-- for feature, value in next, features do
+-- if value then
+-- local found = false
+-- for i=1,#sequences do
+-- local sequence = sequences[i]
+-- local features = sequence.features
+-- if features then
+-- local scripts = features[feature]
+-- if scripts then
+-- local languages = scripts[script]
+-- if languages and languages[language] then
+-- if found then
+-- -- more than one lookup
+-- if trace_automode then
+-- report_defining("forcing node mode in font %s for feature %s, script %s, language %s (multiple lookups)",file.basename(tfmdata.properties.name),feature,script,language)
+-- end
+-- features.mode = "node"
+-- return "node"
+-- elseif needsnodemode[sequence.type] then
+-- if trace_automode then
+-- report_defining("forcing node mode in font %s for feature %s, script %s, language %s (no base support)",file.basename(tfmdata.properties.name),feature,script,language)
+-- end
+-- features.mode = "node"
+-- return "node"
+-- else
+-- -- at least one lookup
+-- found = true
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+-- end
+-- return "base"
+-- else
+-- return mode
+-- end
+-- end
+
+local function checkedscript(tfmdata,resources,features)
+ local latn = false
+ local script = false
+ for g, list in next, resources.features do
+ for f, scripts in next, list do
+ if privatefeatures[f] then
+ -- skip
+ elseif scripts.dflt then
+ script = "dflt"
+ break
+ elseif scripts.latn then
+ latn = true
end
end
- if script == "auto" then
- script = latn and "latn" or "dflt"
- end
- features.script = script
- if trace_automode then
- report_defining("auto script mode: using script '%s' in font '%s'",script,file.basename(tfmdata.properties.name))
- end
end
- if mode == "auto" then
- local sequences = resources.sequences
- if sequences and #sequences > 0 then
- local script = features.script or "dflt"
- local language = features.language or "dflt"
- for feature, value in next, features do
- if value then
- local found = false
- for i=1,#sequences do
- local sequence = sequences[i]
- local features = sequence.features
- if features then
- local scripts = features[feature]
- if scripts then
- local languages = scripts[script]
- if languages and languages[language] then
- if found then
- -- more than one lookup
- if trace_automode then
- report_defining("forcing node mode in font %s for feature %s, script %s, language %s (multiple lookups)",file.basename(tfmdata.properties.name),feature,script,language)
- end
- features.mode = "node"
- return "node"
- elseif needsnodemode[sequence.type] then
- if trace_automode then
- report_defining("forcing node mode in font %s for feature %s, script %s, language %s (no base support)",file.basename(tfmdata.properties.name),feature,script,language)
- end
- features.mode = "node"
- return "node"
- else
- -- at least one lookup
- found = true
+ if not script then
+ script = latn and "latn" or "dflt"
+ end
+ if trace_automode then
+ report_defining("auto script mode: using script '%s' in font '%s'",script,file.basename(tfmdata.properties.name))
+ end
+ features.script = script
+ return script
+end
+
+local function checkedmode(tfmdata,resources,features)
+ local sequences = resources.sequences
+ if sequences and #sequences > 0 then
+ local script = features.script or "dflt"
+ local language = features.language or "dflt"
+ for feature, value in next, features do
+ if value then
+ local found = false
+ for i=1,#sequences do
+ local sequence = sequences[i]
+ local features = sequence.features
+ if features then
+ local scripts = features[feature]
+ if scripts then
+ local languages = scripts[script]
+ if languages and languages[language] then
+ if found then
+ -- more than one lookup
+ if trace_automode then
+ report_defining("forcing node mode in font %s for feature %s, script %s, language %s (multiple lookups)",file.basename(tfmdata.properties.name),feature,script,language)
+ end
+ features.mode = "node"
+ return "node"
+ elseif needsnodemode[sequence.type] then
+ if trace_automode then
+ report_defining("forcing node mode in font %s for feature %s, script %s, language %s (no base support)",file.basename(tfmdata.properties.name),feature,script,language)
end
+ features.mode = "node"
+ return "node"
+ else
+ -- at least one lookup
+ found = true
end
end
end
@@ -276,10 +358,32 @@ local function modechecker(tfmdata,features,mode) -- we cannot adapt features as
end
end
end
- return "base"
+ end
+ features.mode = "base" -- new, or is this wrong?
+ return "base"
+end
+
+definers.checkedscript = checkedscript
+definers.checkedmode = checkedmode
+
+local function modechecker(tfmdata,features,mode) -- we cannot adapt features as they are shared!
+ if trace_features then
+ report_features(serialize(features,"used"))
+ end
+ local rawdata = tfmdata.shared.rawdata
+ local resources = rawdata and rawdata.resources
+ local script = features.script
+ if resources then
+ if script == "auto" then
+ script = checkedscript(tfmdata,resources,features)
+ end
+ if mode == "auto" then
+ mode = checkedmode(tfmdata,resources,features)
+ end
else
- return mode
+ report_features("missing resources for font''%s'",file.basename(tfmdata.properties.name))
end
+ return mode
end
registerotffeature {