Files
claude 6b10c4a57c bitmap-font-maker: fontc - .font glyph grids -> atlas PNG + metrics JSON + text rendering
- .font format: glyph sections with #/. grids, proportional widths,
  literal unicode glyph names, spacing/space-width/line-height/baseline
- build (atlas white-on-transparent + JSON metrics), render (text -> PNG
  with \n, scale, color), info, preview (terminal half-blocks)
- example tiny5 font: A-Z, ÅÄÖ, 0-9, punctuation (47 glyphs, 3x5)
- go tests: parsing, errors, atlas metrics, text rendering

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MmdG9GqfSWCzts7AkDwRDh
2026-07-14 07:03:04 +02:00

76 lines
1.9 KiB
Markdown

# bitmap-font-maker (`fontc`)
Turns `.font` text files — pixel glyph grids an agent can read and edit
directly — into **font atlases (PNG + JSON metrics)** and renders text
strings to PNG. Proportional widths, unicode glyph names (ÅÄÖ works).
Go, zero dependencies, single static binary.
## Build
```bash
# Arch/Garuda: sudo pacman -S go
cd bitmap-font-maker
go build -o build/fontc . # or the VS Code task "build bitmap-font-maker"
go test ./...
```
## The `.font` format
```
# comment
font: tiny5 optional name
spacing: 1 px between glyphs (default 1)
space-width: 3 advance of ' ' (default: width of '0')
line-height: 7 default: glyph height + 1
baseline: 5 default: glyph height
glyph A:
.#.
#.#
###
#.#
#.#
glyph :: the char between "glyph " and ":" is literal
.
#
.
#
.
```
- `#` = pixel on, `.` = off.
- **All glyphs share one height; widths may differ** (proportional fonts —
`M` can be 5 px wide while `.` is 1 px).
- Max glyph size 64x64.
## Commands
```bash
fontc build tiny5.font -o out/tiny5 # -> tiny5.png (atlas) + tiny5.json (metrics)
fontc render tiny5.font 'HEJ!\nRAD 2' --scale 4 --color '#FFD700' -o title.png
fontc info tiny5.font # validate + list glyphs
fontc preview tiny5.font 'HELLO' # draw in the terminal
```
## Atlas + metrics
The atlas draws glyphs **white on transparent** so game engines can tint
them. The JSON carries everything a loader needs:
```json
{
"name": "tiny5", "atlas": "tiny5.png",
"height": 5, "lineHeight": 6, "baseline": 5,
"spacing": 1, "spaceWidth": 3,
"glyphs": { "A": {"x": 0, "y": 0, "w": 3, "h": 5, "advance": 4}, ... }
}
```
Drawing text in a game: blit `glyphs[c]` from the atlas, advance the
cursor by `advance`; spaces advance `spaceWidth + spacing`; new lines
step `lineHeight`.
[`examples/tiny5.font`](examples/tiny5.font) is a complete 3x5 font:
A-Z, ÅÄÖ, 0-9 and punctuation.