Contextual Substitutions in FontForge
Contextual substitutions allow your font to dynamically replace glyphs based on surrounding characters, enabling features like advanced ligatures, script swashes, and alternate styles. This guide explains how to configure OpenType Contextual Chaining Substitutions in FontForge using lookups, sub-tables, and coverage or class rules to trigger automated glyph changes within text.
1. Prepare Your Alternate Glyphs
Before creating rules, ensure all necessary base glyphs and alternate glyphs exist in your font.
- Open your project in FontForge.
- Create or identify the replacement glyphs. For example, if you want
an alternate lowercase e to appear after
r, create a glyph named
e.alt. - Ensure both the original glyphs and their alternates have proper Unicode values or valid PostScript names.
2. Create the Nested Substitution Lookup
Contextual substitutions do not perform glyph replacements directly; instead, they trigger standard substitutions when a condition is met. You must first create the simple replacement rule.
- Go to Element > Font Info.
- Select Lookups from the left-hand menu, then open the GSUB (Glyph Substitution) tab.
- Click Add Lookup.
- Set the Type to Single Substitution.
- Leave the feature list blank for now (this lookup will be called
internally), then name the lookup (e.g.,
lookup_single_e_alt) and click OK. - Select the newly created lookup and click Add Subtable.
- In the mapping list, map the base glyph to the alternate glyph
(e.g., set
eto transform intoe.alt). Click OK.
3. Create the Contextual Chaining Lookup
Next, create the primary contextual lookup that checks the surrounding text.
- Still in Font Info > Lookups > GSUB, click Add Lookup.
- Set the Type to Contextual Chaining Substitution.
- Under the Feature column, assign a tag such as
calt(Contextual Alternates). - Provide a descriptive lookup name (e.g.,
lookup_contextual_calt) and click OK.
4. Define the Contextual Subtable
Contextual rules are divided into three areas: Backtrack (characters before), Input (the target character), and Lookahead (characters after).
- Select your new Contextual Chaining lookup and click Add Subtable.
- Choose By Coverage (recommended for specific glyph sequences) or By Classes (recommended for broad categories of letters). Click Next.
- Define the sequence:
- Backtrack: Enter the preceding glyph (e.g.,
r). - Input: Enter the target glyph being changed (e.g.,
e). - Lookahead: Leave blank unless you also require a specific glyph to follow the target.
- Backtrack: Enter the preceding glyph (e.g.,
- Link the substitution:
- At the bottom of the dialog, set the sequence position (the input
glyph is at position
0). - Assign the single substitution lookup you created in Step 2
(
lookup_single_e_alt) to position0.
- At the bottom of the dialog, set the sequence position (the input
glyph is at position
- Click OK, then click OK again to close the Font Info window.
5. Test the Substitution
- Open the Metrics window by navigating to Metrics > New Metrics Window.
- Type the trigger sequence (e.g.,
re). - Ensure that the OpenType feature tag you assigned
(
calt) is enabled in the Metrics view. - The target glyph should automatically switch to its alternate form when preceded by the specified context.