Skip to main content

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.json file 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 files
  • base_font.ttf: Template font file
  • output.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

MIT License

Author

GenXLabs

Support

For issues, questions, or contributions, please visit the GitHub repository.

Metadata

Release files for font-generator 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for font-generator 1.0.1
File Size Uploaded Provenance Actions
font_generator-1.0.1.tar.gz 16.8 kB Without provenance Details for font_generator-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for font-generator 1.0.1
File Interpreter ABI Platform Actions
font_generator-1.0.1-py3-none-any.whl Python 3 none any Details for font_generator-1.0.1-py3-none-any.whl

Total release size: 33.7 kB

Release files / font_generator-1.0.1.tar.gz

Download URL font_generator-1.0.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
60df250934ae03292b0addd8678e41573bedd95b3d00638eece94cb27105a168
BLAKE2b-256 checksum
How to use checksums
59f484a5f9a7e5344397bd0d2f936e0fa76531c978681088504727b2d9eed986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / font_generator-1.0.1-py3-none-any.whl

Download URL font_generator-1.0.1-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02789218be3e5ae7b73cbbd3aeb5852e67a16b4458118e2831feff7917f7c630
BLAKE2b-256 checksum
How to use checksums
c13206b11b2feb28cecf43388684916d8b001fa60fbd5191340e77a03b0ad150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for font-generator 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page