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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::documents::BuildXML;
use crate::types::*;
use crate::xml_builder::*;

#[derive(Debug)]
pub struct Font<'a> {
    name: &'a str,
    charset: &'a str,
    family: &'a str,
    pitch: FontPitchType,
}

impl<'a> Font<'a> {
    pub fn new(name: &'a str, charset: &'a str, family: &'a str, pitch: FontPitchType) -> Font<'a> {
        Font {
            name,
            charset,
            family,
            pitch,
        }
    }
}

impl<'a> BuildXML for Font<'a> {
    fn build(&self) -> Vec<u8> {
        let b = XMLBuilder::new();
        b.open_font(self.name)
            .charset(self.charset)
            .family(self.family)
            .pitch(&self.pitch.to_string())
            .close()
            .build()
    }
}

#[cfg(test)]
mod tests {

    use super::*;
    #[cfg(test)]
    use pretty_assertions::assert_eq;
    use std::str;

    #[test]
    fn test_build() {
        let c = Font::new("Arial", "00", "swiss", FontPitchType::Variable);
        let b = c.build();
        assert_eq!(
            str::from_utf8(&b).unwrap(),
            r#"<w:font w:name="Arial">
  <w:charset w:val="00" />
  <w:family w:val="swiss" />
  <w:pitch w:val="variable" />
</w:font>"#
        );
    }
}