-
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 metrics to transformations filter #238
Open
moyogo
wants to merge
4
commits into
googlefonts:main
Choose a base branch
from
moyogo:transformations-metrics
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from __future__ import print_function, division, absolute_import | ||
from ufo2ft.filters.transformations import TransformationsFilter, log | ||
from ufo2ft.filters.transformations import TransformationsFilter, logger | ||
from fontTools.misc.loggingTools import CapturingLogHandler | ||
from fontTools.misc.py23 import isclose | ||
import defcon | ||
|
@@ -18,6 +18,8 @@ | |
{ | ||
'name': 'a', | ||
'width': 350, | ||
'height': 400, | ||
'verticalOrigin': 350, | ||
'outline': [ | ||
('moveTo', ((0, 0),)), | ||
('lineTo', ((300, 0),)), | ||
|
@@ -33,6 +35,8 @@ | |
{ | ||
'name': 'b', | ||
'width': 450, | ||
'height': 400, | ||
'verticalOrigin': 350, | ||
'outline': [ | ||
('addComponent', ('a', (1, 0, 0, 1, 0, 0))), | ||
('addComponent', ('c', (1, 0, 0, 1, 0, 0))), | ||
|
@@ -63,6 +67,8 @@ def font(request): | |
for param in request.param['glyphs']: | ||
glyph = font.newGlyph(param['name']) | ||
glyph.width = param.get('width', 0) | ||
glyph.height = param.get('height', 0) | ||
glyph.verticalOrigin = param.get('verticalOrigin', None) | ||
pen = glyph.getPen() | ||
for operator, operands in param.get('outline', []): | ||
getattr(pen, operator)(*operands) | ||
|
@@ -192,3 +198,99 @@ def test_composite_glyphs(self, font): | |
# its original transform had a scale, so it was necessary to | ||
# compensate for the transformation applied on the base glyph | ||
assert d.components[0].transformation == (1, 0, 0, -1, 0, 102) | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_Width(self, font, name): | ||
value = -2 | ||
filter_ = TransformationsFilter( | ||
Width=value, include={name}) | ||
glyph = font[name] | ||
previousWidth = glyph.width | ||
assert {name} == filter_(font) | ||
assert glyph.width == previousWidth + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_Height(self, font, name): | ||
value = -4 | ||
filter_ = TransformationsFilter( | ||
Height=value, include={name}) | ||
glyph = font[name] | ||
previousHeight = glyph.height | ||
assert {name} == filter_(font) | ||
assert glyph.height == previousHeight + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_LSB(self, font, name): | ||
value = -10 | ||
filter_ = TransformationsFilter( | ||
LSB=value, include={name}) | ||
glyph = font[name] | ||
previousLeftMargin = glyph.leftMargin | ||
assert {name} == filter_(font) | ||
assert glyph.leftMargin == previousLeftMargin + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_RSB(self, font, name): | ||
value = +10 | ||
filter_ = TransformationsFilter( | ||
RSB=value, include={name}) | ||
glyph = font[name] | ||
previousRightMargin = glyph.rightMargin | ||
assert {name} == filter_(font) | ||
assert glyph.rightMargin == previousRightMargin + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_TSB(self, font, name): | ||
value = -12 | ||
filter_ = TransformationsFilter( | ||
TSB=value, include={name}) | ||
glyph = font[name] | ||
previousTopMargin = glyph.topMargin | ||
assert {name} == filter_(font) | ||
assert glyph.topMargin == previousTopMargin + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b", "c", "d"]) | ||
def test_BSB(self, font, name): | ||
value = +12 | ||
filter_ = TransformationsFilter( | ||
BSB=value, include={name}) | ||
glyph = font[name] | ||
previousBottomMargin = glyph.bottomMargin | ||
assert {name} == filter_(font) | ||
assert glyph.bottomMargin == previousBottomMargin + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["a", "b"]) | ||
def test_verticalOrigin(self, font, name): | ||
value = +13 | ||
filter_ = TransformationsFilter( | ||
VerticalOrigin=value, include={name}) | ||
glyph = font[name] | ||
previousVerticalOrigin = glyph.verticalOrigin | ||
assert {name} == filter_(font) | ||
assert glyph.verticalOrigin == previousVerticalOrigin + value | ||
|
||
@pytest.mark.parametrize( | ||
"name", | ||
["c", "d"]) | ||
def test_verticalOrigin_undefined(self, font, name): | ||
value = +14 | ||
with CapturingLogHandler(logger, level="WARNING") as captor: | ||
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. Since we are doing pytest-style tests you could use the caplog fixture |
||
filter_ = TransformationsFilter( | ||
VerticalOrigin=value, include={name}) | ||
filter_(font) | ||
captor.assertRegex( | ||
"Cannot add %i to undefined verticalOrigin in %s" % (value, name)) |
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.
minor suggestion: you don’t need to increment value +=current_value, just setattr(glyph, attr, current_value+value)