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.
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.
WOFFDirectoryEntry
[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
()¶
-
-
fontTools.ttLib.sfnt.
calcChecksum
(data)[source]¶ 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(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).