1use crate::shared::{
2 load_font_file, parse_font_content, render, FIGcharacter, FIGure, FontData, HeaderLine,
3};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone)]
8pub struct FIGlet {
9 pub header_line: HeaderLine,
10 pub comments: String,
11 pub fonts: HashMap<u32, FIGcharacter>,
12}
13
14impl FIGlet {
15 pub fn from_content(contents: &str) -> Result<FIGlet, String> {
17 Ok(parse_font_content(contents)?.into())
18 }
19
20 pub fn from_file(fontname: &str) -> Result<FIGlet, String> {
22 Ok(load_font_file(fontname)?.into())
23 }
24
25 pub fn standard() -> Result<FIGlet, String> {
29 Ok(parse_font_content(include_str!("../resources/standard.flf"))?.into())
30 }
31
32 pub fn small() -> Result<FIGlet, String> {
34 Ok(parse_font_content(include_str!("../resources/small.flf"))?.into())
35 }
36
37 pub fn big() -> Result<FIGlet, String> {
39 Ok(parse_font_content(include_str!("../resources/big.flf"))?.into())
40 }
41
42 pub fn slant() -> Result<FIGlet, String> {
44 Ok(parse_font_content(include_str!("../resources/slant.flf"))?.into())
45 }
46
47 pub fn convert(&self, message: &str) -> Option<FIGure<'_>> {
49 render(&self.header_line, &self.fonts, message)
50 }
51}
52
53impl From<FontData> for FIGlet {
54 fn from(data: FontData) -> Self {
55 Self {
56 header_line: data.header_line,
57 comments: data.comments,
58 fonts: data.fonts,
59 }
60 }
61}