Skip to content

Commit

Permalink
markFeatureWriter: Ignore contextual anchors
Browse files Browse the repository at this point in the history
We don’t support contextual anchors in markFeatureWriter, but glyphsLib
subclasses it and adds support for them. However, since we are unaware
of contextual anchors, we end up with positioning statements with
duplicated mark positions like this:

    pos base beh-ar.init
        <anchor 91 -316> mark @MC_top
        <anchor 91 -226> 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).

This PR adds isContextual to NamedAnchor and ignores any such anchors
when writing pose statements. It is already set by glyphsLib’s
MarkFeatureWriter, but otherwise should not affect ufo2ft’s as it always
sets it to False.
  • Loading branch information
khaledhosny committed Sep 3, 2024
1 parent 12b68f0 commit dcae755
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Lib/ufo2ft/featureWriters/markFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ def parseAnchorName(
class NamedAnchor:
"""A position with a name, and an associated markClass."""

__slots__ = ("name", "x", "y", "isMark", "key", "number", "markClass")
__slots__ = (
"name",
"x",
"y",
"isMark",
"key",
"number",
"markClass",
"isContextual",
)

# subclasses can customize these to use different anchor naming schemes
markPrefix = MARK_PREFIX
Expand Down Expand Up @@ -190,6 +199,7 @@ def __init__(self, name, x, y, markClass=None):
self.key = key
self.number = number
self.markClass = markClass
self.isContextual = False

@property
def markAnchorName(self):
Expand Down Expand Up @@ -620,6 +630,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:
Expand All @@ -640,6 +655,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",
Expand Down Expand Up @@ -671,6 +691,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 <anchor NULL>
if not anchor.key:
Expand Down

0 comments on commit dcae755

Please sign in to comment.