1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use super::*; 

pub trait AtlasBuilder: Sized {
    type AtlasType;
    fn with_font_file(self, font: String) -> Result<Self, &'static str>;
    fn with_pages(self, pages: Vec<Vec<u8>>) -> Self;
    fn build(self) -> Self::AtlasType;
}

impl AtlasBuilder for Incomplete<HieroAtlas> {
    type AtlasType = HieroAtlas;

    fn with_font_file(mut self, fnt_file: String) -> Result<Self, &'static str> {
        let mut table: Vec<Vec<HieroToken>> = Vec::new();
        for line in fnt_file.lines() {
            table.push(HieroTokenizer::tokenize_line(line));
        }
        self.inner.info = parse::parse_info(&table)?;
        self.inner.common = parse::parse_common(&table)?;
        self.inner.bitmap_table = parse::parse_glyphs(&table)?;
        self.inner.kerning_table = parse::parse_kerning_table(&table)?;
        Ok(self)
    }

    fn with_pages(mut self, pages: Vec<Vec<u8>>) -> Self {
        self.inner.compressed_pages = pages;
        self
    }

    fn build(self) -> Self::AtlasType {
        self.inner
    }
}