Debian Codegraph @

doc/sphinx/ui/dialogs/lookups.rst

raw
1 Manipulating OpenType Lookups
2 =============================
3
4 .. figure:: /images/fontinfo-lookups.png
5
6 .. epigraph::
7
8 "The question is," said Humpty Dumpty, "which is to be master --" *(you or
9 the word)*
10
11 -- Through the Looking-Glass -- Lewis Carroll
12
13 You use the Lookups pane of the :doc:`Element->Font Info <fontinfo>` command to
14 control OpenType lookups.
15
16 A lookup is a collection of commands that provide a text layout program with a
17 transformation to apply on the input glyph stream. A lookup might specify how to
18 form ligatures or how to do kerning, or any of a number of other things.
19
20 Every lookup is composed of a number of subtables. Often this complexity is not
21 needed and many lookups will contain just one subtable.
22
23 Every lookup is named and every subtable is named. No two lookups may have the
24 same name, nor may any two subtables.
25
26 There are two major classes of lookups, those that reside in the GSUB table and
27 substitute one glyph (or several) with another (ligatures) and those which live
28 in the GPOS table and position one glyph relative to another (kerning).
29
30 The order in which the lookups and subtables appear in this dialog is important.
31 This is the same order in which they will be applied. All lookups in the GSUB
32 table will be applied before any lookups in the GPOS table.
33
34 There are buttons on the side for reordering the lookups. Up, Down, Top, Bottom
35 should be obvious. You can also drag and drop lookups to reorder them. The
36 [Sort] button will sort lookups depending on the canonical order of the
37 features attached to them. This will not always be the desired ordering, but it
38 is a place to start.
39
40 Lookups are applied in the order listed here. Which lookups will be applied
41 depends on the script, language, and what features have been enabled (this will
42 be controlled by the text layout engine, and perhaps ultimately by the user).
43
44 Within a lookup, the subtables will be applied in order until one of them
45 actually does something. Then no further subtables will be executed. Note that
46 this is different from the way lookups behave -- all active lookups will always
47 be applied, but only one subtable in a lookup will be.
48
49 Suppose for example that you have a kerning class, and a few kerning pairs. If
50 you put both of these into one lookup, with the kerning pairs in the first
51 subtable and the kerning class in the second, then if a kerning pair matches the
52 input stream the kerning class will not be applied (so you can have special
53 cases that override the data in the kerning class).
54
55 On the other hand if you put the pairs in one lookup, and the kerning class in
56 another lookup, then both would be applied. And the resultant motion would be
57 the sum of the two.
58
59 .. _lookups.Add-Lookup:
60
61 .. image:: /images/lookup-metadata.png
62 :align: left
63
64 The ``[Add Lookup]`` and ``[Edit Metadata]`` buttons will bring up a dialog that
65 allows you to control the attributes of the lookup. Every lookup has a lookup
66 type (here "Single Substitution") which specifies broadly what kinds of things
67 this lookup can do.
68
69 .. container:: clearer
70
71 ..
72
73 :ref:`Single Substitution <lookups.basic-subs>`
74
75 Substitute exactly one glyph with another.
76
77 :ref:`Multiple Substitution <lookups.basic-subs>`
78
79 Substitutes exactly one glyph with several others.
80
81 :ref:`Alternate Substitution <lookups.basic-subs>`
82
83 Provides the user with a choice of substitute glyphs for each glyph.
84
85 :ref:`Ligature Substitution <lookups.basic-subs>`
86
87 Substitutes multiple glyphs with a single one
88
89 :ref:`Contextual Substitution <lookups.contextual-subs>`
90
91 Performs substitutions depending on the glyphs around the current one
92
93 :ref:`Contextual Chaining Substitutions <lookups.contextual-subs>`
94
95 A more complicated way of performing contextual substitutions
96
97 :ref:`Reverse Contextual Chaining Substitutions <lookups.contextual-subs>`
98
99 For arabic scripts where substitutions need to be done backwards.
100
101 :ref:`Mac Indic State Machine <lookups.sm-subs>`
102
103 (Not an OpenType lookup at all, but one for Apple's Advanced typography
104 tables -- rearranges indic glyphs)
105
106 :ref:`Mac Contextual State Machine <lookups.sm-subs>`
107
108 (Not an OpenType lookup at all, but one for Apple's Advanced typography
109 tables -- contextual substitutions)
110
111 :ref:`Mac Insertion State Machine <lookups.sm-subs>`
112
113 (Not an OpenType lookup at all, but one for Apple's Advanced typography
114 tables -- contextually inserts glyphs)
115
116 --------------------------------------------------------------------------------
117
118 :ref:`Single Positioning <lookups.Single-pos>`
119
120 Moves a single glyph around
121
122 :ref:`Pair Positioning (kerning) <lookups.Pair>`
123
124 Moves two glyphs relative to each other
125
126 :ref:`Cursive Positioning <lookups.Anchor>`
127
128 For Urdu and other similar scripts. Positions one glyph at the appropriate
129 anchor point relative to another.
130
131 :ref:`Mark to Base Positioning <lookups.Anchor>`
132
133 Positions a mark (or accent) relative to a base letter
134
135 :ref:`Mark to Ligature Positioning <lookups.Anchor>`
136
137 Positions a mark relative to ta ligature
138
139 :ref:`Mark to Mark Positioning <lookups.Anchor>`
140
141 Positions a mark relative to another mark.
142
143 :ref:`Contextual Positioning <lookups.contextual-pos>`
144
145 Positions glyphs depending on other glyphs around them
146
147 :ref:`Contextual chaining Positioning <lookups.contextual-pos>`
148
149 A more complex form of the above.
150
151 :ref:`Mac Kerning State Machine <lookups.sm-kern>`
152
153 (Not an OpenType lookup at all, but one for Apple's Advanced typography
154 tables -- contextual kerning)
155
156 A lookup may be associated with one or more feature tags each of which may be
157 active for various scripts and languages. You may edit the feature tag directly,
158 or you may click on the little box and get a list of feature tags identified by
159 their "friendly names" (so instead of 'smcp' you would see "Lowercase to Small
160 Capitals").
161
162 Similarly you may edit the script and language list directly, or you may press
163 on the rectangle to get a friendlier dialog (see
164 :ref:`below <lookups.scripts-dlg>`).
165
166 Every lookup is associated with a set of flags which control its behavior. The
167 "Mark Class:" field is only active if there are
168 :ref:`Mark Classes <fontinfo.MarkClass-MarkSets>` defined, and the "Mark Set:" field is
169 active if there are :ref:`Mark Sets <fontinfo.MarkClass-MarkSets>` defined. Mark classes
170 and sets are very similar, with mark sets being the newer (largely unsupported
171 as I write in spring 2009) but more versatile of the two. These provide an
172 extension of the Ignore Marks flag -- if you specify a mark class (or set) then
173 all marks will be ignored except those in the class (or set).
174
175 Every lookup must be named. You may assign the name as you wish -- except that
176 it must not be blank and must be unique. No two lookups may have the same name.
177 (If you intend to use feature files, then lookup names should be: less than 31
178 characters, composed of ASCII alphanumerics, underscores and periods -- no
179 spaces).
180
181 For ligatures you have the option of specifying whether you want these ligatures
182 output in an afm file.
183
184 .. _lookups.scripts-dlg:
185
186 .. image:: /images/lang-dlg.png
187 :align: right
188
189 .. image:: /images/script-lang-dlg.png
190 :align: left
191
192 The script dialog allows you to enter scripts and languages. Again you may edit
193 these directly or press on the little rectangles to get a list of friendly
194 names. If you choose to bring up the language dialog you may choose more than
195 one language in it (use the control key to make disjoint selections).
196
197 After you have created a lookup you may add subtables to it. In most cases you
198 will only need to create one subtable, but for contextual or kerning lookups you
199 may need two or more (the second would contain a set of kerning classes, while
200 the first would contain any special cases).
201
202 The ``[Add Subtable]`` button will prompt you to name the new subtable, and will
203 then bring up a dialog to allow you to edit the commands, the data, of that
204 subtable. You may also bring up this dialog by selecting an existing subtable
205 and double clicking on it (or by pressing the ``[Edit Data]`` button). The
206 format of the dialog will depend on the lookup type.
207
208 .. rubric:: Basic substitutions
209
210 .. flex-grid::
211 :name: lookups.basic-subs
212
213 * - .. figure:: /images/subtable-gsub-single.png
214 :alt: GSUB single glyph substitution
215
216 GSUB single glyph substitution dialog
217 - .. figure:: /images/subtable-gsub-ligature.png
218
219 GSUB ligature substitution dialog
220
221 Many of the basic substitution dialogs are very similar. Most of the dialog
222 contains a list glyph names (one per line) on the left, and a list of
223 substitution glyph names on the right. So in the example above left, the 'smcp'
224 feature will map the glyph named "a" to the glyph named "a.sc", "b" to "b.sc"
225 and so on. The multiple and alternate substitution dialogs allow a list of
226 replacement glyph names on the right. In a multiple substitution the glyph will
227 be replaced with all the glyphs named on the left, while in an alternate
228 substitution the word processor will provide the user with a menu from which to
229 pick a glyph. The ligature substitution is backwards in that the replacement
230 glyph is the one on the left -- if the glyphs on the right appear together and
231 in order then they will be replaced with the glyph on the left. So if an "f" is
232 followed by an "f" then it will be replaced by an "ff" ligature glyph.
233
234 The ``[Populate]`` button will fill the dialog with all glyphs in any of the
235 scripts for which this dialog is active. If FontForge can figure out a default
236 replacement glyph then it will in provide that as the default value (if it can't
237 figure out a good replacement it will just leave the right side blank).
238
239 The ``[Add Selected]`` button works in much the same way, but will only add
240 glyphs selected in the font view.
241
242 The ``[Default Using Suffix:]`` button will behave similarly (except it will
243 only insert entries for which FontForge can find a replacement, and glyph name
244 of that replacement will be found by appending the specified suffix to the glyph
245 name of the base glyph).
246
247 The ``[Remove Empty]`` button will remove any entries with no replacement
248 glyph(s). The ``[Delete]`` button will delete the currently selected row.
249
250 The various radio buttons and check boxes at the top of the dialog control how
251 the base glyphs are ordered in the display -- either in <>Alphabetic order (by
252 glyph name) or in Unicode code point order. If [] By Base Char is checked then
253 composed characters like "Egrave" will be ordered closer to "E" than to "Eth".
254 If [] By Scripts is checked then glyphs of one script system will be grouped
255 together no matter how they are ordered alphabetically or unicodally, thus "A"
256 would be grouped with "B" and not with "Alpha".
257
258
259 .. _lookups.contextual-subs:
260
261 Contextual substitutions
262 ------------------------
263
264 The contextual substitution dialog is quite complicated and is discussed in its
265 :doc:`own section <contextchain>`. These lookups can only live in an OpenType
266 font, not in an Apple Advanced Typography font.
267
268
269 .. _lookups.sm-subs:
270
271 Substitution by State Machine
272 -----------------------------
273
274 The state machine substitution dialog is quite complicated and is discussed in
275 its :doc:`own section <statemachine>`. These lookups can only live in an Apple
276 Advanced Typography font.
277
278 .. rubric:: Single Positioning
279
280 .. flex-grid::
281 :name: lookups.Single-pos
282
283 * - .. image:: /images/subtable-gpos-singlehide.png
284 - .. image:: /images/subtable-gpos-singlefull.png
285
286 The single glyph positionioning lookup can potentially be quite complex, but
287 generally in any specific case very little of that complexity is used and the
288 dialog can be simplified. The lookup allows four different adjustments to each
289 glyph:
290
291 #. The glyph may be moved left or right by a certain number of em-units
292 #. The glyph may be moved up or down by a certain number of em-units
293 #. The glyph's horizontal advance width may be altered by a certain number of
294 em-units
295 #. In fonts with vertical metrics a glyph's vertical advance may be altered by a
296 certain number of em-units
297
298 In addition to this you may provide pixel adjustments that apply to specific
299 point sizes. At small pixel sizes (such as those used for screen fonts) the
300 rounding error introduced by converting from em-units to pixels may be as large
301 as the movement itself. In the example at right, if the 'subs' feature is
302 applied to the glyph "a.sinf" that glyph should be moved downward by -560
303 em-units. Then if the pixel-size of the rasterization is 10 pixels, it should be
304 moved down a further pixel, while if the pixel-size is 12 it should be moved up
305 a pixel.
306
307 The [] Hide Unused Columns check box will toggle between the two views above
308 (well, not quite, I added two device table adjustments in the image on the
309 right, so the adjustment column would remain after checking the checkbox).
310
311 Often all the adjustments in a subtable will be the same (the ones here are) so
312 the [*] Default new entries to first check box will give all new entries the
313 same value as the first line.
314
315
316 .. _lookups.Pair:
317
318 Pair Positioning (kerning)
319 --------------------------
320
321
322 Kerning format dialog
323 ^^^^^^^^^^^^^^^^^^^^^
324
325 .. image:: /images/kerningformat.png
326 :align: right
327
328 When you create a kerning subtable you will first be asked whether you want to
329 create a kerning class subtable, or a kerning subtable with a list of glyph
330 pairs.
331
332 In either case, FontForge will ask if you want to it to automagically fill up
333 the sub-table with guesses at appropriate kerning values. This is called
334 "autokern"ing.
335
336 In addition, FontForge can guess appropriate glyph classes for kerning by
337 classes.
338
339 If you aren't interested in autokerning and want to do everything by hand, most
340 of this dialog is irrelevant, you are only interested in the two radio buttons
341 at the top and the [OK] button at the bottom.
342
343 But if you are interested in autokerning, you need to tell FontForge how closely
344 it should kern glyphs, and what glyphs to kern. In addition if you want
345 FontForge to pick kerning classes for you, you must specify the maximum
346 allowable amount of cumuliative error between two glyphs before they must be in
347 separate classes.
348
349 The ``Default Separation`` and ``Min Kern`` fields are used in AutoKerning. The
350 goal of kerning to to make the optical separation between all glyphs to be
351 constant, and the ``Default Separation`` field specifies that desired value. The
352 ``Min Kern`` value is simply to prevent the dialog from filling with useless
353 junk. If AutoKerning suggests that two glyphs should be kerned by 1 em unit then
354 this won't make any difference to the human eye and there is no point in
355 including it. So if the kerning value (in absolute value) suggested by AutoKern
356 is less than ``Min Kern`` then fontforge will ignore that value. Selecting
357 ``[] Touching`` makes AutoKerning work in a slightly different way, instead of
358 trying to make the optical distance be the desired value this attempts to make
359 the minimum separation be the desired value (This is rarely useful, but
360 occasionally people want to set text where the letters actually touch one
361 another). The ``[] Only kern glyphs closer`` flag means that FontForge will only
362 generate negative kerning offset, which will move glyphs closer together.
363
364 Below these fields are two panes which look rather like fontviews. Here you may
365 specify the selections you want to describe the glyphs being autokerned. There
366 are two of these panes because you usually have a slightly different set of
367 glyphs of interest on the left and right sides of a kerning pair. In English, a
368 capital letter will rarely occur in the middle of a word, so you don't need it
369 on the right side of a kerning pair. (Of course there are exceptions:
370 "FontForge" uses an internal capital, but that is rare and if you want to save
371 space in your font tables you can ignore it). Similarly the closing quote
372 character will almost never be on the left side of a kerning pair.
373
374
375 Kerning pairs
376 ^^^^^^^^^^^^^
377
378 .. figure:: /images/subtable-gpos-kernpair.png
379
380 The kerning class dialog is described in its
381 :ref:`own section <metricsview.kernclass>`, while the kerning pair subtable
382 dialog is described below.
383
384 Each entry in the dialog specifies a pair of glyphs and then adjustments that
385 may be made to each of those glyphs. Each glyph may be adjusted by any (or all)
386 of the four adjustments mentioned above, so there are eight potential
387 adjustments (and possibly device tables for each of those).
388
389 In practice kerning tends to use only one of those 8 adjustments. For left to
390 right text this is generally the horizontal advance of the first glyph
391 (x_adv#1), for right to left kerning the horizontal advance of the second glyph
392 is used instead, and for vertical top to bottom text the vertical advance of the
393 first glyph (y_adv#1). Again, the [] Hide Unused Columns may be used to simplify
394 the dialog.
395
396 Each time you enter a new combination, FontForge will try to guess a kerning
397 offset for you (autokerning). So the ``Separation`` text fields have a similar
398 meaning to that which they had above -- with the exception that the ``Min Kern``
399 and ``Only kern closer`` fields will be ignored for individual pairs.
400
401 For more elaborate usage, ``[AutoKern]`` button will look at all combinations of
402 glyphs in all scripts in the feature attached to this lookup. The
403 ``[AutoKern Selected]`` button will look at all combinations of glyphs which are
404 selected in the fontview (Neither of these will override existing combinations).
405
406 Below the value matrix is a visual display of the currently selected kerning
407 pair. You may adjust the kerning value by moving the second glyph around.
408
409 You may select a pixel size at which to rasterize your glyphs. You may also
410 request to see that rasterization magnified (Note: This is different from just
411 rasterizing at twice the pixelsize, each pixel will be twice as big and the
412 effects of rounding errors will be more obvious). Magnification is probably only
413 useful if you are working on device tables for screen pixelsizes.
414
415
416 .. _lookups.lookups-undoes:
417
418 Undo System Interaction
419 ^^^^^^^^^^^^^^^^^^^^^^^
420
421 Changes made to kerning pairs are tracked by a font level undo system. If you
422 have made no changes to the lookup then no new undo record will be created. The
423 undo system will track only the minimal amount of information needed to recreate
424 the old kerning table. This is useful when you are editing a very complex
425 kerning table which might have thousands of kerning pairs and requires many
426 megabytes of storage just for the kerning table.
427
428 The font level undo system will allow you to undo all of the edits you have made
429 in a single interaction with the kerning class dialog. For simplicity, let us
430 consider the scenario where you open the kerning class dialog and edit a few
431 kerning pairs, then select the OK button. We will refer to this as a single
432 "round" of editing.
433
434 If you have only changed two pairs in a round of editing then only two pairs are
435 remembered by the undo system so that the kerning table can be restored to how
436 it was before your performed this last round of edits.
437
438 To undo the changes you have made in a round, select the Undo Font Level menu
439 option from the edit menu in the font view window.
440
441
442 .. _lookups.Anchor:
443
444 Anchor Positioning
445 ------------------
446
447 .. image:: /images/subtable-gpos-anchor.png
448 :align: left
449
450 Marks (diacritical accents, vowel marks, etc.) may be attached to base glyphs
451 using anchors. In the latin script, the grave, accute and circumflex accents
452 might all attach to their base glyph at the same point, so these would all live
453 in one anchor class. The dot below accent attaches at a different point and
454 would need a different class.
455
456 You may create as many anchor classes as you like. One mark may not be in
457 multiple attachment classes, but a base glyph may.
458
459 Anchor classes may also be used in cursive systems such as Urdu where the text
460 slopes up the page. Each glyph has an entry point and an exit point, and the
461 entry of a glyph will be attached to the exit of the preceding glyph.
462
463 Marks may also be attached to marks. Vietnamese will often stack accents on top
464 of one another.
465
466 Finally, ligatures may have several attachment sites, one for each ligature
467 component.
468
469 .. image:: /images/anchorcontrol-base.png
470 :align: right
471
472 The above dialog may be used to create a set of classes for each type of anchor
473 subtable, then click on the :doc:`[Anchor Control...] <anchorcontrol>` button to
474 view the marks anchored to bases glyphs.
475
476 One glyph is selected (in this case a base) and its anchor point is displayed
477 relative to it (the blue star in the first pane after the controls). Subsequent
478 panes show all possible mark attachments.
479
480 You may adjust the pixelsize of the display and the magnification factor (again
481 the magnification factor is most useful if you are looking at small pixelsizes.
482
483 You may provide device table adjustments for each pixelsize.
484
485
486 .. _lookups.contextual-pos:
487
488 Contextual Positioning
489 ^^^^^^^^^^^^^^^^^^^^^^
490
491 The contextual substitution dialog is quite complicated and is discussed in its
492 :doc:`own section <contextchain>`. These lookups can only live in an OpenType
493 font, not in an Apple Advanced Typography font.
494
495
496 .. _lookups.sm-kern:
497
498 Kerning by State Machine
499 ^^^^^^^^^^^^^^^^^^^^^^^^
500
501 The state machine substitution dialog is quite complicated and is discussed in
502 its :doc:`own section <statemachine>`. These lookups can only live in an Apple
503 Advanced Typography font.