Reverse Chaining Substitution in FontForge

Reverse chaining contextual substitution is an advanced OpenType feature that substitutes a single glyph based on surrounding glyphs while processing text in reverse order. This article explains what reverse chaining contextual substitution is, why type designers use it, and provides a direct, step-by-step guide to implementing it inside FontForge.

What is Reverse Chaining Contextual Substitution?

In OpenType typography, standard contextual substitutions evaluate glyphs from the beginning of a sequence to the end. Reverse Chaining Contextual Single Substitution—defined as Lookup Type 8 in the OpenType GSUB (Glyph Substitution) specification—processes glyph sequences in reverse (from the end of the text stream back to the beginning).

While moving backward through the text, it replaces a target glyph with another glyph based on two sets of context:

  • Backtrack Sequence: The glyphs that appear before the target glyph in logical reading order.
  • Lookahead Sequence: The glyphs that appear after the target glyph in logical reading order.

This mechanism is primarily utilized in complex scripts such as Arabic, Urdu Nastaliq, and Indic scripts, or in sophisticated connected scripts. By resolving contextual variants from back to front, designers can chain dynamic shaping rules together without causing the infinite loops or multi-pass conflicts common in standard forward-processing contextual lookups.

Key Rules of Reverse Chaining

  1. Single Substitution Only: A reverse chaining rule can only replace one target glyph with one alternative glyph per match. It cannot insert, delete, or perform multiple substitutions in a single operation.
  2. Evaluation Order: Because it evaluates from right to left (in logical index order), lookahead context glyphs have already been evaluated and substituted by earlier steps in the reverse chain, allowing cascading modifications to settle cleanly.

How to Use Reverse Chaining Substitution in FontForge

FontForge provides native support for creating Type 8 reverse chaining lookups within its font information interface.

Step 1: Open the Lookups Window

  1. Open your font project in FontForge.
  2. Navigate to the top menu and select Element > Font Info.
  3. In the left sidebar of the Font Info dialog, select Lookups.
  4. Click on the GSUB tab at the top of the Lookups panel.

Step 2: Create a Reverse Chaining Lookup

  1. Click the Add Lookup button.
  2. Set the Type dropdown to Reverse chaining contextual single substitution.
  3. Choose or type the OpenType Feature tag under which this rule should execute (such as calt for Contextual Alternates, rlig for Required Ligatures, or a script-specific feature tag).
  4. Provide a descriptive name for the lookup in the Lookup Name field.
  5. Click OK.

Step 3: Add a Subtable

  1. Select the newly created lookup in the GSUB list.
  2. Click the Add Subtable button on the right side.
  3. FontForge will open the subtable configuration window where contextual matching rules are defined.

Step 4: Define Context and Substitutions

A reverse chaining subtable requires three distinct fields to be populated:

  • Backtrack: Specify the glyphs or glyph classes that must immediately precede the target glyph.
  • Match (Target): Specify the target glyph(s) that should be evaluated for replacement.
  • Lookahead: Specify the glyphs or glyph classes that must immediately follow the target glyph.
  • Substitutions: Define the replacement glyph for each target glyph listed in the Match field.

Glyphs can be entered by name, separated by spaces, or grouped into brackets representing glyph classes (e.g., [a e i o u]).

Step 5: Save and Test

  1. Click OK to close the subtable dialog, then click OK in the Font Info dialog to apply changes.
  2. Test the lookup by navigating to Metrics > New Metrics Window.
  3. Type the string of characters representing your target, backtrack, and lookahead contexts to verify that the reverse substitution triggers as expected.