-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add translate anchors filter #514
Open
simoncozens
wants to merge
6
commits into
googlefonts:main
Choose a base branch
from
simoncozens:translate-anchors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
afb06e4
Add translate anchors filter
simoncozens 1637a0f
Sanity check before translating
simoncozens c3660cb
Use basefilter directly
simoncozens 91688b0
Check for component use, fix sanity checks
simoncozens 626701a
Downgrade warning to info
simoncozens cea39cb
Too stuff
simoncozens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ | ||
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 | ||
|
||
# More sanity checks: skip over spacing marks | ||
if glyph.width != 0: | ||
return False | ||
# Also skip over marks which are deliberately positioned over the | ||
# previous glyphs | ||
if glyph.getBounds().xMax < 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a heuristic as to guess whether a mark was "deliberately positioned over the previous glyph", I think this is a bit too fragile. It's conceivable that the xMax still be >= 0 while the mark being intentionally designed to fall on top of another (e.g. narrow) base glyph |
||
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to explicitly call the
BaseFilter.set_context(self, font, glyphSet)
since that is what you are after.