From 0d22f981382ca60d5a5c0de2b532b0228a010a5d Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 27 Feb 2024 13:41:17 +0000 Subject: [PATCH 1/2] Sort carets correctly --- Lib/ufo2ft/featureWriters/gdefFeatureWriter.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/ufo2ft/featureWriters/gdefFeatureWriter.py b/Lib/ufo2ft/featureWriters/gdefFeatureWriter.py index fcd41f19..eda11bf1 100644 --- a/Lib/ufo2ft/featureWriters/gdefFeatureWriter.py +++ b/Lib/ufo2ft/featureWriters/gdefFeatureWriter.py @@ -1,8 +1,15 @@ +from fontTools.feaLib.variableScalar import VariableScalar from fontTools.misc.fixedTools import otRound from ufo2ft.featureWriters import BaseFeatureWriter, ast +def caretSortKey(caret): + if isinstance(caret, VariableScalar): + return list(caret.values.values())[0] + return caret + + class GdefFeatureWriter(BaseFeatureWriter): """Generates a GDEF table based on OpenType Category and glyph anchors. @@ -67,9 +74,7 @@ def _getLigatureCarets(self): if glyphCarets: if self.context.isVariable: - carets[glyphName] = sorted( - glyphCarets, key=lambda caret: list(caret.values.values())[0] - ) + carets[glyphName] = sorted(glyphCarets, key=caretSortKey) else: carets[glyphName] = [otRound(c) for c in sorted(glyphCarets)] From cbb9a4088eb72f752fa1dad2b0741ea844fe40f4 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 27 Feb 2024 13:59:01 +0000 Subject: [PATCH 2/2] Add test; passes with patch, AttributeError without --- tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif | 1 + tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif | 1 + tests/featureWriters/variableFeatureWriter_test.py | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif b/tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif index a8e87507..ed2734bd 100644 --- a/tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif +++ b/tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif @@ -2,6 +2,7 @@ + diff --git a/tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif b/tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif index 03c6ba3a..25a15b41 100644 --- a/tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif +++ b/tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif @@ -2,6 +2,7 @@ + diff --git a/tests/featureWriters/variableFeatureWriter_test.py b/tests/featureWriters/variableFeatureWriter_test.py index 92092c65..b6be9c9b 100644 --- a/tests/featureWriters/variableFeatureWriter_test.py +++ b/tests/featureWriters/variableFeatureWriter_test.py @@ -41,6 +41,10 @@ def test_variable_features(FontClass): } mark; + table GDEF { + LigatureCaretByPos peh-ar.init 100; + } GDEF; + feature curs { lookup curs { lookupflag RightToLeft IgnoreMarks;