diff --git a/Lib/fontTools/ttLib/tables/C_P_A_L_.py b/Lib/fontTools/ttLib/tables/C_P_A_L_.py index 25d50a5ef..c687c7a1e 100644 --- a/Lib/fontTools/ttLib/tables/C_P_A_L_.py +++ b/Lib/fontTools/ttLib/tables/C_P_A_L_.py @@ -56,8 +56,7 @@ class table_C_P_A_L_(DefaultTable.DefaultTable): if offset == 0: return [0] * numElements result = array.array("H", data[offset : offset + 2 * numElements]) - if sys.byteorder != "big": - result.byteswap() + if sys.byteorder != "big": result.byteswap() assert len(result) == numElements, result return result.tolist() @@ -65,8 +64,7 @@ class table_C_P_A_L_(DefaultTable.DefaultTable): if offset == 0: return [0] * numElements result = array.array("I", data[offset : offset + 4 * numElements]) - if sys.byteorder != "big": - result.byteswap() + if sys.byteorder != "big": result.byteswap() assert len(result) == numElements, result return result.tolist() diff --git a/Lib/fontTools/ttLib/tables/G_P_K_G_.py b/Lib/fontTools/ttLib/tables/G_P_K_G_.py index 4e13830b0..b835f4af7 100644 --- a/Lib/fontTools/ttLib/tables/G_P_K_G_.py +++ b/Lib/fontTools/ttLib/tables/G_P_K_G_.py @@ -25,8 +25,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable): GMAPoffsets = array.array("I") endPos = (self.numGMAPs+1) * 4 GMAPoffsets.fromstring(newData[:endPos]) - if sys.byteorder != "big": - GMAPoffsets.byteswap() + if sys.byteorder != "big": GMAPoffsets.byteswap() self.GMAPs = [] for i in range(self.numGMAPs): start = GMAPoffsets[i] @@ -36,8 +35,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable): endPos = pos + (self.numGlyplets + 1)*4 glyphletOffsets = array.array("I") glyphletOffsets.fromstring(newData[pos:endPos]) - if sys.byteorder != "big": - glyphletOffsets.byteswap() + if sys.byteorder != "big": glyphletOffsets.byteswap() self.glyphlets = [] for i in range(self.numGlyplets): start = glyphletOffsets[i] @@ -58,8 +56,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable): pos += len(self.GMAPs[i-1]) GMAPoffsets[i] = pos gmapArray = array.array("I", GMAPoffsets) - if sys.byteorder != "big": - gmapArray.byteswap() + if sys.byteorder != "big": gmapArray.byteswap() dataList.append(gmapArray.tostring()) glyphletOffsets[0] = pos @@ -67,8 +64,7 @@ class table_G_P_K_G_(DefaultTable.DefaultTable): pos += len(self.glyphlets[i-1]) glyphletOffsets[i] = pos glyphletArray = array.array("I", glyphletOffsets) - if sys.byteorder != "big": - glyphletArray.byteswap() + if sys.byteorder != "big": glyphletArray.byteswap() dataList.append(glyphletArray.tostring()) dataList += self.GMAPs dataList += self.glyphlets diff --git a/Lib/fontTools/ttLib/tables/G__l_o_c.py b/Lib/fontTools/ttLib/tables/G__l_o_c.py index d77c4837a..c388883b0 100644 --- a/Lib/fontTools/ttLib/tables/G__l_o_c.py +++ b/Lib/fontTools/ttLib/tables/G__l_o_c.py @@ -30,23 +30,23 @@ class table_G__l_o_c(DefaultTable.DefaultTable): 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.byteswap() + if sys.byteorder != "big": self.locations.byteswap() self.attribIds = array.array('H') if flags & 2: self.attribIds.fromstring(data[-self.numAttribs * 2:]) - self.attribIds.byteswap() + if sys.byteorder != "big": self.attribIds.byteswap() def compile(self, ttFont): data = sstruct.pack(Gloc_header, dict(version=1.0, flags=(bool(self.attribIds) << 1) + (self.locations.typecode == 'I'), numAttribs=self.numAttribs)) - self.locations.byteswap() + if sys.byteorder != "big": self.locations.byteswap() data += self.locations.tostring() - self.locations.byteswap() + if sys.byteorder != "big": self.locations.byteswap() if self.attribIds: - self.attribIds.byteswap() + if sys.byteorder != "big": self.attribIds.byteswap() data += self.attribIds.tostring() - self.attribIds.byteswap() + if sys.byteorder != "big": self.attribIds.byteswap() return data def set(self, locations): diff --git a/Lib/fontTools/ttLib/tables/S__i_l_f.py b/Lib/fontTools/ttLib/tables/S__i_l_f.py index 2afd71eaa..44dd69b0d 100644 --- a/Lib/fontTools/ttLib/tables/S__i_l_f.py +++ b/Lib/fontTools/ttLib/tables/S__i_l_f.py @@ -717,7 +717,7 @@ class Pass(object): data = data[2 * self.numRules + 2:] for i in range(self.numTransitional): 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) data = data[self.numTransitional * self.numColumns * 2 + 1:] self.passConstraints = data[:pConstraint] @@ -738,9 +738,9 @@ class Pass(object): constraintCode = "\000" + "".join(self.ruleConstraints) transes = [] for t in self.stateTrans: - t.byteswap() + if sys.byteorder != "big": t.byteswap() transes.append(t.tostring()) - t.byteswap() + if sys.byteorder != "big": t.byteswap() if not len(transes): self.startStates = [0] oRuleMap = reduce(lambda a, x: (a[0]+len(x), a[1]+[a[0]]), self.rules+[[]], (0, []))[1] diff --git a/Lib/fontTools/ttLib/tables/T_S_I__5.py b/Lib/fontTools/ttLib/tables/T_S_I__5.py index dbf9e5a2c..61b76044c 100644 --- a/Lib/fontTools/ttLib/tables/T_S_I__5.py +++ b/Lib/fontTools/ttLib/tables/T_S_I__5.py @@ -18,8 +18,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable): assert len(data) == 2 * numGlyphs a = array.array("H") a.fromstring(data) - if sys.byteorder != "big": - a.byteswap() + if sys.byteorder != "big": a.byteswap() self.glyphGrouping = {} for i in range(numGlyphs): self.glyphGrouping[ttFont.getGlyphName(i)] = a[i] @@ -29,8 +28,7 @@ class table_T_S_I__5(DefaultTable.DefaultTable): a = array.array("H") for i in range(len(glyphNames)): a.append(self.glyphGrouping.get(glyphNames[i], 0)) - if sys.byteorder != "big": - a.byteswap() + if sys.byteorder != "big": a.byteswap() return a.tostring() def toXML(self, writer, ttFont): diff --git a/Lib/fontTools/ttLib/tables/TupleVariation.py b/Lib/fontTools/ttLib/tables/TupleVariation.py index 5fa71c844..92d07a11b 100644 --- a/Lib/fontTools/ttLib/tables/TupleVariation.py +++ b/Lib/fontTools/ttLib/tables/TupleVariation.py @@ -267,8 +267,7 @@ class TupleVariation(object): points = array.array("B") pointsSize = numPointsInRun points.fromstring(data[pos:pos+pointsSize]) - if sys.byteorder != "big": - points.byteswap() + if sys.byteorder != "big": points.byteswap() assert len(points) == numPointsInRun pos += pointsSize @@ -425,8 +424,7 @@ class TupleVariation(object): deltas = array.array("b") deltasSize = numDeltasInRun deltas.fromstring(data[pos:pos+deltasSize]) - if sys.byteorder != "big": - deltas.byteswap() + if sys.byteorder != "big": deltas.byteswap() assert len(deltas) == numDeltasInRun pos += deltasSize result.extend(deltas) diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py index eccf69e00..5bc9354f2 100644 --- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py +++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py @@ -340,8 +340,7 @@ class cmap_format_2(CmapSubtable): allKeys = array.array("H") allKeys.fromstring(data[:512]) data = data[512:] - if sys.byteorder != "big": - allKeys.byteswap() + if sys.byteorder != "big": allKeys.byteswap() subHeaderKeys = [ key//8 for key in allKeys] maxSubHeaderindex = max(subHeaderKeys) @@ -356,8 +355,7 @@ class cmap_format_2(CmapSubtable): giDataPos = pos + subHeader.idRangeOffset-2 giList = array.array("H") giList.fromstring(data[giDataPos:giDataPos + subHeader.entryCount*2]) - if sys.byteorder != "big": - giList.byteswap() + if sys.byteorder != "big": giList.byteswap() subHeader.glyphIndexArray = giList subHeaderList.append(subHeader) # How this gets processed. @@ -702,8 +700,7 @@ class cmap_format_4(CmapSubtable): allCodes.fromstring(data) self.data = data = None - if sys.byteorder != "big": - allCodes.byteswap() + if sys.byteorder != "big": allCodes.byteswap() # divide the data endCode = allCodes[:segCount] @@ -829,10 +826,9 @@ class cmap_format_4(CmapSubtable): charCodeArray = array.array("H", endCode + [0] + startCode) idDeltaArray = array.array("H", idDelta) restArray = array.array("H", idRangeOffset + glyphIndexArray) - if sys.byteorder != "big": - charCodeArray.byteswap() - idDeltaArray.byteswap() - restArray.byteswap() + 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() 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!!! gids = array.array("H") gids.fromstring(data[:2 * int(entryCount)]) - if sys.byteorder != "big": - gids.byteswap() + if sys.byteorder != "big": gids.byteswap() self.data = data = None charCodes = list(range(firstCode, firstCode + len(gids))) @@ -892,8 +887,7 @@ class cmap_format_6(CmapSubtable): for code in codes ] gids = array.array("H", valueList) - if sys.byteorder != "big": - gids.byteswap() + if sys.byteorder != "big": gids.byteswap() data = gids.tostring() else: data = b"" diff --git a/Lib/fontTools/ttLib/tables/_c_v_t.py b/Lib/fontTools/ttLib/tables/_c_v_t.py index 4fbee7bfc..21df0bad8 100644 --- a/Lib/fontTools/ttLib/tables/_c_v_t.py +++ b/Lib/fontTools/ttLib/tables/_c_v_t.py @@ -10,14 +10,12 @@ class table__c_v_t(DefaultTable.DefaultTable): def decompile(self, data, ttFont): values = array.array("h") values.fromstring(data) - if sys.byteorder != "big": - values.byteswap() + if sys.byteorder != "big": values.byteswap() self.values = values def compile(self, ttFont): values = self.values[:] - if sys.byteorder != "big": - values.byteswap() + if sys.byteorder != "big": values.byteswap() return values.tostring() def toXML(self, writer, ttFont): diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py index 58c1eb2ce..c1118c911 100644 --- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py +++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py @@ -512,8 +512,7 @@ class Glyph(object): def decompileCoordinates(self, data): endPtsOfContours = array.array("h") endPtsOfContours.fromstring(data[:2*self.numberOfContours]) - if sys.byteorder != "big": - endPtsOfContours.byteswap() + if sys.byteorder != "big": endPtsOfContours.byteswap() self.endPtsOfContours = endPtsOfContours.tolist() data = data[2*self.numberOfContours:] @@ -625,8 +624,7 @@ class Glyph(object): assert len(self.coordinates) == len(self.flags) data = [] endPtsOfContours = array.array("h", self.endPtsOfContours) - if sys.byteorder != "big": - endPtsOfContours.byteswap() + if sys.byteorder != "big": endPtsOfContours.byteswap() data.append(endPtsOfContours.tostring()) instructions = self.program.getBytecode() data.append(struct.pack(">h", len(instructions))) diff --git a/Lib/fontTools/ttLib/tables/_g_v_a_r.py b/Lib/fontTools/ttLib/tables/_g_v_a_r.py index 9f97c31a2..608b6a2d9 100644 --- a/Lib/fontTools/ttLib/tables/_g_v_a_r.py +++ b/Lib/fontTools/ttLib/tables/_g_v_a_r.py @@ -121,8 +121,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable): offsets = array.array("I") offsetsSize = (glyphCount + 1) * 4 offsets.fromstring(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. # This is not documented in Apple's TrueType specification, @@ -152,8 +151,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable): else: packed = array.array("I", offsets) tableFormat = 1 - if sys.byteorder != "big": - packed.byteswap() + if sys.byteorder != "big": packed.byteswap() return (packed.tostring(), tableFormat) def toXML(self, writer, ttFont): diff --git a/Lib/fontTools/ttLib/tables/_h_m_t_x.py b/Lib/fontTools/ttLib/tables/_h_m_t_x.py index e6b8ea9bd..6f8bb972f 100644 --- a/Lib/fontTools/ttLib/tables/_h_m_t_x.py +++ b/Lib/fontTools/ttLib/tables/_h_m_t_x.py @@ -40,8 +40,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable): sideBearings = array.array("h", data[:2 * numberOfSideBearings]) data = data[2 * numberOfSideBearings:] - if sys.byteorder != "big": - sideBearings.byteswap() + if sys.byteorder != "big": sideBearings.byteswap() if data: log.warning("too much '%s' table data" % self.tableTag) self.metrics = {} @@ -98,8 +97,7 @@ class table__h_m_t_x(DefaultTable.DefaultTable): else: raise additionalMetrics = array.array("h", additionalMetrics) - if sys.byteorder != "big": - additionalMetrics.byteswap() + if sys.byteorder != "big": additionalMetrics.byteswap() data = data + additionalMetrics.tostring() return data diff --git a/Lib/fontTools/ttLib/tables/_k_e_r_n.py b/Lib/fontTools/ttLib/tables/_k_e_r_n.py index 6e21a4bd2..98eb70923 100644 --- a/Lib/fontTools/ttLib/tables/_k_e_r_n.py +++ b/Lib/fontTools/ttLib/tables/_k_e_r_n.py @@ -130,8 +130,7 @@ class KernTable_format_0(object): nPairs = min(nPairs, len(data) // 6) datas = array.array("H", data[:6 * nPairs]) - if sys.byteorder != "big": # pragma: no cover - datas.byteswap() + if sys.byteorder != "big": datas.byteswap() it = iter(datas) glyphOrder = ttFont.getGlyphOrder() for k in range(nPairs): diff --git a/Lib/fontTools/ttLib/tables/_l_o_c_a.py b/Lib/fontTools/ttLib/tables/_l_o_c_a.py index 2fcd52840..6aa530308 100644 --- a/Lib/fontTools/ttLib/tables/_l_o_c_a.py +++ b/Lib/fontTools/ttLib/tables/_l_o_c_a.py @@ -21,8 +21,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable): format = "H" locations = array.array(format) locations.fromstring(data) - if sys.byteorder != "big": - locations.byteswap() + if sys.byteorder != "big": locations.byteswap() if not longFormat: l = array.array("I") for i in range(len(locations)): @@ -47,8 +46,7 @@ class table__l_o_c_a(DefaultTable.DefaultTable): else: locations = array.array("I", self.locations) ttFont['head'].indexToLocFormat = 1 - if sys.byteorder != "big": - locations.byteswap() + if sys.byteorder != "big": locations.byteswap() return locations.tostring() def set(self, locations): diff --git a/Lib/fontTools/ttLib/tables/_p_o_s_t.py b/Lib/fontTools/ttLib/tables/_p_o_s_t.py index ede62dabc..4874ecd94 100644 --- a/Lib/fontTools/ttLib/tables/_p_o_s_t.py +++ b/Lib/fontTools/ttLib/tables/_p_o_s_t.py @@ -84,8 +84,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable): data = data[2:] indices = array.array("H") indices.fromstring(data[:2*numGlyphs]) - if sys.byteorder != "big": - indices.byteswap() + if sys.byteorder != "big": indices.byteswap() data = data[2*numGlyphs:] self.extraNames = extraNames = unpackPStrings(data) self.glyphOrder = glyphOrder = [""] * int(ttFont['maxp'].numGlyphs) @@ -134,8 +133,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable): numGlyphs = ttFont['maxp'].numGlyphs indices = array.array("H") indices.fromstring(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 # the number of glyphs. Sometimes it's bigger, sometimes smaller. self.glyphOrder = glyphOrder = [''] * int(numGlyphs) @@ -173,8 +171,7 @@ class table__p_o_s_t(DefaultTable.DefaultTable): extraDict[psName] = len(extraNames) extraNames.append(psName) indices.append(index) - if sys.byteorder != "big": - indices.byteswap() + if sys.byteorder != "big": indices.byteswap() return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(extraNames) 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)) else: indices.append(0xFFFF) - if sys.byteorder != "big": - indices.byteswap() + if sys.byteorder != "big": indices.byteswap() return indices.tostring() def toXML(self, writer, ttFont): diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py index 04b82fef7..c71cc8dbe 100644 --- a/Lib/fontTools/ttLib/tables/otBase.py +++ b/Lib/fontTools/ttLib/tables/otBase.py @@ -145,8 +145,7 @@ class OTTableReader(object): pos = self.pos newpos = pos + count * 2 value = array.array("H", self.data[pos:newpos]) - if sys.byteorder != "big": - value.byteswap() + if sys.byteorder != "big": value.byteswap() self.pos = newpos return value diff --git a/Lib/fontTools/ttLib/woff2.py b/Lib/fontTools/ttLib/woff2.py index 1952682c5..c0c0e7044 100644 --- a/Lib/fontTools/ttLib/woff2.py +++ b/Lib/fontTools/ttLib/woff2.py @@ -582,8 +582,7 @@ class WOFF2LocaTable(getTableClass('loca')): locations.append(self.locations[i] // 2) else: locations = array.array("I", self.locations) - if sys.byteorder != "big": - locations.byteswap() + if sys.byteorder != "big": locations.byteswap() data = locations.tostring() else: # use the most compact indexFormat given the current glyph offsets @@ -627,8 +626,7 @@ class WOFF2GlyfTable(getTableClass('glyf')): self.bboxStream = self.bboxStream[bboxBitmapSize:] self.nContourStream = array.array("h", self.nContourStream) - if sys.byteorder != "big": - self.nContourStream.byteswap() + if sys.byteorder != "big": self.nContourStream.byteswap() assert len(self.nContourStream) == self.numGlyphs if 'head' in ttFont: