refactor array.fromstring to array.frombytes

fromstring is a deprecated array method
This commit is contained in:
Chris Simpkins 2019-08-29 22:58:42 -04:00
parent 11555c2fe0
commit 12814aa7b1
11 changed files with 19 additions and 19 deletions

View File

@ -23,7 +23,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
GMAPoffsets = array.array("I")
endPos = (self.numGMAPs+1) * 4
GMAPoffsets.fromstring(newData[:endPos])
GMAPoffsets.frombytes(newData[:endPos])
if sys.byteorder != "big": GMAPoffsets.byteswap()
self.GMAPs = []
for i in range(self.numGMAPs):
@ -33,7 +33,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
pos = endPos
endPos = pos + (self.numGlyplets + 1)*4
glyphletOffsets = array.array("I")
glyphletOffsets.fromstring(newData[pos:endPos])
glyphletOffsets.frombytes(newData[pos:endPos])
if sys.byteorder != "big": glyphletOffsets.byteswap()
self.glyphlets = []
for i in range(self.numGlyplets):

View File

@ -30,11 +30,11 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
flags = self.flags
del self.flags
self.locations = array.array('I' if flags & 1 else 'H')
self.locations.fromstring(data[:len(data) - self.numAttribs * (flags & 2)])
self.locations.frombytes(data[:len(data) - self.numAttribs * (flags & 2)])
if sys.byteorder != "big": self.locations.byteswap()
self.attribIds = array.array('H')
if flags & 2:
self.attribIds.fromstring(data[-self.numAttribs * 2:])
self.attribIds.frombytes(data[-self.numAttribs * 2:])
if sys.byteorder != "big": self.attribIds.byteswap()
def compile(self, ttFont):

View File

@ -18,7 +18,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
# ouch: the assertion is not true in Chicago!
#assert numGlyphs == ttFont['maxp'].numGlyphs
yPels = array.array("B")
yPels.fromstring(data)
yPels.frombytes(data)
self.yPels = {}
for i in range(numGlyphs):
self.yPels[ttFont.getGlyphName(i)] = yPels[i]

View File

@ -16,7 +16,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
numGlyphs = ttFont['maxp'].numGlyphs
assert len(data) == 2 * numGlyphs
a = array.array("H")
a.fromstring(data)
a.frombytes(data)
if sys.byteorder != "big": a.byteswap()
self.glyphGrouping = {}
for i in range(numGlyphs):

View File

@ -269,7 +269,7 @@ class TupleVariation(object):
else:
points = array.array("B")
pointsSize = numPointsInRun
points.fromstring(data[pos:pos+pointsSize])
points.frombytes(data[pos:pos+pointsSize])
if sys.byteorder != "big": points.byteswap()
assert len(points) == numPointsInRun
@ -426,7 +426,7 @@ class TupleVariation(object):
else:
deltas = array.array("b")
deltasSize = numDeltasInRun
deltas.fromstring(data[pos:pos+deltasSize])
deltas.frombytes(data[pos:pos+deltasSize])
if sys.byteorder != "big": deltas.byteswap()
assert len(deltas) == numDeltasInRun
pos += deltasSize

View File

@ -252,7 +252,7 @@ class cmap_format_0(CmapSubtable):
data = self.data # decompileHeader assigns the data after the header to self.data
assert 262 == self.length, "Format 0 cmap subtable not 262 bytes"
gids = array.array("B")
gids.fromstring(self.data)
gids.frombytes(self.data)
charCodes = list(range(len(gids)))
self.cmap = _make_map(self.ttFont, charCodes, gids)
@ -336,7 +336,7 @@ class cmap_format_2(CmapSubtable):
maxSubHeaderindex = 0
# get the key array, and determine the number of subHeaders.
allKeys = array.array("H")
allKeys.fromstring(data[:512])
allKeys.frombytes(data[:512])
data = data[512:]
if sys.byteorder != "big": allKeys.byteswap()
subHeaderKeys = [ key//8 for key in allKeys]
@ -352,7 +352,7 @@ class cmap_format_2(CmapSubtable):
pos += 8
giDataPos = pos + subHeader.idRangeOffset-2
giList = array.array("H")
giList.fromstring(data[giDataPos:giDataPos + subHeader.entryCount*2])
giList.frombytes(data[giDataPos:giDataPos + subHeader.entryCount*2])
if sys.byteorder != "big": giList.byteswap()
subHeader.glyphIndexArray = giList
subHeaderList.append(subHeader)
@ -694,7 +694,7 @@ class cmap_format_4(CmapSubtable):
segCount = segCountX2 // 2
allCodes = array.array("H")
allCodes.fromstring(data)
allCodes.frombytes(data)
self.data = data = None
if sys.byteorder != "big": allCodes.byteswap()
@ -864,7 +864,7 @@ class cmap_format_6(CmapSubtable):
data = data[4:]
#assert len(data) == 2 * entryCount # XXX not true in Apple's Helvetica!!!
gids = array.array("H")
gids.fromstring(data[:2 * int(entryCount)])
gids.frombytes(data[:2 * int(entryCount)])
if sys.byteorder != "big": gids.byteswap()
self.data = data = None

View File

@ -8,7 +8,7 @@ class table__c_v_t(DefaultTable.DefaultTable):
def decompile(self, data, ttFont):
values = array.array("h")
values.fromstring(data)
values.frombytes(data)
if sys.byteorder != "big": values.byteswap()
self.values = values

View File

@ -681,7 +681,7 @@ class Glyph(object):
def decompileCoordinates(self, data):
endPtsOfContours = array.array("h")
endPtsOfContours.fromstring(data[:2*self.numberOfContours])
endPtsOfContours.frombytes(data[:2*self.numberOfContours])
if sys.byteorder != "big": endPtsOfContours.byteswap()
self.endPtsOfContours = endPtsOfContours.tolist()

View File

@ -126,7 +126,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
# Long format: array of UInt32
offsets = array.array("I")
offsetsSize = (glyphCount + 1) * 4
offsets.fromstring(data[0 : offsetsSize])
offsets.frombytes(data[0 : offsetsSize])
if sys.byteorder != "big": offsets.byteswap()
# In the short format, offsets need to be multiplied by 2.

View File

@ -19,7 +19,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
else:
format = "H"
locations = array.array(format)
locations.fromstring(data)
locations.frombytes(data)
if sys.byteorder != "big": locations.byteswap()
if not longFormat:
l = array.array("I")

View File

@ -82,7 +82,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
numGlyphs = ttFont['maxp'].numGlyphs
data = data[2:]
indices = array.array("H")
indices.fromstring(data[:2*numGlyphs])
indices.frombytes(data[:2*numGlyphs])
if sys.byteorder != "big": indices.byteswap()
data = data[2*numGlyphs:]
self.extraNames = extraNames = unpackPStrings(data)
@ -131,7 +131,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
from fontTools import agl
numGlyphs = ttFont['maxp'].numGlyphs
indices = array.array("H")
indices.fromstring(data)
indices.frombytes(data)
if sys.byteorder != "big": indices.byteswap()
# In some older fonts, the size of the post table doesn't match
# the number of glyphs. Sometimes it's bigger, sometimes smaller.