elvis_core/value/
font.rs

1/// Font Style
2#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug)]
3pub enum FontStyle {
4    /// Italic Font
5    Italic,
6    /// Nomal Font
7    Normal,
8}
9
10impl ToString for FontStyle {
11    fn to_string(&self) -> String {
12        match self {
13            FontStyle::Italic => "italic",
14            FontStyle::Normal => "normal",
15        }
16        .to_string()
17    }
18}
19
20impl From<&str> for FontStyle {
21    fn from(s: &str) -> FontStyle {
22        match s.to_lowercase().as_str() {
23            "italic" => FontStyle::Italic,
24            _ => FontStyle::Normal,
25        }
26    }
27}
28
29/// Font Family
30#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
31pub enum FontFamily {
32    /// Helvetica Neue Font
33    Mix(Box<FontFamily>, Box<FontFamily>),
34    /// Helvetica Font
35    Helvetica,
36    /// Neue Font
37    Neue,
38    /// Arial Font
39    Arial,
40    /// Derive Font Families
41    Derive(Vec<FontFamily>),
42}
43
44impl ToString for FontFamily {
45    fn to_string(&self) -> String {
46        match self {
47            FontFamily::Mix(a, b) => format!("\"{} {}\",", a.to_string(), b.to_string()),
48            FontFamily::Helvetica => "Helvetica".to_string(),
49            FontFamily::Neue => "Neue".to_string(),
50            FontFamily::Arial => "Arial".to_string(),
51            FontFamily::Derive(v) => {
52                if v.len() == 1 && v[0].to_string().ends_with(',') {
53                    let s = v[0].to_string();
54                    s[..s.len() - 1].to_string()
55                } else {
56                    v.iter()
57                        .map(|f| f.to_string())
58                        .collect::<Vec<String>>()
59                        .join(" ")
60                }
61            }
62        }
63    }
64}
65
66impl From<&str> for FontFamily {
67    fn from(s: &str) -> FontFamily {
68        match s.to_lowercase().as_str() {
69            "Helvetica" => FontFamily::Helvetica,
70            "Neue" => FontFamily::Neue,
71            _ => FontFamily::Arial,
72        }
73    }
74}