From 40048170575e93c5ba3bbe5de135855910f71c16 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 4 Sep 2024 22:20:38 +0300 Subject: [PATCH] markFeatureWriter: Ignore contextual anchors in non-contextual lookups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we end up with positioning statements that have duplicated mark classes like this: pos base a mark @MC_top mark @MC_top; (one is the regular anchor, and the other is the contextual one). Which makes no sense (feaLib shouldn’t probably allow the same mark class to be used multiple times in the same statement). --- Lib/ufo2ft/featureWriters/markFeatureWriter.py | 15 +++++++++++++++ tests/featureWriters/markFeatureWriter_test.py | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Lib/ufo2ft/featureWriters/markFeatureWriter.py b/Lib/ufo2ft/featureWriters/markFeatureWriter.py index 16df5b4d..a5891978 100644 --- a/Lib/ufo2ft/featureWriters/markFeatureWriter.py +++ b/Lib/ufo2ft/featureWriters/markFeatureWriter.py @@ -649,6 +649,11 @@ def _makeMarkToBaseAttachments(self): # skip '_1', '_2', etc. suffixed anchors for this lookup # type; these will be are added in the mark2liga lookup continue + if anchor.isContextual: + # Skip contextual anchors. We don't support them in ufo2ft + # and isContextual is always False, but subclasses may + # handle them (e.g. glyphsLib’s MarkFeatureWriter). + continue assert not anchor.isMark baseMarks.append(anchor) if not baseMarks: @@ -669,6 +674,11 @@ def _makeMarkToMarkAttachments(self): # skip anchors for which no mark class is defined if anchor.markClass is None or anchor.isMark: continue + if anchor.isContextual: + # Skip contextual anchors. We don't support them in ufo2ft + # and isContextual is always False, but subclasses may + # handle them (e.g. glyphsLib’s MarkFeatureWriter). + continue if anchor.number is not None: self.log.warning( "invalid ligature anchor '%s' in mark glyph '%s'; " "skipped", @@ -700,6 +710,11 @@ def _makeMarkToLigaAttachments(self): if number is None: # we handled these in the mark2base lookup continue + if anchor.isContextual: + # Skip contextual anchors. We don't support them in ufo2ft + # and isContextual is always False, but subclasses may + # handle them (e.g. glyphsLib’s MarkFeatureWriter). + continue # unnamed anchors with only a number suffix "_1", "_2", etc. # are understood as the ligature component having if not anchor.key: diff --git a/tests/featureWriters/markFeatureWriter_test.py b/tests/featureWriters/markFeatureWriter_test.py index 6a60dee6..2d7311d3 100644 --- a/tests/featureWriters/markFeatureWriter_test.py +++ b/tests/featureWriters/markFeatureWriter_test.py @@ -1818,7 +1818,6 @@ def test_contextual_anchors_no_mark_feature(self, testufo): lookup mark2base { pos base a - mark @MC_top mark @MC_top; } mark2base;