diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/font-otc.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/font-otc.lua | 230 |
1 files changed, 150 insertions, 80 deletions
diff --git a/Master/texmf-dist/tex/context/base/font-otc.lua b/Master/texmf-dist/tex/context/base/font-otc.lua index 1b4983ce01a..ae463e750a2 100644 --- a/Master/texmf-dist/tex/context/base/font-otc.lua +++ b/Master/texmf-dist/tex/context/base/font-otc.lua @@ -51,7 +51,8 @@ local function addfeature(data,feature,specifications) local unicodes = resources.unicodes local lookuptypes = resources.lookuptypes local splitter = lpeg.splitter(" ",unicodes) - local done = 0 + local done = 0 + local skip = 0 if not specifications[1] then -- so we accept a one entry specification specifications = { specifications } @@ -59,92 +60,113 @@ local function addfeature(data,feature,specifications) -- subtables are tables themselves but we also accept flattened singular subtables for s=1,#specifications do local specification = specifications[s] - local askedfeatures = specification.features or everywhere - local subtables = specification.subtables or { specification.data } or { } - local featuretype = types[specification.type or "substitution"] - local featureflags = specification.flags or noflags - local added = false - local featurename = format("ctx_%s_%s",feature,s) - local st = { } - for t=1,#subtables do - local list = subtables[t] - local full = format("%s_%s",featurename,t) - st[t] = full - if featuretype == "gsub_ligature" then - lookuptypes[full] = "ligature" - for code, ligature in next, list do - local unicode = tonumber(code) or unicodes[code] - local description = descriptions[unicode] - if description then - local slookups = description.slookups - if type(ligature) == "string" then - ligature = { lpegmatch(splitter,ligature) } - end - if slookups then - slookups[full] = ligature - else - description.slookups = { [full] = ligature } + local valid = specification.valid + if not valid or valid(data,specification,feature) then + local initialize = specification.initialize + if initialize then + -- when false is returned we initialize only once + specification.initialize = initialize(specification) and initialize or nil + end + local askedfeatures = specification.features or everywhere + local subtables = specification.subtables or { specification.data } or { } + local featuretype = types[specification.type or "substitution"] + local featureflags = specification.flags or noflags + local added = false + local featurename = format("ctx_%s_%s",feature,s) + local st = { } + for t=1,#subtables do + local list = subtables[t] + local full = format("%s_%s",featurename,t) + st[t] = full + if featuretype == "gsub_ligature" then + lookuptypes[full] = "ligature" + for code, ligature in next, list do + local unicode = tonumber(code) or unicodes[code] + local description = descriptions[unicode] + if description then + local slookups = description.slookups + if type(ligature) == "string" then + ligature = { lpegmatch(splitter,ligature) } + end + local present = true + for i=1,#ligature do + if not descriptions[ligature[i]] then + present = false + break + end + end + if present then + if slookups then + slookups[full] = ligature + else + description.slookups = { [full] = ligature } + end + done, added = done + 1, true + else + skip = skip + 1 + end end - done, added = done + 1, true end - end - elseif featuretype == "gsub_single" then - lookuptypes[full] = "substitution" - for code, replacement in next, list do - local unicode = tonumber(code) or unicodes[code] - local description = descriptions[unicode] - if description then - local slookups = description.slookups - replacement = tonumber(replacement) or unicodes[replacement] - if slookups then - slookups[full] = replacement - else - description.slookups = { [full] = replacement } + elseif featuretype == "gsub_single" then + lookuptypes[full] = "substitution" + for code, replacement in next, list do + local unicode = tonumber(code) or unicodes[code] + local description = descriptions[unicode] + if description then + local slookups = description.slookups + replacement = tonumber(replacement) or unicodes[replacement] + if descriptions[replacement] then + if slookups then + slookups[full] = replacement + else + description.slookups = { [full] = replacement } + end + done, added = done + 1, true + end end - done, added = done + 1, true end end end - end - if added then - -- script = { lang1, lang2, lang3 } or script = { lang1 = true, ... } - for k, v in next, askedfeatures do - if v[1] then - askedfeatures[k] = table.tohash(v) + if added then + -- script = { lang1, lang2, lang3 } or script = { lang1 = true, ... } + for k, v in next, askedfeatures do + if v[1] then + askedfeatures[k] = table.tohash(v) + end end - end - sequences[#sequences+1] = { - chain = 0, - features = { [feature] = askedfeatures }, - flags = featureflags, - name = featurename, - subtables = st, - type = featuretype, - } - -- register in metadata (merge as there can be a few) - if not gsubfeatures then - gsubfeatures = { } - fontfeatures.gsub = gsubfeatures - end - local k = gsubfeatures[feature] - if not k then - k = { } - gsubfeatures[feature] = k - end - for script, languages in next, askedfeatures do - local kk = k[script] - if not kk then - kk = { } - k[script] = kk + sequences[#sequences+1] = { + chain = 0, + features = { [feature] = askedfeatures }, + flags = featureflags, + name = featurename, + subtables = st, + type = featuretype, + } + -- register in metadata (merge as there can be a few) + if not gsubfeatures then + gsubfeatures = { } + fontfeatures.gsub = gsubfeatures end - for language, value in next, languages do - kk[language] = value + local k = gsubfeatures[feature] + if not k then + k = { } + gsubfeatures[feature] = k + end + for script, languages in next, askedfeatures do + local kk = k[script] + if not kk then + kk = { } + k[script] = kk + end + for language, value in next, languages do + kk[language] = value + end end end end end - if done > 0 and trace_loading then - report_otf("enhance: registering %s feature (%s glyphs affected)",feature,done) + if trace_loading then + report_otf("enhance: registering feature '%s', %s glyphs affected, %s glyphs skipped",feature,done,skip) end end end @@ -179,9 +201,9 @@ local tlig = { local tlig_specification = { type = "ligature", - features = everywhere, -- { ["*"] = { ["*"] = true } }, + features = everywhere, data = tlig, - flags = noflags, -- { }, + flags = noflags, } otf.addfeature("tlig",tlig_specification) @@ -201,9 +223,9 @@ local trep = { local trep_specification = { type = "substitution", - features = everywhere, -- { ["*"] = { ["*"] = true } }, + features = everywhere, data = trep, - flags = noflags, -- { }, + flags = noflags, } otf.addfeature("trep",trep_specification) @@ -213,6 +235,39 @@ registerotffeature { description = 'tex replacements', } +-- tcom + +if characters.combined then + + local tcom = { } + + local function initialize() + characters.initialize() + for first, seconds in next, characters.combined do + for second, combination in next, seconds do + tcom[combination] = { first, second } + end + end + -- return false + end + + local tcom_specification = { + type = "ligature", + features = everywhere, + data = tcom, + flags = noflags, + initialize = initialize, + } + + otf.addfeature("tcom",tcom_specification) + + registerotffeature { + name = 'tcom', + description = 'tex combinations', + } + +end + -- anum local anum_arabic = { @@ -241,22 +296,37 @@ local anum_persian = { [0x0039] = 0x06F9, } +local function valid(data) + local features = data.resources.features + if features then + for k, v in next, features do + for k, v in next, v do + if v.arab then + return true + end + end + end + end +end + local anum_specification = { { type = "substitution", features = { arab = { URD = true, dflt = true } }, data = anum_arabic, flags = noflags, -- { }, + valid = valid, }, { type = "substitution", features = { arab = { URD = true } }, data = anum_persian, flags = noflags, -- { }, + valid = valid, }, } -otf.addfeature("anum",anum_specification) +otf.addfeature("anum",anum_specification) -- todo: only when there is already an arab script feature registerotffeature { name = 'anum', |