fontTools.ttLib.html

Package Contents
         __init__ — fontTools.ttLib — a package for dealing with TrueType fonts.
macUtils
sfnt — ttLib/sfnt.py — low-level module to deal with the sfnt file format.
standardGlyphOrder
tables (package)
test (package)
xmlImport
 
Classes
        
Exception(BaseException)
TTLibError
GlyphOrder
TTFont
_TTGlyph
_TTGlyphSet
 
class GlyphOrder
    A pseudo table. The glyph order isn‘t in the font as a separate
table, but it‘s nice to present it as such in the TTX format.
 
  Methods defined here:


__init__(self, tag)

fromXML(self, (name, attrs, content), ttFont)

toXML(self, writer, ttFont)
 
class TTFont
    The main font object. It manages file input and output, and offers
a convenient way of accessing tables. 
Tables will be only decompiled when neccesary, ie. when they‘re actually
accessed. This means that simple operations can be extremely fast.
 
  Methods defined here:


__contains__ = 
has_key(self, tag)

__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, allowVID
=0, ignoreDecompileErrors
=False)
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:

        1) glyph bounding boxes

        2) maxp font bounding box

        3) 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.

 

If the allowVID argument is set to true, then virtual GID‘s are

supported. Asking for a glyph ID with a glyph name or GID that is not in

the font will return a virtual GID.   This is valid for GSUB and cmap

tables. For SING glyphlets, the cmap table is used to specify Unicode

values for virtual GI‘s used in GSUB/GPOS rules. If the gid Nis requested

and does not exist in the font, or the glyphname has the form glyphN

and does not exist in the font, then N is used as the virtual GID.

Else, the first virtual GID is assigned as 0x1000 -1; for subsequent new

virtual GIDs, the next is one less than the previous.

 

If ignoreDecompileErrors is set to True, exceptions raised in

individual tables during decompilation will be ignored, falling

back to the DefaultTable implementation, which simply keeps the

binary data.

__len__(self)

__setitem__(self, tag, table)

close(self)
If we still have a reader object, close it.

getGlyphID(self, glyphName, requireReal
=0)

getGlyphName(self, glyphID, requireReal
=0)

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)

getGlyphSet(self, preferCFF
=1)
Return a generic GlyphSet, which is a dict-like object

mapping glyph names to glyph objects. The returned glyph objects

have a .draw() method that supports the Pen protocol, and will

have an attribute named ‘width‘, but only *after* the .draw() method

has been called.

 

If the font is CFF-based, the outlines will be taken from the ‘CFF ‘

table. Otherwise the outlines will be taken from the ‘glyf‘ table.

If the font contains both a ‘CFF ‘ and a ‘glyf‘ table, you can use

the ‘preferCFF‘ argument to specify which one should be taken.

getReverseGlyphMap(self, rebuild
=0)

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, reorderTables
=1)
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)
 
class TTLibError(Exception)
     
Method resolution order:
TTLibError
Exception
BaseException
object

Data descriptors defined here:

__weakref__
list of weak references to the object (if defined)

Methods inherited from Exception:


__init__(…)
x.
__init__(…) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from Exception:

__new__ = <built-in method __new__ of type object at 0x8108c0>
T.
__new__(S, …) -> a new object with type S, a subtype of T

Methods inherited from BaseException:


__delattr__(…)
x.
__delattr__(‘name‘) <==> del x.name

__getattribute__(…)
x.
__getattribute__(‘name‘) <==> x.name

__getitem__(…)
x.
__getitem__(y) <==> x[y]

__getslice__(…)
x.
__getslice__(i, j) <==> x[i:j]

 

Use of negative indices is not supported.

__reduce__(…)

__repr__(…)
x.
__repr__() <==> repr(x)

__setattr__(…)
x.
__setattr__(‘name‘, value) <==> x.name = value

__setstate__(…)

__str__(…)
x.
__str__() <==> str(x)

__unicode__(…)

Data descriptors inherited from BaseException:

__dict__
args
message
 
class _TTGlyph
    Wrapper for a TrueType glyph that supports the Pen protocol, meaning
that it has a .draw() method that takes a pen object as its only
argument. Additionally there is a ‘width‘ attribute.
 
  Methods defined here:


__init__(self, glyphName, ttFont)

draw(self, pen)
Draw the glyph onto Pen. See fontTools.pens.basePen for details

how that works.
 
class _TTGlyphSet
    Generic dict-like GlyphSet class, meant as a TrueType counterpart
to CFF‘s CharString dict. See TTFont.getGlyphSet().
 
  Methods defined here:


__contains__ = 
has_key(self, glyphName)

__getitem__(self, glyphName)

__init__(self, ttFont)

get(self, glyphName, default
=None)

has_key(self, glyphName)

keys(self)
 
Functions
        

_escapechar(c)
Helper function for 
tagToIdentifier()

debugmsg(msg)

getTableClass(tag)
Fetch the packer/unpacker class for a table. 

Return None when no class is found.

getTableModule(tag)
Fetch the packer/unpacker module for a table. 

Return None when no module is found.

identifierToTag(ident)
the opposite of 
tagToIdentifier()

newTable(tag)
Return a new instance of a table.

reorderFontTables(inFile, outFile, tableOrder
=None, checkChecksums
=0)
Rewrite a font file, ordering the tables as recommended by the

OpenType specification 1.4.

sortedTagList(tagList, tableOrder
=None)
Return a sorted copy of tagList, sorted according to the OpenType

specification, or according to a custom tableOrder. If given and not

None, tableOrder needs to be a list of tag names.

tagToIdentifier(tag)
Convert a table tag to a valid (but UGLY) python identifier, 

as well as a filename that‘s guaranteed to be unique even on a 

caseless file system. Each character is mapped to two characters.

Lowercase letters get an underscore before the letter, uppercase

letters get an underscore after the letter. Trailing spaces are

trimmed. Illegal characters are escaped as two hex bytes. If the

result starts with a number (as the result of a hex escape), an

extra underscore is prepended. Examples: 

        ‘glyf‘ -> ‘_g_l_y_f‘

        ‘cvt ‘ -> ‘_c_v_t‘

        ‘OS/2‘ -> ‘O_S_2f_2‘

tagToXML(tag)
Similarly to 
tagToIdentifier(), this converts a TT tag

to a valid XML element name. Since XML element names are

case sensitive, this is a fairly simple/readable translation.

xmlToTag(tag)
The opposite of 
tagToXML()
 
Data
         OTFTableOrder = [‘head‘, ‘hhea‘, ‘maxp‘, ‘OS/2‘, ‘name‘, ‘cmap‘, ‘post‘, ‘CFF ‘]
TTFTableOrder = [‘head‘, ‘hhea‘, ‘maxp‘, ‘OS/2‘, ‘hmtx‘, ‘LTSH‘, ‘VDMX‘, ‘hdmx‘, ‘cmap‘, ‘fpgm‘, ‘prep‘, ‘cvt ‘, ‘loca‘, ‘glyf‘, ‘kern‘, ‘name‘, ‘post‘, ‘gasp‘, ‘PCLT‘]
__file__ = ‘/home/mcfletch/pylive/fontTools/ttLib/__init__.pyc‘
__name__ = ‘fontTools.ttLib‘
__package__ = ‘fontTools.ttLib‘
__path__ = [‘/home/mcfletch/pylive/fontTools/ttLib‘]
haveMacSupport = 0