# fontTools Docs

## About

fontTools is a family of libraries and utilities for manipulating fonts in Python.

The project has an MIT open-source license. Among other things this means you can use it free of charge.

## Installation

Note

fontTools requires Python 3.6 or later.

The package is listed in the Python Package Index (PyPI), so you can install it with pip:

    pip install fonttools

See the Optional Requirements section below for details about module-specific dependencies that must be installed in select cases.

## Utilities

fontTools installs four command-line utilities:

- `pyftmerge`, a tool for merging fonts; see `fontTools.merge`

- `pyftsubset`, a tool for subsetting fonts; see `fontTools.subset`

- `ttx`, a tool for converting between OpenType binary fonts (OTF) and an XML representation (TTX); see `fontTools.ttx`

- `fonttools`, a “meta-tool” for accessing other components of the fontTools family.

This last utility takes a subcommand, which could be one of:

- `cffLib.width`: Calculate optimum defaultWidthX/nominalWidthX values

- `cu2qu`: Convert a UFO font from cubic to quadratic curves

- `feaLib`: Add features from a feature file (.fea) into a OTF font

- `help`: Show this help

- `merge`: Merge multiple fonts into one

- `mtiLib`: Convert a FontDame OTL file to TTX XML

- `subset`: OpenType font subsetter and optimizer

- `ttLib.woff2`: Compress and decompress WOFF2 fonts

- `ttx`: Convert OpenType fonts to XML and back

- `varLib`: Build a variable font from a designspace file and masters

- `varLib.instancer`: Partially instantiate a variable font.

- `varLib.interpolatable`: Test for interpolatability issues between fonts

- `varLib.interpolate_layout`: Interpolate GDEF/GPOS/GSUB tables for a point on a designspace

- `varLib.models`: Normalize locations on a given designspace

- `varLib.mutator`: Instantiate a variation font

- `varLib.varStore`: Optimize a font’s GDEF variation store

## Libraries

The main library you will want to access when using fontTools for font engineering is likely to be `fontTools.ttLib.ttFont`, which is the module for handling TrueType/OpenType fonts. However, there are many other libraries in the fontTools suite:

- `fontTools.afmLib`: Module for reading and writing AFM files

- `fontTools.agl`: Access to the Adobe Glyph List

- `fontTools.cffLib`: Read/write tools for Adobe CFF fonts

- `fontTools.colorLib`: Module for handling colors in CPAL/COLR fonts

- `fontTools.config`: Configure fontTools

- `fontTools.cu2qu`: Module for cubic to quadratic conversion

- `fontTools.designspaceLib`: Read and write designspace files

- `fontTools.encodings`: Support for font-related character encodings

- `fontTools.feaLib`: Read and read AFDKO feature files

- `fontTools.fontBuilder`: Construct TTF/OTF fonts from scratch

- `fontTools.merge`: Tools for merging font files

- `fontTools.pens`: Various classes for manipulating glyph outlines

- `fontTools.subset`: OpenType font subsetting and optimization

- `fontTools.svgLib.path`: Library for drawing SVG paths onto glyphs

- `fontTools.t1Lib`: Tools for PostScript Type 1 fonts (Python2 only)

- `fontTools.tfmLib`: Module for reading TFM files

- `fontTools.ttLib`: Module for reading/writing OpenType and Truetype fonts

- `fontTools.ttx`: Module for converting between OTF and XML representation

- `fontTools.ufoLib`: Module for reading and writing UFO files

- `fontTools.unicodedata`: Convert between Unicode and OpenType script information

- `fontTools.varLib`: Module for dealing with ‘gvar’-style font variations

- `fontTools.voltLib`: Module for dealing with Visual OpenType Layout Tool (VOLT) files

A selection of sample Python programs using these libaries can be found in the Snippets directory of the fontTools repository.

## Optional Dependencies

The fontTools package currently has no (required) external dependencies besides the modules included in the Python Standard Library. However, a few extra dependencies are required to unlock optional features in some of the library modules. See the optional requirements page for more information.

## Developer information

Information for developers can be found here.

## License

MIT license. See the full text of the license for details.

## Table of Contents

Library

- afmLib: Read/write Adobe Font Metrics files
  - `error`
  - `AFM`
- agl: Interface to the Adobe Glyph List
  - `AGLError`
  - `toUnicode()`
- cffLib: read/write Adobe CFF fonts
  - `CFFFontSet`
  - `CFFWriter`
  - `CharStrings`
  - `CharStringsCompiler`
  - `FDArrayIndex`
  - `FDArrayIndexCompiler`
  - `GlobalSubrsCompiler`
  - `GlobalSubrsIndex`
  - `Index`
  - `IndexCompiler`
  - `IndexedStrings`
  - `IndexedStringsCompiler`
  - `StopHintCountEvent`
  - `SubrsCompiler`
  - `SubrsIndex`
  - `TopDict`
  - `TopDictIndex`
  - `TopDictIndexCompiler`
  - specializer: T2CharString operator specializer and generalizer
  - width: T2CharString glyph width optimizer
- colorLib.builder: Build COLR/CPAL tables from scratch
  - `ColorPaletteType`
  - `buildCOLR()`
  - `buildCPAL()`
  - `populateCOLRv0()`
- config: configure fontTools
  - `Config`
- cu2qu: Cubic to quadratic curve conversion
  - fontTools.cu2qu.cu2qu
  - fontTools.cu2qu.ufo
