use genpdf::fonts::{FontData, FontFamily};
use log::info;
use std::error::Error;
pub struct FontsDir {
pub font_family: FontFamily<FontData>,
}
impl FontsDir {
pub fn build() -> Self {
FontsDir {
font_family : FontsDir::load_embedded_font_family().expect("Embedded fonts failed to load. \
this is a fatal failure that is caused by a corrupt build. Please contact the DEV or submit and Issue \
under https://github.com/jurassicLizard/vex2pdf/issues")
}
}
pub fn print_fonts_info() {
info!("Active font path: <embedded liberationSans fonts> -- the env variable VEX2PDF_SHOW_OSS_LICENSES=true shows Font license details");
info!("");
}
fn load_embedded_font_family() -> Result<FontFamily<FontData>, Box<dyn Error>> {
let regular_font_data =
include_bytes!("../../external/fonts/liberation-fonts/LiberationSans-Regular.ttf");
let bold_font_data =
include_bytes!("../../external/fonts/liberation-fonts/LiberationSans-Bold.ttf");
let italic_font_data =
include_bytes!("../../external/fonts/liberation-fonts/LiberationSans-Italic.ttf");
let bold_italic_font_data =
include_bytes!("../../external/fonts/liberation-fonts/LiberationSans-BoldItalic.ttf");
let regular = FontData::new(regular_font_data.to_vec(), None)?;
let bold = FontData::new(bold_font_data.to_vec(), None)?;
let italic = FontData::new(italic_font_data.to_vec(), None)?;
let bold_italic = FontData::new(bold_italic_font_data.to_vec(), None)?;
Ok(FontFamily {
regular,
bold,
italic,
bold_italic,
})
}
}