diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index 1e255506fc..b4586e39e1 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -1170,13 +1170,13 @@ def array(self): return self._a def isFloat(self): - return self._a.typecode == 'f' + return self._a.typecode == 'd' def _ensureFloat(self): if self.isFloat(): return # The conversion to list() is to work around Jython bug - self._a = array.array("f", list(self._a)) + self._a = array.array("d", list(self._a)) def _checkFloat(self, p): if self.isFloat(): diff --git a/Tests/ttLib/tables/_g_l_y_f_test.py b/Tests/ttLib/tables/_g_l_y_f_test.py index 7bb300fc6c..313a6e919a 100644 --- a/Tests/ttLib/tables/_g_l_y_f_test.py +++ b/Tests/ttLib/tables/_g_l_y_f_test.py @@ -143,3 +143,13 @@ def test__bool__(self): assert bool(g) == True g = GlyphCoordinates([(0,.5), (0,0)]) assert bool(g) == True + + def test_double_precision_float(self): + # https://github.com/fonttools/fonttools/issues/963 + afloat = 242.50000000000003 + g = GlyphCoordinates([(afloat, 0)]) + g.toInt() + # this would return 242 if the internal array.array typecode is 'f', + # since the Python float is truncated to a C float. + # when using typecode 'd' it should return the correct value 243 + assert g[0][0] == round(afloat)