[fonttools/fonttools] ff6051: [feaLib] Fix tracking for redundant script statements

2 views
Skip to first unread message

Colin Rofls

unread,
Sep 8, 2026, 11:45:04 AM (9 days ago) Sep 8
to fontto...@googlegroups.com
Branch: refs/heads/main
Home: https://github.com/fonttools/fonttools
Commit: ff605197e04d39abbe344b02b29b182e690a2fdb
https://github.com/fonttools/fonttools/commit/ff605197e04d39abbe344b02b29b182e690a2fdb
Author: Colin Rofls <co...@cmyr.net>
Date: 2026-09-04 (Fri, 04 Sep 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py
M Tests/feaLib/builder_test.py
A Tests/feaLib/data/script_language_tracking.fea
A Tests/feaLib/data/script_language_tracking.ttx
A Tests/feaLib/data/script_language_tracking_DFLT.fea
A Tests/feaLib/data/script_language_tracking_DFLT.ttx
A Tests/feaLib/data/script_language_tracking_multi.fea
A Tests/feaLib/data/script_language_tracking_multi.ttx
A Tests/feaLib/data/script_language_tracking_redundant.fea
A Tests/feaLib/data/script_language_tracking_redundant.ttx

Log Message:
-----------
[feaLib] Fix tracking for redundant script statements

This bit of behaviour has been a major source of headaches both here as
well as in fea-rs; for a bit of history, see:

- https://github.com/fonttools/fonttools/issues/613
- https://github.com/fonttools/fonttools/issues/1824
- https://github.com/fonttools/fonttools/pull/1883
- https://github.com/fonttools/fonttools/issues/2522 (still open)
- https://github.com/fonttools/fonttools/issues/3748
- https://github.com/googlefonts/fontc/pull/959
- https://github.com/googlefonts/fontc/pull/1595

Digging into some remaining funny diffs has uncovered that both
implementations were still not quite correct.

Here the issue was that start_feature() hardcoded self.script_ = "DFLT", and
set_script() returned early without assigning self.script_ when the script
matched the declared language systems.

Given,

```fea
languagesystem latn dflt;
feature derp {
script latn;
language dflt;
sub a by b;
} derp;
```

`script_` stayed "DFLT", 'sub a by b' ended up in DFLT/dflt, and the
font got no latn ScriptRecord at all.

The solution is to track the current script and language explicitly instead.
start_feature() now seeds them from the _first declared language system_
(rather than DFLT) and set_script() guards its early return on the _current
script and language_ rather than on the set of declared language systems.

The early return exists so that a script statement naming the already-current
script does not reset the lookupflag (#1824); that is preserved, and now applies
to the first declared language system as well.

This fix is directly based on the logic in makeotf. A separate patch in
fea-rs will implement the same behaviour.


Commit: d30db24fc883f27c3ea5e0560c52dfe501a38918
https://github.com/fonttools/fonttools/commit/d30db24fc883f27c3ea5e0560c52dfe501a38918
Author: Colin Rofls <co...@cmyr.net>
Date: 2026-09-08 (Tue, 08 Sep 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py
M Tests/feaLib/builder_test.py
A Tests/feaLib/data/script_language_tracking.fea
A Tests/feaLib/data/script_language_tracking.ttx
A Tests/feaLib/data/script_language_tracking_DFLT.fea
A Tests/feaLib/data/script_language_tracking_DFLT.ttx
A Tests/feaLib/data/script_language_tracking_multi.fea
A Tests/feaLib/data/script_language_tracking_multi.ttx
A Tests/feaLib/data/script_language_tracking_redundant.fea
A Tests/feaLib/data/script_language_tracking_redundant.ttx

Log Message:
-----------
Merge pull request #4169 from cmyr/fealib-script-tracking-afdko

[feaLib] Fix tracking for redundant script statements


Compare: https://github.com/fonttools/fonttools/compare/7af8bf5cbf71...d30db24fc883

To unsubscribe from these emails, change your notification settings at https://github.com/fonttools/fonttools/settings/notifications
Reply all
Reply to author
Forward
0 new messages