A Python package for font manipulation and conversion
Project description
Font Generator
A Python package for font manipulation and conversion. Convert TTF/OTF fonts to SVG format, convert SVG files back to fonts, and add handwritten effects to fonts.
Features
- TTF to SVG Conversion: Extract individual glyphs from TrueType/OpenType fonts as SVG files
- SVG to TTF Conversion: Combine SVG files back into a TTF font
- Handwritten Effect: Add a handwritten, jittery effect to fonts using FontForge (see HANDWRITTEN.md)
- CLI Interface: Easy-to-use command-line interface for all operations
- Python API: Use as a library in your Python projects
Installation
From PyPI
pip install font-generator
From Source
git clone https://github.com/GenXLabs-org/font-generator.git
cd font-generator
pip install -e .
Quick Start
Running Without Installation
You can run the CLI directly without installing the package:
# From the project root directory
python -m font_generator.cli ttf-to-svg input/Allura-Regular.ttf output/
Command Line Usage
Convert TTF to SVG
font-generator ttf-to-svg input/Allura-Regular.ttf output/
This will extract all glyphs from the font and save them as individual SVG files in the output directory, along with
a _font_metadata.json file containing font metrics.
Convert SVG to TTF
font-generator svg-to-ttf output/input_svgs/ input/Allura-Regular.ttf output/CustomFont.ttf --width 800
This will combine SVG files from the input directory into a new TTF font, using the base font as a template.
Python API Usage
from font_generator import ttf_to_svg, svg_to_ttf, make_handwritten
# Convert TTF to SVG
ttf_to_svg('input/Allura-Regular.ttf', 'output/')
# Convert SVG to TTF
svg_to_ttf('output/input_svgs/', 'input/Allura-Regular.ttf', 'output/CustomFont.ttf')
# Add handwritten effect
make_handwritten('input/Allura-Regular.ttf', 'output/Allura-Handwritten.ttf')
Detailed Usage
TTF to SVG Conversion
The ttf-to-svg command extracts all glyphs from a font file:
font-generator ttf-to-svg input/Allura-Regular.ttf output/
Output:
- Individual SVG files for each glyph (named with Unicode values)
_font_metadata.jsonfile containing:- Font metadata (name, family, version)
- Font metrics (units per em, ascent, descent)
- Glyph metrics (width, left bearing)
- OpenType feature information (GSUB/GPOS)
SVG to TTF Conversion
The svg-to-ttf command combines SVG files into a font:
font-generator svg-to-ttf output/input_svgs/ input/Allura-Regular.ttf output/CustomFont.ttf --width 800
Parameters:
svg_folder/: Directory containing SVG filesbase_font.ttf: Template font fileoutput.ttf: Output font file path--width: Default glyph width (default: 800)
Note: SVG files should be named to match glyph names (e.g., A.svg, uni0041_A.svg). The command uses a default
Unicode map for A-Z, but you can customize this in the Python API.
Requirements
- Python >=3.7
- fonttools >= 4.0.0
- svgpathtools >= 1.4.0
- fontforge (optional, for handwritten feature)
Examples
Example 1: Extract Glyphs from a Font
font-generator ttf-to-svg input/Allura-Regular.ttf output/
This creates individual SVG files for each character in the font, saved in the output/ directory.
Example 2: Create Custom Font from SVGs
# First, extract glyphs
font-generator ttf-to-svg input/Arya-Regular.ttf output/input_svgs/
# Edit SVG files as needed...
# Then rebuild the font
font-generator svg-to-ttf output/input_svgs/ input/Arya-Regular.ttf output/CustomFont.ttf
Troubleshooting
Invalid Font File Error
Make sure you're using a valid TTF or OTF file. The tool validates font files by checking their headers.
SVG Conversion Issues
- Ensure SVG files are properly formatted
- Check that glyph names match the Unicode map
- Verify the base font file is valid
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Author
Support
For issues, questions, or contributions, please visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file font_generator-1.0.1.tar.gz.
File metadata
- Download URL: font_generator-1.0.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60df250934ae03292b0addd8678e41573bedd95b3d00638eece94cb27105a168
|
|
| MD5 |
9be47ec737a4797774b04e764948a96b
|
|
| BLAKE2b-256 |
59f484a5f9a7e5344397bd0d2f936e0fa76531c978681088504727b2d9eed986
|
File details
Details for the file font_generator-1.0.1-py3-none-any.whl.
File metadata
- Download URL: font_generator-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02789218be3e5ae7b73cbbd3aeb5852e67a16b4458118e2831feff7917f7c630
|
|
| MD5 |
874de1349df479a158fa0460608290ed
|
|
| BLAKE2b-256 |
c13206b11b2feb28cecf43388684916d8b001fa60fbd5191340e77a03b0ad150
|