Skip to content

[fea-rs] Support inline alternate substitution in contextual rules #1925

@anthrotype

Description

@anthrotype

fea-rs currently rejects inline alternate substitution rules in contextual (chained) context:

  feature calt {
      sub a' comma from [A a.alt1 a.alt2];
      sub b' comma from [B b.alt];
  } calt;

  error: alternate substition rules cannot be specified inline
    |
  6 |     sub a' comma from [A a.alt1 a.alt2];
    |                  ^^^^

Although exotic, this is valid OpenType Feature File syntax. fonttools has supported compiling this since 2016 (fonttools/fonttools@db49f20d6, PR fonttools/fonttools#445). Just today, I added an optimization to reuse the same nested AlternateSubst lookup when consecutive chained alternate rules share the same context (fonttools/fonttools@0903764f8, PR fonttools/fonttools#4061).

In order to match feaLib, fea-rs should:

  1. Parse and compile sub <glyph>' <context> from <alternates>; by creating a nested AlternateSubst lookup
  2. Reuse the same nested lookup when consecutive rules share the same context

fonttools has a test for this: fontTools/Tests/feaLib/data/contextual_merge_alternate.{fea,ttx}.

Discovered while working on #1922 (contextual rule merging).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions