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