Turns BDF fonts into plain old binary blobs
Go to file
Hamcha 20bbcc8147
bump version
2024-05-10 19:37:14 +02:00
src add lib 2024-05-08 11:52:55 +02:00
.gitignore it is done 2024-05-08 00:46:05 +02:00
LICENSE add readme 2024-05-08 10:32:07 +02:00
README.md stuttering 2024-05-08 11:59:02 +02:00
build.zig add module function 2024-05-10 19:31:51 +02:00
build.zig.zon bump version 2024-05-10 19:37:14 +02:00


Absolutely Worthless Binfon

Takes all your precious fonts and puts them in BINs!

Turns bitmap fonts into easily embeddable binary blobs.


zig build builds two targets:

  • binfon is the actual executable that runs the bdf to bin transformation (see Usage below)
  • binfon-viewer takes a .bin and prints its glyphs to console


The inputs must be a .bdf file and a .json configuration file. The JSON configuration file must be formatted as follows:

	"inputFile": "path/to/input.bdf",
	"outputFile": "path/to/output.bin",
	"glyphs": [
		<list of glyphs by ENCODING value>

The output bin will contain all the glyphs in the order they are specified in the configuration without any gaps. Everything is packed using byte padding (exactly as in the BDF input file). Eg. if your font is 8x3, every character will be 3 bytes (1 byte x 3 rows), if your font is 10x8, every character will be 16 bytes (2 bytes x 8 rows).

The formula to seek to a specific char should be roughly:

const ENCODED_WIDTH = <ceil(font.width / 8)>;
const GLYPH_HEIGHT = <font.height>;

fn printChar(characterIndex: usize) void {
	const baseOffset = ENCODED_WIDTH*GLYPH_HEIGHT*characterIndex;
	for (0..GLYPH_HEIGHT) |rowIndex| {
		const rowIndex = baseOffset + rowIndex * ENCODED_WIDTH;
		const bytes = binaryBlob[rowIndex..rowIndex+ENCODED_WIDTH];
		/* drawing routine here */

for width ≤ 8px, code can be simplified to:

const GLYPH_HEIGHT = <font.height>;

fn printChar(characterIndex: usize) void {
	const baseOffset = GLYPH_HEIGHT*characterIndex;
	for (0..GLYPH_HEIGHT) |rowIndex| {
		const byte = binaryBlob[baseOffset + rowIndex];
		/* drawing routine here */