#font #font-file #parser #go #characters #create #pixel

bin+lib spf

.spf (Simple Pixel Font) file parsing, and useful api's to go alongside

6 releases (3 breaking)

0.3.0 Dec 7, 2024
0.2.1 Nov 23, 2024
0.2.0 Oct 31, 2024
0.1.0 Oct 27, 2024
0.0.2 Oct 26, 2024

#1117 in Text processing

Download history 289/week @ 2024-10-21 124/week @ 2024-10-28 25/week @ 2024-11-04 110/week @ 2024-11-18 26/week @ 2024-11-25 139/week @ 2024-12-02 28/week @ 2024-12-09

303 downloads per month

Custom license

36KB
528 lines

The-Nice-One - spf.rs stars - spf.rs forks - spf.rs Rust GitHub tag License issues - spf.rs

A very simple and concrete parser for *.spf (SimplePixelFont) files for Rust. spf.rs provides simple encoding and decoding for the *.spf binary representation through a Vec<u8>. And also includes optional features to conveniently create a texture from a font rendering, which can then be used in your favorite game engine or graphics framework.

Example

Creates a new SimplePixelFont struct and adds the characters o, w, and 😊.

use spf::core::*;

fn main() {
    let mut font = SimplePixelFont::new(
        ConfigurationFlags {
            0: ALIGNMENT_HEIGHT,
            ..Default::default()
        },
        ModifierFlags {
            ..Default::default()
        },
        4,
    );
    font.add_character(Character::inferred(
        'o',
        Bitmap::inferred(&[
            true, true, true, true,
            true, false, false, true,
            true, false, false, true,
            true, true, true, true,
        ]),
    ));
    font.add_character(Character::inferred(
        'w',
        Bitmap::inferred(&[
            true, false, true, false, true,
            true, false, true, false, true,
            true, false, true, false, true,
            true, true, true, true, true,
        ]),
    ));
    font.add_character(Character::inferred(
        '😊',
        Bitmap::inferred(&[
            false, true, true, false,
            false, false, false, false,
            true, false, false, true,
            false, true, true, false,
        ]),
    ));
}

We can then encode the struct and use std::fs to write to a file:

let mut file = std::fs::OpenOptions::new()
    .write(true)
    .create(true)
    .open("./utf8ToyFont.spf")
    .unwrap();
file.write_all(&font.to_vec_u8()).unwrap();

Or we can load an exsisting .spf file using std::fs aswell:

let mut file = std::fs::OpenOptions::new()
    .read(true)
    .open("./utf8ToyFont.spf")
    .unwrap();
let mut buffer: Vec<u8> = vec![];
file.read_to_end(&mut buffer).unwrap();
let font = SimplePixelFont::from_vec_u8(buffer);

Supported File Properties

Flag Type Stability Notes
Alignment Configuration ⚠️ Only height-aligned fonts are supported
Compact Modifier Planned for v0.4

Key:

  • ⚠️ = Work in progress
  • = Not implemented
  • = Stable

No runtime deps

Features