- designspaceLib: Read, write, and edit designspace files
  - 1 DesignSpaceDocument Python API
  - 2 Document XML structure
  - 3 Scripting a designspace
  - Notes
  - Common Lib Key Registry
  - Implementation and differences
  - Version history
- encodings: Support for OpenType-specific encodings
- feaLib: Read/write OpenType feature files
  - Parsing
  - Building
  - Generation/Interrogation
- merge: Merge multiple fonts into one
  - `Merger`
- misc: Miscellaneous libraries helpful for font engineering
  - arrayTools: Various array and rectangle tools
  - bezierTools: Routines for working with Bezier curves
  - classifyTools
  - cliTools: Utilities for command-line interfaces and console scripts
  - configTools
  - eexec: PostScript charstring encryption and decryption routines
  - encodingTools
  - etree
  - filenames: Implements UFO User Name to File Name Algorithm
  - fixedTools: Tools for working with fixed-point numbers
  - intTools: Tools for working with integer values
  - loggingTools: tools for interfacing with the Python logging package
  - macCreatorType: Functions for working with Mac file attributes
  - macRes: Tools for reading Mac resource forks
  - plistlib: Tools for handling .plist files
  - psCharStrings
  - psLib
  - psOperators
  - sstruct
  - symfont
  - testTools
  - textTools
  - timeTools
  - transform
  - xmlReader
  - xmlWriter
- mtiLib: Read Monotype FontDame source files
  - `DeferredMapping`
  - `FeatureNotFoundError`
  - `LookupNotFoundError`
  - `MtiLibError`
  - `ReferenceNotFoundError`
  - `build()`
  - `main()`
- otlLib: Routines for working with OpenType Layout
  - High-level OpenType Layout Lookup Builders
  - Common OpenType Layout Data Structures
  - Low-level GSUB Table Lookup Builders
  - GPOS Shared Table Builders
  - Low-level GPOS Table Lookup Builders
  - GDEF Table Subtable Builders
  - STAT Table Builder
- pens
  - areaPen
  - basePen
  - boundsPen
  - cocoaPen
  - cu2quPen
  - filterPen
  - freetypePen
  - momentsPen
  - perimeterPen
  - pointInsidePen
  - pointPen
  - qtPen
  - recordingPen
  - reportLabPen
  - reverseContourPen
  - roundingPen
  - statisticsPen
  - svgPathPen
  - t2CharStringPen
  - teePen
  - transformPen
  - ttGlyphPen
  - wxPen
- subset
  - cff
  - Initial glyph set specification
  - Other options
  - Output options
  - Glyph set expansion
  - Hinting options
  - Optimization options
  - Font table options
  - Font naming options
  - Glyph naming and encoding options
  - Other font-specific options
  - Application options
  - `Options`
  - `Subsetter`
  - `load_font()`
  - `main()`
  - `parse_gids()`
  - `parse_glyphs()`
  - `parse_unicodes()`
  - `save_font()`
- svgLib
  - path
- t1Lib
  - `T1Error`
  - `T1Font`
  - `assertType1()`
  - `deHexString()`
  - `decryptType1()`
  - `findEncryptedChunks()`
  - `isHex()`
  - `longToString()`
  - `read()`
  - `readLWFN()`
  - `readOther()`
  - `readPFB()`
  - `stringToLong()`
  - `write()`
  - `writeLWFN()`
  - `writeOther()`
  - `writePFB()`
- tfmLib: Read TeX Font Metrics files
  - `TFMException`
  - `TFM`
- ttLib: Read/write OpenType and TrueType fonts
  - ttFont: Read/write OpenType and TrueType fonts
  - ttCollection
  - macUtils
  - sfnt
  - standardGlyphOrder
  - TrueType/OpenType Table Modules
  - woff2
- ttx
  - TTX – From OpenType and TrueType to XML and Back
- ufoLib
  - converters
  - errors
  - filenames
  - glifLib
  - kerning
  - plistlib
  - pointPen
  - utils
  - validators
  - `UFOFileStructure`
  - `UFOLibError`
  - `UFOReader`
  - `UFOReaderWriter`
  - `UFOWriter`
  - `convertFontInfoValueForAttributeFromVersion1ToVersion2()`
  - `convertFontInfoValueForAttributeFromVersion2ToVersion1()`
  - `makeUFOPath()`
  - `validateFontInfoVersion2ValueForAttribute()`
  - `validateFontInfoVersion3ValueForAttribute()`
- unicode
  - `setUnicodeData()`
- unicodedata
  - Blocks
  - OTTags
  - ScriptExtensions
  - Scripts
  - `bidirectional()`
  - `block()`
  - `category()`
  - `combining()`
  - `decimal()`
  - `decomposition()`
  - `digit()`
  - `east_asian_width()`
  - `lookup()`
  - `mirrored()`
  - `name()`
  - `normalize()`
  - `numeric()`
  - `ot_tag_to_script()`
  - `ot_tags_from_script()`
  - `script()`
  - `script_code()`
  - `script_extension()`
  - `script_horizontal_direction()`
  - `script_name()`
- varLib: OpenType Variation Support
  - builder
  - cff
  - errors
  - featureVars
  - instancer
  - interpolatable
  - interpolate_layout
  - iup
  - merger
  - models
  - mutator
  - mvar
  - plot
  - varStore
  - Terminology
- voltLib
  - ast
  - error
  - lexer
  - parser