extern crate clap;
extern crate font_kit;
use clap::{App, Arg, ArgMatches};
use font_kit::loader::Loader;
use font_kit::source::SystemSource;
#[cfg(any(target_family = "windows", target_os = "macos"))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "ArialMT";
#[cfg(not(any(target_family = "windows", target_os = "macos")))]
static SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME: &'static str = "DejaVuSans";
fn get_args() -> ArgMatches<'static> {
let postscript_name_arg = Arg::with_name("POSTSCRIPT-NAME")
.help("PostScript name of the font")
.default_value(SANS_SERIF_FONT_REGULAR_POSTSCRIPT_NAME)
.index(1);
let text_arg = Arg::with_name("TEXT")
.help("Text to query")
.default_value("A")
.index(2);
let locale_arg = Arg::with_name("LOCALE")
.help("Locale for fallback query")
.default_value("en-US")
.index(3);
App::new("fallback")
.version("0.1")
.arg(postscript_name_arg)
.arg(text_arg)
.arg(locale_arg)
.get_matches()
}
fn main() {
let matches = get_args();
let postscript_name = matches.value_of("POSTSCRIPT-NAME").unwrap();
let text = matches.value_of("TEXT").unwrap();
let locale = matches.value_of("LOCALE").unwrap();
let font = SystemSource::new()
.select_by_postscript_name(&postscript_name)
.expect("Font not found")
.load()
.unwrap();
println!("{}: text: {:?}", postscript_name, text);
let fallback_result = font.get_fallbacks(text, locale);
println!(
"fallback valid substring length: {}",
fallback_result.valid_len
);
for font in &fallback_result.fonts {
println!("font: {}", font.font.full_name());
}
}