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,value)
109
110 if 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
203registerotffeature {
204 name = "compactmath",
205 description = "use one math font",
206 initializers = {
207 base = function(...) manipulate(...) initialize(...) end,
208 node = function(...) manipulate(...) initialize(...) end,
209 }
210}
211
212
213
214
215
216
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
242local function initialize(tfmdata,value)
243 if type(value) == "string" then
244 local rawdata = tfmdata.shared.rawdata
245 local rawresources = rawdata and rawdata.resources
246 local mathconstants = rawresources.mathconstants
247 if mathconstants then
248 local bitmap = tex.stringtocodesbitmap(value,tex.mathcontrolcodes)
249
250 tfmdata.properties.mathcontrol = bitmap
251 end
252 end
253end
254
255registerotffeature {
256 name = "mathcontrol",
257 description = "control specific old/new math handling",
258 initializers = {
259 base = initialize,
260 node = initialize,
261 }
262}
263
264local function initialize(tfmdata,value)
265 if value then
266 local validlookups, lookuplist = fonts.handlers.otf.collectlookups(tfmdata.shared.rawdata,"flac","math","dflt")
267 if validlookups then
268
269 local characters = tfmdata.characters
270 local changed = tfmdata.changed
271 for i=1,#lookuplist do
272 local lookup = lookuplist[i]
273 local steps = lookup.steps
274 local nofsteps = lookup.nofsteps
275 for i=1,nofsteps do
276 local coverage = steps[i].coverage
277 if coverage then
278 for k, v in next, coverage do
279 local c = characters[k]
280 local f = characters[v]
281 if c and f then
282 c.flataccent = v
283 if not f.unicode then
284 f.unicode = c.unicode
285 end
286 end
287 end
288 end
289 end
290 end
291 end
292 end
293end
294
295registerotffeature {
296 name = "flattenaccents",
297 description = "mapping accents to flat ones",
298 initializers = {
299 base = initialize,
300 node = initialize,
301 }
302}
303
304
305
306
307
308
309
310
311
312
313
314
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 |