[gvar] Use array.array to decode deltas

This commit is contained in:
Behdad Esfahbod 2016-03-18 15:27:27 -07:00
parent 9987b7e14e
commit 40198a2dec

View File

@ -553,22 +553,32 @@ class GlyphVariation(object):
pos += 1 pos += 1
if numPointsInData == 0: if numPointsInData == 0:
return (range(numPointsInGlyph), pos) return (range(numPointsInGlyph), pos)
result = [] result = []
while len(result) < numPointsInData: while len(result) < numPointsInData:
runHeader = byteord(data[pos]) runHeader = byteord(data[pos])
pos += 1 pos += 1
numPointsInRun = (runHeader & POINT_RUN_COUNT_MASK) + 1 numPointsInRun = (runHeader & POINT_RUN_COUNT_MASK) + 1
point = 0 point = 0
if (runHeader & POINTS_ARE_WORDS) == 0: if (runHeader & POINTS_ARE_WORDS) != 0:
for _ in range(numPointsInRun): points = array.array("H")
point += byteord(data[pos]) pointsSize = numPointsInRun * 2
pos += 1
result.append(point)
else: else:
for _ in range(numPointsInRun): points = array.array("B")
point += struct.unpack(">H", data[pos:pos+2])[0] pointsSize = numPointsInRun
pos += 2 points.fromstring(data[pos:pos+pointsSize])
if sys.byteorder != "big":
points.byteswap()
assert len(points) == numPointsInRun
pos += pointsSize
# Convert relative to absolute, and append
for delta in points:
point += delta
result.append(point) result.append(point)
if max(result) >= numPointsInGlyph: if max(result) >= numPointsInGlyph:
raise TTLibError("malformed 'gvar' table") raise TTLibError("malformed 'gvar' table")
return (result, pos) return (result, pos)