Merge pull request #1712 from chrissimpkins/refactor-array-tofromstring
Refactor deprecated array tostring/fromstring methods to tobytes/frombytes
This commit is contained in:
commit
9938efbef5
@ -2075,7 +2075,7 @@ def remapComponentsFast(self, glyphidmap):
|
|||||||
elif flags & 0x0080: i += 8 # WE_HAVE_A_TWO_BY_TWO
|
elif flags & 0x0080: i += 8 # WE_HAVE_A_TWO_BY_TWO
|
||||||
more = flags & 0x0020 # MORE_COMPONENTS
|
more = flags & 0x0020 # MORE_COMPONENTS
|
||||||
|
|
||||||
self.data = data.tostring()
|
self.data = data.tobytes()
|
||||||
|
|
||||||
@_add_method(ttLib.getTableClass('glyf'))
|
@_add_method(ttLib.getTableClass('glyf'))
|
||||||
def closure_glyphs(self, s):
|
def closure_glyphs(self, s):
|
||||||
|
@ -23,7 +23,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
GMAPoffsets = array.array("I")
|
GMAPoffsets = array.array("I")
|
||||||
endPos = (self.numGMAPs+1) * 4
|
endPos = (self.numGMAPs+1) * 4
|
||||||
GMAPoffsets.fromstring(newData[:endPos])
|
GMAPoffsets.frombytes(newData[:endPos])
|
||||||
if sys.byteorder != "big": GMAPoffsets.byteswap()
|
if sys.byteorder != "big": GMAPoffsets.byteswap()
|
||||||
self.GMAPs = []
|
self.GMAPs = []
|
||||||
for i in range(self.numGMAPs):
|
for i in range(self.numGMAPs):
|
||||||
@ -33,7 +33,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
pos = endPos
|
pos = endPos
|
||||||
endPos = pos + (self.numGlyplets + 1)*4
|
endPos = pos + (self.numGlyplets + 1)*4
|
||||||
glyphletOffsets = array.array("I")
|
glyphletOffsets = array.array("I")
|
||||||
glyphletOffsets.fromstring(newData[pos:endPos])
|
glyphletOffsets.frombytes(newData[pos:endPos])
|
||||||
if sys.byteorder != "big": glyphletOffsets.byteswap()
|
if sys.byteorder != "big": glyphletOffsets.byteswap()
|
||||||
self.glyphlets = []
|
self.glyphlets = []
|
||||||
for i in range(self.numGlyplets):
|
for i in range(self.numGlyplets):
|
||||||
@ -56,7 +56,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
GMAPoffsets[i] = pos
|
GMAPoffsets[i] = pos
|
||||||
gmapArray = array.array("I", GMAPoffsets)
|
gmapArray = array.array("I", GMAPoffsets)
|
||||||
if sys.byteorder != "big": gmapArray.byteswap()
|
if sys.byteorder != "big": gmapArray.byteswap()
|
||||||
dataList.append(gmapArray.tostring())
|
dataList.append(gmapArray.tobytes())
|
||||||
|
|
||||||
glyphletOffsets[0] = pos
|
glyphletOffsets[0] = pos
|
||||||
for i in range(1, self.numGlyplets +1):
|
for i in range(1, self.numGlyplets +1):
|
||||||
@ -64,7 +64,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
glyphletOffsets[i] = pos
|
glyphletOffsets[i] = pos
|
||||||
glyphletArray = array.array("I", glyphletOffsets)
|
glyphletArray = array.array("I", glyphletOffsets)
|
||||||
if sys.byteorder != "big": glyphletArray.byteswap()
|
if sys.byteorder != "big": glyphletArray.byteswap()
|
||||||
dataList.append(glyphletArray.tostring())
|
dataList.append(glyphletArray.tobytes())
|
||||||
dataList += self.GMAPs
|
dataList += self.GMAPs
|
||||||
dataList += self.glyphlets
|
dataList += self.glyphlets
|
||||||
data = bytesjoin(dataList)
|
data = bytesjoin(dataList)
|
||||||
|
@ -30,11 +30,11 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
|
|||||||
flags = self.flags
|
flags = self.flags
|
||||||
del self.flags
|
del self.flags
|
||||||
self.locations = array.array('I' if flags & 1 else 'H')
|
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()
|
if sys.byteorder != "big": self.locations.byteswap()
|
||||||
self.attribIds = array.array('H')
|
self.attribIds = array.array('H')
|
||||||
if flags & 2:
|
if flags & 2:
|
||||||
self.attribIds.fromstring(data[-self.numAttribs * 2:])
|
self.attribIds.frombytes(data[-self.numAttribs * 2:])
|
||||||
if sys.byteorder != "big": self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
@ -42,11 +42,11 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
|
|||||||
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'),
|
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'),
|
||||||
numAttribs=self.numAttribs))
|
numAttribs=self.numAttribs))
|
||||||
if sys.byteorder != "big": self.locations.byteswap()
|
if sys.byteorder != "big": self.locations.byteswap()
|
||||||
data += self.locations.tostring()
|
data += self.locations.tobytes()
|
||||||
if sys.byteorder != "big": self.locations.byteswap()
|
if sys.byteorder != "big": self.locations.byteswap()
|
||||||
if self.attribIds:
|
if self.attribIds:
|
||||||
if sys.byteorder != "big": self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
data += self.attribIds.tostring()
|
data += self.attribIds.tobytes()
|
||||||
if sys.byteorder != "big": self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
|
|||||||
# ouch: the assertion is not true in Chicago!
|
# ouch: the assertion is not true in Chicago!
|
||||||
#assert numGlyphs == ttFont['maxp'].numGlyphs
|
#assert numGlyphs == ttFont['maxp'].numGlyphs
|
||||||
yPels = array.array("B")
|
yPels = array.array("B")
|
||||||
yPels.fromstring(data)
|
yPels.frombytes(data)
|
||||||
self.yPels = {}
|
self.yPels = {}
|
||||||
for i in range(numGlyphs):
|
for i in range(numGlyphs):
|
||||||
self.yPels[ttFont.getGlyphName(i)] = yPels[i]
|
self.yPels[ttFont.getGlyphName(i)] = yPels[i]
|
||||||
@ -33,7 +33,7 @@ class table_L_T_S_H_(DefaultTable.DefaultTable):
|
|||||||
for name in names:
|
for name in names:
|
||||||
yPels[ttFont.getGlyphID(name)] = self.yPels[name]
|
yPels[ttFont.getGlyphID(name)] = self.yPels[name]
|
||||||
yPels = array.array("B", yPels)
|
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):
|
def toXML(self, writer, ttFont):
|
||||||
names = sorted(self.yPels.keys())
|
names = sorted(self.yPels.keys())
|
||||||
|
@ -745,7 +745,7 @@ class Pass(object):
|
|||||||
transes = []
|
transes = []
|
||||||
for t in self.stateTrans:
|
for t in self.stateTrans:
|
||||||
if sys.byteorder != "big": t.byteswap()
|
if sys.byteorder != "big": t.byteswap()
|
||||||
transes.append(t.tostring())
|
transes.append(t.tobytes())
|
||||||
if sys.byteorder != "big": t.byteswap()
|
if sys.byteorder != "big": t.byteswap()
|
||||||
if not len(transes):
|
if not len(transes):
|
||||||
self.startStates = [0]
|
self.startStates = [0]
|
||||||
|
@ -16,7 +16,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
|
|||||||
numGlyphs = ttFont['maxp'].numGlyphs
|
numGlyphs = ttFont['maxp'].numGlyphs
|
||||||
assert len(data) == 2 * numGlyphs
|
assert len(data) == 2 * numGlyphs
|
||||||
a = array.array("H")
|
a = array.array("H")
|
||||||
a.fromstring(data)
|
a.frombytes(data)
|
||||||
if sys.byteorder != "big": a.byteswap()
|
if sys.byteorder != "big": a.byteswap()
|
||||||
self.glyphGrouping = {}
|
self.glyphGrouping = {}
|
||||||
for i in range(numGlyphs):
|
for i in range(numGlyphs):
|
||||||
@ -28,7 +28,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
|
|||||||
for i in range(len(glyphNames)):
|
for i in range(len(glyphNames)):
|
||||||
a.append(self.glyphGrouping.get(glyphNames[i], 0))
|
a.append(self.glyphGrouping.get(glyphNames[i], 0))
|
||||||
if sys.byteorder != "big": a.byteswap()
|
if sys.byteorder != "big": a.byteswap()
|
||||||
return a.tostring()
|
return a.tobytes()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
names = sorted(self.glyphGrouping.keys())
|
names = sorted(self.glyphGrouping.keys())
|
||||||
|
@ -269,7 +269,7 @@ class TupleVariation(object):
|
|||||||
else:
|
else:
|
||||||
points = array.array("B")
|
points = array.array("B")
|
||||||
pointsSize = numPointsInRun
|
pointsSize = numPointsInRun
|
||||||
points.fromstring(data[pos:pos+pointsSize])
|
points.frombytes(data[pos:pos+pointsSize])
|
||||||
if sys.byteorder != "big": points.byteswap()
|
if sys.byteorder != "big": points.byteswap()
|
||||||
|
|
||||||
assert len(points) == numPointsInRun
|
assert len(points) == numPointsInRun
|
||||||
@ -426,7 +426,7 @@ class TupleVariation(object):
|
|||||||
else:
|
else:
|
||||||
deltas = array.array("b")
|
deltas = array.array("b")
|
||||||
deltasSize = numDeltasInRun
|
deltasSize = numDeltasInRun
|
||||||
deltas.fromstring(data[pos:pos+deltasSize])
|
deltas.frombytes(data[pos:pos+deltasSize])
|
||||||
if sys.byteorder != "big": deltas.byteswap()
|
if sys.byteorder != "big": deltas.byteswap()
|
||||||
assert len(deltas) == numDeltasInRun
|
assert len(deltas) == numDeltasInRun
|
||||||
pos += deltasSize
|
pos += deltasSize
|
||||||
|
@ -252,7 +252,7 @@ class cmap_format_0(CmapSubtable):
|
|||||||
data = self.data # decompileHeader assigns the data after the header to self.data
|
data = self.data # decompileHeader assigns the data after the header to self.data
|
||||||
assert 262 == self.length, "Format 0 cmap subtable not 262 bytes"
|
assert 262 == self.length, "Format 0 cmap subtable not 262 bytes"
|
||||||
gids = array.array("B")
|
gids = array.array("B")
|
||||||
gids.fromstring(self.data)
|
gids.frombytes(self.data)
|
||||||
charCodes = list(range(len(gids)))
|
charCodes = list(range(len(gids)))
|
||||||
self.cmap = _make_map(self.ttFont, charCodes, gids)
|
self.cmap = _make_map(self.ttFont, charCodes, gids)
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ class cmap_format_0(CmapSubtable):
|
|||||||
valueList = [getGlyphID(cmap[i]) if i in cmap else 0 for i in range(256)]
|
valueList = [getGlyphID(cmap[i]) if i in cmap else 0 for i in range(256)]
|
||||||
|
|
||||||
gids = array.array("B", valueList)
|
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
|
assert len(data) == 262
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ class cmap_format_2(CmapSubtable):
|
|||||||
maxSubHeaderindex = 0
|
maxSubHeaderindex = 0
|
||||||
# get the key array, and determine the number of subHeaders.
|
# get the key array, and determine the number of subHeaders.
|
||||||
allKeys = array.array("H")
|
allKeys = array.array("H")
|
||||||
allKeys.fromstring(data[:512])
|
allKeys.frombytes(data[:512])
|
||||||
data = data[512:]
|
data = data[512:]
|
||||||
if sys.byteorder != "big": allKeys.byteswap()
|
if sys.byteorder != "big": allKeys.byteswap()
|
||||||
subHeaderKeys = [ key//8 for key in allKeys]
|
subHeaderKeys = [ key//8 for key in allKeys]
|
||||||
@ -352,7 +352,7 @@ class cmap_format_2(CmapSubtable):
|
|||||||
pos += 8
|
pos += 8
|
||||||
giDataPos = pos + subHeader.idRangeOffset-2
|
giDataPos = pos + subHeader.idRangeOffset-2
|
||||||
giList = array.array("H")
|
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()
|
if sys.byteorder != "big": giList.byteswap()
|
||||||
subHeader.glyphIndexArray = giList
|
subHeader.glyphIndexArray = giList
|
||||||
subHeaderList.append(subHeader)
|
subHeaderList.append(subHeader)
|
||||||
@ -694,7 +694,7 @@ class cmap_format_4(CmapSubtable):
|
|||||||
segCount = segCountX2 // 2
|
segCount = segCountX2 // 2
|
||||||
|
|
||||||
allCodes = array.array("H")
|
allCodes = array.array("H")
|
||||||
allCodes.fromstring(data)
|
allCodes.frombytes(data)
|
||||||
self.data = data = None
|
self.data = data = None
|
||||||
|
|
||||||
if sys.byteorder != "big": allCodes.byteswap()
|
if sys.byteorder != "big": allCodes.byteswap()
|
||||||
@ -826,7 +826,7 @@ class cmap_format_4(CmapSubtable):
|
|||||||
if sys.byteorder != "big": charCodeArray.byteswap()
|
if sys.byteorder != "big": charCodeArray.byteswap()
|
||||||
if sys.byteorder != "big": idDeltaArray.byteswap()
|
if sys.byteorder != "big": idDeltaArray.byteswap()
|
||||||
if sys.byteorder != "big": restArray.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)
|
length = struct.calcsize(cmap_format_4_format) + len(data)
|
||||||
header = struct.pack(cmap_format_4_format, self.format, length, self.language,
|
header = struct.pack(cmap_format_4_format, self.format, length, self.language,
|
||||||
@ -864,7 +864,7 @@ class cmap_format_6(CmapSubtable):
|
|||||||
data = data[4:]
|
data = data[4:]
|
||||||
#assert len(data) == 2 * entryCount # XXX not true in Apple's Helvetica!!!
|
#assert len(data) == 2 * entryCount # XXX not true in Apple's Helvetica!!!
|
||||||
gids = array.array("H")
|
gids = array.array("H")
|
||||||
gids.fromstring(data[:2 * int(entryCount)])
|
gids.frombytes(data[:2 * int(entryCount)])
|
||||||
if sys.byteorder != "big": gids.byteswap()
|
if sys.byteorder != "big": gids.byteswap()
|
||||||
self.data = data = None
|
self.data = data = None
|
||||||
|
|
||||||
@ -885,7 +885,7 @@ class cmap_format_6(CmapSubtable):
|
|||||||
]
|
]
|
||||||
gids = array.array("H", valueList)
|
gids = array.array("H", valueList)
|
||||||
if sys.byteorder != "big": gids.byteswap()
|
if sys.byteorder != "big": gids.byteswap()
|
||||||
data = gids.tostring()
|
data = gids.tobytes()
|
||||||
else:
|
else:
|
||||||
data = b""
|
data = b""
|
||||||
firstCode = 0
|
firstCode = 0
|
||||||
|
@ -8,14 +8,14 @@ class table__c_v_t(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
def decompile(self, data, ttFont):
|
def decompile(self, data, ttFont):
|
||||||
values = array.array("h")
|
values = array.array("h")
|
||||||
values.fromstring(data)
|
values.frombytes(data)
|
||||||
if sys.byteorder != "big": values.byteswap()
|
if sys.byteorder != "big": values.byteswap()
|
||||||
self.values = values
|
self.values = values
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
values = self.values[:]
|
values = self.values[:]
|
||||||
if sys.byteorder != "big": values.byteswap()
|
if sys.byteorder != "big": values.byteswap()
|
||||||
return values.tostring()
|
return values.tobytes()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
for i in range(len(self.values)):
|
for i in range(len(self.values)):
|
||||||
|
@ -681,7 +681,7 @@ class Glyph(object):
|
|||||||
|
|
||||||
def decompileCoordinates(self, data):
|
def decompileCoordinates(self, data):
|
||||||
endPtsOfContours = array.array("h")
|
endPtsOfContours = array.array("h")
|
||||||
endPtsOfContours.fromstring(data[:2*self.numberOfContours])
|
endPtsOfContours.frombytes(data[:2*self.numberOfContours])
|
||||||
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
||||||
self.endPtsOfContours = endPtsOfContours.tolist()
|
self.endPtsOfContours = endPtsOfContours.tolist()
|
||||||
|
|
||||||
@ -795,7 +795,7 @@ class Glyph(object):
|
|||||||
data = []
|
data = []
|
||||||
endPtsOfContours = array.array("h", self.endPtsOfContours)
|
endPtsOfContours = array.array("h", self.endPtsOfContours)
|
||||||
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
||||||
data.append(endPtsOfContours.tostring())
|
data.append(endPtsOfContours.tobytes())
|
||||||
instructions = self.program.getBytecode()
|
instructions = self.program.getBytecode()
|
||||||
data.append(struct.pack(">h", len(instructions)))
|
data.append(struct.pack(">h", len(instructions)))
|
||||||
data.append(instructions)
|
data.append(instructions)
|
||||||
@ -859,7 +859,7 @@ class Glyph(object):
|
|||||||
repeat = 0
|
repeat = 0
|
||||||
compressedflags.append(flag)
|
compressedflags.append(flag)
|
||||||
lastflag = flag
|
lastflag = flag
|
||||||
compressedFlags = array.array("B", compressedflags).tostring()
|
compressedFlags = array.array("B", compressedflags).tobytes()
|
||||||
compressedXs = bytesjoin(xPoints)
|
compressedXs = bytesjoin(xPoints)
|
||||||
compressedYs = bytesjoin(yPoints)
|
compressedYs = bytesjoin(yPoints)
|
||||||
return (compressedFlags, compressedXs, compressedYs)
|
return (compressedFlags, compressedXs, compressedYs)
|
||||||
@ -914,9 +914,9 @@ class Glyph(object):
|
|||||||
raise Exception("internal error")
|
raise Exception("internal error")
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
compressedFlags = compressedFlags.tostring()
|
compressedFlags = compressedFlags.tobytes()
|
||||||
compressedXs = compressedXs.tostring()
|
compressedXs = compressedXs.tobytes()
|
||||||
compressedYs = compressedYs.tostring()
|
compressedYs = compressedYs.tobytes()
|
||||||
|
|
||||||
return (compressedFlags, compressedXs, compressedYs)
|
return (compressedFlags, compressedXs, compressedYs)
|
||||||
|
|
||||||
@ -1156,7 +1156,7 @@ class Glyph(object):
|
|||||||
# Remove padding
|
# Remove padding
|
||||||
data = data[:i]
|
data = data[:i]
|
||||||
|
|
||||||
self.data = data.tostring()
|
self.data = data.tobytes()
|
||||||
|
|
||||||
def removeHinting(self):
|
def removeHinting(self):
|
||||||
self.trim (remove_hinting=True)
|
self.trim (remove_hinting=True)
|
||||||
|
@ -126,7 +126,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|||||||
# Long format: array of UInt32
|
# Long format: array of UInt32
|
||||||
offsets = array.array("I")
|
offsets = array.array("I")
|
||||||
offsetsSize = (glyphCount + 1) * 4
|
offsetsSize = (glyphCount + 1) * 4
|
||||||
offsets.fromstring(data[0 : offsetsSize])
|
offsets.frombytes(data[0 : offsetsSize])
|
||||||
if sys.byteorder != "big": offsets.byteswap()
|
if sys.byteorder != "big": offsets.byteswap()
|
||||||
|
|
||||||
# In the short format, offsets need to be multiplied by 2.
|
# In the short format, offsets need to be multiplied by 2.
|
||||||
@ -158,7 +158,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|||||||
packed = array.array("I", offsets)
|
packed = array.array("I", offsets)
|
||||||
tableFormat = 1
|
tableFormat = 1
|
||||||
if sys.byteorder != "big": packed.byteswap()
|
if sys.byteorder != "big": packed.byteswap()
|
||||||
return (packed.tostring(), tableFormat)
|
return (packed.tobytes(), tableFormat)
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
writer.simpletag("version", value=self.version)
|
writer.simpletag("version", value=self.version)
|
||||||
|
@ -108,7 +108,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
|||||||
raise
|
raise
|
||||||
additionalMetrics = array.array("h", additionalMetrics)
|
additionalMetrics = array.array("h", additionalMetrics)
|
||||||
if sys.byteorder != "big": additionalMetrics.byteswap()
|
if sys.byteorder != "big": additionalMetrics.byteswap()
|
||||||
data = data + additionalMetrics.tostring()
|
data = data + additionalMetrics.tobytes()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
|
@ -19,7 +19,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
|
|||||||
else:
|
else:
|
||||||
format = "H"
|
format = "H"
|
||||||
locations = array.array(format)
|
locations = array.array(format)
|
||||||
locations.fromstring(data)
|
locations.frombytes(data)
|
||||||
if sys.byteorder != "big": locations.byteswap()
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
if not longFormat:
|
if not longFormat:
|
||||||
l = array.array("I")
|
l = array.array("I")
|
||||||
@ -46,7 +46,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
|
|||||||
locations = array.array("I", self.locations)
|
locations = array.array("I", self.locations)
|
||||||
ttFont['head'].indexToLocFormat = 1
|
ttFont['head'].indexToLocFormat = 1
|
||||||
if sys.byteorder != "big": locations.byteswap()
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
return locations.tostring()
|
return locations.tobytes()
|
||||||
|
|
||||||
def set(self, locations):
|
def set(self, locations):
|
||||||
self.locations = array.array("I", locations)
|
self.locations = array.array("I", locations)
|
||||||
|
@ -82,7 +82,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
numGlyphs = ttFont['maxp'].numGlyphs
|
numGlyphs = ttFont['maxp'].numGlyphs
|
||||||
data = data[2:]
|
data = data[2:]
|
||||||
indices = array.array("H")
|
indices = array.array("H")
|
||||||
indices.fromstring(data[:2*numGlyphs])
|
indices.frombytes(data[:2*numGlyphs])
|
||||||
if sys.byteorder != "big": indices.byteswap()
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
data = data[2*numGlyphs:]
|
data = data[2*numGlyphs:]
|
||||||
self.extraNames = extraNames = unpackPStrings(data)
|
self.extraNames = extraNames = unpackPStrings(data)
|
||||||
@ -131,7 +131,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
from fontTools import agl
|
from fontTools import agl
|
||||||
numGlyphs = ttFont['maxp'].numGlyphs
|
numGlyphs = ttFont['maxp'].numGlyphs
|
||||||
indices = array.array("H")
|
indices = array.array("H")
|
||||||
indices.fromstring(data)
|
indices.frombytes(data)
|
||||||
if sys.byteorder != "big": indices.byteswap()
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
# In some older fonts, the size of the post table doesn't match
|
# In some older fonts, the size of the post table doesn't match
|
||||||
# the number of glyphs. Sometimes it's bigger, sometimes smaller.
|
# the number of glyphs. Sometimes it's bigger, sometimes smaller.
|
||||||
@ -171,7 +171,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
extraNames.append(psName)
|
extraNames.append(psName)
|
||||||
indices.append(index)
|
indices.append(index)
|
||||||
if sys.byteorder != "big": indices.byteswap()
|
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):
|
def encode_format_4_0(self, ttFont):
|
||||||
from fontTools import agl
|
from fontTools import agl
|
||||||
@ -188,7 +188,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
else:
|
else:
|
||||||
indices.append(0xFFFF)
|
indices.append(0xFFFF)
|
||||||
if sys.byteorder != "big": indices.byteswap()
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
return indices.tostring()
|
return indices.tobytes()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
formatstring, names, fixes = sstruct.getformat(postFormat)
|
formatstring, names, fixes = sstruct.getformat(postFormat)
|
||||||
|
@ -222,7 +222,7 @@ class Program(object):
|
|||||||
def getBytecode(self):
|
def getBytecode(self):
|
||||||
if not hasattr(self, "bytecode"):
|
if not hasattr(self, "bytecode"):
|
||||||
self._assemble()
|
self._assemble()
|
||||||
return self.bytecode.tostring()
|
return self.bytecode.tobytes()
|
||||||
|
|
||||||
def getAssembly(self, preserve=True):
|
def getAssembly(self, preserve=True):
|
||||||
if not hasattr(self, "assembly"):
|
if not hasattr(self, "assembly"):
|
||||||
|
@ -651,7 +651,7 @@ class WOFF2LocaTable(getTableClass('loca')):
|
|||||||
else:
|
else:
|
||||||
locations = array.array("I", self.locations)
|
locations = array.array("I", self.locations)
|
||||||
if sys.byteorder != "big": locations.byteswap()
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
data = locations.tostring()
|
data = locations.tobytes()
|
||||||
else:
|
else:
|
||||||
# use the most compact indexFormat given the current glyph offsets
|
# use the most compact indexFormat given the current glyph offsets
|
||||||
data = super(WOFF2LocaTable, self).compile(ttFont)
|
data = super(WOFF2LocaTable, self).compile(ttFont)
|
||||||
@ -733,7 +733,7 @@ class WOFF2GlyfTable(getTableClass('glyf')):
|
|||||||
for glyphID in range(self.numGlyphs):
|
for glyphID in range(self.numGlyphs):
|
||||||
self._encodeGlyph(glyphID)
|
self._encodeGlyph(glyphID)
|
||||||
|
|
||||||
self.bboxStream = self.bboxBitmap.tostring() + self.bboxStream
|
self.bboxStream = self.bboxBitmap.tobytes() + self.bboxStream
|
||||||
for stream in self.subStreams:
|
for stream in self.subStreams:
|
||||||
setattr(self, stream + 'Size', len(getattr(self, stream)))
|
setattr(self, stream + 'Size', len(getattr(self, stream)))
|
||||||
self.version = 0
|
self.version = 0
|
||||||
@ -961,8 +961,8 @@ class WOFF2GlyfTable(getTableClass('glyf')):
|
|||||||
triplets.append(absY >> 8)
|
triplets.append(absY >> 8)
|
||||||
triplets.append(absY & 0xff)
|
triplets.append(absY & 0xff)
|
||||||
|
|
||||||
self.flagStream += flags.tostring()
|
self.flagStream += flags.tobytes()
|
||||||
self.glyphStream += triplets.tostring()
|
self.glyphStream += triplets.tobytes()
|
||||||
|
|
||||||
|
|
||||||
class WOFF2HmtxTable(getTableClass("hmtx")):
|
class WOFF2HmtxTable(getTableClass("hmtx")):
|
||||||
@ -1093,7 +1093,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
|||||||
)
|
)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big":
|
||||||
advanceWidthArray.byteswap()
|
advanceWidthArray.byteswap()
|
||||||
data += advanceWidthArray.tostring()
|
data += advanceWidthArray.tobytes()
|
||||||
|
|
||||||
if hasLsbArray:
|
if hasLsbArray:
|
||||||
lsbArray = array.array(
|
lsbArray = array.array(
|
||||||
@ -1106,7 +1106,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
|||||||
)
|
)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big":
|
||||||
lsbArray.byteswap()
|
lsbArray.byteswap()
|
||||||
data += lsbArray.tostring()
|
data += lsbArray.tobytes()
|
||||||
|
|
||||||
if hasLeftSideBearingArray:
|
if hasLeftSideBearingArray:
|
||||||
leftSideBearingArray = array.array(
|
leftSideBearingArray = array.array(
|
||||||
@ -1118,7 +1118,7 @@ class WOFF2HmtxTable(getTableClass("hmtx")):
|
|||||||
)
|
)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big":
|
||||||
leftSideBearingArray.byteswap()
|
leftSideBearingArray.byteswap()
|
||||||
data += leftSideBearingArray.tostring()
|
data += leftSideBearingArray.tobytes()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -47,8 +47,6 @@ doctest_optionflags =
|
|||||||
ALLOW_UNICODE
|
ALLOW_UNICODE
|
||||||
ELLIPSIS
|
ELLIPSIS
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore:tostring:DeprecationWarning
|
|
||||||
ignore:fromstring:DeprecationWarning
|
|
||||||
ignore:readPlist:DeprecationWarning:plistlib_test
|
ignore:readPlist:DeprecationWarning:plistlib_test
|
||||||
ignore:writePlist:DeprecationWarning:plistlib_test
|
ignore:writePlist:DeprecationWarning:plistlib_test
|
||||||
ignore:some_function:DeprecationWarning:fontTools.ufoLib.utils
|
ignore:some_function:DeprecationWarning:fontTools.ufoLib.utils
|
||||||
|
Loading…
x
Reference in New Issue
Block a user