font-oti.lua /size: 7904 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-oti
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to font-ini.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
lower
=
string
.
lower
10 11
local
fonts
=
fonts
12
local
constructors
=
fonts
.
constructors
13 14
local
otf
=
constructors
.
handlers
.
otf
15
local
otffeatures
=
constructors
.
features
.
otf
16
local
registerotffeature
=
otffeatures
.
register
17 18
local
otftables
=
otf
.
tables
or
{
}
19
otf
.
tables
=
otftables
20 21
local
allocate
=
utilities
.
storage
.
allocate
22 23
registerotffeature
{
24
name
=
"
features
"
,
25
description
=
"
initialization of feature handler
"
,
26
default
=
true
,
27
}
28 29
-- these are later hooked into node and base initializaters
30 31
local
function
setmode
(
tfmdata
,
value
)
32
if
value
then
33
tfmdata
.
properties
.
mode
=
lower
(
value
)
34
end
35
end
36 37
otf
.
modeinitializer
=
setmode
38 39
local
function
setlanguage
(
tfmdata
,
value
)
40
if
value
then
41
local
cleanvalue
=
lower
(
value
)
42
local
languages
=
otftables
and
otftables
.
languages
43
local
properties
=
tfmdata
.
properties
44
if
not
languages
then
45
properties
.
language
=
cleanvalue
46
elseif
languages
[
value
]
then
47
properties
.
language
=
cleanvalue
48
else
49
properties
.
language
=
"
dflt
"
50
end
51
end
52
end
53 54
local
function
setscript
(
tfmdata
,
value
)
55
if
value
then
56
local
cleanvalue
=
lower
(
value
)
57
local
scripts
=
otftables
and
otftables
.
scripts
58
local
properties
=
tfmdata
.
properties
59
if
not
scripts
then
60
properties
.
script
=
cleanvalue
61
elseif
scripts
[
value
]
then
62
properties
.
script
=
cleanvalue
63
else
64
properties
.
script
=
"
dflt
"
65
end
66
end
67
end
68 69
registerotffeature
{
70
name
=
"
mode
"
,
71
description
=
"
mode
"
,
72
initializers
=
{
73
base
=
setmode
,
74
node
=
setmode
,
75
plug
=
setmode
,
76
}
77
}
78 79
registerotffeature
{
80
name
=
"
language
"
,
81
description
=
"
language
"
,
82
initializers
=
{
83
base
=
setlanguage
,
84
node
=
setlanguage
,
85
plug
=
setlanguage
,
86
}
87
}
88 89
registerotffeature
{
90
name
=
"
script
"
,
91
description
=
"
script
"
,
92
initializers
=
{
93
base
=
setscript
,
94
node
=
setscript
,
95
plug
=
setscript
,
96
}
97
}
98 99
-- here (as also in generic
100 101
otftables
.
featuretypes
=
allocate
{
102
gpos_single
=
"
position
"
,
103
gpos_pair
=
"
position
"
,
104
gpos_cursive
=
"
position
"
,
105
gpos_mark2base
=
"
position
"
,
106
gpos_mark2ligature
=
"
position
"
,
107
gpos_mark2mark
=
"
position
"
,
108
gpos_context
=
"
position
"
,
109
gpos_contextchain
=
"
position
"
,
110
gsub_single
=
"
substitution
"
,
111
gsub_multiple
=
"
substitution
"
,
112
gsub_alternate
=
"
substitution
"
,
113
gsub_ligature
=
"
substitution
"
,
114
gsub_context
=
"
substitution
"
,
115
gsub_contextchain
=
"
substitution
"
,
116
gsub_reversecontextchain
=
"
substitution
"
,
117
gsub_reversesub
=
"
substitution
"
,
118
}
119 120
function
otffeatures
.
checkeddefaultscript
(
featuretype
,
autoscript
,
scripts
)
121
if
featuretype
=
=
"
position
"
then
122
local
default
=
scripts
.
dflt
123
if
default
then
124
if
autoscript
=
=
"
position
"
or
autoscript
=
=
true
then
125
return
default
126
else
127
report_otf
(
"
script feature %s not applied, enable default positioning
"
)
128
end
129
else
130
-- no positioning at all
131
end
132
elseif
featuretype
=
=
"
substitution
"
then
133
local
default
=
scripts
.
dflt
134
if
default
then
135
if
autoscript
=
=
"
substitution
"
or
autoscript
=
=
true
then
136
return
default
137
end
138
end
139
end
140
end
141 142
function
otffeatures
.
checkeddefaultlanguage
(
featuretype
,
autolanguage
,
languages
)
143
if
featuretype
=
=
"
position
"
then
144
local
default
=
languages
.
dflt
145
if
default
then
146
if
autolanguage
=
=
"
position
"
or
autolanguage
=
=
true
then
147
return
default
148
else
149
report_otf
(
"
language feature %s not applied, enable default positioning
"
)
150
end
151
else
152
-- no positioning at all
153
end
154
elseif
featuretype
=
=
"
substitution
"
then
155
local
default
=
languages
.
dflt
156
if
default
then
157
if
autolanguage
=
=
"
substitution
"
or
autolanguage
=
=
true
then
158
return
default
159
end
160
end
161
end
162
end
163 164
-- the following might become available generic in due time but for now
165
-- this is some context playground (development code)
166 167
-- if not context then
168
-- return
169
-- end
170 171
-- local helpers = otf.readers.helpers
172
-- local axistofactors = helpers.axistofactors
173
-- local normalizedaxis = helpers.normalizedaxis
174
-- local getaxisscale = helpers.getaxisscale
175
-- local cleanname = containers.cleanname
176 177
-- local function validvariable(tfmdata)
178
-- if tfmdata.properties.factors then
179
-- return
180
-- end
181
-- local resources = tfmdata.resources
182
-- local variabledata = resources and resources.variabledata
183
-- if not variabledata then
184
-- return
185
-- end
186
-- local instances = variabledata.instances
187
-- local axis = variabledata.axis
188
-- local segments = variabledata.segments
189
-- if instances and axis then
190
-- return instances, axis, segments
191
-- end
192
-- end
193 194
-- local function initializeinstance(tfmdata,value)
195
-- if type(value) == "string" then
196
-- local instances, axis, segments = validvariable(tfmdata)
197
-- if instances then
198
-- local values
199
-- for i=1,#instances do
200
-- local instance = instances[i]
201
-- if cleanname(instance.subfamily) == value then
202
-- values = instance.values
203
-- break
204
-- end
205
-- end
206
-- if values then
207
-- local factors = { }
208
-- for i=1,#axis do
209
-- local a = axis[i]
210
-- factors[i] = getaxisscale(segments,a.minimum,a.default,a.maximum,values[i].value)
211
-- end
212
-- tfmdata.properties.instance = {
213
-- hash = instance,
214
-- factors = factors,
215
-- }
216
-- end
217
-- else
218
-- report("incomplete variable data")
219
-- end
220
-- end
221
-- end
222 223
-- local function initializeaxis(tfmdata,value)
224
-- if type(value) == "string" then
225
-- local instances, axis, segments = validvariable(tfmdata)
226
-- if instances then
227
-- local values = axistofactors(value)
228
-- if values then
229
-- local factors = { }
230
-- for i=1,#axis do
231
-- local a = axis[i]
232
-- local d = a.default
233
-- factors[i] = getaxisscale(segments,a.minimum,d,a.maximum,values[a.name or a.tag] or d)
234
-- end
235
-- tfmdata.properties.instance = {
236
-- hash = cleanname(value),
237
-- factors = factors,
238
-- }
239
-- end
240
-- else
241
-- report("incomplete variable data")
242
-- end
243
-- end
244
-- end
245 246
-- registerotffeature {
247
-- name = "instance",
248
-- description = "variation instance",
249
-- initializers = {
250
-- node = initializeinstance,
251
-- base = initializeinstance,
252
-- }
253
-- }
254 255
-- registerotffeature {
256
-- name = "axis",
257
-- description = "variation axis",
258
-- initializers = {
259
-- node = initializeaxis,
260
-- base = initializeaxis,
261
-- }
262
-- }
263