1if not modules then modules = { } end modules ['font-imp-math'] = {
2 version = 1.001,
3 comment = "companion to font-ini.mkiv and hand-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
9local next, type, tonumber = next, type, tonumber
10local round = math.round
11
12local fonts = fonts
13local helpers = fonts.helpers
14local registerotffeature = fonts.handlers.otf.features.register
15
16local setmetatableindex = table.setmetatableindex
17local sortedhash = table.sortedhash
18local copytable = table.copy
19
20local getmacro = token.getmacro
21
22local texconditionals = tex.conditionals
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78function fonts.helpers.mathscriptslots(tfmdata,textcode)
79 local rawdata = tfmdata.shared.rawdata
80 local rawresources = rawdata and rawdata.resources
81 local rawfeatures = rawresources and rawresources.features
82 local basesubstitutions = rawfeatures and rawfeatures.gsub
83 local sequences = basesubstitutions and tfmdata.resources.sequences
84 if sequences then
85 local characters = tfmdata.characters
86 if characters[textcode] then
87 for s=1,#sequences do
88 local sequence = sequences[s]
89 local sfeatures = sequence.features
90 if sfeatures and sfeatures.ssty then
91 local steps = sequence.steps
92 for i=1,#steps do
93 local coverage = steps[i].coverage
94 if coverage then
95 local okay = coverage[textcode]
96 if okay then
97
98 return okay
99 end
100 end
101 end
102 end
103 end
104 end
105 end
106end
107
108local function manipulate(tfmdata,key,value)
109
110 if key and value then
111 local rawdata = tfmdata.shared.rawdata
112 local rawresources = rawdata and rawdata.resources
113 local rawfeatures = rawresources and rawresources.features
114 local basesubstitutions = rawfeatures and rawfeatures.gsub
115 local sequences = basesubstitutions and tfmdata.resources.sequences
116 if sequences then
117 local characters = tfmdata.characters
118 for s=1,#sequences do
119 local sequence = sequences[s]
120 local sfeatures = sequence.features
121 if sfeatures and sfeatures.ssty then
122 local steps = sequence.steps
123 for i=1,#steps do
124 local coverage = steps[i].coverage
125 if coverage then
126 for textcode, v in next, coverage do
127 local textdata = characters[textcode]
128 if textdata then
129 local scriptcode, scriptscriptcode
130 local sstykind = type(v)
131 if sstykind == "table" then
132 scriptcode = v[1]
133 scriptscriptcode = v[2]
134 elseif sstykind == "number" then
135 scriptcode = v
136 scriptscriptcode = v
137 else
138
139 end
140 if scriptcode then
141 local scriptdata = characters[scriptcode]
142 local scriptscriptdata = characters[scriptscriptcode]
143 if scriptdata and scriptdata ~= textdata then
144 textdata.smaller = scriptcode
145 if scriptscriptdata and scriptdata ~= scriptscriptdata then
146 scriptdata.smaller = scriptscriptcode
147 end
148 end
149 end
150 end
151 end
152 end
153 end
154 end
155 end
156 end
157 end
158end
159
160local function initialize(tfmdata,value)
161
162 if texconditionals["c_font_compact"] then
163 local rawdata = tfmdata.shared.rawdata
164 local rawresources = rawdata and rawdata.resources
165 local mathconstants = rawresources.mathconstants
166 if mathconstants then
167 local parameters = tfmdata.parameters
168 local properties = tfmdata.properties
169 local sizes = {
170 1000,
171 mathconstants.ScriptPercentScaleDown * 10,
172 mathconstants.ScriptScriptPercentScaleDown * 10,
173 }
174 for i=1,3 do
175 value = getmacro("font_basics_mapped_fontsize_"..i,true)
176 local s = tonumber(value)
177 if s then
178 sizes[i] = s
179 end
180 end
181 parameters.textscale = sizes[1]
182 parameters.scriptscale = sizes[2]
183 parameters.scriptscriptscale = sizes[3]
184 properties.compactmath = true
185
186 end
187 end
188end
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203local function bah(tfmdata,value,features)
204
205 manipulate(tfmdata,"compactmath",features.compactmath)
206
207 initialize(tfmdata,value,features)
208end
209
210registerotffeature {
211 name = "compactmath",
212 description = "use one math font",
213 initializers = {
214
215 base = bah,
216 node = bah,
217 }
218}
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250local function initialize(tfmdata,value)
251 if type(value) == "string" then
252 local rawdata = tfmdata.shared.rawdata
253 local rawresources = rawdata and rawdata.resources
254 local mathconstants = rawresources.mathconstants
255 if mathconstants then
256 local bitmap = tex.stringtocodesbitmap(value,tex.mathcontrolcodes)
257
258 tfmdata.properties.mathcontrol = bitmap
259 end
260 end
261end
262
263registerotffeature {
264 name = "mathcontrol",
265 description = "control specific old/new math handling",
266 initializers = {
267 base = initialize,
268 node = initialize,
269 }
270}
271
272local function initialize(tfmdata,value)
273 if value then
274 local validlookups, lookuplist = fonts.handlers.otf.collectlookups(tfmdata.shared.rawdata,"flac","math","dflt")
275 if validlookups then
276
277 local characters = tfmdata.characters
278 local descriptions = tfmdata.descriptions
279 local changed = tfmdata.changed
280 for i=1,#lookuplist do
281 local lookup = lookuplist[i]
282 local steps = lookup.steps
283 local nofsteps = lookup.nofsteps
284 for i=1,nofsteps do
285 local coverage = steps[i].coverage
286 if coverage then
287 for k, v in next, coverage do
288 local c = characters[k]
289 local f = characters[v]
290 if c and f then
291 c.flataccent = v
292local dk = descriptions[k]
293local dv = descriptions[v]
294if not dv.unicode then
295 dv.unicode = dk.unicode or k
296end
297
298
299
300 end
301 end
302 end
303 end
304 end
305 end
306 end
307end
308
309registerotffeature {
310 name = "flattenaccents",
311 description = "mapping accents to flat ones",
312 initializers = {
313 base = initialize,
314 node = initialize,
315 }
316}
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368 |