summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-otc.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-06-05 17:19:50 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-06-05 17:19:50 +0200
commit7a761c8aebf67ee022aa4857247518ad6997d5c1 (patch)
tree3295b12a1cc69ea5c61bce9c7c71172831f89d28 /tex/context/base/mkiv/font-otc.lua
parent2bca80bc96d0182956e57c51b5d4977f714bed5c (diff)
downloadcontext-7a761c8aebf67ee022aa4857247518ad6997d5c1.tar.gz
2016-06-05 16:31:00
Diffstat (limited to 'tex/context/base/mkiv/font-otc.lua')
-rw-r--r--tex/context/base/mkiv/font-otc.lua178
1 files changed, 131 insertions, 47 deletions
diff --git a/tex/context/base/mkiv/font-otc.lua b/tex/context/base/mkiv/font-otc.lua
index a91dac5cf..d50b1ec14 100644
--- a/tex/context/base/mkiv/font-otc.lua
+++ b/tex/context/base/mkiv/font-otc.lua
@@ -51,6 +51,42 @@ local noflags = { false, false, false, false }
-- beware: shared, maybe we should copy the sequence
+local function validspecification(specification,name)
+ local dataset = specification.dataset
+ if dataset then
+ -- okay
+ elseif specification[1] then
+ dataset = specification
+ specification = { dataset = dataset }
+ else
+ dataset = { { data = specification.data } }
+ specification.data = nil
+ specification.dataset = dataset
+ end
+ local first = dataset[1]
+ if first then
+ first = first.data
+ end
+ if not first then
+ report_otf("invalid feature specification, no dataset")
+ return
+ end
+ if type(name) ~= "string" then
+ name = specification.name or first.name
+ end
+ if type(name) ~= "string" then
+ report_otf("invalid feature specification, no name")
+ return
+ end
+ local n = #dataset
+ if n > 0 then
+ for i=1,n do
+ setmetatableindex(dataset[i],specification)
+ end
+ return specification, name
+ end
+end
+
local function addfeature(data,feature,specifications)
-- todo: add some validator / check code so that we're more tolerant to
@@ -63,6 +99,18 @@ local function addfeature(data,feature,specifications)
if not features or not sequences then
return
end
+
+local alreadydone = resources.alreadydone
+if not alreadydone then
+ alreadydone = { }
+ resources.alreadydone = alreadydone
+end
+if alreadydone[specifications] then
+ return
+else
+ alreadydone[specifications] = true
+end
+
-- feature has to be unique but the name entry wins eventually
local fontfeatures = resources.features or everywhere
@@ -72,9 +120,9 @@ local function addfeature(data,feature,specifications)
local skip = 0
local aglunicodes = false
- if not specifications[1] then
- -- so we accept a one entry specification
- specifications = { specifications }
+ local specifications = validspecification(specifications,name)
+ if not specifications then
+ return
end
local function tounicode(code)
@@ -376,11 +424,15 @@ local function addfeature(data,feature,specifications)
return coverage
end
- for s=1,#specifications do
- local specification = specifications[s]
- local valid = specification.valid
- local feature = specification.name or feature
- if not valid or valid(data,specification,feature) then
+ local dataset = specifications.dataset
+
+ for s=1,#dataset do
+ local specification = dataset[s]
+ local valid = specification.valid -- nowhere used
+ local feature = specification.name or feature
+ if not feature or feature == "" then
+ report_otf("no valid name given for extra feature")
+ elseif not valid or valid(data,specification,feature) then -- anum uses this
local initialize = specification.initialize
if initialize then
-- when false is returned we initialize only once
@@ -497,10 +549,37 @@ local function addfeature(data,feature,specifications)
type = types[featuretype],
}
-- todo : before|after|index
- if specification.prepend then
- insert(sequences,1,sequence)
- else
+ local prepend = specification.prepend
+ if prepend == true then
+ prepend = 1
+ end
+ if type(prepend) == "number" then
+ -- okay
+ elseif type(prepend) == "string" then
+ local index = false
+ for i=1,#sequences do
+ local s = sequences[i]
+ local f = s.features
+ if f then
+ for k in next, f do
+ if k == prepend then
+ index = i
+ break
+ end
+ end
+ if index then
+ break
+ end
+ end
+ end
+ prepend = index
+ elseif prepend == true then
+ prepend = 1
+ end
+ if not prepend or prepend <= 0 or prepend > #sequences then
insert(sequences,sequence)
+ else
+ insert(sequences,prepend,sequence)
end
-- register in metadata (merge as there can be a few)
local features = fontfeatures[category]
@@ -540,18 +619,23 @@ local knownfeatures = { }
function otf.addfeature(name,specification)
if type(name) == "table" then
specification = name
- name = specification.name
end
- if type(name) == "string" then
+ if type(specification) ~= "table" then
+ report_otf("invalid feature specification, no valid table")
+ return
+ end
+ specification, name = validspecification(specification,name)
+ if name and specification then
local slot = knownfeatures[name]
if slot then
- -- we overload one
+ -- we overload one .. should be option
else
slot = #extrafeatures + 1
knownfeatures[name] = slot
end
specification.name = name -- to be sure
extrafeatures[slot] = specification
+ -- report_otf("adding feature %a @ %i",name,slot)
end
end
@@ -626,39 +710,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,
- order = { "tcom" },
- flags = noflags,
- initialize = initialize,
- }
-
- otf.addfeature("tcom",tcom_specification)
-
- registerotffeature {
- name = 'tcom',
- description = 'tex combinations',
- }
-
-end
+-- -- tcom (obsolete, was already not set for a while)
+
+-- 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,
+-- order = { "tcom" },
+-- flags = noflags,
+-- initialize = initialize,
+-- }
+--
+-- otf.addfeature("tcom",tcom_specification)
+--
+-- registerotffeature {
+-- name = 'tcom',
+-- description = 'tex combinations',
+-- }
+--
+-- end
-- anum