bitmap2ttf
Convert bitmap font glyphs into TrueType (.ttf) vector fonts.
Takes pixel-grid glyph data and produces valid TrueType fonts with traced vector outlines — no hinting, just clean bitmap-to-outline conversion. Useful for retro game preservation, pixel font creation, and embedding bitmap fonts in applications that require vector formats.
Features
- Generic input: any source that provides per-glyph pixel grids + metrics
- Run-length rect merging for minimal contour counts
- Complete TTF table set: head, hhea, hmtx, maxp, cmap, name, OS/2, post, glyf/loca, gasp, DSIG
- Fallible integer conversions throughout (no panics on overflow)
- BMFont (.fnt + .png atlas) and PNG+JSON CLI input support
Installation
Library
[]
= "0.1"
CLI
Usage
Library
use ;
let glyphs = vec!;
let config = FontConfig ;
let ttf_bytes = build_ttf?;
write?;
Integration in existing importers
Existing bitmap font importers can map their parsed glyph structures directly to BitmapGlyph with no extra format conversion:
use ;
let glyphs: = parsed_glyphs
.iter
.map
.collect;
let config = FontConfig ;
let ttf = build_ttf?;
CLI
Convert a BMFont (.fnt + .png atlas) to TrueType:
Convert a PNG+JSON descriptor to TrueType:
The CLI reads either:
- BMFont text descriptors (
.fnt) with PNG atlas page references - JSON descriptors (
.json) with eitherimage(single page) orpages(multi-page)
JSON descriptor shape:
How It Works
- Each glyph's pixel grid is scanned for filled pixels
- Adjacent filled pixels are merged into minimal rectangles (run-length rect merging)
- Rectangles are converted to vector outlines (straight-edge contours)
- Coordinates are transformed from bitmap space (Y-down) to TrueType space (Y-up) and scaled
- All required TTF tables are constructed and assembled into a valid font file
The output fonts are bitmap-traced vector outlines without hinting. They render correctly at the original pixel size and can be installed system-wide, used in game engines (Unity, Godot, etc.), and previewed at fontdrop.info.
Repository Layout
bitmap2ttf/ # library crate (core conversion logic)
bitmap2ttf-cli/ # CLI binary (BMFont input → TTF output)
License
MIT