use crate::shared::{
load_font_file, parse_font_bytes, parse_font_content, render, FIGcharacter, FIGure, FontData,
HeaderLine,
};
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Toilet {
pub header_line: HeaderLine,
pub comments: String,
pub fonts: HashMap<u32, FIGcharacter>,
}
impl Toilet {
pub fn from_content(contents: &str) -> Result<Toilet, String> {
Ok(parse_font_content(contents)?.into())
}
pub fn from_file(fontname: &str) -> Result<Toilet, String> {
Ok(load_font_file(fontname)?.into())
}
fn from_bytes(bytes: &[u8]) -> Result<Toilet, String> {
Ok(parse_font_bytes(bytes)?.into())
}
pub fn smblock() -> Result<Toilet, String> {
Toilet::from_bytes(include_bytes!("../resources/smblock.tlf"))
}
pub fn mono12() -> Result<Toilet, String> {
Toilet::from_bytes(include_bytes!("../resources/mono12.tlf"))
}
pub fn future() -> Result<Toilet, String> {
Toilet::from_bytes(include_bytes!("../resources/future.tlf"))
}
pub fn wideterm() -> Result<Toilet, String> {
Toilet::from_bytes(include_bytes!("../resources/wideterm.tlf"))
}
pub fn mono9() -> Result<Toilet, String> {
Toilet::from_bytes(include_bytes!("../resources/mono9.tlf"))
}
pub fn convert(&self, message: &str) -> Option<FIGure<'_>> {
render(&self.header_line, &self.fonts, message)
}
}
impl From<FontData> for Toilet {
fn from(data: FontData) -> Self {
Self {
header_line: data.header_line,
comments: data.comments,
fonts: data.fonts,
}
}
}