Debian Codegraph @

texmf-dist/doc/luametatex/base/luametatex-fonts.tex

raw
1 % language=us runpath=texruns:manuals/luametatex
2
3 \environment luametatex-style
4
5 \startdocument[title=Fonts]
6
7 \startsection[title={Introduction}]
8
9 The \LUATEX\ engine changed the approach to loading fonts and processing kerns
10 and ligatures by introducing a \LUA\ loader and callbacks for processing
11 replacement and positioning features. In \LUAMETATEX\ we go a step further and no
12 longer load fonts otherwise than with \LUA. In the end, all that \TEX\ needs are
13 a few dimensions and optionally ligature and kerning tables. Of course for math a
14 bit more is needed but even there we can safely delegate all loading to \LUA. In
15 \LUAMETATEX\ we still have the traditional kerning and ligature built in because
16 after all that method is the reference for traditional fonts and the amount of
17 code needed is relatively small.
18
19 The backend is gone, so here the final font inclusion is also done by \LUA. This
20 means that in the engine the amount of code involved in that is zero. In the
21 engine we have glyphs and glyphs traditionally carry a font identifier (an
22 number) and a glyph reference (also a number). Both are used to fetch the width,
23 height, depth, italic correction ans some more from the fonts registered in the
24 engine. For \TEX\ a font is more of an abstraction that from \LUA, where we can
25 manipulate details and deal with the real shapes.
26
27 In \LUAMETATEX\ the situation is simplified on the one hand, read: no font
28 loader, but complicated on the other, for instance because we have dynamic
29 scaling. In this chapter we discuss what data is stored in glyphs, what
30 primitives are involved, and how loading takes place. Because a lot can be done
31 in \LUA\ and because there are no standards involved, we don't need to discuss
32 how a macro package is supposed to deal with all this; one can consider \CONTEXT\
33 as a reference implementation if needed.
34
35 Removing the font loader and backend had relatively little impact on \CONTEXT\
36 because we already did most in \LUA, but as we developed \LUAMETATEX\ both
37 subsystems evolved further. Especially moving more backend processing to \LUA\
38 had some impact on performance but in the end the engine is much faster so we
39 gained that back. Additions to the font system, like dynamic scaling of course
40 have impact too but we could also limit the amount of fonts that get loaded which
41 compensates for any loss in performance. The most complicated and demanding part
42 of the backend code is that what deals with fonts: sharing, subsetting,
43 devirtualizing, scaling, effects like weight, slanting, expansion, accuracy,
44 accessibility, \unknown, all of that has to be dealt with.
45
46 In this chapter we discuss a few aspects like primitives, defining fonts, \LUA\
47 helpers, and virtual fonts, but for a more complete picture one really has to
48 read the documents that describe how all evolved, how fonts are used in \CONTEXT\
49 as well as look at how we apply all this. There is no reason to repeat everything
50 here, especially because for most users this is not something they need to know.
51 There are dedicated manuals and articles that cover different aspects.
52
53 \stopsection
54
55 \startsection[title={Primitives}]
56
57 \startsubsection[title=Basic properties]
58
59 Although primitives are discusses in their own chapter we repeat some here
60 because it impacts following sections. Let's start with the commands that change
61 the look and feel of a font:
62
63 \startbuffer
64 \begingroup glyphs represent characters \endgroup
65 \begingroup \glyphscale 1200 glyphs represent characters \endgroup
66 \begingroup \glyphxscale 1200 glyphs represent characters \endgroup
67 \begingroup \glyphyscale 800 glyphs represent characters \endgroup
68 \begingroup \glyphslant 200 glyphs represent characters \endgroup
69 \begingroup \glyphweight 200 glyphs represent characters \endgroup
70 \stopbuffer
71
72 \typebuffer[option=TEX]
73
74 This results in:
75
76 \startlines \getbuffer \stoplines
77
78 These parameters are applied to glyphs that get added to the current list of
79 nodes. Whenever the engine (or the \LUA\ end) needs a dimension, two scales have
80 to be applied, depending on the dimension being horizontal or vertical. Sometimes
81 the slant and weight also have to be taken into account. Later we will see that
82 we have additional math scaling so you can imagine that applying a handful of
83 scales has a bit of impact on the code and also performance. However, the later
84 will not be noticed because computers are fast enough.
85
86 Here is how we can apply the scaling factors to dimensions:
87
88 \startbuffer
89 {\glyphxscale 1500 \the\glyphxscaled 100pt} and
90 {\glyphyscale 750 \the\glyphyscaled 100pt} and
91 {\glyphscale 1500 \glyphxscale 500 \the\glyphxscaled 100pt}
92 \stopbuffer
93
94 \typebuffer[option=TEX]
95
96 We get: \inlinebuffer. In scenarios like these you need to keep in mind that the
97 currently set scales also apply. The main reason why we use these 1000 based
98 factor is that it is the way \TEX\ does things. We could have used posits instead
99 but those were added later so for now it's factors that dominate.
100
101 \stopsubsection
102
103 \startsubsection[title=Specifications]
104
105 A font is loaded at a specific size, so these properties start from that: the
106 design size and the requested size which results in a scaling factor. Every font
107 has a number so here we have:
108
109 \startbuffer
110 \tf \the \fontid \font \hskip1cm
111 \bf \the \fontid \font \hskip1cm
112 \sl \the \fontid \font
113 \stopbuffer
114
115 \typebuffer[option=TEX]
116
117 \start \getbuffer \stop
118
119 A set of settings can be combined in specification, here \type {\font} is the
120 current font, from which the specification takes the identifier.
121
122 \startbuffer
123 \fontspecdef \MyFontA \font xscale 2000 yscale 800 weight 200 slant 200 \relax
124 \fontspecdef \MyFontB \font all 1000 1500 800 250 150 \relax
125
126 \begingroup \MyFontA Is this neat or not? \endgroup
127 \begingroup \MyFontB Is this neat or not? \endgroup
128 \stopbuffer
129
130 \typebuffer[option=TEX]
131
132 \startlines \getbuffer \stoplines
133
134 Instead of an id an already defined specification can be given in which case we
135 start from a copy:
136
137 \starttyping[option=TEX]
138 \fontspecdef \MyFontA 2 all 1000
139 \fontspecdef \MyFontB \MyFontA xscale 1200
140 \stoptyping
141
142 Say that we have:
143
144 \startbuffer
145 \fontspecdef\MyFoo\font xscale 1200 \relax
146 \stopbuffer
147
148 \typebuffer[option=TEX] \getbuffer
149
150 The four properties of such a specification can then be queried as follows:
151
152 \startbuffer
153 [\the\fontspecid \MyFoo]
154 [\the\fontspecscale \MyFoo]
155 [\the\fontspecxscale \MyFoo]
156 [\the\fontspecyscale \MyFoo]
157 [\the\fontspecifiedsize\MyFoo]
158 [\fontspecifiedname \MyFoo]
159 \stopbuffer
160
161 \typebuffer[option=TEX] \getbuffer
162
163 A font specification obeys grouping but is not a register. Like \type
164 {\integerdef} and \type {\dimendef} it is just a control sequence with a special
165 meaning.
166
167 If you read about compact font mode in \CONTEXT, this is what we're using there.
168 It started out by more aggressive sharing and scaling but eventually all five
169 properties were integrated in a fast font switch. However, setting these five
170 properties, even with one command has some overhead because they are saved on the
171 save stack. Okay, that was a bit if a lie: no one will notice that overhead:
172
173 \startbuffer
174 \fontspecdef \MyFontA \font
175 scale 1100 xscale 2000 yscale 800 weight 200 slant 200
176 \relax
177 \fontspecdef \MyFontB \font
178 scale 1200 xscale 1000 yscale 200 weight 100 slant 100
179 \relax
180 \stopbuffer
181
182 \typebuffer [option=TEX]
183
184 A 100.000 times \type {{\MyFontA \MyFontB}} grouped expansion takes 0.02 seconds
185 runtime on my 2018 laptop, which is just noise once we start processing text:
186 100.000 times \type {{\MyFontA efficient \MyFontB efficient}} takes 1.4 seconds
187 and 100.000 times \type {{\MyFontA test \MyFontB test}} takes 0.4 seconds. Guess
188 why.
189
190 \stopsubsection
191
192 \startsubsection[title=Offsets]
193
194 These two parameters control the horizontal and vertical shift of glyphs with,
195 when applied to a stretch of them, the horizontal offset probably being the least
196 useful. The values default to the currently set values. Here is a \CONTEXT\ example:
197
198 \startbuffer
199 \ruledhbox \bgroup
200 \ruledhbox {\glyph yoffset 1ex xoffset -.5em 123}
201 \ruledhbox {\glyph yoffset 1ex 125}
202 \ruledhbox \bgroup
203 baseline
204 \glyphyoffset 1ex \glyphxscale 800 \glyphyscale \glyphxscale
205 raised%
206 \egroup
207 \egroup
208 \stopbuffer
209
210 \typebuffer
211
212 Visualized:
213
214 \startlinecorrection[blank]
215 \getbuffer
216 \stoplinecorrection
217
218 \stopsubsection
219
220 \startsubsection[title=Math scales and identifiers]
221
222 More details about fonts in math mode can be found in the chapters about math and
223 primitives so here we just mention a few of these primitives. The internal \type
224 {\glyphtextscale}, \type {\glyphscriptscale} and \type {\glyphscriptscriptscale}
225 registers can be set to enforce additional scaling of math, like this:
226
227 \startbuffer
228 $ a = b^2 = c^{d^2}$
229 $\glyphtextscale 800 a = b^2 = c^{d^2}$
230 $\glyphscriptscale 800 a = b^2 = c^{d^2}$
231 $\glyphscriptscriptscale 800 a = b^2 = c^{d^2}$
232 \stopbuffer
233
234 \typebuffer[option=TEX]
235
236 You can of course set them all in any mix as long as the value is larger than
237 zero and doesn't exceed 1000. In \CONTEXT\ we use this for special purposes so
238 don't mess with it there. as there can be unexpected (but otherwise valid) side
239 effects.
240
241 \startlines
242 \getbuffer
243 \stoplines
244
245 The next few reported values depend on the font setup. A math font can be loaded
246 at a certain scale and further scaled on the fly. An open type math font comes
247 with recommended script and script script scales and gets passed to the engine
248 scaled. The values reported by \type {\mathscale} are {\em additional} scales.
249
250 \startbuffer
251 $\the\mathscale\textfont \zerocount$
252 $\the\mathscale\scriptfont \zerocount$
253 $\the\mathscale\scriptscriptfont\zerocount$
254 \stopbuffer
255
256 \typebuffer[option=TEX]
257
258 gives: \inlinebuffer
259
260 In math mode the font id depends on the style because there we have a family of
261 three related fonts or the same font with different scales. In this document we
262 get the following identifiers:
263
264 \startbuffer
265 $\the\mathstylefontid\scriptscriptstyle \fam$
266 $\the\mathstylefontid\scriptstyle \fam$
267 $\the\mathstylefontid\textstyle \fam$
268 \stopbuffer
269
270 \typebuffer[option=TEX]
271
272 Gives: \inlinebuffer, which is no surprise because we use the same font for all
273 sizes combined with the \type {smaller} field options discusses later. In \CONTEXT\
274 math uses compact font mode with in-place scaling by default.
275
276 \stopsubsection
277
278 \startsubsection[title={Scaled fontdimensions}]
279
280 When you use \type {\glyphscale}, \type {\glyphxscale} and|/|or \type
281 {\glyphyscale} the font dimensions also scale. The values that are currently used
282 can be queried:
283
284 \starttabulate[|l|c|c|c|]
285 \FL
286 \BC dimension \BC scale \BC xscale \BC yscale \NC\NR
287 \TL
288 \NC \type {\scaledemwidth} \NC \star \NC \star \NC \NC\NR
289 \NC \type {\scaledexheight} \NC \star \NC \NC \star \NC\NR
290 \NC \type {\scaledextraspace} \NC \star \NC \star \NC \NC\NR
291 \NC \type {\scaledinterwordshrink} \NC \star \NC \star \NC \NC\NR
292 \NC \type {\scaledinterwordspace} \NC \star \NC \star \NC \NC\NR
293 \NC \type {\scaledinterwordstretch} \NC \star \NC \star \NC \NC\NR
294 \NC \type {\scaledslantperpoint} \NC \star \NC \star \NC \NC\NR
295 \LL
296 \stoptabulate
297
298 The next table shows the effective sized when we scale by 2000. The last two
299 columns scale twice: the shared scale and the $x$ or $y$ scale.
300
301 \def\ShowThem#1%
302 {\normalexpanded{
303 \BC \small \prm {\csstring\parametermark1}
304 \NC {\localcontrolled{\glyphscale2000 \glyphxscale1000 \glyphyscale 1000} \withoutpt\parametermark1}
305 \NC {\localcontrolled{\glyphscale1000 \glyphxscale2000 \glyphyscale 1000} \withoutpt\parametermark1}
306 \NC {\localcontrolled{\glyphscale1000 \glyphxscale1000 \glyphyscale 2000} \withoutpt\parametermark1}
307 \NC {\localcontrolled{\glyphscale2000 \glyphxscale2000 \glyphyscale 1000} \withoutpt\parametermark1}
308 \NC {\localcontrolled{\glyphscale2000 \glyphxscale1000 \glyphyscale 2000} \withoutpt\parametermark1}
309 \NC \NR}}
310
311 \starttabulate[|l|c{.}|c{.}|c{.}|c{.}|c{.}|]
312 \ShowThem\scaledemwidth
313 \ShowThem\scaledexheight
314 \ShowThem\scaledextraspace
315 \ShowThem\scaledinterwordshrink
316 \ShowThem\scaledinterwordspace
317 \ShowThem\scaledinterwordstretch
318 \ShowThem\scaledslantperpoint
319 \stoptabulate
320
321 \stopsubsection
322
323 \startsubsection[title=Character properties]
324
325 The \type {\fontcharwd}, \type {\fontcharht}, \type {\fontchardp} and \type
326 {\fontcharic} give access to character properties. To this repertoire
327 \LUAMETATEX\ adds the top and bottom accent accessors \type {\fontcharta} and
328 \type {\fontcharba} that came in handy for tracing. You pass a font reference and
329 character code. Normally only \OPENTYPE\ math fonts have this property.
330
331 \stopsubsection
332
333 \startsubsection[title=Glyph options]
334
335 In \LUATEX\ the \type {\noligs} and \type {\nokerns} primitives suppress these
336 features but in \LUAMETATEX\ these primitives are gone. They are replace by a
337 more generic control primitive \type {\glyphoptions}. This numerical parameter is
338 a bitset with the following fields:
339
340 \starttworows
341 \getbuffer[engine:syntax:glyphoptions]
342 \stoptworows
343
344 The effects speak for themselves. They provide detailed control over individual
345 glyph, this because the current value of this option is stored with glyphs. In
346 \CONTEXT\ we have commands that set flags like that and also make sure that there
347 is no interference in setting them. it's good to know that some of these options
348 are there so that we can properly demonstrate, discuss and document \LUAMETATEX\
349 behavior. The current value of this parameter is {\tt 0x\tohexadecimal
350 \glyphoptions} but that can of course change because we experiment with options
351 and bit positions might change over time, which is why we can query the engine.
352
353 \stopsubsection
354
355 \stopsection
356
357 \startsection[title={Nodes}]
358
359 This chapter is not about nodes so we keep this section short. A glyph node is an
360 important one and a page easily has a few thousand of them. When a list that has
361 glyphs nodes is processed, depending on the font quite some passes over that list
362 are made in order to sort out substitutions, alternatives and ligatures as well
363 as font kerning and anchoring. When the paragraph is constructed these glyphs are
364 consulted and dimensions and expansion properties are accessed and scaling can
365 happen. These glyph nodes are among the largest and have many fields. To what
366 extend you can use these fields depends on the macro package and the reason is
367 that some of these fields also affect the backend and the backend is provided by
368 the macro package. When the script|/|language combination that you use supports
369 hyphenation, there can be discretionary nodes that have a pre, post and|/|or
370 replace component set that are node lists that can contain glyph nodes and
371 whenever we mess around with glyphs we also need to check these.
372
373 The most important fields are \type {font} and \type {character}, as these
374 uniquely point to what shape is used. That also means that at the \LUA\ end we
375 can have more information than \TEX\ needs and can do things that \TEX\ in its
376 role as constructor is unaware of. The par builder doesn't really care what it
377 deals with, it only needs dimensions and maybe some properties.
378
379 The \type {data}, \type {state}, \type {script} and \type {protected} fields are
380 used for instance by \CONTEXT\ and in particular the font handler. There are
381 primitives that can query and set these fields, like \typ {\glyphdatafield}, \typ
382 {\glyphscriptfield} and \typ {\glyphstatefield}.
383
384 These primitives can be used to set an additional glyph properties. Of course
385 it's very macro package dependent what is done with that. It started with just
386 the first one as experiment, simply because we had some room left in the glyph
387 data structure. It's basically an single attribute. Then, when we got rid of the
388 ligature pointer we could either drop it or use that extra field for some more,
389 and because \CONTEXT\ already used the data field, that is what happened. The
390 script and state fields are shorts, that is, they run from zero to \type {0xFFFF}
391 where we assume that zero means \quote {unset}. Although they can be used for
392 whatever purpose their use in \CONTEXT\ is fixed. So far for a historical note.
393
394 The \typ {language} field is used by the hyphenator but can also be used by the
395 macro package. The \type {lhmin} and \type {rhmin} are only useful for the
396 hyphenator and these values are set by the language mechanisms and primitives.
397 The \type {discpart} bitset registers what the engine did which can be handy for
398 tracing.
399
400 We already mentioned scales, slant and weight and these go to fields \type
401 {scale}, \type {xscale}, \type {yscale}, \type {slant} and \type {weight}. The
402 \type {expansion}, \type {raise}, \type {left}, \type {right}, \type {xoffset}
403 and \type {yoffset} can be set by \TEX\ but also by the font handler. Messing
404 with any of these fields at the \TEX\ end is easy but one really should take into
405 account what the macro packages needs them for and does with them at the \LUA\
406 end and in the backend. In that respect \LUAMETATEX\ lets the user free but it
407 also means that you cannot expect macro packages (assuming that \CONTEXT\ is not
408 the only user) to behave the same.
409
410 The various math subsystems use \type {properties}, \type {group} and \type
411 {index} and again this also macro package specific. The \type {options} bitset
412 controls all kind of processes in the engine when it comes to using glyphs (user
413 level \type {\glyphoptions}) as do \type {control} and \type {hyphenate}.
414
415 It would take many pages to explain all this so again we just refer to how
416 \CONTEXT\ uses these fields, the way they can be set from \TEX\ and accessed in
417 \LUA. In the end, all the users see of this is shapes anyway, while macro
418 packages integrate and present these as features.
419
420 \stopsection
421
422 \startsection[title={Loading}]
423
424 A font is normally defined by \type {\font} which in \LUAMETATEX\ is just a
425 trigger for a callback. You can even do without that primitive because you can
426 load a font and then use \type {\setfontid} or the previously mentioned
427 specification to switch to a font. The callback, discussed in the callbacks
428 chapter, gets a name and size, and is supposed to return a font identifier. You
429 can use the name to locate and load a font, register the font using the following
430 function, which gives you an identifier that satisfies the callback.
431
432 \starttyping [option=LUA]
433 function font.define ( <t:table> font, <t:integer> id )
434 return <t:integer> id
435 end
436 \stoptyping
437
438 with respect to \type {\font} it's good to know that the engine accept a braced
439 argument as a font name:
440
441 \starttyping[option=TEX]
442 \font\myfont = {My Fancy Font}
443 \stoptyping
444
445 This allows for embedded spaces, without the need for double quotes. Macro
446 expansion takes place inside the argument. Although in \CONTEXT\ \LMTX\ we don't
447 use the \type {\font} for defining fonts, it still can be uses.
448
449 The font table is mandate but the identifier is optional. The table has the
450 following fields, most of which concern math. The \type {name} field is mandate
451 because it is needed in various feedback scenarios.
452
453 % \showenginekeylist{font.getfontfields()}
454
455 \starttabulate[|l|l|pl|]
456 \FL
457 \BC key \BC type \BC description \NC \NR
458 \ML
459 \NC \type {name} \NC string \NC metric (file) name \NC \NR
460 \NC \type {original} \NC string \NC the name used in logging and feedback \NC \NR
461 \NC \type {designsize} \NC number \NC expected size (default: 655360 == 10pt) \NC \NR
462 \NC \type {size} \NC number \NC the required scaling (by default the same as \type {designsize}) \NC \NR
463 \HL
464 \NC \type {compactmath} \NC boolean \NC use the \type {smaller} fields in lookups \NC \NR
465 \NC \type {mathcontrol} \NC bitset \NC this controls various options in the math engine \NC \NR
466 \NC \type {textcontrol} \NC bitset \NC this controls various options in the text engine \NC \NR
467 \NC \type {nomath} \NC boolean \NC don't check for math parameters and properties \NC \NR
468 \HL
469 \NC \type {characters} \NC table \NC the defined glyphs of this font \NC \NR
470 \NC \type {fonts} \NC table \NC locally used fonts \NC \NR
471 \NC \type {parameters} \NC table \NC parameters by index and/or key \NC \NR
472 \NC \type {MathConstants} \NC table \NC \OPENTYPE\ math parameter \NC \NR
473 \HL
474 \NC \type {hyphenchar} \NC number \NC default: \TEX's \type {\hyphenchar} \NC \NR
475 \NC \type {skewchar} \NC number \NC default: \TEX's \type {\skewchar} \NC \NR
476 \HL
477 \NC \type {textscale} \NC number \NC scale applied to math text \NC \NR
478 \NC \type {scriptscale} \NC number \NC scale applied to math script \NC \NR
479 \NC \type {scriptscriptscale} \NC number \NC scale applied to math script script \NC \NR
480 \HL
481 \NC \type {textxscale} \NC number \NC horizontal scale applied to math text \NC \NR
482 \NC \type {scriptxscale} \NC number \NC horizontal scale applied to math script \NC \NR
483 \NC \type {scriptxscriptscale} \NC number \NC horizontal scale applied to math script script \NC \NR
484 \HL
485 \NC \type {textyscale} \NC number \NC vertical scale applied to math text \NC \NR
486 \NC \type {scriptyscale} \NC number \NC vertical scale applied to math script \NC \NR
487 \NC \type {scriptyscriptscale} \NC number \NC vertical scale applied to math script script \NC \NR
488 \HL
489 \NC \type {textweight} \NC number \NC weight applied to math text \NC \NR
490 \NC \type {scriptweight} \NC number \NC weight applied to math script \NC \NR
491 \NC \type {scriptscriptweight} \NC number \NC weight applied to math script script \NC \NR
492 \LL
493 \stoptabulate
494
495 % % The \type {mathcontrol} bitset is mostly there for experimental purposes. Because
496 % % there is inconsistency in the \OPENTYPE\ math fonts with respect to for instance
497 % % glyph dimensions, it is possible to force the traditional code path. We just mention
498 % % the possible flags:
499 % %
500 % % \startluacode
501 % % context.starttabulate { "|||" }
502 % % context.DB() context("value") context.BC() context("effect") context.NC() context.NR()
503 % % context.TB()
504 % % for k, v in table.sortedhash(tex.getmathcontrolvalues()) do
505 % % context.NC() context("0x%04X",k) context.NC() context(v) context.NC() context.NR()
506 % % end
507 % % context.LL()
508 % % context.stoptabulate()
509 % % \stopluacode
510 %
511 %
512 % % The \type {textcontrol} field is used to control some aspects of text processing.
513 % % More options might be added in the future.
514 %
515 % % \startluacode
516 % % context.starttabulate { "|||" }
517 % % context.DB() context("value") context.BC() context("effect") context.NC() context.NR()
518 % % context.TB()
519 % % for k, v in table.sortedhash(tex.gettextcontrolvalues()) do
520 % % context.NC() context("0x%04X",k) context.NC() context(v) context.NC() context.NR()
521 % % end
522 % % context.LL()
523 % % context.stoptabulate()
524 % % \stopluacode
525 % %
526 % % In \CONTEXT\ these are interfaced via pseudo features. The math control flags of
527 % % a font can be overloaded by \prm {mathcontrolmode} on the spot and the set
528 % % controls of a font can be queried by \prm {fontmathcontrol}. The text control
529 % % flags in a font always win over the ones set by other parameters, like \prm
530 % % {hyphenationmode}. They can be queried with \prm {fonttextcontrol}.
531
532 There are three tables that need their own explanation. The \type {parameters}
533 table is a hash with mixed key types. There are seven possible string keys, as
534 well as a number of integer indices. The seven strings are actually used instead
535 of the bottom seven indices, because that gives a nicer user interface. There are
536 additional indexed entries possible for math fonts but nowadays one will use
537 \OPENTYPE\ math fonts so these no longer make sense.
538
539 % \showenginekeylist{font.getparameterfields()}
540
541 \starttabulate[|l|c|]
542 \FL
543 \BC name \BC index \NC \NR
544 \ML
545 \NC \type {slant} \NC 1 \NC \NR
546 \NC \type {space} \NC 2 \NC \NR
547 \NC \type {spacestretch} \NC 3 \NC \NR
548 \NC \type {spaceshrink} \NC 4 \NC \NR
549 \NC \type {xheight} \NC 5 \NC \NR
550 \NC \type {quad} \NC 6 \NC \NR
551 \NC \type {extraspace} \NC 7 \NC \NR
552 \LL
553 \stoptabulate
554
555 The \type {characters} table can be pretty large when we have \OPENTYPE\ fonts.
556 In \CONTEXT\ we use \UNICODE\ as encoding which means that glyphs are organized
557 as such. This also means that we have a hash and not an indexed array due to
558 gaps. There can be more data in the glyph sub tables than the engine needs
559 because the engine only picks up those that it needs. You can also later decide
560 to pass additional properties and even glyphs to the engine, but changes can of
561 course have consequences because at some point the backend will pick up data and
562 use that. Additions are fine but changes have to be consistent. Of course it all
563 depends on how you implement a backend.
564
565 When a character in the input is turned into a glyph node, it gets a character
566 code that normally refers to an entry in that table. For proper paragraph
567 building and math rendering the fields in the tables below can best be present in
568 an entry in the \type {characters} table. As said, you can of course add all kind
569 of extra fields. The engine only uses those that it needs for typesetting a
570 paragraph or formula. The sub tables that define ligatures and kerns are also
571 hashes with integer keys, and these indices should point to entries in the main
572 characters table. The fields common to text and math chartacters are:
573 \showenginekeylist {font.gettextcharacterfields()}.
574
575 Providing ligatures and kerns via this table permits \TEX\ to construct ligatures
576 and add inter|-|character kerning. However, normally you will use an \OPENTYPE\
577 font in combination with \LUA\ code that does this. In \CONTEXT\ we have base
578 mode that uses the engine, and node mode that uses \LUA. A mono spaced font
579 normally has no ligatures and inter character kerns and is normally not processed
580 at all.
581
582 We can group the parameters. All characters have the following base set. It must
583 be noted here that \OPENTYPE\ doesn't have a italic property and that the height
584 and depth are also not part of the design: one can choose to derive them from the
585 bounding box.
586
587 \starttabulate[|l|l|pl|]
588 \FL
589 \BC key \BC type \BC description \NC \NR
590 \ML
591 \NC \type {width} \NC number \NC width in sp (default 0) \NC \NR
592 \NC \type {height} \NC number \NC height in sp (default 0) \NC \NR
593 \NC \type {depth} \NC number \NC depth in sp (default 0) \NC \NR
594 \NC \type {italic} \NC number \NC italic correction in sp (default 0) \NC \NR
595 \LL
596 \stoptabulate
597
598 There are four parameters that are more optional and relate to advanced optical
599 paragraph optimization:
600
601 \starttabulate[|l|l|pl|]
602 \FL
603 \BC key \BC type \BC description \NC \NR
604 \ML
605 \NC \type {leftprotruding} \NC number \NC left protruding factor (\type {\lpcode}) \NC \NR
606 \NC \type {rightprotruding} \NC number \NC right protruding factor (\type {\rpcode}) \NC \NR
607 \NC \type {expansion} \NC number \NC expansion factor (\type {\efcode}) \NC \NR
608 \NC \type {compression} \NC number \NC compression factor (\type {\cfcode}) \NC \NR
609 \LL
610 \stoptabulate
611
612 The left and right protrusion factors as well as the expansion factor are
613 comparable to the ones introduced by \PDFTEX, but compression is new and
614 complements expansion. In \LUAMETATEX\ the expansion mechanism is also available
615 in math. You might have noticed that we don't have expansion related parameters
616 in the main font table. This is because we have a more dynamic model. These
617 values are anyway only used when \type {\protrudechars} and|/|or \type
618 {\adjustspacing} are set. The later can also be controlled by so called par
619 passes and thereby applied more selectively. Because setting these fields using
620 specific glyph properties can take time, it is also possible to delay these
621 settings till a dedicated callback is triggered when they are needed.
622
623 From \TEX\ we inherit the following tables. Ligatures are only used in so call
624 base mode, when the engine does the font magic. Kerns are used in base mode text
625 and optionally in math.
626
627 \starttabulate[|l|l|pl|]
628 \FL
629 \BC key \BC type \BC description \NC \NR
630 \ML
631 \NC \type {ligatures} \NC table \NC ligaturing information \NC \NR
632 \NC \type {kerns} \NC table \NC kerning information \NC \NR
633 \LL
634 \stoptabulate
635
636 The next fields control the engine and are a variant on \TEX's \TFM\ tag
637 property. In a future we might provide a bit more (local) control although
638 currently we see no need. Originally the \type {tag} and \type {next} field were
639 combined into a packed integer but in current \LUAMETATEX\ we have a 32 bit tag
640 and the next field moved to the math blob as it only is used as variant selector.
641
642 \starttabulate[|l|l|pl|]
643 \FL
644 \BC key \BC type \BC description \NC \NR
645 \ML
646 \NC \type {tag} \NC number \NC a bitset, currently not really exposed \NC\NR
647 %NC \type {reserved} \NC number \NC note for myself \NC \NR
648 \stoptabulate
649
650 In a math font characters have many more fields: \showenginekeylist
651 {font.getmathcharacterfields()}.
652
653 \starttabulate[|l|l|pl|]
654 \FL
655 \BC key \BC type \BC description \NC \NR
656 \ML
657 \NC \type {smaller} \NC number \NC the next smaller math size character \NC \NR
658 \NC \type {mirror} \NC number \NC a right to left alternative \NC \NR
659 \NC \type {flataccent} \NC number \NC an accent alternative with less height (\OPENTYPE) \NC \NR
660 \NC \type {next} \NC number \NC \quote {next larger} character index \NC \NR
661 \HL
662 \NC \type {topleft} \NC number \NC alternative script kern \NC \NR
663 \NC \type {topright} \NC number \NC alternative script kern \NC \NR
664 \NC \type {bottomleft} \NC number \NC alternative script kern \NC \NR
665 \NC \type {bottomright} \NC number \NC alternative script kern \NC \NR
666 \HL
667 \NC \type {topmargin} \NC number \NC alternative accent calculation margin \NC \NR
668 \NC \type {bottomargin} \NC number \NC alternative accent calculation margin \NC \NR
669 \NC \type {leftmargin} \NC number \NC alternative accent calculation margin \NC \NR
670 \NC \type {rightmargin} \NC number \NC alternative accent calculation margin \NC \NR
671 \HL
672 \NC \type {topovershoot} \NC number \NC accent width tolerance \NC \NR
673 \NC \type {bottomovershoot} \NC number \NC accent width tolerance \NC \NR
674 \HL
675 \NC \type {topanchor} \NC number \NC horizontal top accent alignment position \NC \NR
676 \NC \type {bottomanchor} \NC number \NC horizontal bottom accent alignment position \NC \NR
677 \HL
678 \NC \type {innerlocation} \NC string \NC \type {left} or \type {right} \NC \NR
679 \NC \type {innerxoffset} \NC number \NC radical degree horizontal position \NC \NR
680 \NC \type {inneryoffset} \NC number \NC radical degree vertical position \NC \NR
681 \HL
682 \NC \type {parts} \NC table \NC constituent parts of an extensible \NC \NR
683 \NC \type {partsitalic} \NC number \NC the italic correction applied with the extensible \NC \NR
684 \NC \type {partsorientation} \NC number \NC \type {horizontal} or \type {vertical} \NC \NR
685 \HL
686 \NC \type {mathkerns} \NC table \NC math cut-in specifications \NC \NR
687 \HL
688 \NC \type {extensible} \NC table \NC stretch a fixed width accent to fit \NC \NR
689 \LL
690 \stoptabulate
691
692 In \LUAMETATEX\ combined with \CONTEXT\ \MKXL\ we go beyond \OPENTYPE\ math and
693 have more fields here than in \LUATEX. In \CONTEXT\ those values are set with so
694 called tweaks and defined in so called font goody files. This relates to the
695 extended math rendering engine in \LUAMETATEX.
696
697 Bidirectional math is also supported and driven by (in \CONTEXT\ speak) tweaks
698 which means that it has to be set up explicitly as it uses a combination of
699 fonts. The \type {mirror} field points to an alternative glyph. The \type
700 {smaller} field points to a script glyph alternative and that glyph can then
701 point to a script script one (in \OPENTYPE\ speak \type {ssty} alternates
702 respectively one 1 and 2). In \CONTEXT\ is also uses specific features of the
703 font subsystems that hook into the backend where we have a more advanced virtual
704 font subsystem than in \LUATEX. Because this is macro package dependent it will
705 not be discussed here.
706
707 Here is the character \quote {f} (decimal 102) in the font \type {cmr10 at 10pt}.
708 The numbers that represent dimensions are in scaled points. Of course you will
709 use Latin Modern \OPENTYPE\ instead but the principles are the same:
710
711 \starttyping[option=LUA]
712 [102] = {
713 ["width"] = 200250,
714 ["height"] = 455111,
715 ["depth"] = 0,
716 ["italic"] = 50973,
717 ["kerns"] = {
718 [63] = 50973,
719 [93] = 50973,
720 [39] = 50973,
721 [33] = 50973,
722 [41] = 50973
723 },
724 ["ligatures"] = {
725 [102] = { ["char"] = 11, ["type"] = 0 },
726 [108] = { ["char"] = 13, ["type"] = 0 },
727 [105] = { ["char"] = 12, ["type"] = 0 }
728 }
729 }
730 \stoptyping
731
732 In \CONTEXT, when they are really needed, we normally turn these traditional
733 eight bit fonts into emulated \OPENTYPE\ (\UNICODE) fonts so there you will only
734 encounter tables like this when we process a font in base mode.
735
736 Two very special string indexes can be used also: \type {leftboundary} is a
737 virtual character whose ligatures and kerns are used to handle word boundary
738 processing. \type {rightboundary} is similar but not actually used for anything
739 (yet).
740
741 The values of \type {topanchor}, \type {bottomanchor} and \type {mathkern} are
742 used only for math accent and superscript placement, see \at {page} [math] in
743 this manual for details. The italic corrections are a story in themselves and
744 discussed in detail in other manuals. The additional parameters that deal with
745 kerns, margins, overshoots, inner anchoring, etc. are engine specific and not
746 part of \OPENTYPE. More information can be found in the \CONTEXT\ distribution;
747 they relate the upgraded math engine project by Mikael and Hans.
748
749 A math character can have a \type {next} field that points to a next larger
750 shape. However, the presence of \type {extensible} will overrule \type {next}, if
751 that is also present. The \type {extensible} field in turn can be overruled by
752 \type {parts}, the \OPENTYPE\ version. The \type {extensible} table is very
753 simple:
754
755 \starttabulate[|l|l|p|]
756 \FL
757 \BC key \BC type \BC description \NC \NR
758 \ML
759 \NC \type{top} \NC number \NC top character index \NC \NR
760 \NC \type{mid} \NC number \NC middle character index \NC \NR
761 \NC \type{bot} \NC number \NC bottom character index \NC \NR
762 \NC \type{rep} \NC number \NC repeatable character index \NC \NR
763 \LL
764 \stoptabulate
765
766 The \type {parts} entry is an arrays of components. Each of those components is
767 itself a hash of up to five keys:
768
769 \starttabulate[|l|l|p|]
770 \FL
771 \BC key \BC type \BC description \NC \NR
772 \ML
773 \NC \type{glyph} \NC number \NC character index \NC \NR
774 \NC \type{extender} \NC number \NC (1) if this part is repeatable, (0) otherwise \NC \NR
775 \NC \type{start} \NC number \NC maximum overlap at the starting side (scaled points) \NC \NR
776 \NC \type{end} \NC number \NC maximum overlap at the ending side (scaled points) \NC \NR
777 \NC \type{advance} \NC number \NC advance width of this item (width is default) \NC \NR
778 \LL
779 \stoptabulate
780
781 The traditional (text and math) \type {kerns} table is a hash indexed by
782 character index (and \quote {character index} is defined as either a
783 non|-|negative integer or the string value \type {rightboundary}), with the
784 values of the kerning to be applied, in scaled points.
785
786 The traditional (text) \type {ligatures} table is a hash indexed by character
787 index (and \quote {character index} is defined as either a non|-|negative integer
788 or the string value \type {rightboundary}), with the values being yet another
789 small hash, with two fields:
790
791 \starttabulate[|l|l|p|]
792 \FL
793 \BC key \BC type \BC description \NC \NR
794 \ML
795 \NC \type{type} \NC number \NC the type of this ligature command (default 0) \NC \NR
796 \NC \type{char} \NC number \NC the character index of the resultant ligature \NC \NR
797 \LL
798 \stoptabulate
799
800 The \type {char} field in a ligature is required. The \type {type} field inside a
801 ligature is the numerical or string value of one of the eight possible ligature
802 types supported by \TEX. When \TEX\ inserts a new ligature, it puts the new glyph
803 in the middle of the left and right glyphs. The original left and right glyphs
804 can optionally be retained, and when at least one of them is kept, it is also
805 possible to move the new \quote {insertion point} forward one or two places. The
806 glyph that ends up to the right of the insertion point will become the next
807 \quote {left}.
808
809 \starttabulate[|l|c|l|l|]
810 \FL
811 \BC textual (Knuth) \BC number \BC string \BC result \NC \NR
812 \ML
813 \NC \type{l + r =: n} \NC 0 \NC \type{=:} \NC \type{|n} \NC \NR
814 \NC \type{l + r =:| n} \NC 1 \NC \type{=:|} \NC \type{|nr} \NC \NR
815 \NC \type{l + r |=: n} \NC 2 \NC \type{|=:} \NC \type{|ln} \NC \NR
816 \NC \type{l + r |=:| n} \NC 3 \NC \type{|=:|} \NC \type{|lnr} \NC \NR
817 \NC \type{l + r =:|> n} \NC 5 \NC \type{=:|>} \NC \type{n|r} \NC \NR
818 \NC \type{l + r |=:> n} \NC 6 \NC \type{|=:>} \NC \type{l|n} \NC \NR
819 \NC \type{l + r |=:|> n} \NC 7 \NC \type{|=:|>} \NC \type{l|nr} \NC \NR
820 \NC \type{l + r |=:|>> n} \NC 11 \NC \type{|=:|>>} \NC \type{ln|r} \NC \NR
821 \LL
822 \stoptabulate
823
824 The default value is~0, and can be left out. That signifies a \quote {normal}
825 ligature where the ligature replaces both original glyphs. In this table the~\type {|}
826 indicates the final insertion point.
827
828 The third table has the \type {MathConstants} as the camel case name suggests.
829 These are not discussed here. The \type {fonts} table relates to virtual fonts
830 that are discussed later.
831
832 \stopsection
833
834 \startsection[title=Helpers]
835
836 Without argument this function returns the current font identifier and when
837 an identifier is passed that one is made current.
838
839 \starttyping [option=LUA]
840 function font.current ( <t:nil> | <t:integer> )
841 -- no return value
842 end
843 \stoptyping
844
845 This returns the maximum font identifier in use:
846
847 \starttyping [option=LUA]
848 function font.max ( )
849 return <t:integer> -- identifier
850 end
851 \stoptyping
852
853 This one defines a font but needs an identifier, for instance reserved by \type
854 {font.nextid}. The table is the same as with \type {font.define}.
855
856 \starttyping [option=LUA]
857 function font.setfont ( <t:integer> identifier, <t:table> data )
858 -- no return value
859 end
860 \stoptyping
861
862 The next function can be used to add characters to a font. The table is the same
863 as the table used when defining the characters in a font. The identifier must be
864 known.
865
866 \starttyping [option=LUA]
867 function font.addcharacters ( <t:integer> identifier, <t:table> characters )
868 -- no return value
869 end
870 \stoptyping
871
872 When protrusion or expansion data is needed for a character in a font and the
873 relevant values are not yet known, a callback can be triggered and the next function
874 can then be used to assign these.
875
876 \starttyping [option=LUA]
877 function font.addquality (
878 <t:integer> identifier,
879 <t:table> characters
880 )
881 -- no return value
882 end
883 \stoptyping
884
885 The table looks like this:
886
887 \starttyping [option=LUA]
888 {
889 [index] = {
890 leftprotrusion = <t:integer>,
891 rightprotrusion = <t:integer>,
892 expansion = <t:integer>,
893 compression = <t:integer>,
894 },
895 ...
896 }
897 \stoptyping
898
899 Sometimes it can be handy to check what the next identifier will be. The optional
900 boolean, when true, makes that the font is allocated.
901
902 \starttyping [option=LUA]
903 function font.nextid ( <t:nil> | <t:boolean> )
904 return <t:integer> -- identifier
905 end
906 \stoptyping
907
908 This function does a lookup by name and returns the font identifier when it's
909 known:
910
911 \starttyping [option=LUA]
912 function font.id ( <t:string> name )
913 return <t:integer> -- identifier
914 end
915 \stoptyping
916
917 The value that gets returned or is assigned is always an integer because that is
918 what these parameters are: scaled dimensions, percentages, factors.
919
920 \starttyping [option=LUA]
921 function font.getfontdimen (
922 <t:integer> identifier,
923 <t:integer> parameter
924 )
925 return <t:integer> -- value
926 end
927 \stoptyping
928
929 \starttyping [option=LUA]
930 function font.setfontdimen (
931 <t:integer> identifier,
932 <t:integer> parameter,
933 <t:integer> value
934 )
935 -- no return value
936 end
937 \stoptyping
938
939 This one returns the properties that relate to a \type {\fontspecdef}:
940
941 \starttyping [option=LUA]
942 function font.getfontspec ( <t:string> name )
943 return
944 <t:integer>, -- identifier
945 <t:integer>, -- scale
946 <t:integer>, -- xscale
947 <t:integer>, -- yscale
948 <t:integer>, -- slant
949 <t:integer> -- weight
950 end
951 \stoptyping
952
953 Math characters are not really defined along with a font but their family can
954 bind them to one. However, in \CONTEXT\ we have them decoupled and families are
955 assigned fonts when the need is there.
956
957 \starttyping [option=LUA]
958 function font.getmathspec ( )
959 return
960 <t:integer>, -- class
961 <t:integer>, -- family
962 <t:integer> -- character
963
964 end
965 \stoptyping
966
967 Internally a math font parameter has a number. This function returns that number
968 plus a boolean indicating if we have an variable that is not officially in
969 \OPENTYPE\ math but an addition to the \LUAMETATEX\ engine.
970
971 \starttyping [option=LUA]
972 function font.getmathindex ( <t:string> | <t:number> )
973 return
974 <t:number> -- index
975 <t:boolean> -- engine
976 end
977 \stoptyping
978
979 These two don't operate on a font but multiply the given value by the \type
980 {\glyphscale} and \type {\glyphxscale} respectively
981 \type {\glyphyscale}.
982
983 \starttyping [option=LUA]
984 function font.xscaled ( <t:number> value)
985 return <t:number> -- scaled value
986 end
987 \stoptyping
988
989 \starttyping [option=LUA]
990 function font.yscaled ( <t:number> value)
991 return <t:number> -- scaled value
992 end
993 \stoptyping
994
995 Like in other places the engine can report what fields we have, which is handy
996 when we want to check manuals like this one.
997
998 \starttyping [option=LUA]
999 function font.getparameterfields ( ) return <t:table> end
1000 function font.getfontfields ( ) return <t:table> end
1001 function font.gettextcharacterfields ( ) return <t:table> end
1002 function font.getmathcharacterfields ( ) return <t:table> end
1003 \stoptyping
1004
1005 \stopsection
1006
1007 \startsection[title={Virtual fonts}]
1008
1009 Virtual fonts have been introduced in \TEX\ because they permit combining fonts
1010 and constructing for instance accented characters from several glyphs and they
1011 are what one nowadays tags as a \quote {cool} feature, especially because in
1012 \LUATEX\ we can use this mechanism runtime. The nice thing is that because all
1013 that \TEX\ needs is dimensions, the hard work is delegated to the backend which
1014 means that the front end can be agnostic when it comes to virtual fonts.
1015
1016 So, in the beginning they were mostly used for providing a direct mapping from
1017 for instance accented characters onto a glyph btu we use it for a lot of other
1018 situations, like math. But keep in mind that because we basically define the
1019 backend ourselves and because we also control everything fonts, we can go way
1020 further in \CONTEXT\ than in other engines and macro packages.
1021
1022 A character is virtual when it has a \type {commands} array as part of the data.
1023 A virtual character can itself point to virtual characters but be careful with
1024 nesting as you can create loops and overflow the stack (which often indicates an
1025 error anyway).
1026
1027 At the font level there can be a an (indexed) \type {fonts} table. The values are
1028 one- or two|-|key hashes themselves, each entry indicating one of the base fonts
1029 in a virtual font. In case your font is referring to itself in for instance a
1030 virtual font, you can use the \type {slot} command with a zero font reference,
1031 which indicates that the font itself is used. So, a table looks like this:
1032
1033 \starttyping
1034 fonts = {
1035 { name = "ptmr8a", size = 655360 }, -- referenced as font 1
1036 { name = "psyr", size = 600000 }, -- referenced as font 2
1037 { id = 38 } -- referenced as font 3
1038 }
1039 \stoptyping
1040
1041 The first referenced font (at index~1) in this virtual font is \type {ptrmr8a}
1042 loaded at 10pt, and the second is \type {psyr} loaded at a little over 9pt. The
1043 third one is a previously defined font that is known to \LUAMETATEX\ as font
1044 id~38. The array index numbers are used by the character command definitions that
1045 are part of each character.
1046
1047 However, the only place in \CONTEXT\ where we really need this \type {fonts}
1048 table is in some math fonts where we, also as illustration and as recognition of
1049 past work, assemble a \UNICODE\ math font from sort of obsolete \TYPEONE\ fonts.
1050 In most cases the virtual glyphs use glyphs that are also in the font. In that
1051 case we can use \type {id} zero which is resolved to the font identifiers of the
1052 font itself.
1053
1054 The \type {commands} array is a hash where each item is another small array, with
1055 the first entry representing a command and the extra items being the parameters
1056 to that command. The frontend is only interested in the dimensions, ligatures and
1057 kerns of a font, which is the reason why the \TEX\ engine didn't have to be
1058 extended when virtual fonts showed up: dealing with it is up to the driver that
1059 comes after the backend. The first block in the next table is what the standard
1060 mentions. These two engines also support the \type {special} and \LUATEX\ brings
1061 the \type {pdf} and \type {pdfmode} commands but in \LUAMETATEX\ we dropped all
1062 three and also \LUATEX's \type {image}.
1063
1064 But \unknown\ in \LUAMETATEX\ there is no backend built in but we might assume
1065 that the one provided deals with the standard entries. However, a provided
1066 backend can provide more and that is indeed what happens in \CONTEXT. Because we
1067 no longer have compacting (of passed tables) and unpacking (when embedding) of
1068 these tables going on we stay in the \LUA\ domain. None of the virtual
1069 specification is ever seen in the engine.
1070
1071 \starttabulate[|l|l|l|p|]
1072 \FL
1073 \BC command \BC arguments \BC type \BC description \NC \NR
1074 \ML
1075 \NC \type{font} \NC 1 \NC number \NC select a new font from the local \type {fonts} table \NC \NR
1076 \NC \type{char} \NC 1 \NC number \NC typeset this character number from the current font,
1077 and move right by the character's width \NC \NR
1078 \NC \type{slot} \NC 2 \NC 2 numbers \NC a shortcut for the combination of a font and char command\NC \NR
1079 \NC \type{push} \NC 0 \NC \NC save current position\NC \NR
1080 \NC \type{pop} \NC 0 \NC \NC pop position \NC \NR
1081 \NC \type{rule} \NC 2 \NC 2 numbers \NC output a rule $ht*wd$, and move right. \NC \NR
1082 \NC \type{down} \NC 1 \NC number \NC move down on the page \NC \NR
1083 \NC \type{right} \NC 1 \NC number \NC move right on the page \NC \NR
1084 \HL
1085 \NC \type{nop} \NC 0 \NC \NC do nothing \NC \NR
1086 \NC \type{node} \NC 1 \NC node \NC output this node (list), and move right
1087 by the width of this list\NC \NR
1088 \NC \type{lua} \NC 1 \NC string,
1089 function \NC execute a \LUA\ script when the glyph is embedded; in case of a
1090 function it gets the font id and character code passed \NC \NR
1091 \NC \type{comment} \NC any \NC any \NC the arguments of this command are ignored \NC \NR
1092 \LL
1093 \stoptabulate
1094
1095 The default value for \type {font} is always~1 at the start of the \type
1096 {commands} array. Therefore, if the virtual font is essentially only a
1097 re|-|encoding, then you do usually not have created an explicit \quote {font}
1098 command in the array. Rules inside of \type {commands} arrays are built up using
1099 only two dimensions: they do not have depth. For correct vertical placement, an
1100 extra \type {down} command may be needed. Regardless of the amount of movement
1101 you create within the \type {commands}, the output pointer will always move by
1102 exactly the width that was given in the \type {width} key of the character hash.
1103 Any movements that take place inside the \type {commands} array are ignored on
1104 the upper level.
1105
1106 In addition to the above in \CONTEXT\ we have \type {use}, \type {left}, \type
1107 {up}, \type {offset}, \type {stay}, \type {compose}, \type {frame}, \type {line},
1108 \type {inspect}, \type {trace} and a plugin feature so that we can add more
1109 commands (which we do). These not only provide more advanced trickery but also
1110 make for smaller command tables. For some features we don't even need virtual
1111 magic but have additional parameters in the glyph tables. But all that is not
1112 part of the engine and its specification so it will be discussed elsewhere.
1113
1114 \stopsection
1115
1116 \startsection[title={Callbacks}]
1117
1118 The traditional \TEX\ ligature and kerning routines are build into the engine but
1119 anything more (like \OPENTYPE\ rendering) has to be implemented in \LUA. The same
1120 is true for math: the engine has some expectations, for instance with respect to
1121 script and script script sizes, larger sizes and extensibles and needs to know at
1122 least dimensions and slots in fonts in order to assemble the math. Actually there
1123 are additional scaling factors in play here because math has its own scaling
1124 demands.
1125
1126 \stopsection
1127
1128 \startsection[title=Protrusion]
1129
1130 This is more an implementation note. Compared to \PDFTEX\ and \LUATEX\ the
1131 protrusion detection mechanism is enhanced a bit to enable a bit more complex
1132 situations. When protrusion characters are identified some nodes are skipped:
1133
1134 \startitemize[packed,columns,two]
1135 \startitem zero glue \stopitem
1136 \startitem penalties \stopitem
1137 \startitem empty discretionaries \stopitem
1138 \startitem normal zero kerns \stopitem
1139 \startitem rules with zero dimensions \stopitem
1140 \startitem math nodes with a surround of zero \stopitem
1141 \startitem dir nodes \stopitem
1142 \startitem empty horizontal lists \stopitem
1143 \startitem local par nodes \stopitem
1144 \startitem inserts, marks and adjusts \stopitem
1145 \startitem boundaries \stopitem
1146 \startitem whatsits \stopitem
1147 \stopitemize
1148
1149 Because this can not be enough, you can also use a protrusion boundary node to
1150 make the next node being ignored. When the value is~1 or~3, the next node will be
1151 ignored in the test when locating a left boundary condition. When the value is~2
1152 or~3, the previous node will be ignored when locating a right boundary condition
1153 (the search goes from right to left). This permits protrusion combined with for
1154 instance content moved into the margin:
1155
1156 \starttyping
1157 \protrusionboundary1\llap{!\quad}«Who needs protrusion?»
1158 \stoptyping
1159
1160 \stopsection
1161
1162 \startsection[title=Spaces]
1163
1164 There are officially no spaces in \TEX, there is only glue. This is not problem,
1165 on the contrary, it is what makes the rendering so good. In \CONTEXT\ the backend
1166 can convert glue to spaces in a font but that's not an engine feature.
1167
1168 The \type {\nospaces} primitive can be used to overrule the usual \type
1169 {\spaceskip} related heuristics when a space character is seen in a text flow.
1170 The value~\type{1} triggers no injection while \type{2} results in injection of a
1171 zero skip. In \in {figure} [fig:nospaces] we see the results for four characters
1172 separated by a space.
1173
1174 \startplacefigure[reference=fig:nospaces,title={The \type {nospaces} options.}]
1175 \startcombination[3*2]
1176 {\ruledhbox to 5cm{\vtop{\hsize 10mm\nospaces=0\relax x x x x \par}\hss}} {\type {0 / hsize 10mm}}
1177 {\ruledhbox to 5cm{\vtop{\hsize 10mm\nospaces=1\relax x x x x \par}\hss}} {\type {1 / hsize 10mm}}
1178 {\ruledhbox to 5cm{\vtop{\hsize 10mm\nospaces=2\relax x x x x \par}\hss}} {\type {2 / hsize 10mm}}
1179 {\ruledhbox to 5cm{\vtop{\hsize 1mm\nospaces=0\relax x x x x \par}\hss}} {\type {0 / hsize 1mm}}
1180 {\ruledhbox to 5cm{\vtop{\hsize 1mm\nospaces=1\relax x x x x \par}\hss}} {\type {1 / hsize 1mm}}
1181 {\ruledhbox to 5cm{\vtop{\hsize 1mm\nospaces=2\relax x x x x \par}\hss}} {\type {2 / hsize 1mm}}
1182 \stopcombination
1183 \stopplacefigure
1184
1185 \start \showmakeup[space]
1186 You can, in \CONTEXT\ see where spaces are added by enabling a visualizer: \type
1187 {\showmakeup [space]} does the trick, as in this paragraph. We see
1188 regular spaces as well as spaces that have a space factor applied (after
1189 punctuation).
1190 \stop
1191
1192 \stopsection
1193
1194 \stopdocument