Font Pixel Generator
A robust, modular CLI tool and Python library designed to bridge the gap between high-quality typography and embedded systems. This tool rasterizes TTF font files from the Google Fonts library into clean, C++ compatible header files for use in memory-constrained GUI projects.
Overview
Working with embedded displays often requires custom, bitmap-based fonts. This tool automates the process of finding fonts, rasterizing specific characters into boolean arrays, and exporting them as C++ constants. It includes intelligent symbol mapping to ensure all exported character variables adhere to C++ naming conventions.
Features
- Automated Repository Handling: Automatically downloads and manages a local cache of the Google Fonts repository.
- Fuzzy Font Discovery: Easily find and select fonts by family name and style variant.
- C++ Header Generation: Exports character data into
.hfiles with namespaced structures. - Symbol Safety: Automatically maps non-alphanumeric characters (like
#or@) to safe, readable names (e.g.,char_hash,char_at). - Visual Previewing: Uses
matplotlibto render and display a pixel preview of your selected character before finalizing your export.
Installation
Clone the repository:
pip install glyph-bridge
CLI Reference
You can run the tool directly from your terminal:
glyph-bridge \
--family "Inter" \
--style "Regular" \
--size 48 \
--export \
--output "./include/fonts" \
--char "A"
Argument Details
| Argument | Type | Default | Description |
|---|---|---|---|
--family |
String | Required | The name of the font family (e.g., "Roboto"). |
--style |
String | "Regular" |
The specific weight/variant (e.g., "Bold"). |
--size |
Integer | 50 |
Font height in pixels. |
--export |
Flag | False |
If set, generates a .h file. |
--output |
String | "." |
The target directory for the header. |
--char |
String | "A" |
The character to visualize in the preview. |
Library API Usage
Beyond the CLI, font_gen can be imported into your own Python automation scripts:
from font_gen import get_glyph_data, export_header
# 1. Generate glyph data (returns a NumPy boolean array)
pixel_data = get_glyph_data(
char="A",
font_path="path/to/font.ttf",
size=48,
is_fake_italic=False
)
# 2. Export an entire set to a C++ header
export_header(
font_path="path/to/font.ttf",
fam="Inter",
sty="Regular",
size=48,
is_fake_italic=False,
output_dir="./gui_assets"
)
How It Works
- Rasterization: Uses the Pillow library to render text to an off-screen buffer.
- Thresholding: Converts grayscale pixel data into a
boolarray (truefor foreground,falsefor background). - Serialization: Writes the data as a namespaced C++ constant array, sanitizing special symbols to prevent compilation errors.
License & Requirements
Requirements: numpy, matplotlib, Pillow, requests
Metadata
Release files for glyph-bridge 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| glyph_bridge-0.1.3.tar.gz | 6.8 kB | Without provenance | Details for glyph_bridge-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| glyph_bridge-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for glyph_bridge-0.1.3-py3-none-any.whl |
Total release size: 14.3 kB
Release files / glyph_bridge-0.1.3.tar.gz
| Download URL | glyph_bridge-0.1.3.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0069629213dc32dbaa0c8d7b07eb163dbf426fe1aa3977347306df52fb4b1a36
|
|
BLAKE2b-256 checksum How to use checksums |
a9b7e79391ae05d69b0085d08c42045785014e2771251c0d94d6443bc45cc1cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / glyph_bridge-0.1.3-py3-none-any.whl
| Download URL | glyph_bridge-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba753a18f67117050d029b5f96f5bd2e424171339c57af7fcb4f6c9ebbda5e3d
|
|
BLAKE2b-256 checksum How to use checksums |
e59aec395f0b0914535e0c1cde93b41c08354fa750091fff11d60cb6f88d3252
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for glyph-bridge 0.1.3
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.