refactor array.tostring to array.tobytes
the array.tostring method is deprecated
This commit is contained in:
parent
96abac75f5
commit
791f619029
@ -2075,7 +2075,7 @@ def remapComponentsFast(self, glyphidmap):
|
||||
elif flags & 0x0080: i += 8 # WE_HAVE_A_TWO_BY_TWO
|
||||
more = flags & 0x0020 # MORE_COMPONENTS
|
||||
|
||||
self.data = data.tostring()
|
||||
self.data = data.tobytes()
|
||||
|
||||
@_add_method(ttLib.getTableClass('glyf'))
|
||||
def closure_glyphs(self, s):
|
||||
|
@ -56,7 +56,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
||||
GMAPoffsets[i] = pos
|
||||
gmapArray = array.array("I", GMAPoffsets)
|
||||
if sys.byteorder != "big": gmapArray.byteswap()
|
||||
dataList.append(gmapArray.tostring())
|
||||
dataList.append(gmapArray.tobytes())
|
||||
|
||||
glyphletOffsets[0] = pos
|
||||
for i in range(1, self.numGlyplets +1):
|
||||
@ -64,7 +64,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
||||
glyphletOffsets[i] = pos
|
||||
glyphletArray = array.array("I", glyphletOffsets)
|
||||
if sys.byteorder != "big": glyphletArray.byteswap()
|
||||
dataList.append(glyphletArray.tostring())
|
||||
dataList.append(glyphletArray.tobytes())
|
||||
dataList += self.GMAPs
|
||||
dataList += self.glyphlets
|
||||
data = bytesjoin(dataList)
|
||||
|
@ -42,11 +42,11 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
|
||||
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'),
|
||||
numAttribs=self.numAttribs))
|
||||
if sys.byteorder != "big": self.locations.byteswap()
|
||||
data += self.locations.tostring()
|
||||
data += self.locations.tobytes()
|
||||
if sys.byteorder != "big": self.locations.byteswap()
|
||||
if self.attribIds:
|
||||
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||
data += self.attribIds.tostring()
|
||||
data += self.attribIds.tobytes()
|
||||
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||
return data
|
||||
|
||||
|
@ -33,7 +33,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
|
||||
for name in names:
|
||||
yPels[ttFont.getGlyphID(name)] = self.yPels[name]
|
||||
yPels = array.array("B", yPels)
|
||||
return struct.pack(">HH", version, numGlyphs) + yPels.tostring()
|
||||
return struct.pack(">HH", version, numGlyphs) + yPels.tobytes()
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
names = sorted(self.yPels.keys())
|
||||
|
@ -745,7 +745,7 @@ class Pass(object):
|
||||
transes = []
|
||||
for t in self.stateTrans:
|
||||
if sys.byteorder != "big": t.byteswap()
|
||||
transes.append(t.tostring())
|
||||
transes.append(t.tobytes())
|
||||
if sys.byteorder != "big": t.byteswap()
|
||||
if not len(transes):
|
||||
self.startStates = [0]
|
||||
|
@ -28,7 +28,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
|
||||
for i in range(len(glyphNames)):
|
||||
a.append(self.glyphGrouping.get(glyphNames[i], 0))
|
||||
if sys.byteorder != "big": a.byteswap()
|
||||
return a.tostring()
|
||||
return a.tobytes()
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
names = sorted(self.glyphGrouping.keys())
|
||||
|
@ -266,7 +266,7 @@ class cmap_format_0(CmapSubtable):
|
||||
valueList = [getGlyphID(cmap[i]) if i in cmap else 0 for i in range(256)]
|
||||
|
||||
gids = array.array("B", valueList)
|
||||
data = struct.pack(">HHH", 0, 262, self.language) + gids.tostring()
|
||||
data = struct.pack(">HHH", 0, 262, self.language) + gids.tobytes()
|
||||
assert len(data) == 262
|
||||
return data
|
||||
|
||||
@ -826,7 +826,7 @@ class cmap_format_4(CmapSubtable):
|
||||
if sys.byteorder != "big": charCodeArray.byteswap()
|
||||
if sys.byteorder != "big": idDeltaArray.byteswap()
|
||||
if sys.byteorder != "big": restArray.byteswap()
|
||||
data = charCodeArray.tostring() + idDeltaArray.tostring() + restArray.tostring()
|
||||
data = charCodeArray.tobytes() + idDeltaArray.tobytes() + restArray.tobytes()
|
||||
|
||||
length = struct.calcsize(cmap_format_4_format) + len(data)
|
||||
header = struct.pack(cmap_format_4_format, self.format, length, self.language,
|
||||
@ -885,7 +885,7 @@ class cmap_format_6(CmapSubtable):
|
||||
]
|
||||
gids = array.array("H", valueList)
|
||||
if sys.byteorder != "big": gids.byteswap()
|
||||
data = gids.tostring()
|
||||
data = gids.tobytes()
|
||||
else:
|
||||
data = b""
|
||||
firstCode = 0
|
||||
|
@ -15,7 +15,7 @@ class table__c_v_t(DefaultTable.DefaultTable):
|
||||
def compile(self, ttFont):
|
||||
values = self.values[:]
|
||||
if sys.byteorder != "big": values.byteswap()
|
||||
return values.tostring()
|
||||
return values.tobytes()
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
for i in range(len(self.values)):
|
||||
|
@ -795,7 +795,7 @@ class Glyph(object):
|
||||
data = []
|
||||
endPtsOfContours = array.array("h", self.endPtsOfContours)
|
||||
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
||||
data.append(endPtsOfContours.tostring())
|
||||
data.append(endPtsOfContours.tobytes())
|
||||
instructions = self.program.getBytecode()
|
||||
data.append(struct.pack(">h", len(instructions)))
|
||||
data.append(instructions)
|
||||
@ -859,7 +859,7 @@ class Glyph(object):
|
||||
repeat = 0
|
||||
compressedflags.append(flag)
|
||||
lastflag = flag
|
||||
compressedFlags = array.array("B", compressedflags).tostring()
|
||||
compressedFlags = array.array("B", compressedflags).tobytes()
|
||||
compressedXs = bytesjoin(xPoints)
|
||||
compressedYs = bytesjoin(yPoints)
|
||||
return (compressedFlags, compressedXs, compressedYs)
|
||||
@ -914,9 +914,9 @@ class Glyph(object):
|
||||
raise Exception("internal error")
|
||||
except StopIteration:
|
||||
pass
|
||||
compressedFlags = compressedFlags.tostring()
|
||||
compressedXs = compressedXs.tostring()
|
||||
compressedYs = compressedYs.tostring()
|
||||
compressedFlags = compressedFlags.tobytes()
|
||||
compressedXs = compressedXs.tobytes()
|
||||
compressedYs = compressedYs.tobytes()
|
||||
|
||||
return (compressedFlags, compressedXs, compressedYs)
|
||||
|
||||
@ -1156,7 +1156,7 @@ class Glyph(object):
|
||||
# Remove padding
|
||||
data = data[:i]
|
||||
|
||||
self.data = data.tostring()
|
||||
self.data = data.tobytes()
|
||||
|
||||
def removeHinting(self):
|
||||
self.trim (remove_hinting=True)
|
||||
|
@ -158,7 +158,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
||||
packed = array.array("I", offsets)
|
||||
tableFormat = 1
|
||||
if sys.byteorder != "big": packed.byteswap()
|
||||
return (packed.tostring(), tableFormat)
|
||||
return (packed.tobytes(), tableFormat)
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
writer.simpletag("version", value=self.version)
|
||||
|
@ -108,7 +108,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
||||
raise
|
||||
additionalMetrics = array.array("h", additionalMetrics)
|
||||
if sys.byteorder != "big": additionalMetrics.byteswap()
|
||||
data = data + additionalMetrics.tostring()
|
||||
data = data + additionalMetrics.tobytes()
|
||||
return data
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
|
@ -46,7 +46,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
|
||||
locations = array.array("I", self.locations)
|
||||
ttFont['head'].indexToLocFormat = 1
|
||||
if sys.byteorder != "big": locations.byteswap()
|
||||
return locations.tostring()
|
||||
return locations.tobytes()
|
||||
|
||||
def set(self, locations):
|
||||
self.locations = array.array("I", locations)
|
||||
|
@ -171,7 +171,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
||||
extraNames.append(psName)
|
||||
indices.append(index)
|
||||
if sys.byteorder != "big": indices.byteswap()
|
||||
return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(extraNames)
|
||||
return struct.pack(">H", numGlyphs) + indices.tobytes() + packPStrings(extraNames)
|
||||
|
||||
def encode_format_4_0(self, ttFont):
|
||||
from fontTools import agl
|
||||
@ -188,7 +188,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
||||
else:
|
||||
indices.append(0xFFFF)
|
||||
if sys.byteorder != "big": indices.byteswap()
|
||||
return indices.tostring()
|
||||
return indices.tobytes()
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
formatstring, names, fixes = sstruct.getformat(postFormat)
|
||||
|
@ -222,7 +222,7 @@ class Program(object):
|
||||
def getBytecode(self):
|
||||
if not hasattr(self, "bytecode"):
|
||||
self._assemble()
|
||||
return self.bytecode.tostring()
|
||||
return self.bytecode.tobytes()
|
||||
|
||||
def getAssembly(self, preserve=True):
|
||||
if not hasattr(self, "assembly"):
|
||||
|
@ -651,7 +651,7 @@ class WOFF2LocaTable(getTableClass('loca')):
|
||||
else:
|
||||
locations = array.array("I", self.locations)
|
||||
if sys.byteorder != "big": locations.byteswap()
|
||||
data = locations.tostring()
|
||||
data = locations.tobytes()
|
||||
else:
|
||||
# use the most compact indexFormat given the current glyph offsets
|
||||
data = super(WOFF2LocaTable, self).compile(ttFont)
|
||||
@ -733,7 +733,7 @@ class WOFF2GlyfTable(getTableClass('glyf')):
|
||||
for glyphID in range(self.numGlyphs):
|
||||
self._encodeGlyph(glyphID)
|
||||
|
||||
self.bboxStream = self.bboxBitmap.tostring() + self.bboxStream
|
||||
self.bboxStream = self.bboxBitmap.tobytes() + self.bboxStream
|
||||
for stream in self.subStreams:
|
||||
setattr(self, stream + 'Size', len(getattr(self, stream)))
|
||||
self.version = 0
|
||||
@ -961,8 +961,8 @@ class WOFF2GlyfTable(getTableClass('glyf')):
|
||||
triplets.append(absY >> 8)
|
||||
triplets.append(absY & 0xff)
|
||||
|
||||
self.flagStream += flags.tostring()
|
||||
self.glyphStream += triplets.tostring()
|
||||
self.flagStream += flags.tobytes()
|
||||
self.glyphStream += triplets.tobytes()
|
||||
|
||||
|
||||
class WOFF2HmtxTable(getTableClass("hmtx")):
|
||||
@ -1093,7 +1093,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
||||
)
|
||||
if sys.byteorder != "big":
|
||||
advanceWidthArray.byteswap()
|
||||
data += advanceWidthArray.tostring()
|
||||
data += advanceWidthArray.tobytes()
|
||||
|
||||
if hasLsbArray:
|
||||
lsbArray = array.array(
|
||||
@ -1106,7 +1106,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
||||
)
|
||||
if sys.byteorder != "big":
|
||||
lsbArray.byteswap()
|
||||
data += lsbArray.tostring()
|
||||
data += lsbArray.tobytes()
|
||||
|
||||
if hasLeftSideBearingArray:
|
||||
leftSideBearingArray = array.array(
|
||||
@ -1118,7 +1118,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
||||
)
|
||||
if sys.byteorder != "big":
|
||||
leftSideBearingArray.byteswap()
|
||||
data += leftSideBearingArray.tostring()
|
||||
data += leftSideBearingArray.tobytes()
|
||||
|
||||
return data
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user