1use crate::constants::DEFAULT_MARGIN;
4
5#[derive(Debug, Clone, Copy, PartialEq)]
7pub struct Color {
8 pub r: f32,
9 pub g: f32,
10 pub b: f32,
11}
12
13impl Color {
14 pub fn rgb(r: f32, g: f32, b: f32) -> Self {
16 Self {
17 r: r.clamp(0.0, 1.0),
18 g: g.clamp(0.0, 1.0),
19 b: b.clamp(0.0, 1.0),
20 }
21 }
22
23 pub fn black() -> Self {
25 Self::rgb(0.0, 0.0, 0.0)
26 }
27
28 pub fn white() -> Self {
30 Self::rgb(1.0, 1.0, 1.0)
31 }
32
33 pub fn gray(level: f32) -> Self {
35 let l = level.clamp(0.0, 1.0);
36 Self::rgb(l, l, l)
37 }
38
39 pub fn light_gray() -> Self {
41 Self::gray(0.8)
42 }
43}
44
45impl Default for Color {
46 fn default() -> Self {
47 Self::black()
48 }
49}
50
51#[derive(Debug, Clone, Copy, PartialEq)]
53pub enum Alignment {
54 Left,
55 Center,
56 Right,
57}
58
59impl Default for Alignment {
60 fn default() -> Self {
61 Self::Left
62 }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq)]
67pub enum VerticalAlignment {
68 Top,
69 Middle,
70 Bottom,
71}
72
73impl Default for VerticalAlignment {
74 fn default() -> Self {
75 Self::Middle
76 }
77}
78
79#[derive(Debug, Clone, Copy, PartialEq)]
81pub enum BorderStyle {
82 None,
83 Solid,
84 Dashed,
85 Dotted,
86}
87
88impl Default for BorderStyle {
89 fn default() -> Self {
90 Self::Solid
91 }
92}
93
94#[derive(Debug, Clone, Copy)]
96pub struct Padding {
97 pub top: f32,
98 pub right: f32,
99 pub bottom: f32,
100 pub left: f32,
101}
102
103impl Padding {
104 pub fn uniform(value: f32) -> Self {
106 Self {
107 top: value,
108 right: value,
109 bottom: value,
110 left: value,
111 }
112 }
113
114 pub fn symmetric(vertical: f32, horizontal: f32) -> Self {
116 Self {
117 top: vertical,
118 bottom: vertical,
119 left: horizontal,
120 right: horizontal,
121 }
122 }
123}
124
125impl Default for Padding {
126 fn default() -> Self {
127 Self::uniform(5.0)
128 }
129}
130
131#[derive(Debug, Clone)]
133pub struct TableStyle {
134 pub border_style: BorderStyle,
135 pub border_width: f32,
136 pub border_color: Color,
137 pub background_color: Option<Color>,
138 pub padding: Padding,
139 pub font_name: String,
141 pub default_font_size: f32,
142 pub page_height: Option<f32>,
144 pub top_margin: f32,
146 pub bottom_margin: f32,
148 pub repeat_headers: bool,
150 pub embedded_font_resource_name: Option<String>,
154 pub embedded_font_resource_name_bold: Option<String>,
157}
158
159impl Default for TableStyle {
160 fn default() -> Self {
161 Self {
162 border_style: BorderStyle::Solid,
163 border_width: 1.0,
164 border_color: Color::black(),
165 background_color: None,
166 padding: Padding::default(),
167 font_name: "Helvetica".to_string(),
168 default_font_size: 10.0,
169 page_height: None, top_margin: DEFAULT_MARGIN,
171 bottom_margin: DEFAULT_MARGIN,
172 repeat_headers: true,
173 embedded_font_resource_name: None,
174 embedded_font_resource_name_bold: None,
175 }
176 }
177}
178
179#[derive(Debug, Clone)]
181pub struct RowStyle {
182 pub background_color: Option<Color>,
183 pub border_top: Option<(BorderStyle, f32, Color)>,
184 pub border_bottom: Option<(BorderStyle, f32, Color)>,
185 pub height: Option<f32>,
186}
187
188impl Default for RowStyle {
189 fn default() -> Self {
190 Self {
191 background_color: None,
192 border_top: None,
193 border_bottom: None,
194 height: None,
195 }
196 }
197}
198
199#[derive(Debug, Clone)]
201pub struct CellStyle {
202 pub background_color: Option<Color>,
203 pub text_color: Color,
204 pub font_size: Option<f32>,
205 pub font_name: Option<String>,
208 pub bold: bool,
209 pub italic: bool,
210 pub alignment: Alignment,
211 pub vertical_alignment: VerticalAlignment,
212 pub padding: Option<Padding>,
213 pub border_left: Option<(BorderStyle, f32, Color)>,
214 pub border_right: Option<(BorderStyle, f32, Color)>,
215 pub border_top: Option<(BorderStyle, f32, Color)>,
216 pub border_bottom: Option<(BorderStyle, f32, Color)>,
217 pub embedded_font_resource_name: Option<String>,
220}
221
222impl Default for CellStyle {
223 fn default() -> Self {
224 Self {
225 background_color: None,
226 text_color: Color::black(),
227 font_size: None,
228 font_name: None,
229 bold: false,
230 italic: false,
231 alignment: Alignment::Left,
232 vertical_alignment: VerticalAlignment::Middle,
233 padding: None,
234 border_left: None,
235 border_right: None,
236 border_top: None,
237 border_bottom: None,
238 embedded_font_resource_name: None,
239 }
240 }
241}
242
243impl CellStyle {
244 pub fn header() -> Self {
246 Self {
247 bold: true,
248 alignment: Alignment::Center,
249 background_color: Some(Color::light_gray()),
250 ..Default::default()
251 }
252 }
253}