sfnt

ttLib/sfnt.py – low-level module to deal with the sfnt file format.

Defines two public classes:

SFNTReader SFNTWriter

(Normally you don’t have to use these classes explicitly; they are used automatically by ttLib.TTFont.)

The reading and writing of sfnt files is separated in two distinct classes, since whenever the number of tables changes or whenever a table’s length changes you need to rewrite the whole file anyway.

class fontTools.ttLib.sfnt.DirectoryEntry[source]
decodeData(rawData)[source]
encodeData(data)[source]
fromFile(file)[source]
fromString(str)[source]
loadData(file)[source]
saveData(file, data)[source]
toString()[source]
class fontTools.ttLib.sfnt.SFNTDirectoryEntry[source]
decodeData(rawData)
encodeData(data)
format = '\n\t\t> # big endian\n\t\ttag:            4s\n\t\tcheckSum:       L\n\t\toffset:         L\n\t\tlength:         L\n'
formatSize = 16
fromFile(file)
fromString(str)
loadData(file)
saveData(file, data)
toString()
class fontTools.ttLib.sfnt.SFNTReader(*args, **kwargs)[source]
close()[source]
has_key(tag)[source]
keys()[source]
class fontTools.ttLib.sfnt.SFNTWriter(*args, **kwargs)[source]
close()[source]

All tables must have been written to disk. Now write the directory.

reordersTables()[source]
setEntry(tag, entry)[source]
writeMasterChecksum(directory)[source]
class fontTools.ttLib.sfnt.WOFFDirectoryEntry[source]
decodeData(rawData)[source]
encodeData(data)[source]
format = '\n\t\t> # big endian\n\t\ttag:            4s\n\t\toffset:         L\n\t\tlength:         L    # compressed length\n\t\torigLength:     L    # original length\n\t\tcheckSum:       L    # original checksum\n'
formatSize = 20
fromFile(file)
fromString(str)
loadData(file)
saveData(file, data)
toString()
class fontTools.ttLib.sfnt.WOFFFlavorData(reader=None)[source]
Flavor = 'woff'
fontTools.ttLib.sfnt.calcChecksum(data)[source]

Calculate the checksum for an arbitrary block of data.

If the data length is not a multiple of four, it assumes it is to be padded with null byte.

>>> print(calcChecksum(b"abcd"))
1633837924
>>> print(calcChecksum(b"abcdxyz"))
3655064932
fontTools.ttLib.sfnt.compress(data, level=6)[source]

Compress ‘data’ to Zlib format. If ‘USE_ZOPFLI’ variable is True, zopfli is used instead of the zlib module. The compression ‘level’ must be between 0 and 9. 1 gives best speed, 9 gives best compression (0 gives no compression at all). The default value is a compromise between speed and compression (6).

fontTools.ttLib.sfnt.readTTCHeader(file)[source]
fontTools.ttLib.sfnt.writeTTCHeader(file, numFonts)[source]