glypher
v1.2.3
Published
Fast and efficient font manipulation tool
Maintainers
Readme
glypher
Fast and efficient font manipulation tool.
Glypher is a successor of glyphhanger, providing fast and efficient font manipulation tools. You had to install external tools like pyftsubset, brotli or zopfli to enable specific features. This project focuses on providing all the features in a single tool without the need for external installations or dependencies.
The glypher CLI provides a TypeScript interface that wraps the core WebAssembly functionality for font subsetting and conversion operations.
Features
- Subset fonts to include only specific glyphs
- Convert fonts to different formats (WOFF, WOFF2)
- Crawl websites to extract glyphs
- Limitation: CSR, SSR websites not fully supported since content might be added after page load
- Use predefined Unicode ranges for common scripts
- Use best matching ranges instead of exact glyphs
- Use Unicode code points or glyph IDs
- Use range notation or U+ notation
- Use hex notation or plain hex (without prefix)
Installation
npm install -g glypherOr use with npx:
npx glypher [options]Usage
Glypher uses a unified command structure where you can subset, convert, or do both in a single command.
npx glypher -i <input> [-o <output>] [-f <format>] [-g <glyphs>] [-r <ranges...>]Options
| Option | Alias | Description | Required |
|--------|-------|-------------|----------|
| --input <path> | -i | Input font file | Yes (except with --crawl only) |
| --output <path> | -o | Output font file | When subsetting without format |
| --format <format> | -f | Convert to format: woff or woff2 | No |
| --glyphs <glyphs> | -g | Glyphs to subset (Unicode code points or glyph IDs) | No |
| --range <ranges...> | -r | Predefined character range(s) for subsetting | No |
| --crawl | | Crawl a website to extract glyphs | No |
| --url <url> | -u | URL to crawl (requires --crawl) | When using --crawl |
| --depth <depth> | -d | Crawl depth (0 = single page only, default: 0) | No |
| --use-range | | Use best matching range instead of exact glyphs (with --crawl) | No |
Note: At least one of --format, --glyphs, --range, or --crawl must be specified.
Examples
Convert Only
Convert a font file to WOFF2 format:
npx glypher -i input.ttf -f woff2Convert to WOFF format:
npx glypher -i input.ttf -f woffConvert with explicit output path:
npx glypher -i input.ttf -f woff2 -o output.woff2Subset Only
Subset a font to include only specific glyphs:
Using predefined ranges (recommended for language support):
# Single range
npx glypher -i input.ttf -o output.ttf -r LATIN_BASIC
# Multiple ranges
npx glypher -i input.ttf -o output.ttf -r LATIN_BASIC GREEK
# Extended Latin support
npx glypher -i input.ttf -o output.ttf -r LATIN_EXTENDEDUsing Unicode code points:
# Using U+ notation
npx glypher -i input.ttf -o output.ttf -g U+0041,U+0042,U+0043
# Using hex notation (0x prefix)
npx glypher -i input.ttf -o output.ttf -g 0x0041,0x0042,0x0043
# Using plain hex (without prefix)
npx glypher -i input.ttf -o output.ttf -g 0041,0042,0043Using glyph IDs (font-specific):
npx glypher -i input.ttf -o output.ttf -g 36,37,38Subset and Convert
Subset a font and convert to WOFF2 in a single command:
npx glypher -i input.ttf -f woff2 -g U+0041,U+0042,U+0043 -o output.woff2Using predefined ranges with conversion:
npx glypher -i input.ttf -f woff2 -r LATIN_BASIC -o output.woff2You can omit -o when using -f, and the output filename will be auto-generated:
npx glypher -i input.ttf -f woff2 -r LATIN_BASIC
# Outputs: input.woff2Website Crawling
Crawl a website to discover which glyphs are actually used:
Basic crawl (analyze only):
npx glypher --crawl -u https://example.comCrawl with depth (follow links):
# Crawl the page and one level of linked pages
npx glypher --crawl -u https://example.com -d 1
# Crawl two levels deep
npx glypher --crawl -u https://example.com -d 2Crawl and subset a font with exact glyphs found:
npx glypher --crawl -u https://example.com -i input.ttf -o output.ttfCrawl and subset using the best matching range:
npx glypher --crawl -u https://example.com -i input.ttf -o output.ttf --use-rangeCrawl, subset, and convert in one command:
npx glypher --crawl -u https://example.com -i input.ttf -f woff2 -o output.woff2Crawl with range matching and convert:
npx glypher --crawl -u https://example.com -i input.ttf -f woff2 --use-rangeOutput Path Behavior
- When using
--formatwithout--output: Output file uses the input filename with the new extension (e.g.,input.ttf→input.woff2) - When only subsetting without
--output: Output file is auto-generated as<input>-subset.<ext>(e.g.,input.ttf→input-subset.ttf) - When
--outputis specified: Uses the exact path provided
Notes
- Unicode code points are font-independent and recommended for subsetting
- Glyph IDs are font-specific and may vary between fonts
- Predefined ranges are useful for ensuring full language support
- The
--use-rangeflag with--crawlhelps ensure you include a complete character set rather than only the exact glyphs found - Website crawling works best with static HTML content; dynamically loaded content (CSR/SSR) may not be captured
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
Reporting Issues
Issues are welcomed! If you encounter a bug or have a feature request, please open an issue.
