Skip to main content

A utility to convert Google Fonts to C++ header files.

Project description

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 .h files 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 matplotlib to 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

  1. Rasterization: Uses the Pillow library to render text to an off-screen buffer.
  2. Thresholding: Converts grayscale pixel data into a bool array (true for foreground, false for background).
  3. Serialization: Writes the data as a namespaced C++ constant array, sanitizing special symbols to prevent compilation errors.

License & Requirements

Requirements: numpy, matplotlib, Pillow, requests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glyph_bridge-0.1.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glyph_bridge-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file glyph_bridge-0.1.2.tar.gz.

File metadata

  • Download URL: glyph_bridge-0.1.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for glyph_bridge-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fcbe043f1327f23c2da1b666c14ba02e09adb52ccd1d987e0b193c49a3cf7f66
MD5 4aaec99042d93bb43668625823149247
BLAKE2b-256 58c9c472776c2bf5b35d9fca17e0b41d0ded9d01e8f13d6718c62fcd11d2ada9

See more details on using hashes here.

File details

Details for the file glyph_bridge-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: glyph_bridge-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for glyph_bridge-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c72d8991757be32ae6b6c532fb0585e6e97adcad5d5db82823fdaca56e8981f
MD5 ed64b9bdd132e4df76830fa9e4b548db
BLAKE2b-256 1df339d1c55429520a950e21d347bc3655127bbf473f42182f44b2d001b1827e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page