8000 [_g_l_y_f] fix float precision loss in GlyphCoordinates by anthrotype · Pull Request #964 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[_g_l_y_f] fix float precision loss in GlyphCoordinates #964

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

Merged
merged 2 commits into from
May 16, 2017
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
8000
4 changes: 2 additions & 2 deletions Lib/fontTools/ttLib/tables/_g_l_y_f.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
10 changes: 10 additions & 0 deletions Tests/ttLib/tables/_g_l_y_f_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
0