[graphite] Fix for big-endian
Make all "if sys.byteorder..." and "byteswap" be on the same line for earsier grep verification. Fixes https://github.com/fonttools/fonttools/issues/1311
This commit is contained in:
parent
c895f4f4a2
commit
349cd94d17
@ -56,8 +56,7 @@ class table_C_P_A_L_(DefaultTable.DefaultTable):
|
|||||||
if offset == 0:
|
if offset == 0:
|
||||||
return [0] * numElements
|
return [0] * numElements
|
||||||
result = array.array("H", data[offset : offset + 2 * numElements])
|
result = array.array("H", data[offset : offset + 2 * numElements])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": result.byteswap()
|
||||||
result.byteswap()
|
|
||||||
assert len(result) == numElements, result
|
assert len(result) == numElements, result
|
||||||
return result.tolist()
|
return result.tolist()
|
||||||
|
|
||||||
@ -65,8 +64,7 @@ class table_C_P_A_L_(DefaultTable.DefaultTable):
|
|||||||
if offset == 0:
|
if offset == 0:
|
||||||
return [0] * numElements
|
return [0] * numElements
|
||||||
result = array.array("I", data[offset : offset + 4 * numElements])
|
result = array.array("I", data[offset : offset + 4 * numElements])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": result.byteswap()
|
||||||
result.byteswap()
|
|
||||||
assert len(result) == numElements, result
|
assert len(result) == numElements, result
|
||||||
return result.tolist()
|
return result.tolist()
|
||||||
|
|
||||||
|
@ -25,8 +25,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.fromstring(newData[:endPos])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": GMAPoffsets.byteswap()
|
||||||
GMAPoffsets.byteswap()
|
|
||||||
self.GMAPs = []
|
self.GMAPs = []
|
||||||
for i in range(self.numGMAPs):
|
for i in range(self.numGMAPs):
|
||||||
start = GMAPoffsets[i]
|
start = GMAPoffsets[i]
|
||||||
@ -36,8 +35,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
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.fromstring(newData[pos:endPos])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": glyphletOffsets.byteswap()
|
||||||
glyphletOffsets.byteswap()
|
|
||||||
self.glyphlets = []
|
self.glyphlets = []
|
||||||
for i in range(self.numGlyplets):
|
for i in range(self.numGlyplets):
|
||||||
start = glyphletOffsets[i]
|
start = glyphletOffsets[i]
|
||||||
@ -58,8 +56,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
pos += len(self.GMAPs[i-1])
|
pos += len(self.GMAPs[i-1])
|
||||||
GMAPoffsets[i] = pos
|
GMAPoffsets[i] = pos
|
||||||
gmapArray = array.array("I", GMAPoffsets)
|
gmapArray = array.array("I", GMAPoffsets)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": gmapArray.byteswap()
|
||||||
gmapArray.byteswap()
|
|
||||||
dataList.append(gmapArray.tostring())
|
dataList.append(gmapArray.tostring())
|
||||||
|
|
||||||
glyphletOffsets[0] = pos
|
glyphletOffsets[0] = pos
|
||||||
@ -67,8 +64,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable):
|
|||||||
pos += len(self.glyphlets[i-1])
|
pos += len(self.glyphlets[i-1])
|
||||||
glyphletOffsets[i] = pos
|
glyphletOffsets[i] = pos
|
||||||
glyphletArray = array.array("I", glyphletOffsets)
|
glyphletArray = array.array("I", glyphletOffsets)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": glyphletArray.byteswap()
|
||||||
glyphletArray.byteswap()
|
|
||||||
dataList.append(glyphletArray.tostring())
|
dataList.append(glyphletArray.tostring())
|
||||||
dataList += self.GMAPs
|
dataList += self.GMAPs
|
||||||
dataList += self.glyphlets
|
dataList += self.glyphlets
|
||||||
|
@ -30,23 +30,23 @@ class table_G__l_o_c(DefaultTable.DefaultTable):
|
|||||||
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.fromstring(data[:len(data) - self.numAttribs * (flags & 2)])
|
||||||
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.fromstring(data[-self.numAttribs * 2:])
|
||||||
self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
data = sstruct.pack(Gloc_header, dict(version=1.0,
|
data = sstruct.pack(Gloc_header, dict(version=1.0,
|
||||||
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'),
|
flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'),
|
||||||
numAttribs=self.numAttribs))
|
numAttribs=self.numAttribs))
|
||||||
self.locations.byteswap()
|
if sys.byteorder != "big": self.locations.byteswap()
|
||||||
data += self.locations.tostring()
|
data += self.locations.tostring()
|
||||||
self.locations.byteswap()
|
if sys.byteorder != "big": self.locations.byteswap()
|
||||||
if self.attribIds:
|
if self.attribIds:
|
||||||
self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
data += self.attribIds.tostring()
|
data += self.attribIds.tostring()
|
||||||
self.attribIds.byteswap()
|
if sys.byteorder != "big": self.attribIds.byteswap()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def set(self, locations):
|
def set(self, locations):
|
||||||
|
@ -717,7 +717,7 @@ class Pass(object):
|
|||||||
data = data[2 * self.numRules + 2:]
|
data = data[2 * self.numRules + 2:]
|
||||||
for i in range(self.numTransitional):
|
for i in range(self.numTransitional):
|
||||||
a = array("H", data[i*self.numColumns*2:(i+1)*self.numColumns*2])
|
a = array("H", data[i*self.numColumns*2:(i+1)*self.numColumns*2])
|
||||||
a.byteswap()
|
if sys.byteorder != "big": a.byteswap()
|
||||||
self.stateTrans.append(a)
|
self.stateTrans.append(a)
|
||||||
data = data[self.numTransitional * self.numColumns * 2 + 1:]
|
data = data[self.numTransitional * self.numColumns * 2 + 1:]
|
||||||
self.passConstraints = data[:pConstraint]
|
self.passConstraints = data[:pConstraint]
|
||||||
@ -738,9 +738,9 @@ class Pass(object):
|
|||||||
constraintCode = "\000" + "".join(self.ruleConstraints)
|
constraintCode = "\000" + "".join(self.ruleConstraints)
|
||||||
transes = []
|
transes = []
|
||||||
for t in self.stateTrans:
|
for t in self.stateTrans:
|
||||||
t.byteswap()
|
if sys.byteorder != "big": t.byteswap()
|
||||||
transes.append(t.tostring())
|
transes.append(t.tostring())
|
||||||
t.byteswap()
|
if sys.byteorder != "big": t.byteswap()
|
||||||
if not len(transes):
|
if not len(transes):
|
||||||
self.startStates = [0]
|
self.startStates = [0]
|
||||||
oRuleMap = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.rules+[[]], (0, []))[1]
|
oRuleMap = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.rules+[[]], (0, []))[1]
|
||||||
|
@ -18,8 +18,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
|
|||||||
assert len(data) == 2 * numGlyphs
|
assert len(data) == 2 * numGlyphs
|
||||||
a = array.array("H")
|
a = array.array("H")
|
||||||
a.fromstring(data)
|
a.fromstring(data)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": a.byteswap()
|
||||||
a.byteswap()
|
|
||||||
self.glyphGrouping = {}
|
self.glyphGrouping = {}
|
||||||
for i in range(numGlyphs):
|
for i in range(numGlyphs):
|
||||||
self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
|
self.glyphGrouping[ttFont.getGlyphName(i)] = a[i]
|
||||||
@ -29,8 +28,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable):
|
|||||||
a = array.array("H")
|
a = array.array("H")
|
||||||
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":
|
if sys.byteorder != "big": a.byteswap()
|
||||||
a.byteswap()
|
|
||||||
return a.tostring()
|
return a.tostring()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
|
@ -267,8 +267,7 @@ class TupleVariation(object):
|
|||||||
points = array.array("B")
|
points = array.array("B")
|
||||||
pointsSize = numPointsInRun
|
pointsSize = numPointsInRun
|
||||||
points.fromstring(data[pos:pos+pointsSize])
|
points.fromstring(data[pos:pos+pointsSize])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": points.byteswap()
|
||||||
points.byteswap()
|
|
||||||
|
|
||||||
assert len(points) == numPointsInRun
|
assert len(points) == numPointsInRun
|
||||||
pos += pointsSize
|
pos += pointsSize
|
||||||
@ -425,8 +424,7 @@ class TupleVariation(object):
|
|||||||
deltas = array.array("b")
|
deltas = array.array("b")
|
||||||
deltasSize = numDeltasInRun
|
deltasSize = numDeltasInRun
|
||||||
deltas.fromstring(data[pos:pos+deltasSize])
|
deltas.fromstring(data[pos:pos+deltasSize])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": deltas.byteswap()
|
||||||
deltas.byteswap()
|
|
||||||
assert len(deltas) == numDeltasInRun
|
assert len(deltas) == numDeltasInRun
|
||||||
pos += deltasSize
|
pos += deltasSize
|
||||||
result.extend(deltas)
|
result.extend(deltas)
|
||||||
|
@ -340,8 +340,7 @@ class cmap_format_2(CmapSubtable):
|
|||||||
allKeys = array.array("H")
|
allKeys = array.array("H")
|
||||||
allKeys.fromstring(data[:512])
|
allKeys.fromstring(data[:512])
|
||||||
data = data[512:]
|
data = data[512:]
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": allKeys.byteswap()
|
||||||
allKeys.byteswap()
|
|
||||||
subHeaderKeys = [ key//8 for key in allKeys]
|
subHeaderKeys = [ key//8 for key in allKeys]
|
||||||
maxSubHeaderindex = max(subHeaderKeys)
|
maxSubHeaderindex = max(subHeaderKeys)
|
||||||
|
|
||||||
@ -356,8 +355,7 @@ class cmap_format_2(CmapSubtable):
|
|||||||
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.fromstring(data[giDataPos:giDataPos + subHeader.entryCount*2])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": giList.byteswap()
|
||||||
giList.byteswap()
|
|
||||||
subHeader.glyphIndexArray = giList
|
subHeader.glyphIndexArray = giList
|
||||||
subHeaderList.append(subHeader)
|
subHeaderList.append(subHeader)
|
||||||
# How this gets processed.
|
# How this gets processed.
|
||||||
@ -702,8 +700,7 @@ class cmap_format_4(CmapSubtable):
|
|||||||
allCodes.fromstring(data)
|
allCodes.fromstring(data)
|
||||||
self.data = data = None
|
self.data = data = None
|
||||||
|
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": allCodes.byteswap()
|
||||||
allCodes.byteswap()
|
|
||||||
|
|
||||||
# divide the data
|
# divide the data
|
||||||
endCode = allCodes[:segCount]
|
endCode = allCodes[:segCount]
|
||||||
@ -829,10 +826,9 @@ class cmap_format_4(CmapSubtable):
|
|||||||
charCodeArray = array.array("H", endCode + [0] + startCode)
|
charCodeArray = array.array("H", endCode + [0] + startCode)
|
||||||
idDeltaArray = array.array("H", idDelta)
|
idDeltaArray = array.array("H", idDelta)
|
||||||
restArray = array.array("H", idRangeOffset + glyphIndexArray)
|
restArray = array.array("H", idRangeOffset + glyphIndexArray)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": charCodeArray.byteswap()
|
||||||
charCodeArray.byteswap()
|
if sys.byteorder != "big": idDeltaArray.byteswap()
|
||||||
idDeltaArray.byteswap()
|
if sys.byteorder != "big": restArray.byteswap()
|
||||||
restArray.byteswap()
|
|
||||||
data = charCodeArray.tostring() + idDeltaArray.tostring() + restArray.tostring()
|
data = charCodeArray.tostring() + idDeltaArray.tostring() + restArray.tostring()
|
||||||
|
|
||||||
length = struct.calcsize(cmap_format_4_format) + len(data)
|
length = struct.calcsize(cmap_format_4_format) + len(data)
|
||||||
@ -872,8 +868,7 @@ class cmap_format_6(CmapSubtable):
|
|||||||
#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.fromstring(data[:2 * int(entryCount)])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": gids.byteswap()
|
||||||
gids.byteswap()
|
|
||||||
self.data = data = None
|
self.data = data = None
|
||||||
|
|
||||||
charCodes = list(range(firstCode, firstCode + len(gids)))
|
charCodes = list(range(firstCode, firstCode + len(gids)))
|
||||||
@ -892,8 +887,7 @@ class cmap_format_6(CmapSubtable):
|
|||||||
for code in codes
|
for code in codes
|
||||||
]
|
]
|
||||||
gids = array.array("H", valueList)
|
gids = array.array("H", valueList)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": gids.byteswap()
|
||||||
gids.byteswap()
|
|
||||||
data = gids.tostring()
|
data = gids.tostring()
|
||||||
else:
|
else:
|
||||||
data = b""
|
data = b""
|
||||||
|
@ -10,14 +10,12 @@ 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.fromstring(data)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": values.byteswap()
|
||||||
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":
|
if sys.byteorder != "big": values.byteswap()
|
||||||
values.byteswap()
|
|
||||||
return values.tostring()
|
return values.tostring()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
|
@ -512,8 +512,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.fromstring(data[:2*self.numberOfContours])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
||||||
endPtsOfContours.byteswap()
|
|
||||||
self.endPtsOfContours = endPtsOfContours.tolist()
|
self.endPtsOfContours = endPtsOfContours.tolist()
|
||||||
|
|
||||||
data = data[2*self.numberOfContours:]
|
data = data[2*self.numberOfContours:]
|
||||||
@ -625,8 +624,7 @@ class Glyph(object):
|
|||||||
assert len(self.coordinates) == len(self.flags)
|
assert len(self.coordinates) == len(self.flags)
|
||||||
data = []
|
data = []
|
||||||
endPtsOfContours = array.array("h", self.endPtsOfContours)
|
endPtsOfContours = array.array("h", self.endPtsOfContours)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": endPtsOfContours.byteswap()
|
||||||
endPtsOfContours.byteswap()
|
|
||||||
data.append(endPtsOfContours.tostring())
|
data.append(endPtsOfContours.tostring())
|
||||||
instructions = self.program.getBytecode()
|
instructions = self.program.getBytecode()
|
||||||
data.append(struct.pack(">h", len(instructions)))
|
data.append(struct.pack(">h", len(instructions)))
|
||||||
|
@ -121,8 +121,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|||||||
offsets = array.array("I")
|
offsets = array.array("I")
|
||||||
offsetsSize = (glyphCount + 1) * 4
|
offsetsSize = (glyphCount + 1) * 4
|
||||||
offsets.fromstring(data[0 : offsetsSize])
|
offsets.fromstring(data[0 : offsetsSize])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": offsets.byteswap()
|
||||||
offsets.byteswap()
|
|
||||||
|
|
||||||
# In the short format, offsets need to be multiplied by 2.
|
# In the short format, offsets need to be multiplied by 2.
|
||||||
# This is not documented in Apple's TrueType specification,
|
# This is not documented in Apple's TrueType specification,
|
||||||
@ -152,8 +151,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|||||||
else:
|
else:
|
||||||
packed = array.array("I", offsets)
|
packed = array.array("I", offsets)
|
||||||
tableFormat = 1
|
tableFormat = 1
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": packed.byteswap()
|
||||||
packed.byteswap()
|
|
||||||
return (packed.tostring(), tableFormat)
|
return (packed.tostring(), tableFormat)
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
|
@ -40,8 +40,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
|||||||
sideBearings = array.array("h", data[:2 * numberOfSideBearings])
|
sideBearings = array.array("h", data[:2 * numberOfSideBearings])
|
||||||
data = data[2 * numberOfSideBearings:]
|
data = data[2 * numberOfSideBearings:]
|
||||||
|
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": sideBearings.byteswap()
|
||||||
sideBearings.byteswap()
|
|
||||||
if data:
|
if data:
|
||||||
log.warning("too much '%s' table data" % self.tableTag)
|
log.warning("too much '%s' table data" % self.tableTag)
|
||||||
self.metrics = {}
|
self.metrics = {}
|
||||||
@ -98,8 +97,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
additionalMetrics = array.array("h", additionalMetrics)
|
additionalMetrics = array.array("h", additionalMetrics)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": additionalMetrics.byteswap()
|
||||||
additionalMetrics.byteswap()
|
|
||||||
data = data + additionalMetrics.tostring()
|
data = data + additionalMetrics.tostring()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -130,8 +130,7 @@ class KernTable_format_0(object):
|
|||||||
|
|
||||||
nPairs = min(nPairs, len(data) // 6)
|
nPairs = min(nPairs, len(data) // 6)
|
||||||
datas = array.array("H", data[:6 * nPairs])
|
datas = array.array("H", data[:6 * nPairs])
|
||||||
if sys.byteorder != "big": # pragma: no cover
|
if sys.byteorder != "big": datas.byteswap()
|
||||||
datas.byteswap()
|
|
||||||
it = iter(datas)
|
it = iter(datas)
|
||||||
glyphOrder = ttFont.getGlyphOrder()
|
glyphOrder = ttFont.getGlyphOrder()
|
||||||
for k in range(nPairs):
|
for k in range(nPairs):
|
||||||
|
@ -21,8 +21,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
|
|||||||
format = "H"
|
format = "H"
|
||||||
locations = array.array(format)
|
locations = array.array(format)
|
||||||
locations.fromstring(data)
|
locations.fromstring(data)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
locations.byteswap()
|
|
||||||
if not longFormat:
|
if not longFormat:
|
||||||
l = array.array("I")
|
l = array.array("I")
|
||||||
for i in range(len(locations)):
|
for i in range(len(locations)):
|
||||||
@ -47,8 +46,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable):
|
|||||||
else:
|
else:
|
||||||
locations = array.array("I", self.locations)
|
locations = array.array("I", self.locations)
|
||||||
ttFont['head'].indexToLocFormat = 1
|
ttFont['head'].indexToLocFormat = 1
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
locations.byteswap()
|
|
||||||
return locations.tostring()
|
return locations.tostring()
|
||||||
|
|
||||||
def set(self, locations):
|
def set(self, locations):
|
||||||
|
@ -84,8 +84,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
data = data[2:]
|
data = data[2:]
|
||||||
indices = array.array("H")
|
indices = array.array("H")
|
||||||
indices.fromstring(data[:2*numGlyphs])
|
indices.fromstring(data[:2*numGlyphs])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
indices.byteswap()
|
|
||||||
data = data[2*numGlyphs:]
|
data = data[2*numGlyphs:]
|
||||||
self.extraNames = extraNames = unpackPStrings(data)
|
self.extraNames = extraNames = unpackPStrings(data)
|
||||||
self.glyphOrder = glyphOrder = [""] * int(ttFont['maxp'].numGlyphs)
|
self.glyphOrder = glyphOrder = [""] * int(ttFont['maxp'].numGlyphs)
|
||||||
@ -134,8 +133,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
numGlyphs = ttFont['maxp'].numGlyphs
|
numGlyphs = ttFont['maxp'].numGlyphs
|
||||||
indices = array.array("H")
|
indices = array.array("H")
|
||||||
indices.fromstring(data)
|
indices.fromstring(data)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
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.
|
||||||
self.glyphOrder = glyphOrder = [''] * int(numGlyphs)
|
self.glyphOrder = glyphOrder = [''] * int(numGlyphs)
|
||||||
@ -173,8 +171,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
extraDict[psName] = len(extraNames)
|
extraDict[psName] = len(extraNames)
|
||||||
extraNames.append(psName)
|
extraNames.append(psName)
|
||||||
indices.append(index)
|
indices.append(index)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
indices.byteswap()
|
|
||||||
return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(extraNames)
|
return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(extraNames)
|
||||||
|
|
||||||
def encode_format_4_0(self, ttFont):
|
def encode_format_4_0(self, ttFont):
|
||||||
@ -191,8 +188,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
|||||||
indices.append(int(glyphID[3:],16))
|
indices.append(int(glyphID[3:],16))
|
||||||
else:
|
else:
|
||||||
indices.append(0xFFFF)
|
indices.append(0xFFFF)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": indices.byteswap()
|
||||||
indices.byteswap()
|
|
||||||
return indices.tostring()
|
return indices.tostring()
|
||||||
|
|
||||||
def toXML(self, writer, ttFont):
|
def toXML(self, writer, ttFont):
|
||||||
|
@ -145,8 +145,7 @@ class OTTableReader(object):
|
|||||||
pos = self.pos
|
pos = self.pos
|
||||||
newpos = pos + count * 2
|
newpos = pos + count * 2
|
||||||
value = array.array("H", self.data[pos:newpos])
|
value = array.array("H", self.data[pos:newpos])
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": value.byteswap()
|
||||||
value.byteswap()
|
|
||||||
self.pos = newpos
|
self.pos = newpos
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -582,8 +582,7 @@ class WOFF2LocaTable(getTableClass('loca')):
|
|||||||
locations.append(self.locations[i] // 2)
|
locations.append(self.locations[i] // 2)
|
||||||
else:
|
else:
|
||||||
locations = array.array("I", self.locations)
|
locations = array.array("I", self.locations)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": locations.byteswap()
|
||||||
locations.byteswap()
|
|
||||||
data = locations.tostring()
|
data = locations.tostring()
|
||||||
else:
|
else:
|
||||||
# use the most compact indexFormat given the current glyph offsets
|
# use the most compact indexFormat given the current glyph offsets
|
||||||
@ -627,8 +626,7 @@ class WOFF2GlyfTable(getTableClass('glyf')):
|
|||||||
self.bboxStream = self.bboxStream[bboxBitmapSize:]
|
self.bboxStream = self.bboxStream[bboxBitmapSize:]
|
||||||
|
|
||||||
self.nContourStream = array.array("h", self.nContourStream)
|
self.nContourStream = array.array("h", self.nContourStream)
|
||||||
if sys.byteorder != "big":
|
if sys.byteorder != "big": self.nContourStream.byteswap()
|
||||||
self.nContourStream.byteswap()
|
|
||||||
assert len(self.nContourStream) == self.numGlyphs
|
assert len(self.nContourStream) == self.numGlyphs
|
||||||
|
|
||||||
if 'head' in ttFont:
|
if 'head' in ttFont:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user