-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86c3357
commit afb06e4
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from ufo2ft.filters.transformations import TransformationsFilter | ||
from fontTools.misc.transform import Identity, Transform | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class OptimizeAnchorsFilter(TransformationsFilter): | ||
def set_context(self, font, glyphSet): | ||
# Skip over transformations filter to base filter | ||
return super(TransformationsFilter, self).set_context(font, glyphSet) | ||
|
||
def filter(self, glyph): | ||
if len(glyph.anchors) == 0 or any( | ||
not (a.name.startswith("_")) for a in glyph.anchors | ||
): | ||
# We're a base! | ||
return False | ||
|
||
# We are a mark glyph with (at least) one attachment point. | ||
theanchor = glyph.anchors[0] | ||
self.context.matrix = Identity.translate(-theanchor.x, -theanchor.y) | ||
log.warn( | ||
"Transforming glyph %s to zero anchor %s: %s" | ||
% (glyph.name, theanchor.name, self.context.matrix) | ||
) | ||
return super().filter(glyph) |