From 91688b0cee2279aaa63307a55c8ffcb2aa3a93b6 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 16 Jul 2021 13:17:22 +0100 Subject: [PATCH] Check for component use, fix sanity checks --- Lib/ufo2ft/filters/optimizeAnchors.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Lib/ufo2ft/filters/optimizeAnchors.py b/Lib/ufo2ft/filters/optimizeAnchors.py index 1df49e566..3806a7b20 100644 --- a/Lib/ufo2ft/filters/optimizeAnchors.py +++ b/Lib/ufo2ft/filters/optimizeAnchors.py @@ -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.