# Editing Contextual or Chaining Contextual features

## What is a Contextual Positioning feature?

There are two types of contextual positioning modes: Contextual Positioning and Chained Contextual Positioning. In the simplest form of the first you may specify a list glyphs and specify repositioning to occur if that sequence is matched. For example you might specify (in English)
`5 t h`
and if that sequence were found raise the "t" and "h" to 5th. You can also specify classes of glyphs so you could say something like:
`[0-9] t h`
to raise "t" and "h" after any digit.

Chained Contextual Positioning does not really give you any more capabilities than Contextual Positioning, but it allows you to specify things in a slightly more logical fashion. In a chained feature you specify three match strings, one for glyphs before the current glyph, one for the current search, and one for glyphs after the current search. The advantage of this is that you can apply a transformation at the current glyph rather than having to apply it to some other glyph.

## What is a Contextual Substitution feature?

Substitutions come in three types. The first two are similar to the two types for positioning, the third is designed to handle a very specific case of arabic typography and is applied backwards.

Suppose you had a script font where the most letters join at the base line, but after some letters (b,o,v,w) the join is near the x-height, so a special version of each lower case letter needs to be created designed for a left side join near the x-height. You would want to be able to say:
`[bovw] [a-z]`
Note that this just specifies the cases in which the substitution may be applied. It does not specify the substitution itself, that is done in a separate lookup.

You may pull down an example script font with this substitution from FormalScript.tgz

## More complete descriptions

For more information on contextual features see Adobe's Docs:

- The GPOS table, for positioning glyphs
- The GSUB table, for substituting glyphs

## How do these relate to Apple Advanced Typography features?

In some cases a contextual or chaining contextual substitution can be converted into one of Apple's contextual glyph substitution subtables. See the page on Apple Advanced Typography for more information as to when and caveats about how.

## Creating a contextual feature

Before you can edit one of these features you must create it from the Element->Font Info->Contextual dialog.

## Editing a feature

### Format

Except for the reverse chaining features, any of these may come in one of three formats.

The simplest format is a list of glyphs. You may specify several glyph sequences in a single feature. So the script example above could be specified (quite inefficiently) by 4*26 lines like:
`b a`
`b b`
`...
o a`
`...`

The next format allows you to specify a list of classes. In the script example we would define 2 classes:
`[bovw]`
`[ac-np-ux-z]`
and define two patterns as:
`class1 [class2]
class1 [class1]`

The third format is the most general and allows you to specify your pattern by a separate list of glyphs for each glyph position:
`[bovw] [a-z]`

### Coverage

This display shows a list whose entries are coverage tables -- that is lists of glyphs. A match occurs if the current glyph matches one of the glyphs named in the current coverage table.

In the example at right there is only a single coverage table here (but there could be more).

In a Chaining Contextual feature it is also possible to specify a list of coverage tables to match glyphs before the current glyph, and another list to match glyphs after.

The buttons under the coverage list allow you to create new coverage tables to go to the end of the list (ie. to be added to the end of the match string), to edit current coverage tables, to remove a coverage table, or to reorder the coverage tables.

This feature does not directly describe how transformations are to happen to the glyphs, instead it provides a list of nested features (actually lookups, but I'm trying to hide that distinction) that are to be applied to specific positions in the match string (positions in the backtrack and lookahead lists my not be transformed).

In the example at right, the feature 'L041' will be applied to any glyph that matches the coverage table at the top of the list. Again the buttons under the sequence lookup list allow you to add, change, remove or reorder these transformations. (And yes, the order the transformations are applied can matter in complex situations).

#### Creating or editing a sequence lookup pair

This dialog allows you to specify which position in the match string is to have which nested feature applied to it.

A nested feature is very similar to a normal feature (position, pair, substitution, ligature, anchor, etc.) except that instead of having a script/language list it has a special value of "Nested".

### Setting a coverage table

If you press the [New] or [Edit] buttons from the coverage dialog above you get the page to the right. The text field provides the names of all glyphs in the coverage table. You may edit this list directly by typing in it, or you may press the [Set] button which sets the text field to contain the names of all glyphs selected in the font view. And the [Select] button changes the selection of the font view to match the contents of the text field.

If you wish to cancel this operation press the [<Prev] button and you will be returned to the coverage list page (and any changes made here will be lost), while pressing [Next>] will accept those changes.

### Glyphs

This format allows you to specify several glyph lists to match. In the example at right the string "A,B,C" will be matched in the glyphs before the current glyph, then "D E" starting at the current location, and finally "F G H" after them. If everything matched then the feature 'beef' will be applied to location 0 (in this case "D") and then 'dead' will be applied to location 1 ("E").

The buttons underneath allow you to add, change, remove and reorder these entries. The order is significant, word processors will stop at the first match they find so in the following:
`b a`
`b a f`
the second entry would never be matched because "b a" would be applied first. While:
`b a f`
`b a`
would apply match "b a f" when an "f" was present, and "b a" otherwise.

### Selecting glyphs

The text field may be manipulated as above. However here we are specifying a string of glyphs each of which must be matched, rather than a class of glyphs any of which could match. So in the example at right, "DE" would match, but "E" would not.

As above a set of lookups can be applied after the match occurs.

### Classes

When specifying a class match, you must specify at least one set of glyph classes. (you may also specify separate sets of classes for the backtrack and lookahead lists, or you use the same set for everything). You must also specify a list of patterns where each pattern is a list of numbers and each number is the index of the class into the class list.

Every set of classes has a magic class at index 0 which matches whatever glyphs are not explicitly mentioned in another class. FontForge displays this by calling it "{Everything Else}". You may not delete, edit nor reorder this class. Other classes are just unordered lists of glyph names (rather like coverage tables above), however any specific glyph may belong to at most one class at a time (whereas a glyph may occur in as many coverage tables as desired).

### A list of Class numbers

Once you have set up your classes, you may then edit the patterns you want to match. To remind you of what your classes are, FontForge displays the class list underneath the pattern. Clicking on a class will insert that class's index into the pattern.

Finally you must set the nested lookups. This is exactly the same as previous sequence / lookup settings.

-- Up -- TOC --