This document covers the basic usage of the compositor package. For more detailed information read the documentation strings in the source.
from compositor import Font
font = Font(path)
path A path to an OpenType font.
glyph = font["aGlyphName"]
Returns the glyph object named “aGlyphName”. This will raise a KeyError if “aGlyphName” is not in the font.
isThere = "aGlyphName" in font
Returns a boolean representing if “aGlyphName” is in the font.
font.keys()
A list of all glyph names in the font.
glyphRecords = font.process(aString)
This is the most important method. It takes a string (Unicode or plain ASCII) and processes it with the features defined in the font’s GSUB and GPOS tables. A list of GlyphRecord objects will be returned.
featureTags = font.getFeatureList()
A list of all available features in GSUB and GPOS.
state = font.getFeatureState(featureTag)
Get a boolean representing if a feature is on or not. This assumes that the feature state is consistent in both the GSUB and GPOS tables. A CompositorError will be raised if the feature is inconsistently applied. A CompositorError will be raised if featureTag is not defined in GSUB or GPOS.
font.setFeatureState(self, featureTag, state)
Set the application state of a feature.
info The Info object for the font.
glyphName The name of the referenced glyph.
xPlacement Horizontal placement.
yPlacement Vertical placement.
xAdvance Horizontal adjustment for advance.
yAdvance Vertical adjustment for advance.
alternates A list of GlyphRecords indicating alternates for the glyph.
glyph.draw(pen)
Draws the glyph with a FontTools pen.
name The name of the glyph.
index The glyph’s index within the source font.
width The width of the glyph.
bounds The bounding box for the glyph. Formatted as (xMin, yMin, xMax, yMax). If the glyph contains no outlines, this will return None.
familyName
styleName
unitsPerEm
ascender
descender