[fonttools/fonttools] 2a6072: Merge consecutive contextual rules with same context

0 views
Skip to first unread message

Cosimo Lupo

unread,
Mar 12, 2026, 10:30:57 AMMar 12
to fontto...@googlegroups.com
Branch: refs/heads/merge-chained-rules
Home: https://github.com/fonttools/fonttools
Commit: 2a6072fee98412ddcf5ff5d662c71967c60fabf8
https://github.com/fonttools/fonttools/commit/2a6072fee98412ddcf5ff5d662c71967c60fabf8
Author: Cosimo Lupo <cl...@google.com>
Date: 2026-03-12 (Thu, 12 Mar 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py

Log Message:
-----------
Merge consecutive contextual rules with same context

Add _merge_contextual_rule() helper that merges consecutive contextual
rules sharing the same prefix, suffix, and lookups into a single rule
with broader input coverage. Applied to all contextual builder methods:
add_chain_context_subst, add_chain_context_pos, add_single_subst_chained_,
add_multi_subst_chained_, and add_single_pos_chained_.

This matches the broad merge strategy used by fea-rs, which merges all
contextual rule types in its shared ContextBuilder::add().

Fixes https://github.com/fonttools/fonttools/issues/4016


Commit: bbdcfc20f4e074983ec838d39f0ba6568fcb640d
https://github.com/fonttools/fonttools/commit/bbdcfc20f4e074983ec838d39f0ba6568fcb640d
Author: Cosimo Lupo <cl...@google.com>
Date: 2026-03-12 (Thu, 12 Mar 2026)

Changed paths:
M Tests/feaLib/builder_test.py
M Tests/feaLib/data/bug463.ttx
M Tests/feaLib/data/bug512.ttx
A Tests/feaLib/data/contextual_merge_gpos_named.fea
A Tests/feaLib/data/contextual_merge_gpos_named.ttx
A Tests/feaLib/data/contextual_merge_gsub_named.fea
A Tests/feaLib/data/contextual_merge_gsub_named.ttx
A Tests/feaLib/data/contextual_merge_ignore.fea
A Tests/feaLib/data/contextual_merge_ignore.ttx
M Tests/feaLib/data/feature_aalt.ttx

Log Message:
-----------
Add tests for contextual rule merge optimization

Update expected TTX output for bug463, bug512, and feature_aalt to
reflect merged contextual rules (fewer subtables, broader input
coverage).

Add new test cases for contextual rule merge beyond inline multi-subst:
- GSUB contextual substitution with named lookup references
- GPOS contextual positioning with named lookup references
- Ignore rules with no nested lookups


Compare: https://github.com/fonttools/fonttools/compare/3666aaea5592...bbdcfc20f4e0

To unsubscribe from these emails, change your notification settings at https://github.com/fonttools/fonttools/settings/notifications

Cosimo Lupo

unread,
Mar 13, 2026, 7:55:32 AMMar 13
to fontto...@googlegroups.com
Branch: refs/heads/main
Commit: 0903764f84a971c1b4854ffabdf7a266000f5db9
https://github.com/fonttools/fonttools/commit/0903764f84a971c1b4854ffabdf7a266000f5db9
Author: Cosimo Lupo <cl...@google.com>
Date: 2026-03-13 (Fri, 13 Mar 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py
M Lib/fontTools/otlLib/builder.py
M Tests/feaLib/builder_test.py
A Tests/feaLib/data/contextual_merge_alternate.fea
A Tests/feaLib/data/contextual_merge_alternate.ttx

Log Message:
-----------
Reuse and merge chained alternate subst lookups

Add find_chainable_alternate_subst() to find an existing AlternateSubst
lookup that can accommodate a new glyph without conflict. This allows
consecutive chained alternate rules to share a single nested lookup and
merge into one contextual rule via _merge_contextual_rule().

Previously each chained alternate rule unconditionally created a fresh
AlternateSubstBuilder, preventing both lookup reuse and rule merging.


Commit: 8060f6a1ae4e4077e5021d48a5f0e54c72d27151
https://github.com/fonttools/fonttools/commit/8060f6a1ae4e4077e5021d48a5f0e54c72d27151
Author: Cosimo Lupo <cl...@google.com>
Date: 2026-03-13 (Fri, 13 Mar 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py

Log Message:
-----------
Rename _merge_contextual_rule to _add_contextual_rule

Fold the append logic into the method so callers don't need to
duplicate the fallback path


Commit: ad47e608c0796fb9796fc283ab5f871d2d768d57
https://github.com/fonttools/fonttools/commit/ad47e608c0796fb9796fc283ab5f871d2d768d57
Author: Cosimo Lupo <cos...@anthrotype.com>
Date: 2026-03-13 (Fri, 13 Mar 2026)

Changed paths:
M Lib/fontTools/feaLib/builder.py
M Lib/fontTools/otlLib/builder.py
M Tests/feaLib/builder_test.py
M Tests/feaLib/data/bug463.ttx
M Tests/feaLib/data/bug512.ttx
A Tests/feaLib/data/contextual_merge_alternate.fea
A Tests/feaLib/data/contextual_merge_alternate.ttx
A Tests/feaLib/data/contextual_merge_gpos_named.fea
A Tests/feaLib/data/contextual_merge_gpos_named.ttx
A Tests/feaLib/data/contextual_merge_gsub_named.fea
A Tests/feaLib/data/contextual_merge_gsub_named.ttx
A Tests/feaLib/data/contextual_merge_ignore.fea
A Tests/feaLib/data/contextual_merge_ignore.ttx
M Tests/feaLib/data/feature_aalt.ttx

Log Message:
-----------
Merge pull request #4061 from fonttools/merge-chained-rules

[feaLib] Merge consecutive contextual rules with same context


Compare: https://github.com/fonttools/fonttools/compare/11e9bfa11a6a...ad47e608c079
Reply all
Reply to author
Forward
0 new messages