Ejemplo n.º 1
0
 def compile(self, ttFont):
         if not hasattr(self, "names"):
                 # only happens when there are NO name table entries read
                 # from the TTX file
                 self.names = []
         self.names.sort()  # sort according to the spec; see NameRecord.__cmp__()
         stringData = ""
         format = 0
         n = len(self.names)
         stringoffset = 6 + n * sstruct.calcsize(nameRecordFormat)
         data = struct.pack(">HHH", format, n, stringoffset)
         lastoffset = 0
         done = {}  # remember the data so we can reuse the "pointers"
         for name in self.names:
                 if done.has_key(name.string):
                         name.offset, name.length = done[name.string]
                 else:
                         name.offset, name.length = done[name.string] = len(stringData), len(name.string)
                         stringData = stringData + name.string
                 data = data + sstruct.pack(nameRecordFormat, name)
         return data + stringData
Ejemplo n.º 2
0
                self.file.seek(self.tables['head'].offset + 8)
                self.file.write(struct.pack(">l", checksumadjustment))


# -- sfnt directory helpers and cruft

sfntDirectoryFormat = """
                > # big endian
                sfntVersion:    4s
                numTables:      H    # number of tables
                searchRange:    H    # (max2 <= numTables)*16
                entrySelector:  H    # log2(max2 <= numTables)
                rangeShift:     H    # numTables*16-searchRange
"""

sfntDirectorySize = sstruct.calcsize(sfntDirectoryFormat)

sfntDirectoryEntryFormat = """
                > # big endian
                tag:            4s
                checkSum:       l
                offset:         l
                length:         l
"""

sfntDirectoryEntrySize = sstruct.calcsize(sfntDirectoryEntryFormat)

class SFNTDirectoryEntry:

        def fromFile(self, file):
                sstruct.unpack(sfntDirectoryEntryFormat,