diff --git a/Lib/fontMath/mathKerning.py b/Lib/fontMath/mathKerning.py index 07f2e18..204b5b3 100644 --- a/Lib/fontMath/mathKerning.py +++ b/Lib/fontMath/mathKerning.py @@ -271,6 +271,8 @@ def _isLessish(self, first, second): return False elif first[key] < second[key]: return True + elif first[key] > second[key]: + return False return None def __lt__(self, other): diff --git a/Lib/fontMath/test/test_mathKerning.py b/Lib/fontMath/test/test_mathKerning.py index e7fdcb0..c1d7fba 100644 --- a/Lib/fontMath/test/test_mathKerning.py +++ b/Lib/fontMath/test/test_mathKerning.py @@ -438,6 +438,37 @@ def test_compare_same_kerning_diff_groups(self): self.assertFalse(mathKerning1 > mathKerning2) self.assertNotEqual(mathKerning1, mathKerning2) + def test_compare_first_kerning_difference(self): + first = MathKerning({("A", "V"): -80, ("T", "o"): -20}) + second = MathKerning({("A", "V"): -70, ("T", "o"): -30}) + + self.assertTrue(first < second) + self.assertFalse(second < first) + self.assertEqual(sorted([first, second]), [first, second]) + self.assertEqual(sorted([second, first]), [first, second]) + + def test_compare_first_group_difference(self): + for prefix in ("public.kern1.", "public.kern2."): + with self.subTest(prefix=prefix): + first = MathKerning(groups={ + prefix + "A": ["A"], prefix + "B": ["Z"]}) + second = MathKerning(groups={ + prefix + "A": ["B"], prefix + "B": ["Y"]}) + + self.assertTrue(first < second) + self.assertFalse(second < first) + self.assertEqual(sorted([first, second]), [first, second]) + self.assertEqual(sorted([second, first]), [first, second]) + + def test_compare_kerning_before_groups(self): + first = MathKerning({("A", "V"): -80}, + {"public.kern1.A": ["Z"]}) + second = MathKerning({("A", "V"): -70}, + {"public.kern1.A": ["A"]}) + + self.assertTrue(first < second) + self.assertFalse(second < first) + def test_div_tuple_factor(self): kerning = { ("A", "A"): 0,