googlefonts / ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
MIT License
152 stars 43 forks source link

Instantiator: rule substitutions behave differently than for OT feature variations #852

Open madig opened 5 months ago

madig commented 5 months ago

Rules that work for variable fonts may not work for instances, because varLib/feature variations and the instantiator work differently.

The reproducers are described in more detail on https://github.com/daltonmaag/designspace-rules-reproducers.

What I expect (from instance-ref-stacked-high.ttf, made from in instance-reference.designspace, with the test string "Aa"):

image

What actually happens (in instance-test-stacked-high.ttf, made from instance-test.designspace):

image

The "a" is the original glyph rather than "a.break".

The rub lies in the way substitutions work:

  1. In feature variations, the shaper is expected to find the first condition set that matches and then stop there.
  2. The instantiator will collect all rules where the condition set matches and then swap glyph contents. On rule boundaries (like HGHT=750 for instance-test-stacked-high.ttf), when rules contain duplicate substitutions and start and end points overlap, it may collect two or more rules. Any duplicate substitutions can then cause a swap back and forth, undoing substitutions.