Skip to content

Commit f6b4f42

Browse files
authored
Fix variable GDEF building (#821)
* Sort carets correctly * Add test; passes with patch, AttributeError without
1 parent b7a19ed commit f6b4f42

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Lib/ufo2ft/featureWriters/gdefFeatureWriter.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
from fontTools.feaLib.variableScalar import VariableScalar
12
from fontTools.misc.fixedTools import otRound
23

34
from ufo2ft.featureWriters import BaseFeatureWriter, ast
45

56

7+
def caretSortKey(caret):
8+
if isinstance(caret, VariableScalar):
9+
return list(caret.values.values())[0]
10+
return caret
11+
12+
613
class GdefFeatureWriter(BaseFeatureWriter):
714
"""Generates a GDEF table based on OpenType Category and glyph anchors.
815
@@ -67,9 +74,7 @@ def _getLigatureCarets(self):
6774

6875
if glyphCarets:
6976
if self.context.isVariable:
70-
carets[glyphName] = sorted(
71-
glyphCarets, key=lambda caret: list(caret.values.values())[0]
72-
)
77+
carets[glyphName] = sorted(glyphCarets, key=caretSortKey)
7378
else:
7479
carets[glyphName] = [otRound(c) for c in sorted(glyphCarets)]
7580

tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<glyph name="peh-ar.init" format="2">
33
<advance width="600"/>
44
<unicode hex="067E"/>
5+
<anchor x="100" y="100" name="caret_1"/>
56
<anchor x="73" y="89" name="exit"/>
67
<outline>
78
<contour>

tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<glyph name="peh-ar.init" format="2">
33
<advance width="600"/>
44
<unicode hex="067E"/>
5+
<anchor x="100" y="100" name="caret_1"/>
56
<anchor x="161" y="54" name="exit"/>
67
<outline>
78
<contour>

tests/featureWriters/variableFeatureWriter_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def test_variable_features(FontClass):
4141
4242
} mark;
4343
44+
table GDEF {
45+
LigatureCaretByPos peh-ar.init 100;
46+
} GDEF;
47+
4448
feature curs {
4549
lookup curs {
4650
lookupflag RightToLeft IgnoreMarks;

0 commit comments

Comments
 (0)