L_T_S_H_.py revision dc66e7e1180e77999ba8c02683956fb31f0e1003
1import DefaultTable 2import array 3import struct 4from fontTools.misc.textTools import safeEval 5 6# XXX I've lowered the strictness, to make sure Apple's own Chicago 7# XXX gets through. They're looking into it, I hope to raise the standards 8# XXX back to normal eventually. 9 10class table_L_T_S_H_(DefaultTable.DefaultTable): 11 12 def decompile(self, data, ttFont): 13 version, numGlyphs = struct.unpack(">HH", data[:4]) 14 data = data[4:] 15 assert version == 0, "unknown version: %s" % version 16 assert (len(data) % numGlyphs) < 4, "numGlyphs doesn't match data length" 17 # ouch: the assertion is not true in Chicago! 18 #assert numGlyphs == ttFont['maxp'].numGlyphs 19 yPels = array.array("B") 20 yPels.fromstring(data) 21 self.yPels = {} 22 for i in range(numGlyphs): 23 self.yPels[ttFont.getGlyphName(i)] = yPels[i] 24 25 def compile(self, ttFont): 26 version = 0 27 names = self.yPels.keys() 28 numGlyphs = len(names) 29 yPels = [0] * numGlyphs 30 # ouch: the assertion is not true in Chicago! 31 #assert len(self.yPels) == ttFont['maxp'].numGlyphs == numGlyphs 32 for name in names: 33 yPels[ttFont.getGlyphID(name)] = self.yPels[name] 34 yPels = array.array("B", yPels) 35 return struct.pack(">HH", version, numGlyphs) + yPels.tostring() 36 37 def toXML(self, writer, ttFont): 38 names = self.yPels.keys() 39 names.sort() 40 for name in names: 41 writer.simpletag("yPel", name=name, value=self.yPels[name]) 42 writer.newline() 43 44 def fromXML(self, (name, attrs, content), ttFont): 45 if not hasattr(self, "yPels"): 46 self.yPels = {} 47 if name <> "yPel": 48 return # ignore unknown tags 49 self.yPels[attrs["name"]] = safeEval(attrs["value"]) 50 51