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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#[derive(Debug, Clone)]
pub struct Settings {
pub text_width: f32,
pub text_height: f32,
pub optimize: bool,
pub compact_path: bool,
pub class: Option<String>,
pub id: Option<String>,
pub font_family: String,
pub font_size: f32,
pub stroke_width: f32,
pub stroke_color: String,
pub background_color: String
}
impl Settings {
pub fn set_size(&mut self, text_width: f32, text_height: f32) {
self.text_width = text_width;
self.text_height = text_height;
}
pub fn scale(&mut self, scale: f32) {
self.text_width = self.text_width * scale;
self.text_height = self.text_height * scale;
self.font_size = self.font_size * scale;
self.stroke_width = self.stroke_width * scale;
}
pub fn no_optimization() -> Settings {
let mut settings = Settings::default();
settings.optimize = false;
settings.compact_path = false;
settings
}
pub fn separate_lines() -> Settings {
let mut settings = Settings::default();
settings.optimize = true;
settings.compact_path = false;
settings
}
pub fn compact() -> Settings {
let mut settings = Settings::default();
settings.optimize = true;
settings.compact_path = true;
settings
}
fn set_id(&mut self, id: String) {
self.id = Some(id);
}
fn set_class(&mut self, class: String) {
self.class = Some(class);
}
pub fn set_selector(&mut self, id: Option<String>, class: Option<String>) {
if let Some(id) = id {
self.set_id(id);
}
if let Some(class) = class {
self.set_class(class);
}
}
}
impl Default for Settings {
fn default() -> Settings {
Settings {
text_width: 8.0,
text_height: 16.0,
optimize: true,
compact_path: true,
class: Some("bob".to_string()),
id: None,
font_family: "arial".to_string(),
font_size: 14.0,
stroke_width: 2.0,
stroke_color: "black".into(),
background_color: "white".into(),
}
}
}