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 1 commit
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
10 changes: 10 additions & 0 deletions Lib/ufo2ft/filters/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ def set_context(self, font, glyphSet):

ctx.matrix = m

justscale = m._asdict()
justscale["dx"] = 0
justscale["dy"] = 0
ctx.justscale = Transform(**justscale)

return ctx

def filter(self, glyph):
matrix = self.context.matrix
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 +131,8 @@ def filter(self, glyph):
for a in glyph.anchors:
a.x, a.y = matrix.transformPoint((a.x, a.y))

glyph.width, glyph.height = justscale.transformPoint(
anthrotype marked this conversation as resolved.
Show resolved Hide resolved
(glyph.width, glyph.height)
)

return True
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