summaryrefslogtreecommitdiff
path: root/tex/context/base/font-otl.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2015-07-10 00:15:04 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2015-07-10 00:15:04 +0200
commitd0cd2c4b5b931a812990db3ac953a3e288d0c215 (patch)
tree66f585bbfae40fdd2e748a308555d96e2fa54365 /tex/context/base/font-otl.lua
parentd7b51cfffa3d797c9a19d6cf5366150bcf032554 (diff)
downloadcontext-d0cd2c4b5b931a812990db3ac953a3e288d0c215.tar.gz
2015-07-10 00:08:00
Diffstat (limited to 'tex/context/base/font-otl.lua')
-rw-r--r--tex/context/base/font-otl.lua131
1 files changed, 113 insertions, 18 deletions
diff --git a/tex/context/base/font-otl.lua b/tex/context/base/font-otl.lua
index bd76fced6..4dd95a7d1 100644
--- a/tex/context/base/font-otl.lua
+++ b/tex/context/base/font-otl.lua
@@ -24,7 +24,7 @@ if not modules then modules = { } end modules ['font-otl'] = {
-- todo: less tounicodes
local gmatch, find, match, lower, strip = string.gmatch, string.find, string.match, string.lower, string.strip
-local type, next, tonumber, tostring = type, next, tonumber, tostring
+local type, next, tonumber, tostring, unpack = type, next, tonumber, tostring, unpack
local abs = math.abs
local ioflush = io.flush
local derivetable = table.derive
@@ -603,35 +603,125 @@ registerotffeature {
-- readers
function otf.collectlookups(rawdata,kind,script,language)
- local sequences = rawdata.resources.sequences
- if sequences then
+ if not kind then
+ return
+ end
+ if not script then
+ script = default
+ end
+ if not language then
+ language = default
+ end
+ local lookupcache = rawdata.lookupcache
+ if not lookupcache then
+ lookupcache = { }
+ rawdata.lookupcache = lookupcache
+ end
+ local kindlookup = lookupcache[kind]
+ if not kindlookup then
+ kindlookup = { }
+ lookupcache[kind] = kindlookup
+ end
+ local scriptlookup = kindlookup[script]
+ if not scriptlookup then
+ scriptlookup = { }
+ kindlookup[script] = scriptlookup
+ end
+ local languagelookup = scriptlookup[language]
+ if not languagelookup then
+ local sequences = rawdata.resources.sequences
local featuremap = { }
local featurelist = { }
- for s=1,#sequences do
- local sequence = sequences[s]
- local features = sequence.features
- if features then
- features = features[kind]
+ if sequences then
+ for s=1,#sequences do
+ local sequence = sequences[s]
+ local features = sequence.features
if features then
- features = features[script] or features[default] or features[wildcard]
+ features = features[kind]
if features then
- features = features[language] or features[default] or features[wildcard]
+ -- features = features[script] or features[default] or features[wildcard]
+ features = features[script] or features[wildcard]
if features then
- if not featuremap[sequence] then
- featuremap[sequence] = true
- featurelist[#featurelist+1] = sequence
+ -- features = features[language] or features[default] or features[wildcard]
+ features = features[language] or features[wildcard]
+ if features then
+ if not featuremap[sequence] then
+ featuremap[sequence] = true
+ featurelist[#featurelist+1] = sequence
+ end
end
end
end
end
end
+ if #featurelist == 0 then
+ featuremap, featurelist = false, false
+ end
+ else
+ featuremap, featurelist = false, false
end
- if #featurelist > 0 then
- return featuremap, featurelist
+ languagelookup = { featuremap, featurelist }
+ scriptlookup[language] = languagelookup
+ end
+ return unpack(languagelookup)
+end
+
+-- moved from font-oth.lua
+
+local function getgsub(tfmdata,k,kind,value)
+ local shared = tfmdata.shared
+ local rawdata = shared and shared.rawdata
+ if rawdata then
+ local sequences = rawdata.resources.sequences
+ if sequences then
+ local properties = tfmdata.properties
+ local validlookups, lookuplist = otf.collectlookups(rawdata,kind,properties.script,properties.language)
+ if validlookups then
+ local choice = tonumber(value) or 1 -- no random here (yet)
+ for i=1,#lookuplist do
+ local lookup = lookuplist[i]
+ local steps = lookup.steps
+ local nofsteps = lookup.nofsteps
+ for i=1,nofsteps do
+ local coverage = steps[i].coverage
+ if coverage then
+ local found = coverage[k]
+ if found then
+ return found, lookup.type
+ end
+ end
+ end
+ end
+ end
end
end
end
+otf.getgsub = getgsub -- returns value, gsub_kind
+
+function otf.getsubstitution(tfmdata,k,kind,value)
+ local found, kind = getgsub(tfmdata,k,kind)
+ if not found then
+ --
+ elseif kind == "gsub_single" then
+ return found
+ elseif kind == "gsub_alternate" then
+ local choice = tonumber(value) or 1 -- no random here (yet)
+ return found[choice] or found[1] or k
+ end
+ return k
+end
+
+otf.getalternate = otf.getsubstitution
+
+function otf.getmultiple(tfmdata,k,kind)
+ local found, kind = getgsub(tfmdata,k,kind)
+ if found and kind == "gsub_multiple" then
+ return found
+ end
+ return { k }
+end
+
local function check_otf(forced,specification,suffix)
local name = specification.name
if forced then
@@ -681,7 +771,9 @@ otf.coverup = {
substitution = justset,
alternate = justset,
multiple = justset,
- ligature = function (coverage,unicode,ligature)
+ kern = justset,
+ pair = justset,
+ ligature = function(coverage,unicode,ligature)
local first = ligature[1]
local tree = coverage[first]
if not tree then
@@ -700,7 +792,10 @@ otf.coverup = {
tree.ligature = unicode
end,
},
- register = function(coverage)
- return { coverage = coverage }
+ register = function(coverage,featuretype,format)
+ return {
+ format = format,
+ coverage = coverage,
+ }
end
}