How unight0/8-bit-font-designer works
Purpose and Entry Point
This is a native SDL2-based 8×8 bitmap font editor. It lets a user select one of up to 256 glyphs, toggle pixels, resize the active font range, and save/open font files compatible with the bundled C header format.
Application startup and main event loop are in:
• src/main.cpp
• src/config.h
Application Orchestration
main.cpp initializes the editor runtime, SDL window/rendering context, font state, and command handling. It owns the top-level control flow: process keyboard input, route command characters versus editor navigation, update state, and redraw.
Key integration boundaries:
• SDL2 input/window APIs enter through src/main.cpp.
• Editing commands are delegated to command handling.
• Screen rendering is delegated to the renderer.
• Glyph state is held by the font editor model.
Font Editor State Model
The editable domain is an 8×8 pixel glyph set with a configurable usable symbol count (maximum 256). The model tracks the current glyph index, cursor position within that glyph, and per-pixel on/off values.
Primary model component:
• src/fontedit.h
• src/fontedit.cpp
This is the boundary between interactive controls and persistent font data: keyboard actions mutate the in-memory font model, while load/save operations serialize or replace it.
Command Parsing and File Operations
Commands are typed directly into the application as a command letter followed immediately by an argument. Command handling interprets edit-symbol, save, open, resize, and quit operations.
Command subsystem:
• src/cmdhandl.h
• src/cmdhandl.cpp
Important flow:
1. Raw typed command text is collected by the application.
2. cmdhandl parses command symbol and argument.
3. It changes selected glyph/font size, requests shutdown, or invokes font persistence.
4. Model and renderer reflect the resulting state.
File paths supplied by s<file> and o<file> form the external filesystem boundary.
Rendering and Interactive Input
The renderer projects font-editor state into SDL drawing operations: the 8×8 glyph grid, enabled pixels, and cursor/selection feedback. Keyboard arrows move the grid cursor; space toggles the addressed pixel.
Rendering component:
• src/renderer.h
• src/renderer.cpp
The renderer should consume editor state rather than own it; this keeps visual display separate from glyph mutation and persistence.
Font Format and Export Contract
The repository includes a C header representation intended for importing saved fonts into other code. The editor’s serialization must remain compatible with that format, making font8.h the key output/data contract rather than merely a UI artifact.
Format-related paths:
• src/font8.h
• sample/font0
Runtime and Infrastructure
The project is a compiled C++ desktop program using SDL2 for graphics and keyboard events. Build orchestration is Make-based, with SDL2 and a C++ toolchain as material dependencies.
Build/runtime artifacts:
• Makefile
• src/main.cpp
• src/renderer.cpp
Main entry points: main.cpp Application loop · renderer.cpp Renderer · fontedit.cpp Font editor model · cmdhandl.cpp Command handler
Components 13
Editor application
- Application loop · Owns startup, event routing, state updates, and redraws.
src/main.cpp - Runtime config
src/config.h - Typed commands · Command letter and immediate argument collected by the application.
src/main.cpp - Command handler · Parses edit, resize, open, save, and quit commands.
src/cmdhandl.cpp - Command API
src/cmdhandl.h - Renderer · Draws the glyph grid, enabled pixels, and cursor feedback from model state.
src/renderer.cpp - Renderer API
src/renderer.h
Font domain
- Font editor model · Stores glyph pixels, active glyph, cursor, and usable font range.
src/fontedit.cpp - Font model API
src/fontedit.h
Runtime and data contract
- Make build · Builds the native SDL2 editor.
Makefile - SDL2 · Provides the window, rendering context, and keyboard events.
- C font header format · Compatibility contract for exported font data.
src/font8.h - Font files · Open and save targets, including the bundled sample font.
sample/font0
Connections 18
- Make build → Application loop: builds
- Make build → Renderer: builds
- Make build → SDL2: links
- Runtime config → Application loop: configures
- SDL2 → Application loop: keyboard and window events
- Application loop → Typed commands: collects
- Typed commands → Command handler: dispatches
- Command API → Command handler: declares
- Command handler → Font editor model: edits, resizes, loads, saves
- Font model API → Font editor model: declares
- Application loop → Font editor model: navigation and pixel toggles
- Application loop → Renderer: requests redraw
- Renderer API → Renderer: declares
- Font editor model → Renderer: glyph and cursor state
- Renderer → SDL2: drawing operations
- Command handler → Font files: opens and saves
- Font files → C font header format: serialized as
- C font header format → Font editor model: import/export format