use crate::shared::{
load_font_file, parse_font_content, render, FIGcharacter, FIGure, FontData, HeaderLine,
};
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct FIGlet {
pub header_line: HeaderLine,
pub comments: String,
pub fonts: HashMap<u32, FIGcharacter>,
}
impl FIGlet {
pub fn from_content(contents: &str) -> Result<FIGlet, String> {
Ok(parse_font_content(contents)?.into())
}
pub fn from_file(fontname: &str) -> Result<FIGlet, String> {
Ok(load_font_file(fontname)?.into())
}
pub fn standard() -> Result<FIGlet, String> {
Ok(parse_font_content(include_str!("../resources/standard.flf"))?.into())
}
pub fn small() -> Result<FIGlet, String> {
Ok(parse_font_content(include_str!("../resources/small.flf"))?.into())
}
pub fn big() -> Result<FIGlet, String> {
Ok(parse_font_content(include_str!("../resources/big.flf"))?.into())
}
pub fn slant() -> Result<FIGlet, String> {
Ok(parse_font_content(include_str!("../resources/slant.flf"))?.into())
}
pub fn convert(&self, message: &str) -> Option<FIGure<'_>> {
render(&self.header_line, &self.fonts, message)
}
}
impl From<FontData> for FIGlet {
fn from(data: FontData) -> Self {
Self {
header_line: data.header_line,
comments: data.comments,
fonts: data.fonts,
}
}
}