diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 4468b2750..aa2f97bed 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -465,7 +465,10 @@ class Builder(object): feature_indices = {} required_feature_indices = {} # ('latn', 'DEU') --> 23 scripts = {} # 'latn' --> {'DEU': [23, 24]} for feature #23,24 - for key, lookups in sorted(self.features_.items()): + # Sort the feature table by feature tag: + # https://github.com/behdad/fonttools/issues/568 + sortFeatureTag = lambda f: (f[0][2], f[0][1], f[0][0], f[1]) + for key, lookups in sorted(self.features_.items(), key=sortFeatureTag): script, lang, feature_tag = key # l.lookup_index will be None when a lookup is not needed # for the table under construction. For example, substitution diff --git a/Lib/fontTools/feaLib/builder_test.py b/Lib/fontTools/feaLib/builder_test.py index f664b9555..397ff0ccc 100644 --- a/Lib/fontTools/feaLib/builder_test.py +++ b/Lib/fontTools/feaLib/builder_test.py @@ -58,7 +58,7 @@ class BuilderTest(unittest.TestCase): spec5h1 spec6b_ii spec6d2 spec6e spec6f spec6h_ii spec6h_iii_1 spec6h_iii_3d spec8a spec8b spec8c spec9a spec9b spec9c1 spec9c2 spec9c3 spec9d spec9e spec9f - bug453 bug463 bug501 bug502 bug505 bug506 bug509 bug512 + bug453 bug463 bug501 bug502 bug505 bug506 bug509 bug512 bug568 name size size2 """.split() diff --git a/Lib/fontTools/feaLib/testdata/bug568.fea b/Lib/fontTools/feaLib/testdata/bug568.fea new file mode 100644 index 000000000..3e879b193 --- /dev/null +++ b/Lib/fontTools/feaLib/testdata/bug568.fea @@ -0,0 +1,11 @@ +# https://github.com/behdad/fonttools/issues/568 + +feature tst1 { + script latn; + pos T -20; +} tst1; + +feature tst2 { + script cyrl; + pos T -80; +} tst2; diff --git a/Lib/fontTools/feaLib/testdata/bug568.ttx b/Lib/fontTools/feaLib/testdata/bug568.ttx new file mode 100644 index 000000000..1c171655a --- /dev/null +++ b/Lib/fontTools/feaLib/testdata/bug568.ttx @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lib/fontTools/feaLib/testdata/language_required.ttx b/Lib/fontTools/feaLib/testdata/language_required.ttx index 8d7c1f150..241faf8a0 100644 --- a/Lib/fontTools/feaLib/testdata/language_required.ttx +++ b/Lib/fontTools/feaLib/testdata/language_required.ttx @@ -14,7 +14,7 @@ - + @@ -22,16 +22,16 @@ - - + + - + - + @@ -47,26 +47,26 @@ - - - - - - - - + + + + + + + +