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

Fix multiplication of fontinfo slant and italic angles #189

Merged
merged 1 commit into from
Jun 21, 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
4 changes: 4 additions & 0 deletions Lib/fontMath/mathFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def divPt(pt, f):

def factorAngle(angle, f, func):
(f1, f2) = f
# If both factors are equal, assume a scalar factor and scale the angle as such.
if f1 == f2:
return func(angle, f1)
# Otherwise, scale x and y components separately.
rangle = math.radians(angle)
x = math.cos(rangle)
y = math.sin(rangle)
Expand Down
6 changes: 3 additions & 3 deletions Lib/fontMath/test/test_mathGlyph.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def test_guidelines_mul(self):
]
glyph2 = glyph1 * 3
expected = [
dict(x=1 * 3, y=3 * 3, angle=5, name="test", identifier="1",
dict(x=1 * 3, y=3 * 3, angle=15, name="test", identifier="1",
color="0,0,0,0")
]
self.assertEqual(glyph2.guidelines, expected)
Expand Down Expand Up @@ -428,11 +428,11 @@ def test_guidelines_valid_angle(self):
glyph4 = glyph1 - glyph2
self.assertEqual(glyph4.guidelines, expected_sub)

expected_mul = [dict(name="foo", identifier="1", x=0, y=0, angle=359)]
expected_mul = [dict(name="foo", identifier="1", x=0, y=0, angle=355)]
glyph5 = glyph2 * 5
self.assertEqual(glyph5.guidelines, expected_mul)

expected_div = [dict(name="foo", identifier="1", x=0, y=0, angle=359)]
expected_div = [dict(name="foo", identifier="1", x=0, y=0, angle=71.8)]
glyph6 = glyph2 / 5
self.assertEqual(glyph6.guidelines, expected_div)

Expand Down
24 changes: 22 additions & 2 deletions Lib/fontMath/test/test_mathInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def test_mul(self):
expected[attr] = expectedValue
self.assertEqual(sorted(expected.items()), sorted(written.items()))

def test_angle(self):
info1 = MathInfo(_TestInfoObject())
info1.italicAngle = 10

info2 = info1 - info1
self.assertEqual(info2.italicAngle, 0)
info2 = info1 + info1 + info1
self.assertEqual(info2.italicAngle, 30)
info2 = 10 * info1
self.assertEqual(info2.italicAngle, 100)
info2 = info1 / 20
self.assertEqual(info2.italicAngle, 0.5)

info2 = info1 * 2.5
self.assertEqual(info2.italicAngle, 25)
info2 = info1 * (2.5, 2.5)
self.assertEqual(info2.italicAngle, 25)
info2 = info1 * (2.5, 5)
self.assertEqual(round(info2.italicAngle), 19)

def test_mul_data_subset(self):
info1 = MathInfo(_TestInfoObject(_testDataSubset))
info2 = info1 * 2.5
Expand Down Expand Up @@ -268,7 +288,7 @@ def test_number_lists_with_different_lengths(self):
xHeight=400,
capHeight=650,
ascender=700,
italicAngle=0,
italicAngle=5,
# head
openTypeHeadLowestRecPPEM=5,
# hhea
Expand Down Expand Up @@ -304,7 +324,7 @@ def test_number_lists_with_different_lengths(self):
openTypeVheaCaretSlopeRun=1,
openTypeVheaCaretOffset=1,
# postscript
postscriptSlantAngle=0,
postscriptSlantAngle=-5,
postscriptUnderlineThickness=100,
postscriptUnderlinePosition=-150,
postscriptBlueValues=[-10, 0, 400, 410, 650, 660, 700, 710],
Expand Down