googlefonts / googlefonts/fontmake

Instantiator should swap glyph name references in feature code, along with other references

Open
#619 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
888
Forks
97
Avg merge
4d 52m
Merged PRs (30d)
1

Description

## Context

In a designspace, I have set up rules for glyph substitution along axes (`rvrn`).

Along the slant axis, I have italic forms which sub in. These include obvious subs such as a "single-story" /a and /g, but also many others such as a tall /f, and lots of semi-scripty letterforms. The general form of this is ``.

However, I _also_ want to activate a select number of these italic changes in stylistic sets, to allow users to _specifically_ sub in just the /a.italic or just the /g.italic, etc. This is generally pretty simple, requiring feature code like this:

```
@dfltG = [g gbreve gcaron gcircumflex gcommaaccent gdotaccent ];
@italicG = [g.italic gbreve.italic gcaron.italic gcircumflex.italic gcommaaccent.italic gdotaccent.italic ];

feature ss02 {
featureNames {
# MS, unicode, English
name "Single-story ‘g’";
# Apple, roman, unspecified
name 1 "Single-story ‘g’";
};
sub @dfltG by @italicG;
sub g.mono by g.italic;
} ss02;
```

(My current project, Recursive, also has some substitutions for `.mono` and `.sans` forms, which makes this slightly more complex.)

## The Problem

My feature code is written assuming that these features will go into a variable font. However, if I build a static font, glyphs names are "swapped" to freeze in the rule-based substitutions from the designspace. This works almost entirely perfectly: references are swapped in "outlines, width, component references, kerning references, group membership," according to the code docs.

https://github.com/googlefonts/fontmake/blob/a5529377219a13f5685f38bcefb248150704ff5e/Lib/fontmake/instantiator.py#L556

Feature code is one place glyph references are not yet swapped, however, and it causes many substitutions to fail if they reference glyph names which exist in rules. Suddenly, they are referencing the wrong glyphs.

## Proposed solution

One solution I've started using is to simply write different feature code for static outputs, to patch these issues, and then I'll copy this specific feature code into the right folder when I'm building statics. However, this is a rather manual solution that relies on quite a bit of mostly-duplicated data with unintuitive changes, plus repeated steps on each new build. For my current project, I think that covering all the bases would require 4 different feature files to cover proper substitution for statics, plus the main feature file for the variable font. Of course, another project might require even more duplication.

So, I think the much better solution would be to update the `swap_glyph_names()` function of the instantiator to also swap glyph names in feature code as this is moved into instances.

Is there any reason glyph names are not yet swapped in feature code? Might there be some unintended bad consequences? If not, I think this would be a (hopefully) small but (certainly) very useful update.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.