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

make contextual mark writer continue to work with old ufo2ft #972

Merged
merged 1 commit into from
Jan 26, 2024
Merged
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
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
Loading