Crates.io | spf |
lib.rs | spf |
version | |
source | src |
created_at | 2024-10-26 02:03:32.922912 |
updated_at | 2024-10-31 22:21:18.815478 |
description | .spf (Simple Pixel Font) file parsing, and useful api's to go alongside. |
homepage | |
repository | https://github.com/The-Nice-One/spf.rs |
max_upload_size | |
id | 1423486 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A very simple and concrete parser for *.spf
(SimplePixelFont) files for Rust. spf.rs provides
simple encoding and decoding for *.spf
binary representation through a Vec<u8>
. And also
includes optional features to conveiniently create a texture from a font rendering, which
can then be used in your favorite game engine / graphics framework.
Creates a new SimplePixelFont
struct and adds the characters o
, w
, and 😊
.
use spf::core::*;
fn main() {
let mut font = SimplePixelFont::new(FV0000, Alignment::Height, 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 = fs::OpenOptions::new()
.read(true)
.open("./utf8ToyFont.spf")
.unwrap();
let mut buffer: Vec<u8> = vec![];
file.read(&mut buffer).unwrap();
let font = SimplePixelFont::from_vec_u8(buffer);
Format Version | Stability |
---|---|
FV0000 (Vanilla) |
✔ |