1use crate::shared::{
2 load_font_file, parse_font_bytes, parse_font_content, render, FIGcharacter, FIGure, FontData,
3 HeaderLine,
4};
5use std::collections::HashMap;
6
7#[derive(Debug, Clone)]
9pub struct Toilet {
10 pub header_line: HeaderLine,
11 pub comments: String,
12 pub fonts: HashMap<u32, FIGcharacter>,
13}
14
15impl Toilet {
16 pub fn from_content(contents: &str) -> Result<Toilet, String> {
18 Ok(parse_font_content(contents)?.into())
19 }
20
21 pub fn from_file(fontname: &str) -> Result<Toilet, String> {
23 Ok(load_font_file(fontname)?.into())
24 }
25
26 fn from_bytes(bytes: &[u8]) -> Result<Toilet, String> {
27 Ok(parse_font_bytes(bytes)?.into())
28 }
29
30 pub fn smblock() -> Result<Toilet, String> {
32 Toilet::from_bytes(include_bytes!("../resources/smblock.tlf"))
33 }
34
35 pub fn mono12() -> Result<Toilet, String> {
37 Toilet::from_bytes(include_bytes!("../resources/mono12.tlf"))
38 }
39
40 pub fn future() -> Result<Toilet, String> {
42 Toilet::from_bytes(include_bytes!("../resources/future.tlf"))
43 }
44
45 pub fn wideterm() -> Result<Toilet, String> {
47 Toilet::from_bytes(include_bytes!("../resources/wideterm.tlf"))
48 }
49
50 pub fn mono9() -> Result<Toilet, String> {
52 Toilet::from_bytes(include_bytes!("../resources/mono9.tlf"))
53 }
54
55 pub fn convert(&self, message: &str) -> Option<FIGure<'_>> {
57 render(&self.header_line, &self.fonts, message)
58 }
59}
60
61impl From<FontData> for Toilet {
62 fn from(data: FontData) -> Self {
63 Self {
64 header_line: data.header_line,
65 comments: data.comments,
66 fonts: data.fonts,
67 }
68 }
69}