#true-type #mesh #3d #tessellation #api-bindings

ttf2mesh

Rust API for ttf2mesh - a crossplatform library allows to convert a glyphs of truetype font (ttf) to a mesh objects in 2d and 3d space

15 releases

0.2.1 Apr 11, 2023
0.2.0 Oct 24, 2021
0.1.2 Oct 24, 2021
0.0.11 Sep 28, 2021
0.0.5 Jul 31, 2021

#82 in Multimedia

Download history 121/week @ 2024-07-21 199/week @ 2024-07-28 133/week @ 2024-08-04 146/week @ 2024-08-11 120/week @ 2024-08-18 174/week @ 2024-08-25 84/week @ 2024-09-01 169/week @ 2024-09-08 90/week @ 2024-09-15 322/week @ 2024-09-22 107/week @ 2024-09-29 162/week @ 2024-10-06 50/week @ 2024-10-13 161/week @ 2024-10-20 72/week @ 2024-10-27 45/week @ 2024-11-03

330 downloads per month
Used in bevy_text_mesh

MIT license

555KB
12K SLoC

C 6K SLoC // 0.1% comments C++ 4.5K SLoC // 0.1% comments Rust 561 SLoC // 0.0% comments Visual Studio Project 511 SLoC Python 92 SLoC // 0.0% comments Prolog 61 SLoC

ttf2mesh   Build Status Latest Version Docs Version

A high-level Rust wrapper API for fetisov's ttf2mesh library for generating a 2d/3d mesh (vertices, indices and normals [only for 3D]) from TrueType (.ttf) glyphs.

Installing

Prequisites:

apt-get install build-essential patch

Add to Cargo.toml:

[dependencies]
ttf2mesh = "*" # change to latest version

Examples

See examples -folder and crate docs.

Simple usage:

use ttf2mesh::{Quality, TTFFile, Value};

let mut font = TTFFile::from_file("fonts/FiraMono-Medium.ttf").unwrap();

for char in "Hello_World".chars() {
    let mut glyph = font.glyph_from_char(char).unwrap();
    let mesh = glyph.to_2d_mesh(Quality::Medium).unwrap();

    println!("Mesh data char {:?}", char);
    println!(
        "- vertices: [{}]",
        mesh.iter_vertices()
            .map(|v| {
                let v = v.val();
                format!("({:.3}, {:.2})", v.0, v.1)
            })
            .collect::<Vec<_>>()
            .join(", ")
    );
    println!(
        "- faces: [{}]",
        mesh.iter_faces()
            .map(|v| {
                let v = v.val();
                format!("({}, {}, {})", v.0, v.1, v.2)
            })
            .collect::<Vec<_>>()
            .join(", ")
    );
    println!("");
}


Security

The API surface (mainly .ttf loading) has been fuzzed with cargo-fuzz.

Development

Install prequisites (see above).

Clone repository:

git clone https://github.com/blaind/ttf2mesh-rs.git

Update submodules

git submodule update --init

Develop

License

Licensed under MIT license

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the software by you, shall be licensed as above, without any additional terms or conditions.

Dependencies

~0–2.1MB
~43K SLoC