Skip to content

Commit f78d7f7

Browse files
authored
Merge pull request #176 from anthrotype/mathinfo-undef-num-lists
mathInfo: handle case when one operand is None and attribute is number list
2 parents a07bcc3 + d6b8879 commit f78d7f7

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

Lib/fontMath/mathInfo.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,20 @@ def _processMathOne(self, copiedInfo, otherInfo, ptFunc, func):
5959
v = self._processMathOneNumberList(a, b, func)
6060
else:
6161
v = self._processMathOneNumber(a, b, func)
62+
# when one of the terms is undefined, we treat addition and subtraction
63+
# differently...
64+
# https://github.com/robotools/fontMath/issues/175
65+
# https://github.com/robotools/fontMath/issues/136
6266
elif a is not None and b is None:
63-
#v = a
6467
if func == add:
6568
v = a
6669
else:
67-
v = 0
70+
v = None if attr in _numberListAttrs else 0
6871
elif b is not None and a is None:
69-
#v = b
7072
if func is add:
7173
v = b
7274
else:
73-
v = 0
75+
v = None if attr in _numberListAttrs else 0
7476
if v is not None:
7577
setattr(copiedInfo, attr, v)
7678
# special attributes
@@ -421,6 +423,12 @@ def _openTypeOS2WeightClassFormatter(value):
421423
# postscriptWeightName=unicode
422424
)
423425

426+
_numberListAttrs = {
427+
attr
428+
for attr, (formatter, _) in _infoAttrs.items()
429+
if formatter is _numberListFormatter
430+
}
431+
424432
_postscriptWeightNameOptions = {
425433
100 : "Thin",
426434
200 : "Extra-light",

Lib/fontMath/test/test_mathInfo.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from fontMath.mathFunctions import _roundNumber
3-
from fontMath.mathInfo import MathInfo
3+
from fontMath.mathInfo import MathInfo, _numberListAttrs
44

55

66
class MathInfoTest(unittest.TestCase):
@@ -213,6 +213,27 @@ def test_round(self):
213213
expectedValue = _roundNumber(value)
214214
expected[attr] = expectedValue
215215
self.assertEqual(sorted(expected), sorted(written))
216+
217+
def test_sub_undefined_number_list_does_nothing(self):
218+
self.assertIn("postscriptBlueValues", _numberListAttrs)
219+
220+
info1 = _TestInfoObject()
221+
info1.postscriptBlueValues = None
222+
m1 = MathInfo(info1)
223+
224+
info2 = _TestInfoObject()
225+
info2.postscriptBlueValues = [1, 2, 3]
226+
m2 = MathInfo(info2)
227+
228+
m3 = m2 - m1
229+
230+
self.assertEqual(m3.postscriptBlueValues, [1, 2, 3])
231+
232+
m4 = m1 - m2
233+
234+
self.assertEqual(m4.postscriptBlueValues, None)
235+
236+
216237
# ----
217238
# Test Data
218239
# ----

0 commit comments

Comments
 (0)