[GlyphCoordinates] Store int data as 4byte, not 2byte
The memory increase is negligible, but means that we don't have to worry about integer overflows anymore.
This commit is contained in:
parent
8be2f49b84
commit
e9acd9634f
@ -1432,7 +1432,8 @@ class GlyphComponent(object):
|
|||||||
|
|
||||||
class GlyphCoordinates(object):
|
class GlyphCoordinates(object):
|
||||||
|
|
||||||
def __init__(self, iterable=[], typecode="h"):
|
def __init__(self, iterable=[], typecode='i'):
|
||||||
|
if typecode == 'h': typecode = 'i'
|
||||||
self._a = array.array(typecode)
|
self._a = array.array(typecode)
|
||||||
self.extend(iterable)
|
self.extend(iterable)
|
||||||
|
|
||||||
@ -1451,9 +1452,6 @@ class GlyphCoordinates(object):
|
|||||||
def _checkFloat(self, p):
|
def _checkFloat(self, p):
|
||||||
if self.isFloat():
|
if self.isFloat():
|
||||||
return p
|
return p
|
||||||
if any(v > 0x7FFF or v < -0x8000 for v in p):
|
|
||||||
self._ensureFloat()
|
|
||||||
return p
|
|
||||||
if any(isinstance(v, float) for v in p):
|
if any(isinstance(v, float) for v in p):
|
||||||
p = [int(v) if int(v) == v else v for v in p]
|
p = [int(v) if int(v) == v else v for v in p]
|
||||||
if any(isinstance(v, float) for v in p):
|
if any(isinstance(v, float) for v in p):
|
||||||
@ -1508,7 +1506,7 @@ class GlyphCoordinates(object):
|
|||||||
def toInt(self, *, round=otRound):
|
def toInt(self, *, round=otRound):
|
||||||
if not self.isFloat():
|
if not self.isFloat():
|
||||||
return
|
return
|
||||||
a = array.array("h")
|
a = array.array("i")
|
||||||
for n in self._a:
|
for n in self._a:
|
||||||
a.append(round(n))
|
a.append(round(n))
|
||||||
self._a = a
|
self._a = a
|
||||||
|
@ -173,10 +173,9 @@ class GlyphCoordinatesTest(object):
|
|||||||
assert g[0][0] == otRound(afloat)
|
assert g[0][0] == otRound(afloat)
|
||||||
|
|
||||||
def test__checkFloat_overflow(self):
|
def test__checkFloat_overflow(self):
|
||||||
g = GlyphCoordinates([(1, 1)], typecode="h")
|
g = GlyphCoordinates([(1, 1)])
|
||||||
g.append((0x8000, 0))
|
g.append((0x8000, 0))
|
||||||
assert g.array.typecode == "d"
|
assert list(g.array) == [1.0, 1.0, 32768.0, 0.0]
|
||||||
assert g.array == array.array("d", [1.0, 1.0, 32768.0, 0.0])
|
|
||||||
|
|
||||||
|
|
||||||
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user