Glyph Substitution Chaining in FontForge
Glyph substitution chaining is an advanced OpenType feature that dynamically swaps glyphs based on their surrounding sequence, allowing type designers to handle complex typographic behaviors such as contextual alternates, script joining, and collision avoidance. In FontForge, this is handled through OpenType GSUB Lookup Type 6 (Chained Contextual Substitution), which enables users to define rules that inspect backtrack, input, and lookahead glyphs to determine when a specific substitution should execute.
Understanding Glyph Substitution Chaining
Chained contextual substitution modifies a target sequence of glyphs only when specific sequences appear immediately before or after it. Unlike basic substitutions (such as single substitutions or standard ligatures) that apply universally, chained substitutions inspect three distinct sequences:
- Backtrack Sequence: The glyphs that must appear immediately before the target glyphs. These glyphs are examined for context but are not modified.
- Input Sequence: The target glyph or sequence of glyphs to be replaced or modified.
- Lookahead Sequence: The glyphs that must appear immediately after the target glyphs. Like backtrack glyphs, these are only checked for matching conditions and remain unchanged.
When a text engine encounters a match for the backtrack, input, and lookahead sequences simultaneously, it applies pre-defined sub-lookups (such as single, alternate, or ligature substitutions) specifically to the input sequence.
How FontForge Handles Chaining Lookups
FontForge exposes OpenType layout features through its Font Info interface, allowing designers to visually build or write chained contextual rules without requiring a standalone OpenType Feature File (FEA) compiler.
1. Creating the Base and Nested Lookups
Before configuring a chained substitution in FontForge, the secondary
lookup that performs the actual replacement must exist. For example, if
glyph a changes to a.alt when preceded by
f, a Single Substitution lookup must first
be created to map a to a.alt.
2. Defining the Chained Contextual Lookup
- Navigate to Element > Font Info > Lookups.
- Select the GSUB tab and click Add Lookup.
- Set the lookup type to Chained Contextual Substitution.
- Assign an OpenType feature tag (such as
caltfor Contextual Alternates, orligafor Standard Ligatures) and configure the appropriate script and language systems.
3. Setting Up Subtables and Formats
Under the newly created lookup, click Add Subtable. FontForge supports three formats for defining chaining contexts:
- By Glyphs: Direct lists of specific glyph names. This format is ideal for isolated, one-off substitutions (e.g., swapping a specific letter when flanked by punctuation).
- By Classes: Groups glyphs into defined classes (e.g., ascenders, vowels, figures). This format is the most efficient and scalable method for complex fonts, as rules are written once for entire categories of characters rather than individual glyphs.
- By Coverage: Sets lists of glyph sets for each position in the backtrack, input, and lookahead sequences.
4. Mapping Sequences to Nested Lookups
Within the subtable editor, FontForge provides interface fields for each sequence stage:
- Backtrack: Enter the glyphs or classes that must precede the target. Note that OpenType processes backtrack sequences in reverse order (closest to the input first); FontForge manages this alignment based on the interface specifications.
- Input: Enter the glyphs or classes that will be matched for substitution.
- Lookahead: Enter the glyphs or classes that must follow the target.
- Lookups Applied: Map the target index within the input sequence to the previously created nested lookup (e.g., applying the single substitution to Input Position 0).
Compiling and Testing
Once the rules are established, FontForge validates the chained
context against the font's existing glyph set. During font generation
(OTF or TTF), FontForge compiles these visual rules directly into the
font's binary GSUB table. Designers can verify the chaining
behavior directly inside FontForge using the Metrics Window
(Metrics > New Metrics Window) by typing sample
strings to confirm that the substitutions trigger under the intended
contextual conditions.