1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
\usemodule[present-banner]
\startdocument
[title={OPENTYPE FONTS},
subtitle={the generic loader},
location={Hans Hagen \endash\ bacho\TeX\ 2016}]
\starttitle[title={how engines sees a font}]
\startsubject[title={\TeX}]
\highlight [nb] {fields:} width, height, depth, italic correction, kern table,
ligature tree, vf commands, next size pointer, extensible specification
\highlight [nb] {and} a set of text and math parameters
\stopsubject
\startsubject[title={\pdfTeX}]
\highlight [nb] {extra fields:} left protruding, right protruding, expansion
factor \highlight [nb] {and} parameters to control these
\stopsubject
\startsubject[title={\LuaTeX}]
\highlight [nb] {extra fields:} math top accent, math bot accent, tounicode,
adapted extensible specification, vertical variants, horizontal variants,
name, index, used status, math kerns \highlight [nb] {and} extra parameters
\highlight [nb] {and} math constants \highlight [nb] {and} no 8~bit
limitations
\stopsubject
\startsubject[title={\XeTeX}]
probably something similar
\stopsubject
\stoptitle
\starttitle[title={font handling}]
\startsubject[title={loading opentype font data}]
\startitemize
\startitem
till recently we used the built|-|in fontforge loader library
\stopitem
\startitem
but now we use a recently written \Lua\ loader
\stopitem
\startitem
but use a similar feature handler
\stopitem
\startitem
in \ConTeXt\ one can fall back to the old loader/handler
\stopitem
\stopitemize
\stopsubject
\startsubject[title={applying (opentype) features}]
\highlight [nb] {generic modes:} base, node \crlf
\highlight [nb] {\ConTeXt\ modes:} base, node, auto, dynamic
\stopsubject
\startsubject[title={locating (opentype) fonts}]
\startitemize
\startitem
\highlight [nb] {file}: kpse in generic, resolvers in \ConTeXt
\stopitem
\startitem
\highlight [nb] {name}: simple in generic, extended in \ConTeXt,
different in \LaTeX
\stopitem
\startitem
\highlight [nb] {spec}: not in generic (uses font database)
\stopitem
\startitem
\highlight [nb] {virtual}: not in generic
\stopitem
\startitem
\highlight [nb] {lua}: delegated to low level interfaces
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={preparations}]
\startsubject[title={after loading}]
\startitemize
\startitem
initialize format driven substitution
\stopitem
\startitem
initialize format driven positioning
\stopitem
\startitem
enable analysis of states/properties
\stopitem
\startitem
initialize additional data for engine (protrusion, expansion, extend,
slant)
\stopitem
\startitem
apply user or \TeX\ format extensions
\stopitem
\startitem
apply manipulations before and after loading
\stopitem
\startitem
(build virtual fonts)
\stopitem
\startitem
enable special script handlers (fuzzy side of opentype)
\stopitem
\startitem
pass metrics and some metadata to \TeX
\stopitem
\stopitemize
\stopsubject
\startsubject[title={benefit}]
efficient access to all font properties for additional processing beforehand
or afterwards
\stopsubject
\stoptitle
\starttitle[title={processing}]
\startsubject[title={steps}]
\startitemize
\startitem
(comes after hyphenation)
\stopitem
\startitem
first identifies to be handled modes
\stopitem
\startitem
normalization (in \ConTeXt) node list
\stopitem
\startitem
delegate handling to \TeX\ or \Lua
\stopitem
\startitem
when using \Lua\ features are applied in prescribed order:
substitution, positioning, etc.
\stopitem
\startitem
as last step positioning is finalized (left/right kern injection,
space kerning, anchoring, cursives)
\stopitem
\stopitemize
\stopsubject
\startsubject[title={remarks}]
\startitemize
\startitem
efficient contextual analysis is|-|non trivial
\stopitem
\startitem
discretionaries need special care: ...pre ...replace... post...
\stopitem
\startitem
there is no real limit in extensions
\stopitem
\startitem
it's not too hard to inject experimental code
\stopitem
\startitem
so users can add their own features
\stopitem
\startitem
some day there may be alternative handlers
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={math}]
\startsubject[title={format}]
the opentype math specification stays close to \TeX, but has extensions and
more control (see articles & presentations by Ulrik Vieth)
\stopsubject
\startsubject[title={loading}]
\startitemize
\startitem
maps more or less directly onto internal structures
\stopitem
\startitem
in \ConTeXt\ we use(d) virtual unicode fonts awaiting lm/gyre
\stopitem
\stopitemize
\stopsubject
\startsubject[title={processing}]
character mapping and special element handling remains macro package
dependent
\stopsubject
\startsubject[title={construction}]
\startitemize
\startitem
we split code paths when needed: traditional or opentype (no longer
heuristics)
\stopitem
\startitem
the \luaTeX\ engine provides much control over spacing and a bit more
over rendering
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={the basics of loading}]
\startsubject[title={the format}]
\startitemize
\startitem
it evolved out of competing formats by apple, microsoft and adobe
\stopitem
\startitem
two flavours can normally be recognized by suffix: \type {ttf} and
\type {otf}
\stopitem
\startitem
main differences are bounding box info, global kern tables, cubic vs
quadratic curves
\stopitem
\startitem
multiple sub fonts inside \type {ttc} files (font collections)
\stopitem
\startitem
it's considered a standard (so it should be possible to implement)
\stopitem
\stopitemize
\stopsubject
\startsubject[title={the specification}]
\startitemize
\startitem
the only useable reference is on the microsoft website
\stopitem
\startitem
(the iso mpeg standard is more or less a bunch of ugly rendered
webpages)
\stopitem
\startitem
trial and error helps understanding/identifying fuzzy aspects
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={the available loaders}]
\startsubject[title={the fontforge loader}]
\startitemize
\startitem
offers the same view on the font as the editor (good for debugging)
\stopitem
\startitem
in order to process a font some optimal data structures are created
after loading
\stopitem
\startitem
we cache fonts because loading and creating these structures takes
time and it saves memory too
\stopitem
\startitem
fontforge has a lot of heuristics (catching issues collected over
time) but these are hard to get rid of when they're wrong
\stopitem
\stopitemize
\stopsubject
\startsubject[title={the lua loader}]
\startitemize
\startitem
this started out as experiment for loading outlines in \MetaFun
\stopitem
\startitem
it avoids the conversion to optimal structures for handling
\stopitem
\startitem
we can hook in better heuristics (data is more raw)
\stopitem
\startitem
it fits in the wish for maximum flexibility (next stage \ConTeXt)
\stopitem
\startitem
it's rather trivial to extend and adapt without hard coding
\stopitem
\startitem
the performance can be a bit less on initial loading (pre|-|cache)
but there is a bit of room to improve
\stopitem
\startitem
it's much more efficient in identifying fonts (not a real issue in
practice)
\stopitem
\startitem
in practice most fonts behave ok (no recovery needed) but there are
some sloppy fonts around
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={what do we load}]
\startsubject[title={tables}]
\startitemize
\startitem
opentype is mostly tables with lots of subtables
\stopitem
\startitem
there are required, truetype outline, postscript outline, (svg and
bitmap), typography & additional ones
\stopitem
\startitem
the typographic tables specify transformations to apply (gdef, gsub,
gpos)
\stopitem
\stopitemize
\stopsubject
\startsubject[title={calculations}]
\startitemize
\startitem
as we need ht/dp we need to calculate the boundingbox of postscript
outlines (cff parser)
\stopitem
\startitem
internally we use unicodes instead of indices
\stopitem
\startitem
we need to identify/filter the right unicode information
\stopitem
\startitem
we want to do more so we need to carry around more info (tounicode etc)
\stopitem
\stopitemize
\stopsubject
\startsubject[title={pitfalls}]
\startitemize
\startitem
there is no real consistent approach to use of basic features:
single, one to multiple, multiple to one & many to many replacements,
and look ahead and/or back based solutions
\stopitem
\startitem
in principle consistent families like lm/gyre could share common data
and logic but otherwise there is much diversity around
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={a few details}]
\startsubject[title={loading}]
\startitemize
\startitem
load the file (subfont if needed) in a \Lua\ friendly format
\stopitem
\startitem
prepare for later processing and/or access
\stopitem
\startitem
optimize data structures
\stopitem
\startitem
cache the instance (and compile to bytecode)
\stopitem
\startitem
share loaded font data where possible
\stopitem
\startitem
initialize & mark enabled features
\stopitem
\startitem
pass metrics, parameters and some properties to \TeX
\stopitem
\stopitemize
\stopsubject
\startsubject[title={processing}]
\startitemize
\startitem
we need to run over enabled features (also virtual non|-|opentype
ones)
\stopitem
\startitem
we use lookup hashes to determine if action is needed
\stopitem
\startitem
if needed we access detailed data and apply it
\stopitem
\startitem
there can be a few but also many hundreds of loops over the node list
\stopitem
\startitem
contextual matching can make us end up with a real lot of access and
analysis
\stopitem
\startitem
descending into discretionaries adds significant overhead (so it's
optimized)
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={traditional fonts}]
\startsubject[title={tfm}]
\startitemize
\startitem
there is a built|-|in loader for \type {tfm}, \type {ofm}, \type {vf}
and \type {ovf} files
\stopitem
\startitem
encoding and filename mapping is as usual (\type {enc} and \type
{map} files)
\stopitem
\startitem
(in the early days \ConTeXt\ filtered info from those \type {enc}
files too)
\stopitem
\stopitemize
\stopsubject
\startsubject[title={type one}]
\startitemize
\startitem
type one fonts have their own loader that gets information from \type
{afm} files
\stopitem
\startitem
the \type {pfb} file is consulted to get the index (to unicode)
mapping
\stopitem
\startitem
the \type {afm} loader was already written in \Lua\ but we now can also use
\Lua\ for the \type {pfb} file
\stopitem
\stopitemize
\stopsubject
\stoptitle
\starttitle[title={remarks}]
\startitemize
\startitem
features like additional character kerning don't belong in the font
handler as they are (to some extent) macro package dependant
\stopitem
\startitem
the same is true for italic correction (often input related and
therefore a macro package specific issue)
\stopitem
\startitem
setting up protrusion and expansion is again somewhat macro package
dependent
\stopitem
\startitem
\ConTeXt\ has many extra font related mechanisms and features
(described in a more technical manual)
\stopitem
\blank
\startitem
this has to work well with the core subsystems: languages especially
hyphenators, specific script demands, typesetting (all kind), builders
(paragraph, page), etc.
\stopitem
\startitem
a complication is that we do this more and more in \Lua, but still need to
support the built|-|in mechanismsm too
\stopitem
\blank
\startitem
the interfacing to macro packages differs (for plain \TeX\ we use
code that ships with \ConTeXt)
\stopitem
\startitem
for bugs and issues of with fonts in \ConTeXt\ you use its mailing list (or
mail me)
\stopitem
\startitem
the \LaTeX\ interface is handled by Philipp Gesang
\stopitemize
\stoptitle
\starttitle[title={future}]
\startitemize
\startitem
we'll improve handling of border cases (within the constraints of
performance)
\stopitem
\startitem
we might provide a few more hooks for plug|-|ins
\stopitem
\startitem
the type one \type {pfb} reader will be extended to provide outlines
(not complex, needed for \MetaFun)
\stopitem
\startitem
we keep playing with extra new features and virtual fonts
\stopitem
\blank
\startitem
maybe some more code can be made generic (fwiw)
\stopitem
\stopitemize
\stoptitle
\starttitle[title={credits}]
\startitemize
\startitem
Kai Eigner and Ivo Geradts for (experimental) patches in the handlers
for rare, complex & creepy fonts
\stopitem
\startitem
Philipp Gesang for binding the generic code to \LaTeX\ font mechanims.
\stopitem
\startitem
Idris Samawi Hamid for testing and providing the very complex and
demanding Husayni font
\stopitem
\startitem
Hartmut Henkel for the initial cleaning up of expansion and protrusion
\stopitem
\startitem
Taco Hoekwater for the original loader and discussions and a lot more
\stopitem
\startitem
Boguslaw Jackowski and friends for the fonts and patience with us
\stopitem
\startitem
Dohyun Kim for testing and suggestions on CJK font support
\stopitem
\startitem
Mojca Miklavec for distributions, managing us, and basically everything
\stopitem
\startitem
Luigi Scarso for patiently testing and managing my patches and testing
very beta code
\stopitem
\startitem
Thomas Schmitz for using betas in deadline critital book production
and making sure we patch fast
\stopitem
\startitem
Ton Otten for permitting me to work on all this \TeX\ related stuff for
ever and ever (and using to the extreme)
\stopitem
\startitem
Wolfgang Schuster for knowing and testing every detail of \ConTeXt\
and writing selectfont (for system fonts)
\stopitem
\blank
\startitem
and all (\ConTeXt) users who patiently accept betas and testing
\stopitem
\stopitemize
\stoptitle
\stopdocument
|