1""" TSI{0,1,2,3,5} are private tables used by Microsoft Visual TrueType (VTT) 2tool to store its hinting source data. 3 4TSI0 is the index table containing the lengths and offsets for the glyph 5programs and 'extra' programs ('fpgm', 'prep', and 'cvt') that are contained 6in the TSI1 table. 7""" 8from __future__ import print_function, division, absolute_import 9from fontTools.misc.py23 import * 10from . import DefaultTable 11import struct 12 13tsi0Format = '>HHL' 14 15def fixlongs(glyphID, textLength, textOffset): 16 return int(glyphID), int(textLength), textOffset 17 18 19class table_T_S_I__0(DefaultTable.DefaultTable): 20 21 dependencies = ["TSI1"] 22 23 def decompile(self, data, ttFont): 24 numGlyphs = ttFont['maxp'].numGlyphs 25 indices = [] 26 size = struct.calcsize(tsi0Format) 27 for i in range(numGlyphs + 5): 28 glyphID, textLength, textOffset = fixlongs(*struct.unpack(tsi0Format, data[:size])) 29 indices.append((glyphID, textLength, textOffset)) 30 data = data[size:] 31 assert len(data) == 0 32 assert indices[-5] == (0XFFFE, 0, 0xABFC1F34), "bad magic number" 33 self.indices = indices[:-5] 34 self.extra_indices = indices[-4:] 35 36 def compile(self, ttFont): 37 if not hasattr(self, "indices"): 38 # We have no corresponding table (TSI1 or TSI3); let's return 39 # no data, which effectively means "ignore us". 40 return b"" 41 data = b"" 42 for index, textLength, textOffset in self.indices: 43 data = data + struct.pack(tsi0Format, index, textLength, textOffset) 44 data = data + struct.pack(tsi0Format, 0XFFFE, 0, 0xABFC1F34) 45 for index, textLength, textOffset in self.extra_indices: 46 data = data + struct.pack(tsi0Format, index, textLength, textOffset) 47 return data 48 49 def set(self, indices, extra_indices): 50 # gets called by 'TSI1' or 'TSI3' 51 self.indices = indices 52 self.extra_indices = extra_indices 53 54 def toXML(self, writer, ttFont): 55 writer.comment("This table will be calculated by the compiler") 56 writer.newline() 57