From 8b69b9412e6ccf3aad4fa488470a0c2a18d0176f Mon Sep 17 00:00:00 2001 From: David Corbett Date: Sat, 13 May 2023 13:24:58 -0400 Subject: [PATCH 1/2] feaLib: Dedupe multiple substitutions with classes --- Lib/fontTools/feaLib/ast.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Lib/fontTools/feaLib/ast.py b/Lib/fontTools/feaLib/ast.py index bbe6e6e74..17c6cc3fb 100644 --- a/Lib/fontTools/feaLib/ast.py +++ b/Lib/fontTools/feaLib/ast.py @@ -1272,15 +1272,18 @@ class MultipleSubstStatement(Statement): replaces.append(replace) replaces = list(zip(*replaces)) + seen_originals = set() for i, original in enumerate(originals): - builder.add_multiple_subst( - self.location, - prefix, - original, - suffix, - replaces and replaces[i] or (), - self.forceChain, - ) + if original not in seen_originals: + seen_originals.add(original) + builder.add_multiple_subst( + self.location, + prefix, + original, + suffix, + replaces and replaces[i] or (), + self.forceChain, + ) def asFea(self, indent=""): res = "sub " From bd00fe24f1679ebf013067418c0b9b23934a7908 Mon Sep 17 00:00:00 2001 From: David Corbett Date: Sun, 14 May 2023 09:35:53 -0400 Subject: [PATCH 2/2] feaLib: Test deduped multiple substitution lookups --- Tests/feaLib/data/GSUB_2.fea | 4 ++++ Tests/feaLib/data/GSUB_2.ttx | 43 +++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Tests/feaLib/data/GSUB_2.fea b/Tests/feaLib/data/GSUB_2.fea index 078cbec39..21db452b5 100644 --- a/Tests/feaLib/data/GSUB_2.fea +++ b/Tests/feaLib/data/GSUB_2.fea @@ -29,3 +29,7 @@ lookup l1 { feature f5 { sub @class' lookup l1 [i l]; } f5; + +feature f6 { + sub [f_i f_i]' j by [f f] [i i]; +} f6; diff --git a/Tests/feaLib/data/GSUB_2.ttx b/Tests/feaLib/data/GSUB_2.ttx index b2bd21bd7..fb87a0590 100644 --- a/Tests/feaLib/data/GSUB_2.ttx +++ b/Tests/feaLib/data/GSUB_2.ttx @@ -10,19 +10,20 @@ - + @@ -58,9 +59,16 @@ + + + + + + + - + @@ -135,6 +143,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +