fonttools-subset
Subset fonts to reduce file size
TLDR
Subset a TTF font file to the Basic Latin Unicode block
Change the file type to WOFF2
Keep only the onum (oldstyle figures) and kern (kerning) OpenType font features
Set the output file's name
SYNOPSIS
fonttools subset [OPTIONS] FONT...
PARAMETERS
-o FILE, --output FILE
Specifies the output font file name. If not provided, a name will be generated.
--text TEXT
Characters to include in the subset, e.g., 'Hello World'. Can be repeated.
--unicodes UNICODES
Unicode codepoints or ranges to keep, e.g., 'U+0041-00FF'. Can be repeated.
--glyphs GLYPHS
Specific glyph names to keep, e.g., 'A,B,C'. Can be repeated.
--layout-features FEATURES
Manages OpenType layout features (e.g., ligatures, kerning) to keep ('+tag') or drop ('-tag').
--flavor FLAVOR
Sets the output font format (e.g., 'woff', 'woff2', 'ttf', 'otf').
--no-hinting
Removes all hinting instructions from the font, further reducing file size.
--drop-tables TABLES
Comma-separated list of OpenType tables to remove (e.g., 'name,hdmx').
--passthrough-tables TABLES
Comma-separated list of OpenType tables to keep untouched.
--drop-tables-all
Drops all known dangerous or unnecessary tables based on common recommendations.
--notdef-glyph / --no-notdef-glyph
Controls whether to keep or remove the '.notdef' glyph.
--recalc-bounds / --no-recalc-bounds
Controls recalculation of the font's bounding box.
-h, --help
Displays the help message and exits.
--version
Shows the program's version information and exits.
DESCRIPTION
The fonttools-subset command is a powerful utility from the FontTools library, designed to reduce the file size of fonts by removing unused glyphs, OpenType features, and tables. This process, known as font subsetting, is particularly beneficial for web performance, embedded systems, or applications where only a specific set of characters or language support is required. By specifying which characters (via text, Unicode ranges, or glyph names) or OpenType layout features to retain, users can create highly optimized font files containing only the essential components, leading to faster loading times and reduced bandwidth consumption. It supports various font formats like TrueType (TTF), OpenType (OTF), WOFF, and WOFF2.
CAVEATS
Subsetting can sometimes lead to unexpected visual changes if not all necessary glyphs or layout features are included, especially for complex scripts or specific language requirements. Aggressive subsetting (e.g., removing all hinting or many tables) might impact font rendering quality on older systems or specific browsers. Always test the subsetted font thoroughly in target environments before deployment.
CHARACTER SELECTION METHODS
The command offers multiple ways to select characters: explicit --text strings, --unicodes codepoint ranges (e.g., "U+0041-U+005A"), or --glyphs by name. Users should choose the method most appropriate for their use case, with Unicode ranges being common for defining language subsets.
OPENTYPE FEATURE CONTROL
Advanced users can precisely control which OpenType layout features (like kerning, ligatures, contextual alternates) are kept or dropped using the --layout-features option, which is crucial for maintaining typographic quality while minimizing file size.
HISTORY
The fonttools library, including its robust subsetting functionality, has been a cornerstone of font development and optimization for the web for many years. Developed and maintained by Just van Rossum and other contributors, it originated in the early 2000s. The subsetting tool evolved significantly with the rise of web fonts, becoming an essential component for delivering performant typography online by enabling precise control over font content and reducing bandwidth. Its Python-based nature makes it highly extensible and scriptable.