fonts-appendix.tex /size: 15 Kb    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/fonts
2
3\startcomponent fonts-appendix
4
5\environment fonts-environment
6
7\startchapter[title=Appendix][color=darkgray]
8
9\startsection[title=The \type {tfm} file,reference=fontdata:tfm]
10
11The (binary) \type {tfm} file is not human readable but can be turned into a
12verbose property list which is not that hard to understand.
13
14\starttyping
15tftopl texnansi-lmr10.tfm
16\stoptyping
17
18Here is an excerpt from the data file. It starts with some general properties of
19the font. The \type {O} means that the value is in octal while the \type {R} is a
20real. Keep in mind that \TEX\ has no datatype \quote {real} so internally it is
21just integers representing scaled points.
22
23\startnarrowtyping
24(FAMILY LMROMAN10)
25(FACE O 352)
26(CODINGSCHEME LY1 ENCODING /TEX'N'ANSI, Y&Y/)
27(DESIGNSIZE R 10.0)
28(COMMENT DESIGNSIZE IS IN POINTS)
29(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)
30(CHECKSUM O 4720464277)
31\stopnarrowtyping
32
33A text font has the following font dimensions:
34
35\startnarrowtyping
36(FONTDIMEN
37    (SLANT      R 0.0)
38    (SPACE      R 0.333333)
39    (STRETCH    R 0.166667)
40    (SHRINK     R 0.111112)
41    (XHEIGHT    R 0.43055)
42    (QUAD       R 1.0)
43    (EXTRASPACE R 0.111112)
44    ...
45)
46\stopnarrowtyping
47
48Kerns and ligatures are packed into a table that is basically a sequence of
49labelled entries. Here we see the entry for the character \type {f} which has
50three ligatures: \type {ff}, \type {fi} and \type {fl}. Because ligatures can be
51chained, octal slot 13 will have ligature entries for \type {ffl} and \type
52{ffi}.
53
54\startnarrowtyping
55(LIGTABLE
56    ...
57    (LABEL C f)
58    (LIG C f   O 13)
59    (LIG C i   O 14)
60    (LIG C l   O 10)
61    (KRN O 135 R 0.027779)
62    (KRN O  41 R 0.027779)
63    (KRN O  51 R 0.027779)
64    (KRN O  77 R 0.027779)
65    (KRN O 223 R 0.027779)
66    (KRN O 224 R 0.027779)
67    (KRN O 140 R 0.027779)
68    (KRN O  47 R 0.027779)
69    (STOP)
70    ...
71)
72\stopnarrowtyping
73
74Each character gets its own entry. In this case there is no depth involved so it
75is not shown. The comment is just a repetition of the entry in the ligtable.
76
77\startnarrowtyping
78(CHARACTER C f
79    (CHARWD R 0.30555)
80    (CHARHT R 0.688875)
81    (CHARIC R 0.079222)
82    (COMMENT
83          (LIG C f   O 13)
84          (LIG C i   O 14)
85          (LIG C l   O 10)
86          (KRN O 135 R 0.027779)
87          (KRN O  41 R 0.027779)
88          (KRN O  51 R 0.027779)
89          (KRN O  77 R 0.027779)
90          (KRN O 223 R 0.027779)
91          (KRN O 224 R 0.027779)
92          (KRN O 140 R 0.027779)
93          (KRN O  47 R 0.027779)
94    )
95)
96\stopnarrowtyping
97
98\stopsection
99
100\startsection[title=The \type {vf} file,reference=fontdata:vf]
101
102A virtual font specification file can be converted to a more readable format with
103\type {vftovp}, for instance:
104
105\starttyping
106vftovp eurm10.vf
107\stoptyping
108
109The information in a \type {vf} file will be combined with the data in the
110accompanying \type {tfm} file so the output looks similar:
111
112\startnarrowtyping
113(VTITLE )
114(FAMILY UNSPECIFIED)
115(FACE F MRR)
116(CODINGSCHEME TEX MATH ITALIC)
117(DESIGNSIZE R 10.0)
118(COMMENT DESIGNSIZE IS IN POINTS)
119(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)
120(CHECKSUM O 24401046203)
121(SEVENBITSAFEFLAG TRUE)
122\stopnarrowtyping
123
124Because this font is a math font there is no space defined.
125
126\startnarrowtyping
127(FONTDIMEN
128    (SLANT      R 0.0)
129    (SPACE      R 0.0)
130    (STRETCH    R 0.0)
131    (SHRINK     R 0.0)
132    (XHEIGHT    R 0.459)
133    (QUAD       R 1.0)
134    (EXTRASPACE R 0.0)
135)
136\stopnarrowtyping
137
138A virtual font will take glyphs from another font and therefore there are entries
139that refer to these fonts. In the following definition index \type {0} is created
140(the \type {D} specifies a decimal entry).
141
142\startnarrowtyping
143(MAPFONT D 0
144    (FONTNAME     eurm10)
145    (FONTCHECKSUM O 4276740471)
146    (FONTAT       R 1.0)
147    (FONTDSIZE    R 10.0)
148)
149(MAPFONT D 1
150    (FONTNAME     cmmi10)
151    (FONTCHECKSUM O 1350061076)
152    (FONTAT       R 1.0)
153    (FONTDSIZE    R 10.0)
154)
155\stopnarrowtyping
156
157The zero indexed font is the default, so in the following entry this font is
158taken:
159
160\startnarrowtyping
161(CHARACTER C W
162    (CHARWD R 0.986)
163    (CHARHT R 0.691)
164    (CHARIC R 0.056)
165    (COMMENT
166        (KRN O 177 R  0.056)
167        (KRN O  75 R -0.056)
168        (KRN O  73 R -0.083)
169        (KRN O  72 R -0.083)
170    )
171    (MAP
172        (SETCHAR C W)
173    )
174)
175\stopnarrowtyping
176
177The next specification is a combination of two other glyphs becoming a new
178glyph. We see here that the \type {MAP} table is actually a sort of program:
179
180\startnarrowtyping
181(CHARACTER O 200
182    (CHARWD R 0.622)
183    (CHARHT R 0.691)
184    (MAP
185        (PUSH)
186        (MOVEDOWN   R -0.18)
187        (MOVERIGHT  R  0.015)
188        (SELECTFONT D  2)
189        (SETCHAR    O 40)
190        (POP)
191        (SELECTFONT D  0)
192        (SETCHAR    C  h)
193    )
194)
195\stopnarrowtyping
196
197The character information is also in the \type {tfm} companion and that is what
198\TEX\ uses. The virtual information kicks in when the backend is creating the
199page stream and embedding the fonts.
200
201\stopsection
202
203\startsection[title=The \type {map} file,reference=fontdata:map]
204
205In a map file each line maps a font name onto a file that contains the font
206shapes in bitmap or outline format. For instance in the file \type
207{lm-texnansi.map} we find the line:
208
209\startnarrowtyping
210texnansi-lmr10 LMRoman10-Regular "enclmtexnansi ReEncodeFont" <lm-texnansi.enc <lmr10.pfb
211\stopnarrowtyping
212
213The backend will fetch the glyph data from \type {lmf10.pfb} and use the given
214encoding file to resolve indices to glyph names. A \type {pfb} file can contain
215more than 256 entries so names are used to access the data. The string between
216quotes is used for the encoding vector in the resulting file.
217
218The second entry in the line is the font name that will be used. This name is
219also used to control subset behaviour. Multiple references to this name will be
220collapsed into one inclusion when possible, thereby making the file as small as
221possible. You better make sure that the names are unique for a specific font.
222
223In addition to this, there can be directives for extending the font (horizontal
224stretch) and transforming it into a slanted variant. Both are to be used with
225care.
226
227In \MKIV\ map files are only used for virtual math fonts and just as in \MKII\ we
228load such files selectively. Users don't have to worry about this.
229
230\stopsection
231
232\startsection[title=The \type {enc} file,reference=fontdata:enc]
233
234For historic reasons, an encoding file is a blob of \POSTSCRIPT, probably because
235it can be copied into the final output directly. Given that \TEX\ got extended
236anyway, you can wonder why this information never ended up in an extended \type
237{tfm} or \type {vf} file. It had definitely made the traditional process much
238more robust.
239
240\startnarrowtyping
241/enclmtexnansi[
242/.notdef
243/Euro
244...
245/dotaccent
246/hungarumlaut
247/ogonek
248...
249/ffi
250/ffl
251/dotlessi
252/dotlessj
253/grave
254...
255/thorn
256/ydieresis
257] def
258\stopnarrowtyping
259
260There are excactly 256 entries in such a vector and the names should match those
261in a \type {pfb} file.
262
263\stopsection
264
265\startsection[title=The \type {afm} file,reference=fontdata:afm]
266
267Here we show an excerpt from an \type {afm} file that comes with Latin Modern
268Roman. Just as with a \type {tfm} file we start with some general information.
269However we don't need to convert the file as is it already in human readable
270format.
271
272\startnarrowtyping
273StartFontMetrics 2.0
274Comment Generated by MetaType1 (a MetaPost-based engine)
275Comment Creation Date: 7th October 2009
276Notice Copyright 2003--2009 by B. Jackowski and J.M. Nowacki (on behalf of TeX USERS GROUPS).
277Comment Supported by CSTUG, DANTE eV, GUST, GUTenberg, NTG, and TUG.
278Comment METATYPE1/Type 1 version by B. Jackowski & J. M. Nowacki
279Comment from GUST (http://www.gust.org.pl).
280Comment This work is released under the GUST Font License.
281Comment For the most recent version of this license see
282Comment This work has the LPPL maintenance status `maintained'.
283Comment The Current Maintainer of this work is Bogus\l{}aw Jackowski and Janusz M. Nowacki.
284Comment This work consists of the files listed in the MANIFEST-Latin-Modern.txt file.
285FontName LMRoman10-Regular
286FullName LMRoman10-Regular
287FamilyName LMRoman10
288Weight Normal
289ItalicAngle 0
290IsFixedPitch false
291UnderlinePosition -146
292UnderlineThickness 40
293Version 2.004
294EncodingScheme FontSpecific
295FontBBox -430 -290 1417 1127
296CapHeight 683.33333
297XHeight 430.55556
298Descender -194.44444
299Ascender 694.44444
300Comment PFM parameters: LMRoman10 0 0 0xEE
301Comment TFM designsize: 10 (in points)
302Comment TFM fontdimen  1: 0          (slant)
303Comment TFM fontdimen  2: 3.33333    (space)
304Comment TFM fontdimen  3: 1.66667    (space stretch)
305Comment TFM fontdimen  4: 1.11111    (space shrink)
306Comment TFM fontdimen  5: 4.3055     (xheight)
307Comment TFM fontdimen  6: 10         (quad)
308Comment TFM fontdimen  7: 1.11111    (extra space)
309Comment TFM fontdimen  8: 6.833      (non-standard: uc height)
310Comment TFM fontdimen  9: 6.9445     (non-standard: ascender)
311Comment TFM fontdimen 10: 11.27      (non-standard: accented cap height)
312Comment TFM fontdimen 11: 1.94443    (non-standard: descender depth)
313Comment TFM fontdimen 12: 11.27      (non-standard: max height)
314Comment TFM fontdimen 13: 2.9        (non-standard: max depth)
315Comment TFM fontdimen 14: 5          (non-standard: digit width)
316Comment TFM fontdimen 15: 0.88889    (non-standard: uc stem)
317Comment TFM fontdimen 16: 12         (non-standard: baselineskip)
318Comment TFM fontdimen 17: 0.69444    (non-standard: lc stem)
319Comment TFM fontdimen 18: 0.55556    (non-standard: u, i.e., font unit)
320Comment TFM fontdimen 19: 0.22223    (non-standard: overshoot)
321Comment TFM fontdimen 20: 0.25       (non-standard: thin stem, hair)
322Comment TFM fontdimen 21: 0.30556    (non-standard: cap thin stem, i.e., cap_hair)
323Comment TFM headerbyte  9: FontSpecific
324Comment TFM headerbyte 49: LMRoman10
325Comment TFM headerbyte 72: 234
326\stopnarrowtyping
327
328Watch the comments! Because \TEX\ needs a couple of so called fontdimens to be
329set, the comments list the appropriate values. When a \type {tfm} file is
330generated from an \type {afm} file, these values have to be used.
331
332Each character (or glyph) gets an entry. When we run out of indices i.e.\ pass
333the 255 boundary (we start at 0) the index becomes \type {-1}. Only the width is
334specified. The height and depth have to be derived from the bounding box for
335which the specification starts with key \type {B}.
336
337\startnarrowtyping
338StartCharMetrics 821
339...
340C  32 ; WX 333.33333 ; N space     ; B   0   0   0   0 ;
341...
342C 102 ; WX 305.55556 ; N f         ; B  33   0 357 705 ; L f ff ; L i fi ; L k f_k ; L l fl ;
343C 105 ; WX 277.77777 ; N i         ; B  33   0 247 657 ;
344C 108 ; WX 277.77777 ; N l         ; B  33   0 255 694 ;
345...
346C  -1 ; WX 500       ; N Acute     ; B 181 493 388 656 ;
347C  -1 ; WX 500       ; N acute     ; B 188 510 374 698 ;
348C  -1 ; WX 500       ; N acute.ts1 ; B 208 513 392 699 ;
349...
350EndCharMetrics
351\stopnarrowtyping
352
353Watch how this font defines a space character and keep in mind that these fonts
354date from the time that there was only one kind of space. The \type {L} entry
355specifies a ligature.
356
357The names of glyphs are standardized, and even the \type {f_k} is conforming to
358standards. This standardization makes it possible to go back from glyphs to characters
359when copying text from a typeset document.
360
361The kern table is pretty large here and for a reason. First of all the file
362defines 821 glyphs so the average amount of kerns per glyph is not that large.
363But take a look at the \type {A}. Because the \type {Aacute} has the same shape
364it kerns in a similar way. This means that ideally all combined characters end up
365with the same value as their base glyph. However, in our case a bit more
366selective approach is taken. The \type {Adieresis} has a different set of kerns,
367probably to save space. It is for this reason that \OPENTYPE\ fonts have a model
368of kern classes so that similar shapes can be treated as one when setting kerns.
369You see a similar issue with ligatures, where often the right part of the shape
370kerns the same as the (stand alone) first part of the shape does.
371
372\startnarrowtyping
373StartKernData
374StartKernPairs 9230
375...
376KPX seven.prop     hyphen.prop     -37
377KPX seven.prop     four.prop       -74
378KPX seven.prop     six.prop        -18.5
379KPX hyphen.prop    one.prop        -37
380KPX hyphen.prop    two.prop        -18.5
381KPX hyphen.prop    seven.prop      -55.5
382KPX seven.oldstyle four.oldstyle   -74
383KPX A              T               -83.333
384KPX Aacute         T               -83.333
385KPX Abreve         T               -83.333
386KPX Acircumflex    T               -83.333
387...
388KPX Adieresis      C               -27.778
389...
390KPX f              bracketright     27.778
391KPX f              exclam           27.778
392KPX f              parenright       27.778
393KPX f              question         27.778
394KPX f              quotedblleft     27.778
395KPX f              quotedblleft.cm  27.778
396KPX f              quotedblright    27.778
397KPX f              quotedblright.cm 27.778
398KPX f              quoteleft        27.778
399KPX f              quoteright       27.778
400...
401KPX ff             bracketright     27.778
402KPX ff             exclam           27.778
403KPX ff             parenright       27.778
404KPX ff             question         27.778
405KPX ff             quotedblleft     27.778
406KPX ff             quotedblleft.cm  27.778
407KPX ff             quotedblright    27.778
408KPX ff             quotedblright.cm 27.778
409KPX ff             quoteleft        27.778
410KPX ff             quoteright       27.778
411...
412EndKernPairs
413EndKernData
414\stopnarrowtyping
415
416If you look closely at the names, you will notice that some glyphs have a
417variant. In \OPENTYPE\ fonts these variants are grouped in features like \type
418{oldstyle}. The first part of such a name is still part of the standardization,
419but the second part is up to the font designer.
420
421The file ends with:
422
423\startnarrowtyping
424EndFontMetrics
425\stopnarrowtyping
426
427\stopsection
428
429\startsection[title=The \type {otf} file,reference=fontdata:otf]
430
431In the \LUATEX\ manual you can find an overview of the raw \OTF\ format as
432exposed in a \LUA\ table. The first decade of \LUATEX\ we used the built|-|in
433loader but even then in \CONTEXT\ we didn't use that format directly but used it
434to create a more compact and efficient table instead. The current release of
435\CONTEXT\ uses its own loader written in \LUA, but the fundamentals have not
436changed much. The tables are cached and can be read in at high speed. The
437structure of the tables is unlikely to change much although more data might get
438added. Although you can access the data it seldom makes sense to do so. Where
439needed interfaces are provided.
440
441\stopsection
442
443\startsection[title=The \type {lfg} file,reference=fontdata:lua]
444
445We use the goodies file control what gets added, replaced, patched or manipulated
446in a font. A goodie file permits us to go beyond what font provide by default.
447The content of a goodie file differs per font. As we also use this for
448experiments, not all entries that you find in such files are meant for users.
449
450\stopsection
451
452\startsection[title=Used fonts]
453
454The examples in the document depend on the fonts used. Here is a list of fonts used
455to render this version. Because fonts might have changed in the meantime, some examples
456might come out other than intended.
457
458\startluacode
459local list = table.load("fonts-mkiv-usedfonts.lua") or { }
460
461local NC, NR = context.NC, context.NR
462
463for i=1,#list do
464    local l = list[i]
465    context.starttabulate { "|lB|l|" }
466        local basename  = string.lower(file.basename(l.filename))
467        local version   = string.lower(l.version)
468        local filesize  = (l.size or 0) / 1000 .. " Kb"
469        local instances = l.instances or 1
470        NC() context("filename")  NC() context.type(basename)  NC() NR()
471        NC() context("instances") NC() context.type(instances) NC() NR()
472        NC() context("filesize")  NC() context.type(filesize)  NC() NR()
473        NC() context("version")   NC() context.type(version)   NC() NR()
474    context.stoptabulate()
475end
476\stopluacode
477
478\stopsection
479
480\stopchapter
481
482\stopcomponent
483
484