From 2c0761934407a66d7ee3088b23bc4b285dc7fafe Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 2 Nov 2023 16:32:15 +0000 Subject: [PATCH] [otlLib] make ClassDefBuilder class order match varLib.mergers see https://github.com/fonttools/fonttools/blob/c3d876/Lib/fontTools/misc/classifyTools.py#L77 i.e. we want (large classes first, then lexicographic order on the glyphs); previously otlLib was sorting by the _reverse_ of (small classes first, then glyphs lexicographic order) -- effectively comparing the reverse of the glyph sets of classes of the same size. Fixes https://github.com/fonttools/fonttools/issues/3321 note the ttx dump of previously built fonts may change but there won't be any functional changes. --- Lib/fontTools/otlLib/builder.py | 2 +- Tests/feaLib/data/PairPosSubtable.ttx | 16 ++++++++-------- Tests/feaLib/data/bug633.ttx | 12 ++++++------ Tests/feaLib/data/spec5f_ii_3.ttx | 22 +++++++++++----------- Tests/feaLib/data/variable_bug2772.ttx | 10 +++++----- Tests/otlLib/builder_test.py | 2 +- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 94628bff1..3508a7e28 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -2674,7 +2674,7 @@ class ClassDefBuilder(object): # class form a contiguous range, the encoding is actually quite # compact, whereas a non-contiguous set might need a lot of bytes # in the output file. We don't get this right with the key below. - result = sorted(self.classes_, key=lambda s: (len(s), s), reverse=True) + result = sorted(self.classes_, key=lambda s: (-len(s), s)) if not self.useClass0_: result.insert(0, frozenset()) return result diff --git a/Tests/feaLib/data/PairPosSubtable.ttx b/Tests/feaLib/data/PairPosSubtable.ttx index 2d78f64fa..d671537e6 100644 --- a/Tests/feaLib/data/PairPosSubtable.ttx +++ b/Tests/feaLib/data/PairPosSubtable.ttx @@ -93,14 +93,14 @@ - - - - - - + + + + + + @@ -112,7 +112,7 @@ - + @@ -120,7 +120,7 @@ - + diff --git a/Tests/feaLib/data/bug633.ttx b/Tests/feaLib/data/bug633.ttx index 075c17779..8be745cd5 100644 --- a/Tests/feaLib/data/bug633.ttx +++ b/Tests/feaLib/data/bug633.ttx @@ -43,10 +43,10 @@ - - - - + + + + @@ -55,10 +55,10 @@ - + - + diff --git a/Tests/feaLib/data/spec5f_ii_3.ttx b/Tests/feaLib/data/spec5f_ii_3.ttx index a94efceab..c03a81fb7 100644 --- a/Tests/feaLib/data/spec5f_ii_3.ttx +++ b/Tests/feaLib/data/spec5f_ii_3.ttx @@ -66,9 +66,9 @@ - + - + @@ -103,18 +103,12 @@ - - - - - - - + @@ -122,7 +116,7 @@ - + @@ -131,7 +125,7 @@ - + @@ -141,6 +135,12 @@ + + + + + + diff --git a/Tests/feaLib/data/variable_bug2772.ttx b/Tests/feaLib/data/variable_bug2772.ttx index 465462099..12fda609b 100644 --- a/Tests/feaLib/data/variable_bug2772.ttx +++ b/Tests/feaLib/data/variable_bug2772.ttx @@ -73,8 +73,8 @@ - - + + @@ -83,6 +83,9 @@ + + + @@ -91,9 +94,6 @@ - - - diff --git a/Tests/otlLib/builder_test.py b/Tests/otlLib/builder_test.py index 548a31e9f..b7a6caa2f 100644 --- a/Tests/otlLib/builder_test.py +++ b/Tests/otlLib/builder_test.py @@ -1080,7 +1080,7 @@ class ClassDefBuilderTest(object): b.add({"e", "f", "g", "h"}) cdef = b.build() assert isinstance(cdef, otTables.ClassDef) - assert cdef.classDefs == {"a": 2, "b": 2, "c": 3, "aa": 1, "bb": 1} + assert cdef.classDefs == {"a": 1, "b": 1, "c": 3, "aa": 2, "bb": 2} def test_build_notUsingClass0(self): b = builder.ClassDefBuilder(useClass0=False)