Skip to content

Commit

Permalink
Merge pull request #972 from googlefonts/back-compat-mark-writer
Browse files Browse the repository at this point in the history
make contextual mark writer continue to work with old ufo2ft
  • Loading branch information
anthrotype authored Jan 26, 2024
2 parents c1e943e + e9e8f97 commit ed02363
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Lib/glyphsLib/featureWriters/markFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MarkToBasePos,
NamedAnchor,
)
from ufo2ft.util import quantize


class ContextuallyAwareNamedAnchor(NamedAnchor):
Expand Down Expand Up @@ -115,6 +116,21 @@ def __init__(self, name, x, y, markClass=None, libData=None):
class ContextualMarkFeatureWriter(MarkFeatureWriter):
NamedAnchor = ContextuallyAwareNamedAnchor

def _getAnchor(self, glyphName, anchorName, anchor=None):
# the variable FEA aware method is defined with ufo2ft v3; make sure we don't
# fail but continue to work unchanged with older ufo2ft MarkFeatureWriter API.
try:
getter = super()._getAnchor
except AttributeError:
x = anchor.x
y = anchor.y
if hasattr(self.options, "quantization"):
x = quantize(x, self.options.quantization)
y = quantize(y, self.options.quantization)
return x, y
else:
return getter(glyphName, anchorName, anchor=anchor)

def _getAnchorLists(self):
gdefClasses = self.context.gdefClasses
if gdefClasses.base is not None:
Expand All @@ -139,7 +155,7 @@ def _getAnchorLists(self):
self.log.warning(
"duplicate anchor '%s' in glyph '%s'", anchorName, glyphName
)
x, y = self._getAnchor(glyphName, anchorName)
x, y = self._getAnchor(glyphName, anchorName, anchor=anchor)
libData = None
if anchor.identifier:
libData = glyph.lib[OBJECT_LIBS_KEY].get(anchor.identifier)
Expand Down

0 comments on commit ed02363

Please sign in to comment.