Skip to content
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

Transform advance width (and height) when scaling #515

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/ufo2ft/filters/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def filter(self, glyph):
if matrix == Identity or not (glyph or glyph.components or glyph.anchors):
return False # nothing to do

justscale = self.context.justscale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should go...

modified = self.context.modified
glyphSet = self.context.glyphSet
for component in glyph.components:
Expand Down Expand Up @@ -125,4 +126,6 @@ def filter(self, glyph):
for a in glyph.anchors:
a.x, a.y = matrix.transformPoint((a.x, a.y))

glyph.width, glyph.height = matrix.transformVector((glyph.width, glyph.height))

return True
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fonttools[lxml,ufo]==4.25.1
fonttools[lxml,ufo]==4.26.1
defcon==0.8.1
cu2qu==1.6.7
compreffor==0.5.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
setup_requires=pytest_runner + wheel + ["setuptools_scm"],
tests_require=["pytest>=2.8"],
install_requires=[
"fonttools[ufo]>=4.25.1",
"fonttools[ufo]>=4.26.1",
"cu2qu>=1.6.7",
"cffsubr>=0.2.8",
"booleanOperations>=0.9.0",
Expand Down
16 changes: 16 additions & 0 deletions tests/filters/transformations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def test_ScaleX(self, font, origin):
assert (a[0][0].x, a[0][0].y) == (0, 0)
assert (a[0][2].x, a[0][2].y) == (150, 300)

assert a.width == 350 * 0.50

def test_ScaleY(self, font, origin):
percent = 50
filter_ = TransformationsFilter(ScaleY=percent, Origin=origin)
Expand Down Expand Up @@ -156,6 +158,7 @@ def test_ScaleXY(self, font, origin):
# both x and y change
assert (a[0][0].x, a[0][0].y) == (0, bottom)
assert (a[0][2].x, a[0][2].y) == (150, top)
assert a.width == 350 * factor

def test_Slant(self, font, origin):
filter_ = TransformationsFilter(Slant=45, Origin=origin)
Expand Down Expand Up @@ -190,3 +193,16 @@ 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)

def test_ScaleOffset_width(self, font, origin):
percent = 50
filter_ = TransformationsFilter(
OffsetX=-100, ScaleX=percent, ScaleY=percent, Origin=origin
)
assert filter_(font)
factor = percent / 100

a = font["a"]
# The offset value here should not change the fact that the glyph
# bounding box is scaled by 50%.
assert a.width == 350 * factor