jaaj-rs/build.rs
2025-02-04 16:34:38 +01:00

39 lines
1.1 KiB
Rust

use std::env;
use std::fs;
use std::path::Path;
use rulet::*;
const JAAJ: &str = "jaaj";
const FONTS_DIR: &str = "fonts/";
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("jaaj.rs");
let jaajs = fs::read_dir(FONTS_DIR)
.expect("Failed to list font folder")
.map(|f| {
let f = f.expect("Failed to get font file");
assert!(f
.file_type()
.expect("Failed to get font file type")
.is_file());
let file = fs::File::open(f.path()).expect("Failed to open font file");
let font = FIGfont::read_from(file).expect("Failed to load font");
let figure = FIGure::new(JAAJ, font, Options::default());
format!("r##\"{}\"##", figure.to_string().replace("\"##", "\"#\\#"))
})
.collect::<Vec<_>>()
.join(",\n");
fs::write(
&dest_path,
format!("pub static JAAJS: &'static [&str] = &[\n{}];", jaajs),
)
.unwrap();
println!("cargo::rerun-if-changed=build.rs");
}