-
Notifications
You must be signed in to change notification settings - Fork 8
/
ttf2obj.rs
52 lines (43 loc) · 1.36 KB
/
ttf2obj.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::env;
/// Create a .obj file from an input .ttf file
///
/// Obj will contain all glyphs as separate 2d meshes
fn main() {
let args = env::args().collect::<Vec<_>>();
if args.len() < 3 {
println!("usage: ttf2obj <font-file.ttf> <output-file.obj> [quality]");
std::process::exit(255);
}
let (font, obj_file) = (&args[1], &args[2]);
let quality = if args.len() > 3 {
let quality_str = &args[3];
match ttf2mesh::Quality::from_str(&quality_str) {
Ok(q) => q,
Err(e) => {
println!(
"Can not parse quality ({}): {:?}. Try 'low', 'medium' or 'high'",
quality_str, e
);
std::process::exit(255);
}
}
} else {
ttf2mesh::Quality::Medium
};
println!("Loading font {:?}...", font);
let mut font = match ttf2mesh::TTFFile::from_file(font) {
Ok(font) => font,
Err(e) => {
println!(" - font load failed: {:?}", e);
std::process::exit(255);
}
};
println!("Export to obj {:?} with quality={:?}...", obj_file, quality);
match font.export_to_obj(obj_file, quality) {
Ok(_) => println!("Done"),
Err(e) => {
println!(" - export failed: {:?}", e);
std::process::exit(255);
}
}
}