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