Skip to content

Commit

Permalink
Check for component use, fix sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Jul 16, 2021
1 parent c3660cb commit 91688b0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Lib/ufo2ft/filters/optimizeAnchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ class OptimizeAnchorsFilter(TransformationsFilter):
def set_context(self, font, glyphSet):
self.context = BaseFilter.set_context(self, font, glyphSet)

self.context.component_use = {}
for g in font.layers["public.default"]:
for comp in g.components:
self.context.component_use[comp.baseGlyph] = True

return self.context


def filter(self, glyph):
if len(glyph.anchors) == 0 or any(
not (a.name.startswith("_")) for a in glyph.anchors
):
if not any(a.name.startswith("_") for a in glyph.anchors):
# We're a base!
return False

# More sanity checks: skip over spacing marks
# Are we a spacing mark?
if glyph.width != 0:
return False

# Are we anywhere used as a component?
if glyph.name in self.context.component_use:
return False

# Also skip over marks which are deliberately positioned over the
# previous glyphs
if glyph.getBounds().xMax < 0:
if len(glyph.components) or glyph.getBounds().xMax < 0:
return False

# We are a mark glyph with (at least) one attachment point.
Expand Down

0 comments on commit 91688b0

Please sign in to comment.