From 64fd837ca1c2669f7e0e9d41f47b376e3fa153c3 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Mon, 5 Sep 2022 14:44:50 +0100 Subject: [PATCH] Allow multiple value record types in the same pairpos table (#2776) * Use buildPairPosClassesSubtable's ability to promote value records (see #2772) * Add tests for #2772 --- Lib/fontTools/otlLib/builder.py | 17 +--- Tests/feaLib/builder_test.py | 2 +- Tests/feaLib/data/variable_bug2772.fea | 4 + Tests/feaLib/data/variable_bug2772.ttx | 103 +++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 Tests/feaLib/data/variable_bug2772.fea create mode 100644 Tests/feaLib/data/variable_bug2772.ttx diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 233edec25..37dc1fc4d 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -1387,27 +1387,16 @@ class PairPosBuilder(LookupBuilder): lookup. """ builders = {} - builder = None + builder = ClassPairPosSubtableBuilder(self) for glyphclass1, value1, glyphclass2, value2 in self.pairs: if glyphclass1 is self.SUBTABLE_BREAK_: - if builder is not None: - builder.addSubtableBreak() + builder.addSubtableBreak() continue - valFormat1, valFormat2 = 0, 0 - if value1: - valFormat1 = value1.getFormat() - if value2: - valFormat2 = value2.getFormat() - builder = builders.get((valFormat1, valFormat2)) - if builder is None: - builder = ClassPairPosSubtableBuilder(self) - builders[(valFormat1, valFormat2)] = builder builder.addPair(glyphclass1, value1, glyphclass2, value2) subtables = [] if self.glyphPairs: subtables.extend(buildPairPosGlyphs(self.glyphPairs, self.glyphMap)) - for key in sorted(builders.keys()): - subtables.extend(builders[key].subtables()) + subtables.extend(builder.subtables()) lookup = self.buildLookup_(subtables) # Compact the lookup diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index 5c298e85c..d70fee12c 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -69,7 +69,7 @@ class BuilderTest(unittest.TestCase): spec9a spec9b spec9c1 spec9c2 spec9c3 spec9d spec9e spec9f spec9g spec10 bug453 bug457 bug463 bug501 bug502 bug504 bug505 bug506 bug509 - bug512 bug514 bug568 bug633 bug1307 bug1459 bug2276 + bug512 bug514 bug568 bug633 bug1307 bug1459 bug2276 variable_bug2772 name size size2 multiple_feature_blocks omitted_GlyphClassDef ZeroValue_SinglePos_horizontal ZeroValue_SinglePos_vertical ZeroValue_PairPos_horizontal ZeroValue_PairPos_vertical diff --git a/Tests/feaLib/data/variable_bug2772.fea b/Tests/feaLib/data/variable_bug2772.fea new file mode 100644 index 000000000..08326902e --- /dev/null +++ b/Tests/feaLib/data/variable_bug2772.fea @@ -0,0 +1,4 @@ +feature kern { + pos [p] g -5; + pos [p] y (wght=1000:-100 wght=200:0); +} kern; diff --git a/Tests/feaLib/data/variable_bug2772.ttx b/Tests/feaLib/data/variable_bug2772.ttx new file mode 100644 index 000000000..465462099 --- /dev/null +++ b/Tests/feaLib/data/variable_bug2772.ttx @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +