Crates.io | ttf2mesh |
lib.rs | ttf2mesh |
version | 0.2.1 |
source | src |
created_at | 2021-07-31 10:46:36.099658 |
updated_at | 2023-04-11 14:31:02.327483 |
description | 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 |
homepage | |
repository | https://github.com/blaind/ttf2mesh-rs |
max_upload_size | |
id | 429653 |
size | 224,689 |
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.
Prequisites:
apt-get install build-essential patch
Add to Cargo.toml
:
[dependencies]
ttf2mesh = "*" # change to latest version
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!("");
}
The API surface (mainly .ttf
loading) has been fuzzed with cargo-fuzz.
Install prequisites (see above).
Clone repository:
git clone https://github.com/blaind/ttf2mesh-rs.git
Update submodules
git submodule update --init
Develop
Licensed under MIT license
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.