fix getsup (HH)
[luatex.git] / manual / luatex-fonts.tex
blob221c0ce852caff0d71497ba8a383d3cbce825500
1 % language=uk
3 \environment luatex-style
4 \environment luatex-logos
6 \startcomponent luatex-fonts
8 \startchapter[reference=fonts,title={Font structure}]
10 \section {The font tables}
12 All \TEX\ fonts are represented to \LUA\ code as tables, and internally as
13 \CCODE~structures. All keys in the table below are saved in the internal font
14 structure if they are present in the table returned by the \type {define_font}
15 callback, or if they result from the normal \TFM|/|\VF\ reading routines if there
16 is no \type {define_font} callback defined.
18 The column \quote {\VF} means that this key will be created by the \type
19 {font.read_vf()} routine, \quote {\TFM} means that the key will be created by the
20 \type {font.read_tfm()} routine, and \quote{used} means whether or not the
21 \LUATEX\ engine itself will do something with the key.
23 The top|-|level keys in the table are as follows:
25 \starttabulate[|Tl|c|c|c|l|p|]
26 \NC \rmbf key \NC \bf vf \NC \bf tfm \NC \bf used \NC \bf value type \NC \bf description \NC \NR
27 \NC name \NC yes \NC yes \NC yes \NC string \NC metric (file) name \NC \NR
28 \NC area \NC no \NC yes \NC yes \NC string \NC (directory) location, typically empty \NC \NR
29 \NC used \NC no \NC yes \NC yes \NC boolean\NC indicates usage (initial: false) \NC \NR
30 \NC characters \NC yes \NC yes \NC yes \NC table \NC the defined glyphs of this font \NC \NR
31 \NC checksum \NC yes \NC yes \NC no \NC number \NC default: 0 \NC \NR
32 \NC designsize \NC no \NC yes \NC yes \NC number \NC expected size (default: 655360 == 10pt) \NC \NR
33 \NC direction \NC no \NC yes \NC yes \NC number \NC default: 0 \NC \NR
34 \NC encodingbytes \NC no \NC no \NC yes \NC number \NC default: depends on \type {format} \NC \NR
35 \NC encodingname \NC no \NC no \NC yes \NC string \NC encoding name \NC \NR
36 \NC fonts \NC yes \NC no \NC yes \NC table \NC locally used fonts \NC \NR
37 \NC psname \NC no \NC no \NC yes \NC string \NC This is the \POSTSCRIPT\ fontname in the incoming font
38 source, and it's used as fontname identifier in the \PDF\
39 output. This has to be a valid string, e.g.\ no spaces
40 and such, as the backend will not do a cleanup. This gives
41 complete control to the loader. \NC \NR
42 \NC fullname \NC no \NC no \NC yes \NC string \NC output font name, used as a fallback in the \PDF\ output
43 if the \type {psname} is not set \NC \NR
44 \NC header \NC yes \NC no \NC no \NC string \NC header comments, if any \NC \NR
45 \NC hyphenchar \NC no \NC no \NC yes \NC number \NC default: \TEX's \type {\hyphenchar} \NC \NR
46 \NC parameters \NC no \NC yes \NC yes \NC hash \NC default: 7 parameters, all zero \NC \NR
47 \NC size \NC no \NC yes \NC yes \NC number \NC loaded (at) size. (default: same as designsize) \NC \NR
48 \NC skewchar \NC no \NC no \NC yes \NC number \NC default: \TEX's \type {\skewchar} \NC \NR
49 \NC type \NC yes \NC no \NC yes \NC string \NC basic type of this font \NC \NR
50 \NC format \NC no \NC no \NC yes \NC string \NC disk format type \NC \NR
51 \NC embedding \NC no \NC no \NC yes \NC string \NC \PDF\ inclusion \NC \NR
52 \NC filename \NC no \NC no \NC yes \NC string \NC the name of the font on disk \NC \NR
53 \NC tounicode \NC no \NC yes \NC yes \NC number \NC When this is set to~1 \LUATEX\ assumes per|-|glyph
54 tounicode entries are present in the font. \NC \NR
55 \NC stretch \NC no \NC no \NC yes \NC number \NC the \quote {stretch} value from \type
56 {\expandglyphsinfont} \NC \NR
57 \NC shrink \NC no \NC no \NC yes \NC number \NC the \quote {shrink} value from \type
58 {\expandglyphsinfont} \NC \NR
59 \NC step \NC no \NC no \NC yes \NC number \NC the \quote {step} value from \type
60 {\expandglyphsinfont} \NC \NR
61 \NC auto_expand \NC no \NC no \NC yes \NC boolean\NC the \quote {autoexpand} keyword from \crlf
62 \type {\expandglyphsinfont} \NC \NR
63 \NC expansion_factor \NC no \NC no \NC no \NC number \NC the actual expansion factor of an expanded font \NC \NR
64 \NC attributes \NC no \NC no \NC yes \NC string \NC the \type {\pdffontattr} \NC \NR
65 \NC cache \NC no \NC no \NC yes \NC string \NC This key controls caching of the \LUA\ table on the
66 \TEX\ end where \type {yes} means: use a reference to
67 the table that is passed to \LUATEX\ (this is the
68 default), and no \type {no} means: don't store the
69 table reference, don't cache any \LUA\ data for this
70 font while \type {renew} means: don't store the table
71 reference, but save a reference to the table that is
72 created at the first access to one of its fields in font.
73 Note: the saved reference is thread|-|local, so be
74 careful when you are using coroutines: an error will be
75 thrown if the table has been cached in one thread, but
76 you reference it from another thread. \NC \NR
77 \NC nomath \NC no \NC no \NC yes \NC boolean\NC This key allows a minor speedup for text fonts. If it
78 is present and true, then \LUATEX\ will not check the
79 character entries for math|-|specific keys. \NC \NR
80 \NC oldmath \NC no \NC no \NC yes \NC boolean\NC This key flags a font as representing an old school \TEX\
81 math font and disables the \OPENTYPE\ code path. \NC \NR
82 \NC slant \NC no \NC no \NC yes \NC number \NC This has the same semantics as the \type {SlantFont}
83 operator in font map files. \NC \NR
84 \NC extent \NC no \NC no \NC yes \NC number \NC This has the same semantics as the \type {ExtendFont}
85 operator in font map files. \NC \NR
86 \stoptabulate
88 The key \type {name} is always required. The keys \type {stretch}, \type
89 {shrink}, \type {step} and optionally \type {auto_expand} only have meaning when
90 used together: they can be used to replace a post|-|loading \type
91 {\expandglyphsinfont} command. The \type {expansion_factor} is value that can be
92 present inside a font in \type {font.fonts}. It is the actual expansion factor (a
93 value between \type {-shrink} and \type {stretch}, with step \type {step}) of a
94 font that was automatically generated by the font expansion algorithm. The key
95 \type {attributes} can be used to set font attributes in the \PDF\ file. The key
96 \type {used} is set by the engine when a font is actively in use, this makes sure
97 that the font's definition is written to the output file (\DVI\ or \PDF). The
98 \TFM\ reader sets it to false. The \type {direction} is a number signalling the
99 \quote {normal} direction for this font. There are sixteen possibilities:
101 \starttabulate[|Tc|Tc|Tc|Tc|]
102 \NC \rmbf number \NC \rmbf meaning \NC \rmbf number \NC \rmbf meaning \NC\NR
103 \NC 0 \NC LT \NC 8 \NC TT \NC\NR
104 \NC 1 \NC LL \NC 9 \NC TL \NC\NR
105 \NC 2 \NC LB \NC 10 \NC TB \NC\NR
106 \NC 3 \NC LR \NC 11 \NC TR \NC\NR
107 \NC 4 \NC RT \NC 12 \NC BT \NC\NR
108 \NC 5 \NC RL \NC 13 \NC BL \NC\NR
109 \NC 6 \NC RB \NC 14 \NC BB \NC\NR
110 \NC 7 \NC RR \NC 15 \NC BR \NC\NR
111 \stoptabulate
113 These are \OMEGA|-|style direction abbreviations: the first character indicates
114 the \quote {first} edge of the character glyphs (the edge that is seen first in
115 the writing direction), the second the \quote {top} side. Keep in mind that
116 \LUATEX\ has a bit different directional model so these values are not used for
117 anything.
119 The \type {parameters} is a hash with mixed key types. There are seven possible
120 string keys, as well as a number of integer indices (these start from 8 up). The
121 seven strings are actually used instead of the bottom seven indices, because that
122 gives a nicer user interface.
124 The names and their internal remapping are:
126 \starttabulate[|lT|c|]
127 \NC \rmbf name \NC \rmbf remapping \NC\NR
128 \NC slant \NC 1 \NC\NR
129 \NC space \NC 2 \NC\NR
130 \NC space_stretch \NC 3 \NC\NR
131 \NC space_shrink \NC 4 \NC\NR
132 \NC x_height \NC 5 \NC\NR
133 \NC quad \NC 6 \NC\NR
134 \NC extra_space \NC 7 \NC\LR
135 \stoptabulate
137 The keys \type {type}, \type {format}, \type {embedding}, \type {fullname} and
138 \type {filename} are used to embed \OPENTYPE\ fonts in the result \PDF.
140 The \type {characters} table is a list of character hashes indexed by an integer
141 number. The number is the \quote {internal code} \TEX\ knows this character by.
143 Two very special string indexes can be used also: \type {left_boundary} is a
144 virtual character whose ligatures and kerns are used to handle word boundary
145 processing. \type {right_boundary} is similar but not actually used for anything
146 (yet).
148 Other index keys are ignored.
150 Each character hash itself is a hash. For example, here is the character \quote
151 {f} (decimal 102) in the font \type {cmr10 at 10pt}:
153 \starttyping
154 [102] = {
155 ['width'] = 200250,
156 ['height'] = 455111,
157 ['depth'] = 0,
158 ['italic'] = 50973,
159 ['kerns'] = {
160 [63] = 50973,
161 [93] = 50973,
162 [39] = 50973,
163 [33] = 50973,
164 [41] = 50973
166 ['ligatures'] = {
167 [102] = {
168 ['char'] = 11,
169 ['type'] = 0
171 [108] = {
172 ['char'] = 13,
173 ['type'] = 0
175 [105] = {
176 ['char'] = 12,
177 ['type'] = 0
181 \stoptyping
183 The following top|-|level keys can be present inside a character hash:
185 \starttabulate[|lT|c|c|c|l|p|]
186 \NC \rmbf key \NC \bf vf \NC \bf tfm \NC \bf used \NC \bf type \NC \bf description \NC\NR
187 \NC width \NC yes \NC yes \NC yes \NC number \NC character's width, in sp (default 0) \NC\NR
188 \NC height \NC no \NC yes \NC yes \NC number \NC character's height, in sp (default 0) \NC\NR
189 \NC depth \NC no \NC yes \NC yes \NC number \NC character's depth, in sp (default 0) \NC\NR
190 \NC italic \NC no \NC yes \NC yes \NC number \NC character's italic correction, in sp (default zero) \NC\NR
191 \NC top_accent \NC no \NC no \NC maybe \NC number \NC character's top accent alignment place, in sp (default zero) \NC\NR
192 \NC bot_accent \NC no \NC no \NC maybe \NC number \NC character's bottom accent alignment place, in sp (default zero) \NC\NR
193 \NC left_protruding \NC no \NC no \NC maybe \NC number \NC character's \type {\lpcode} \NC\NR
194 \NC right_protruding \NC no \NC no \NC maybe \NC number \NC character's \type {\rpcode} \NC\NR
195 \NC expansion_factor \NC no \NC no \NC maybe \NC number \NC character's \type {\efcode} \NC\NR
196 \NC tounicode \NC no \NC no \NC maybe \NC string \NC character's \UNICODE\ equivalent(s), in \UTF|-|16BE hexadecimal format \NC\NR
197 \NC next \NC no \NC yes \NC yes \NC number \NC the \quote {next larger} character index \NC\NR
198 \NC extensible \NC no \NC yes \NC yes \NC table \NC the constituent parts of an extensible recipe \NC\NR
199 \NC vert_variants \NC no \NC no \NC yes \NC table \NC constituent parts of a vertical variant set \NC \NR
200 \NC horiz_variants \NC no \NC no \NC yes \NC table \NC constituent parts of a horizontal variant set \NC \NR
201 \NC kerns \NC no \NC yes \NC yes \NC table \NC kerning information \NC\NR
202 \NC ligatures \NC no \NC yes \NC yes \NC table \NC ligaturing information \NC\NR
203 \NC commands \NC yes \NC no \NC yes \NC array \NC virtual font commands \NC\NR
204 \NC name \NC no \NC no \NC no \NC string \NC the character (\POSTSCRIPT) name \NC\NR
205 \NC index \NC no \NC no \NC yes \NC number \NC the (\OPENTYPE\ or \TRUETYPE) font glyph index \NC\NR
206 \NC used \NC no \NC yes \NC yes \NC boolean \NC typeset already (default: false)? \NC\NR
207 \NC mathkern \NC no \NC no \NC yes \NC table \NC math cut-in specifications \NC\NR
208 \stoptabulate
210 The values of \type {top_accent}, \type {bot_accent} and \type {mathkern} are
211 used only for math accent and superscript placement, see the \at {math chapter}
212 [math] in this manual for details.
214 The values of \type {left_protruding} and \type {right_protruding} are used only
215 when \type {\protrudechars} is non-zero.
217 Whether or not \type {expansion_factor} is used depends on the font's global
218 expansion settings, as well as on the value of \type {\adjustspacing}.
220 The usage of \type {tounicode} is this: if this font specifies a \type
221 {tounicode=1} at the top level, then \LUATEX\ will construct a \type {/ToUnicode}
222 entry for the \PDF\ font (or font subset) based on the character|-|level \type
223 {tounicode} strings, where they are available. If a character does not have a
224 sensible \UNICODE\ equivalent, do not provide a string either (no empty strings).
226 If the font level \type {tounicode} is not set, then \LUATEX\ will build up \type
227 {/ToUnicode} based on the \TEX\ code points you used, and any character-level
228 \type {tounicodes} will be ignored. The string format is exactly the format that
229 is expected by Adobe \CMAP\ files (\UTF-16BE in hexadecimal encoding), minus the
230 enclosing angle brackets. For instance the \type {tounicode} for a \type {fi}
231 ligature would be \type {00660069}. When you pass a number the conversion will be
232 done for you.
234 The presence of \type {extensible} will overrule \type {next}, if that is also
235 present. It in in turn can be overruled by \type {vert_variants}.
237 The \type {extensible} table is very simple:
239 \starttabulate[|lT|l|p|]
240 \NC \rmbf key \NC \bf type \NC \bf description \NC\NR
241 \NC top \NC number \NC top character index \NC\NR
242 \NC mid \NC number \NC middle character index \NC\NR
243 \NC bot \NC number \NC bottom character index \NC\NR
244 \NC rep \NC number \NC repeatable character index \NC\NR
245 \stoptabulate
247 The \type {horiz_variants} and \type {vert_variants} are arrays of components.
248 Each of those components is itself a hash of up to five keys:
250 \starttabulate[|lT|l|p|]
251 \NC \rmbf key \NC \bf type \NC \bf explanation \NC\NR
252 \NC glyph \NC number \NC The character index. Note that this is an encoding number, not a name. \NC \NR
253 \NC extender \NC number \NC One (1) if this part is repeatable, zero (0) otherwise. \NC \NR
254 \NC start \NC number \NC The maximum overlap at the starting side (in scaled points). \NC \NR
255 \NC end \NC number \NC The maximum overlap at the ending side (in scaled points). \NC \NR
256 \NC advance \NC number \NC The total advance width of this item. It can be zero or missing,
257 then the natural size of the glyph for character \type {component}
258 is used. \NC \NR
259 \stoptabulate
261 The \type {kerns} table is a hash indexed by character index (and \quote
262 {character index} is defined as either a non|-|negative integer or the string
263 value \type {right_boundary}), with the values the kerning to be applied, in
264 scaled points.
266 The \type {ligatures} table is a hash indexed by character index (and \quote
267 {character index} is defined as either a non|-|negative integer or the string
268 value \type {right_boundary}), with the values being yet another small hash, with
269 two fields:
271 \starttabulate[|lT|l|p|]
272 \NC \rmbf key \NC \bf type \NC \bf description \NC \NR
273 \NC type \NC number \NC the type of this ligature command, default 0 \NC \NR
274 \NC char \NC number \NC the character index of the resultant ligature \NC \NR
275 \stoptabulate
277 The \type {char} field in a ligature is required.
279 The \type {type} field inside a ligature is the numerical or string value of one
280 of the eight possible ligature types supported by \TEX. When \TEX\ inserts a new
281 ligature, it puts the new glyph in the middle of the left and right glyphs. The
282 original left and right glyphs can optionally be retained, and when at least one
283 of them is kept, it is also possible to move the new \quote {insertion point}
284 forward one or two places. The glyph that ends up to the right of the insertion
285 point will become the next \quote {left}.
287 \starttabulate[|l|c|l|l|]
288 \NC \bf textual (Knuth) \NC \bf number \NC \bf string \NC result \NC\NR
289 \NC \type{l + r =: n} \NC 0 \NC \type{=:} \NC \type{|n} \NC\NR
290 \NC \type{l + r =:| n} \NC 1 \NC \type{=:|} \NC \type{|nr} \NC\NR
291 \NC \type{l + r |=: n} \NC 2 \NC \type{|=:} \NC \type{|ln} \NC\NR
292 \NC \type{l + r |=:| n} \NC 3 \NC \type{|=:|} \NC \type{|lnr} \NC\NR
293 \NC \type{l + r =:|> n} \NC 5 \NC \type{=:|>} \NC \type{n|r} \NC\NR
294 \NC \type{l + r |=:> n} \NC 6 \NC \type{|=:>} \NC \type{l|n} \NC\NR
295 \NC \type{l + r |=:|> n} \NC 7 \NC \type{|=:|>} \NC \type{l|nr} \NC\NR
296 \NC \type{l + r |=:|>> n} \NC 11 \NC \type{|=:|>>} \NC \type{ln|r} \NC\NR
297 \stoptabulate
299 The default value is~0, and can be left out. That signifies a \quote {normal}
300 ligature where the ligature replaces both original glyphs. In this table the~\type {|}
301 indicates the final insertion point.
303 The \type {commands} array is explained below.
305 \section {Real fonts}
307 Whether or not a \TEX\ font is a \quote {real} font that should be written to the
308 \PDF\ document is decided by the \type {type} value in the top|-|level font
309 structure. If the value is \type {real}, then this is a proper font, and the
310 inclusion mechanism will attempt to add the needed font object definitions to the
311 \PDF. Values for \type {type} are:
313 \starttabulate[|Tl|p|]
314 \NC \rmbf value \NC \rmbf description \NC\NR
315 \NC real \NC this is a base font \NC\NR
316 \NC virtual \NC this is a virtual font \NC\NR
317 \stoptabulate
319 The actions to be taken depend on a number of different variables:
321 \startitemize[packed]
322 \startitem
323 Whether the used font fits in an 8-bit encoding scheme or not.
324 \stopitem
325 \startitem
326 The type of the disk font file.
327 \stopitem
328 \startitem
329 The level of embedding requested.
330 \stopitem
331 \stopitemize
333 A font that uses anything other than an 8-bit encoding vector has to be written
334 to the \PDF\ in a different way.
336 The rule is: if the font table has \type {encodingbytes} set to~2, then this is a
337 wide font, in all other cases it isn't. The value~2 is the default for \OPENTYPE\
338 and \TRUETYPE\ fonts loaded via \LUA. For \TYPEONE\ fonts, you have to set \type
339 {encodingbytes} to~2 explicitly. For \PK\ bitmap fonts, wide font encoding is not
340 supported at all.
342 If no special care is needed, \LUATEX\ currently falls back to the
343 mapfile|-|based solution used by \PDFTEX\ and \DVIPS. This behaviour might
344 silently be removed in the future, in which case the related primitives and \LUA\
345 functions will become no|-|ops.
347 If a \quote {wide} font is used, the new subsystem kicks in, and some
348 extra fields have to be present in the font structure. In this case, \LUATEX\
349 does not use a map file at all.
351 The extra fields are: \type {format}, \type {embedding}, \type {fullname}, \type
352 {cidinfo} (as explained above), \type {filename}, and the \type {index} key in
353 the separate characters.
355 Values for \type {format} are:
357 \starttabulate[|Tl|p|]
358 \NC \rmbf value \NC \rmbf description \NC \NR
359 \NC type1 \NC this is a \POSTSCRIPT\ \TYPEONE\ font \NC \NR
360 \NC type3 \NC this is a bitmapped (\PK) font \NC \NR
361 \NC truetype \NC this is a \TRUETYPE\ or \TRUETYPE|-|based \OPENTYPE\ font \NC \NR
362 \NC opentype \NC this is a \POSTSCRIPT|-|based \OPENTYPE\ font \NC \NR
363 \stoptabulate
365 \type {type3} fonts are provided for backward compatibility only, and do not
366 support the new wide encoding options.
368 Values for \type {embedding} are:
370 \starttabulate[|Tl|p|]
371 \NC \rmbf value \NC \rmbf description \NC \NR
372 \NC no \NC don't embed the font at all \NC \NR
373 \NC subset \NC include and atttempt to subset the font \NC \NR
374 \NC full \NC include this font in its entirety \NC \NR
375 \stoptabulate
377 The other fields are used as follows: The \type {fullname} will be the
378 \POSTSCRIPT|/|\PDF\ font name. The \type {cidinfo} will be used as the character
379 set (the CID \type {/Ordering} and \type {/Registry} keys). The \type {filename}
380 points to the actual font file. If you include the full path in the \type
381 {filename} or if the file is in the local directory, \LUATEX\ will run a little
382 bit more efficient because it will not have to re|-|run the \type {find_xxx_file}
383 callback in that case.
385 Be careful: when mixing old and new fonts in one document, it is possible to
386 create \POSTSCRIPT\ name clashes that can result in printing errors. When this
387 happens, you have to change the \type {fullname} of the font.
389 Typeset strings are written out in a wide format using 2~bytes per glyph, using
390 the \type {index} key in the character information as value. The overall effect
391 is like having an encoding based on numbers instead of traditional (\POSTSCRIPT)
392 name|-|based reencoding. The way to get the correct \type {index} numbers for
393 \TYPEONE\ fonts is by loading the font via \type {fontloader.open} and use the table
394 indices as \type {index} fields.
396 In order to make sure that cut and paste of the final document works okay you can
397 best make sure that there is a \type {tounicode} vector enforced.
399 \section[virtualfonts]{Virtual fonts}
401 \subsection{The structure}
403 You have to take the following steps if you want \LUATEX\ to treat the returned
404 table from \type {define_font} as a virtual font:
406 \startitemize[packed]
407 \startitem
408 Set the top|-|level key \type {type} to \type {virtual}.
409 \stopitem
410 \startitem
411 Make sure there is at least one valid entry in \type {fonts} (see below).
412 \stopitem
413 \startitem
414 Give a \type {commands} array to every character (see below).
415 \stopitem
416 \stopitemize
418 The presence of the toplevel \type {type} key with the specific value \type
419 {virtual} will trigger handling of the rest of the special virtual font fields in
420 the table, but the mere existence of 'type' is enough to prevent \LUATEX\ from
421 looking for a virtual font on its own.
423 Therefore, this also works \quote {in reverse}: if you are absolutely certain
424 that a font is not a virtual font, assigning the value \type {base} or \type
425 {real} to \type {type} will inhibit \LUATEX\ from looking for a virtual font
426 file, thereby saving you a disk search.
428 The \type {fonts} is another \LUA\ array. The values are one- or two|-|key
429 hashes themselves, each entry indicating one of the base fonts in a virtual font.
430 In case your font is referring to itself, you can use the \type {font.nextid()}
431 function which returns the index of the next to be defined font which is probably
432 the currently defined one.
434 An example makes this easy to understand
436 \starttyping
437 fonts = {
438 { name = 'ptmr8a', size = 655360 },
439 { name = 'psyr', size = 600000 },
440 { id = 38 }
442 \stoptyping
444 says that the first referenced font (index 1) in this virtual font is \type
445 {ptrmr8a} loaded at 10pt, and the second is \type {psyr} loaded at a little over
446 9pt. The third one is previously defined font that is known to \LUATEX\ as font id
447 \quote {38}.
449 The array index numbers are used by the character command definitions that are
450 part of each character.
452 The \type {commands} array is a hash where each item is another small array,
453 with the first entry representing a command and the extra items being the
454 parameters to that command. The allowed commands and their arguments are:
456 \starttabulate[|Tl|l|l|p|]
457 \NC \rmbf command name \NC \bf arguments \NC \bf type \NC \bf description \NC\NR
458 \NC font \NC 1 \NC number \NC select a new font from the local \type {fonts} table\NC\NR
459 \NC char \NC 1 \NC number \NC typeset this character number from the current font,
460 and move right by the character's width\NC\NR
461 \NC node \NC 1 \NC node \NC output this node (list), and move right
462 by the width of this list\NC\NR
463 \NC slot \NC 2 \NC number \NC a shortcut for the combination of a font and char command\NC\NR
464 \NC push \NC 0 \NC \NC save current position\NC\NR
465 \NC nop \NC 0 \NC \NC do nothing \NC\NR
466 \NC pop \NC 0 \NC \NC pop position \NC\NR
467 \NC rule \NC 2 \NC 2 numbers \NC output a rule $ht*wd$, and move right.\NC\NR
468 \NC down \NC 1 \NC number \NC move down on the page\NC\NR
469 \NC right \NC 1 \NC number \NC move right on the page\NC\NR
470 \NC special \NC 1 \NC string \NC output a \type {\special} command\NC\NR
471 \NC lua \NC 1 \NC string \NC execute a \LUA\ script (at \type {\latelua} time)\NC\NR
472 \NC image \NC 1 \NC image \NC output an image (the argument can be either an \type
473 {<image>} variable or an \type {image_spec} table)\NC\NR
474 \NC comment \NC any \NC any \NC the arguments of this command are ignored\NC\NR
475 \stoptabulate
477 When a font id is set to~0 then it will be replaced by the currently assigned
478 font id. This prevents the need for hackery with future id's (normally one could
479 use \type {font.nextid} but when more complex fonts are built in the meantime
480 other instances could have been loaded.
482 Here is a rather elaborate glyph commands example:
484 \starttyping
486 commands = {
487 { 'push' }, -- remember where we are
488 { 'right', 5000 }, -- move right about 0.08pt
489 { 'font', 3 }, -- select the fonts[3] entry
490 { 'char', 97 }, -- place character 97 (ASCII 'a')
491 { 'pop' }, -- go all the way back
492 { 'down', -200000 }, -- move upwards by about 3pt
493 { 'special', 'pdf: 1 0 0 rg' } -- switch to red color
494 { 'rule', 500000, 20000 } -- draw a bar
495 { 'special','pdf: 0 g' } -- back to black
498 \stoptyping
500 The default value for \type {font} is always~1 at the start of the
501 \type {commands} array. Therefore, if the virtual font is essentially only a
502 re|-|encoding, then you do usually not have create an explicit \quote {font}
503 command in the array.
505 Rules inside of \type {commands} arrays are built up using only two dimensions:
506 they do not have depth. For correct vertical placement, an extra \type {down}
507 command may be needed.
509 Regardless of the amount of movement you create within the \type {commands}, the
510 output pointer will always move by exactly the width that was given in the \type
511 {width} key of the character hash. Any movements that take place inside the \type
512 {commands} array are ignored on the upper level.
514 \subsection{Artificial fonts}
516 Even in a \quote {real} font, there can be virtual characters. When \LUATEX\
517 encounters a \type {commands} field inside a character when it becomes time to
518 typeset the character, it will interpret the commands, just like for a true
519 virtual character. In this case, if you have created no \quote {fonts} array,
520 then the default (and only) \quote {base} font is taken to be the current font
521 itself. In practice, this means that you can create virtual duplicates of
522 existing characters which is useful if you want to create composite characters.
524 Note: this feature does {\it not\/} work the other way around. There can not be
525 \quote {real} characters in a virtual font! You cannot use this technique for
526 font re-encoding either; you need a truly virtual font for that (because
527 characters that are already present cannot be altered).
529 \subsection{Example virtual font}
531 Finally, here is a plain \TEX\ input file with a virtual font demonstration:
533 \startbuffer
534 \directlua {
535 callback.register('define_font',
536 function (name,size)
537 if name == 'cmr10-red' then
538 f = font.read_tfm('cmr10',size)
539 f.name = 'cmr10-red'
540 f.type = 'virtual'
541 f.fonts = {{ name = 'cmr10', size = size }}
542 for i,v in pairs(f.characters) do
543 if (string.char(i)):find('[tacohanshartmut]') then
544 v.commands = {
545 {'special','pdf: 1 0 0 rg'},
546 {'char',i},
547 {'special','pdf: 0 g'},
549 else
550 v.commands = {{'char',i}}
553 else
554 f = font.read_tfm(name,size)
556 return f
561 \font\myfont = cmr10-red at 10pt \myfont This is a line of text \par
562 \font\myfontx= cmr10 at 10pt \myfontx Here is another line of text \par
563 \stopbuffer
565 \typebuffer
567 \section{The \type {font} library}
569 The font library provides the interface into the internals of the font system,
570 and also it contains helper functions to load traditional \TEX\ font metrics
571 formats. Other font loading functionality is provided by the \type {fontloader}
572 library that will be discussed in the next section.
574 \subsection{Loading a \TFM\ file}
576 The behavior documented in this subsection is considered stable in the sense that
577 there will not be backward-incompatible changes any more.
579 \startfunctioncall
580 <table> fnt =
581 font.read_tfm(<string> name, <number> s)
582 \stopfunctioncall
584 The number is a bit special:
586 \startitemize
587 \startitem
588 If it is positive, it specifies an \quote {at size} in scaled points.
589 \stopitem
590 \startitem
591 If it is negative, its absolute value represents a \quote {scaled}
592 setting relative to the designsize of the font.
593 \stopitem
594 \stopitemize
596 The internal structure of the metrics font table that is returned is explained in
597 \in {chapter} [fonts].
599 \subsection{Loading a \VF\ file}
601 The behavior documented in this subsection is considered stable in the sense that
602 there will not be backward-incompatible changes any more.
604 \startfunctioncall
605 <table> vf_fnt =
606 font.read_vf(<string> name, <number> s)
607 \stopfunctioncall
609 The meaning of the number \type {s} and the format of the returned table are
610 similar to the ones in the \type {read_tfm()} function.
612 \subsection{The fonts array}
614 The whole table of \TEX\ fonts is accessible from \LUA\ using a virtual array.
616 \starttyping
617 font.fonts[n] = { ... }
618 <table> f = font.fonts[n]
619 \stoptyping
621 See \in {chapter} [fonts] for the structure of the tables. Because this is a
622 virtual array, you cannot call \type {pairs} on it, but see below for the \type
623 {font.each} iterator.
625 The two metatable functions implementing the virtual array are:
627 \startfunctioncall
628 <table> f = font.getfont(<number> n)
629 font.setfont(<number> n, <table> f)
630 \stopfunctioncall
632 Note that at the moment, each access to the \type {font.fonts} or call to \type
633 {font.getfont} creates a \LUA\ table for the whole font. This process can be quite
634 slow. In a later version of \LUATEX, this interface will change (it will start
635 using userdata objects instead of actual tables).
637 Also note the following: assignments can only be made to fonts that have already
638 been defined in \TEX, but have not been accessed {\it at all\/} since that
639 definition. This limits the usability of the write access to \type {font.fonts}
640 quite a lot, a less stringent ruleset will likely be implemented later.
642 \subsection{Checking a font's status}
644 You can test for the status of a font by calling this function:
646 \startfunctioncall
647 <boolean> f =
648 font.frozen(<number> n)
649 \stopfunctioncall
651 The return value is one of \type {true} (unassignable), \type {false} (can be
652 changed) or \type {nil} (not a valid font at all).
654 \subsection{Defining a font directly}
656 You can define your own font into \type {font.fonts} by calling this function:
658 \startfunctioncall
659 <number> i =
660 font.define(<table> f)
661 \stopfunctioncall
663 The return value is the internal id number of the defined font (the index into
664 \type {font.fonts}). If the font creation fails, an error is raised. The table
665 is a font structure, as explained in \in {chapter} [fonts].
667 \subsection{Projected next font id}
669 \startfunctioncall
670 <number> i =
671 font.nextid()
672 \stopfunctioncall
674 This returns the font id number that would be returned by a \type {font.define}
675 call if it was executed at this spot in the code flow. This is useful for virtual
676 fonts that need to reference themselves.
678 \subsection{Font id}
680 \startfunctioncall
681 <number> i =
682 font.id(<string> csname)
683 \stopfunctioncall
685 This returns the font id associated with \type {csname} string, or $-1$ if \type
686 {csname} is not defined.
688 \subsection{Currently active font}
690 \startfunctioncall
691 <number> i = font.current()
692 font.current(<number> i)
693 \stopfunctioncall
695 This gets or sets the currently used font number.
697 \subsection{Maximum font id}
699 \startfunctioncall
700 <number> i =
701 font.max()
702 \stopfunctioncall
704 This is the largest used index in \type {font.fonts}.
706 \subsection{Iterating over all fonts}
708 \startfunctioncall
709 for i,v in font.each() do
712 \stopfunctioncall
714 This is an iterator over each of the defined \TEX\ fonts. The first returned
715 value is the index in \type {font.fonts}, the second the font itself, as a \LUA\
716 table. The indices are listed incrementally, but they do not always form an array
717 of consecutive numbers: in some cases there can be holes in the sequence.
719 \stopchapter
721 \stopcomponent