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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum FontStyle {
Italic,
Normal,
}
impl ToString for FontStyle {
fn to_string(&self) -> String {
match self {
FontStyle::Italic => "italic",
FontStyle::Normal => "normal",
}
.to_string()
}
}
impl From<&str> for FontStyle {
fn from(s: &str) -> FontStyle {
match s.to_lowercase().as_str() {
"italic" => FontStyle::Italic,
_ => FontStyle::Normal,
}
}
}
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub enum FontFamily {
Mix(Box<FontFamily>, Box<FontFamily>),
Helvetica,
Neue,
Arial,
Derive(Vec<FontFamily>),
}
impl ToString for FontFamily {
fn to_string(&self) -> String {
match self {
FontFamily::Mix(a, b) => format!("\"{} {}\",", a.to_string(), b.to_string()),
FontFamily::Helvetica => "Helvetica".to_string(),
FontFamily::Neue => "Neue".to_string(),
FontFamily::Arial => "Arial".to_string(),
FontFamily::Derive(v) => {
if v.len() == 1 && v[0].to_string().ends_with(',') {
let s = v[0].to_string();
s[..s.len() - 1].to_string()
} else {
v.iter()
.map(|f| f.to_string())
.collect::<Vec<String>>()
.join(" ")
}
}
}
}
}
impl From<&str> for FontFamily {
fn from(s: &str) -> FontFamily {
match s.to_lowercase().as_str() {
"Helvetica" => FontFamily::Helvetica,
"Neue" => FontFamily::Neue,
_ => FontFamily::Arial,
}
}
}