Rust wrapper for libschrift TrueType rendering library.

Kestrel 3b2597f649 Minor README update. 10 сар өмнө
libschrift @ 8e533fd07a 8e5e9426b1 Skeleton with libschrift submodule and compilation. 10 сар өмнө
src d402cf7677 Add documentation. 10 сар өмнө
.gitignore 8e5e9426b1 Skeleton with libschrift submodule and compilation. 10 сар өмнө
.gitmodules 8e5e9426b1 Skeleton with libschrift submodule and compilation. 10 сар өмнө
Cargo.toml d402cf7677 Add documentation. 10 сар өмнө
LICENSE d402cf7677 Add documentation. 10 сар өмнө
README.md 3b2597f649 Minor README update. 10 сар өмнө
build.rs 7d4bfae907 Add caching wrapper. 10 сар өмнө

README.md

schrift-rs

libschrift is a lightweight TrueType rendering library implemented in C, and this crate wraps the libschrift library into safe Rust. The result is a font loading and glyph rendering crate with no runtime dependencies other than the C and Rust standard libraries.

The following example code renders a single glyph into a PGM file:

use schrift_rs::*;
let font = Font::load_from_file(
    concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/libschrift/resources/FiraGO-Regular.ttf")).unwrap();
let sch = Schrift::build(font)
    .with_scale(10.0)
    .flag_y_downwards()
    .build();
let aglyph = sch
    .glyph_lookup('a')
    .expect("couldn't look up lowercase 'a'");

let mut pxdata = vec![0u8; 256];

sch.render(aglyph, pxdata.as_mut_slice(), 16, 16).expect("couldn't render lowercase 'a'");

let mut pgm = String::new();
pgm.push_str("P2\n16 16\n255\n");
for y in 0..16 {
    for x in 0..16 {
        pgm.push_str(format!(" {}", pxdata[x + (y * 16)]).as_str());
    }
    pgm.push_str("\n");
}
std::fs::write(concat!(env!("OUT_DIR"), "render_test.pgm"), pgm).unwrap();