Method summary
- __delitem__(self, tag)
- __getitem__(self, tag)
- __init__(self, file = None, res_name_or_index = None, sfntVersion = '\x00\x01\x00\x00', checkChecksums = 0, verbose = 0, recalcBBoxes = 1)
- __len__(self)
- __setitem__(self, tag, table)
- close(self)
- getGlyphID(self, glyphName)
- getGlyphName(self, glyphID)
- getGlyphNames(self)
- getGlyphNames2(self)
- getGlyphOrder(self)
- getTableData(self, tag)
- has_key(self, tag)
- importXML(self, file, progress = None)
- isLoaded(self, tag)
- keys(self)
- save(self, file, makeSuitcase = 0)
- saveXML(self, fileOrPath, progress = None, tables = None, skipTables = None, splitTables = 0, disassembleInstructions = 1)
- setGlyphOrder(self, glyphOrder)
Methods
- __delitem__(self, tag)
- __getitem__(self, tag)
- __init__(self, file = None, res_name_or_index = None, sfntVersion = '\x00\x01\x00\x00', checkChecksums = 0, verbose = 0, recalcBBoxes = 1)
The constructor can be called with a few different arguments. When reading a font from disk, 'file' should be either a pathname pointing to a file, or a readable file object.
It we're running on a Macintosh, 'res_name_or_index' maybe an sfnt resource name or an sfnt resource index number or zero. The latter case will cause TTLib to autodetect whether the file is a flat file or a suitcase. (If it's a suitcase, only the first 'sfnt' resource will be read!)
The 'checkChecksums' argument is used to specify how sfnt checksums are treated upon reading a file from disk:
- 0: don't check (default)
- 1: check, print warnings if a wrong checksum is found
- 2: check, raise an exception if a wrong checksum is found.
The TTFont constructor can also be called without a 'file' argument: this is the way to create a new empty font. In this case you can optionally supply the 'sfntVersion' argument.
If the recalcBBoxes argument is false, a number of things will not be recalculated upon save/compile:
- glyph bounding boxes
- maxp font bounding box
- hhea min/max values
(1) is needed for certain kinds of CJK fonts (ask Werner Lemberg ;-). Additionally, upon importing an TTX file, this option cause glyphs to be compiled right away. This should reduce memory consumption greatly, and therefore should have some impact on the time needed to parse/compile large fonts.
- __len__(self)
- __setitem__(self, tag, table)
- close(self)
If we still have a reader object, close it.
- getGlyphID(self, glyphName)
- getGlyphName(self, glyphID)
- getGlyphNames(self)
Get a list of glyph names, sorted alphabetically.
- getGlyphNames2(self)
Get a list of glyph names, sorted alphabetically, but not case sensitive.
- getGlyphOrder(self)
- getTableData(self, tag)
Returns raw table data, whether compiled or directly read from disk.
- has_key(self, tag)
- importXML(self, file, progress = None)
Import a TTX file (an XML-based text format), so as to recreate a font object.
- isLoaded(self, tag)
Return true if the table identified by 'tag' has been decompiled and loaded into memory.
- keys(self)
- save(self, file, makeSuitcase = 0)
Save the font to disk. Similarly to the constructor, the 'file' argument can be either a pathname or a writable file object.
On the Mac, if makeSuitcase is true, a suitcase (resource fork) file will we made instead of a flat .ttf file.
- saveXML(self, fileOrPath, progress = None, tables = None, skipTables = None, splitTables = 0, disassembleInstructions = 1)
Export the font as TTX (an XML-based text file), or as a series of text files when splitTables is true. In the latter case, the 'fileOrPath' argument should be a path to a directory. The 'tables' argument must either be false (dump all tables) or a list of tables to dump. The 'skipTables' argument may be a list of tables to skip, but only when the 'tables' argument is false.
- setGlyphOrder(self, glyphOrder)