use std::path::PathBuf;
#[path = "src/text/msdf.rs"]
#[allow(dead_code)]
mod msdf;
#[path = "src/text/msdf_snapshot.rs"]
#[allow(dead_code)]
mod msdf_snapshot;
use msdf::apply_weight_variation;
use msdf_snapshot::{SnapshotHeader, SnapshotSection, bake_font_section, encode_snapshot};
const BASE_EM: u32 = 48;
const SPREAD: f64 = 6.0;
const ERROR_CORRECTION: bool = false;
const TOKEN_INTER: u64 = 0;
const TOKEN_JETBRAINS_MONO: u64 = 1;
fn main() {
println!("cargo:rerun-if-changed=src/text/msdf.rs");
println!("cargo:rerun-if-changed=src/text/msdf_snapshot.rs");
println!("cargo:rerun-if-changed=build.rs");
if std::env::var_os("CARGO_FEATURE_PREBAKED_DEFAULT_FONTS").is_none() {
return;
}
let out =
PathBuf::from(std::env::var_os("OUT_DIR").expect("OUT_DIR")).join("default_atlas.bin");
let chars: Vec<char> = (0x20u32..=0x7Eu32).filter_map(char::from_u32).collect();
let mut sections: Vec<SnapshotSection> = Vec::new();
if std::env::var_os("CARGO_FEATURE_INTER").is_some() {
let mut face = ttf_parser::Face::parse(damascene_fonts::INTER_VARIABLE, 0)
.expect("parse bundled Inter");
for weight in [400u16, 500, 600, 700] {
let applied = apply_weight_variation(&mut face, weight);
assert_eq!(applied, weight, "bundled Inter must expose a wght axis");
sections.push(bake_font_section(
&face,
TOKEN_INTER,
&chars,
applied,
BASE_EM,
SPREAD,
ERROR_CORRECTION,
));
}
}
if std::env::var_os("CARGO_FEATURE_JETBRAINS_MONO").is_some() {
let mut face = ttf_parser::Face::parse(damascene_fonts::JETBRAINS_MONO_VARIABLE, 0)
.expect("parse bundled JetBrains Mono");
let applied = apply_weight_variation(&mut face, 400);
assert_eq!(
applied, 400,
"bundled JetBrains Mono must expose a wght axis"
);
sections.push(bake_font_section(
&face,
TOKEN_JETBRAINS_MONO,
&chars,
applied,
BASE_EM,
SPREAD,
ERROR_CORRECTION,
));
}
let header = SnapshotHeader {
base_em: BASE_EM,
spread: SPREAD,
error_correction: ERROR_CORRECTION,
};
let bytes = encode_snapshot(header, §ions);
std::fs::write(&out, &bytes).expect("write default_atlas.bin");
}