Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable GDEF building #821

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Lib/ufo2ft/featureWriters/gdefFeatureWriter.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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)]

Expand Down
1 change: 1 addition & 0 deletions tests/data/TestVarfea-Bold.ufo/glyphs/peh-ar.init.glif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<glyph name="peh-ar.init" format="2">
<advance width="600"/>
<unicode hex="067E"/>
<anchor x="100" y="100" name="caret_1"/>
<anchor x="73" y="89" name="exit"/>
<outline>
<contour>
Expand Down
1 change: 1 addition & 0 deletions tests/data/TestVarfea-Regular.ufo/glyphs/peh-ar.init.glif
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<glyph name="peh-ar.init" format="2">
<advance width="600"/>
<unicode hex="067E"/>
<anchor x="100" y="100" name="caret_1"/>
<anchor x="161" y="54" name="exit"/>
<outline>
<contour>
Expand Down
4 changes: 4 additions & 0 deletions tests/featureWriters/variableFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading