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 to number of tables changes or whenever a table’s length chages you need to rewrite the whole file anyway.

class fontTools.ttLib.sfnt.SFNTReader(file, checkChecksums=1, fontNumber=-1)
has_key(tag)
keys()
close()
class fontTools.ttLib.sfnt.SFNTWriter(file, numTables, sfntVersion='x00x01x00x00')
close()

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

_calcMasterChecksum(directory)
writeMasterChecksum(directory)
class fontTools.ttLib.sfnt.SFNTDirectoryEntry
fromFile(file)
fromString(str)
toString()
fontTools.ttLib.sfnt.calcChecksum(data)

Calculate the checksum for an arbitrary block of data. Optionally takes a ‘start’ argument, which allows you to calculate a checksum in chunks by feeding it a previous result.

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

>>> print calcChecksum("abcd")
1633837924
>>> print calcChecksum("abcdxyz")
3655064932
fontTools.ttLib.sfnt.maxPowerOfTwo(x)

Return the highest exponent of two, so that (2 ** exponent) <= x

fontTools.ttLib.sfnt.getSearchRange(n)

Calculate searchRange, entrySelector, rangeShift for the sfnt directory. ‘n’ is the number of tables.