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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
use crate::attrmap2::AttrMap2;
use crate::format::ValueFormatRef;
use crate::style::stylemap::StyleMap;
use crate::style::units::{
Angle, Border, CellAlignVertical, FontStyle, FontWeight, Length, LineMode, LineStyle, LineType,
LineWidth, PageBreak, ParaAlignVertical, RotationAlign, TextAlign, TextAlignSource, TextKeep,
TextPosition, TextRelief, TextTransform, WrapOption, WritingMode,
};
use crate::style::{
border_line_width_string, border_string, color_string, percent_string, shadow_string,
StyleOrigin, StyleUse, TextStyleRef,
};
use color::Rgb;
style_ref!(CellStyleRef);
#[derive(Debug, Clone)]
pub struct CellStyle {
origin: StyleOrigin,
styleuse: StyleUse,
name: String,
attr: AttrMap2,
cellstyle: AttrMap2,
paragraphstyle: AttrMap2,
textstyle: AttrMap2,
stylemaps: Option<Vec<StyleMap>>,
}
impl CellStyle {
pub fn empty() -> Self {
Self {
origin: Default::default(),
styleuse: Default::default(),
name: Default::default(),
attr: Default::default(),
cellstyle: Default::default(),
paragraphstyle: Default::default(),
textstyle: Default::default(),
stylemaps: None,
}
}
pub fn new<S: Into<String>>(name: S, value_format: &ValueFormatRef) -> Self {
let mut s = Self {
origin: Default::default(),
styleuse: Default::default(),
name: name.into(),
attr: Default::default(),
cellstyle: Default::default(),
paragraphstyle: Default::default(),
textstyle: Default::default(),
stylemaps: None,
};
s.set_value_format(value_format);
s
}
pub fn style_ref(&self) -> CellStyleRef {
CellStyleRef::from(self.name())
}
pub fn origin(&self) -> StyleOrigin {
self.origin
}
pub fn set_origin(&mut self, origin: StyleOrigin) {
self.origin = origin;
}
pub fn styleuse(&self) -> StyleUse {
self.styleuse
}
pub fn set_styleuse(&mut self, styleuse: StyleUse) {
self.styleuse = styleuse;
}
pub fn name(&self) -> &str {
&self.name
}
pub fn set_name<S: Into<String>>(&mut self, name: S) {
self.name = name.into();
}
pub fn value_format(&self) -> Option<&String> {
self.attr.attr("style:data-style-name")
}
pub fn set_value_format(&mut self, name: &ValueFormatRef) {
self.attr
.set_attr("style:data-style-name", name.to_string());
}
pub fn display_name(&self) -> Option<&String> {
self.attr.attr("style:display-name")
}
pub fn set_display_name<S: Into<String>>(&mut self, name: S) {
self.attr.set_attr("style:display-name", name.into());
}
pub fn parent_style(&self) -> Option<&String> {
self.attr.attr("style:parent-style-name")
}
pub fn set_parent_style(&mut self, name: &CellStyleRef) {
self.attr
.set_attr("style:parent-style-name", name.to_string());
}
pub fn attrmap(&self) -> &AttrMap2 {
&self.attr
}
pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
&mut self.attr
}
pub fn cellstyle(&self) -> &AttrMap2 {
&self.cellstyle
}
pub fn cellstyle_mut(&mut self) -> &mut AttrMap2 {
&mut self.cellstyle
}
pub fn paragraphstyle(&self) -> &AttrMap2 {
&self.paragraphstyle
}
pub fn paragraphstyle_mut(&mut self) -> &mut AttrMap2 {
&mut self.paragraphstyle
}
pub fn textstyle(&self) -> &AttrMap2 {
&self.textstyle
}
pub fn textstyle_mut(&mut self) -> &mut AttrMap2 {
&mut self.textstyle
}
pub fn push_stylemap(&mut self, stylemap: StyleMap) {
self.stylemaps.get_or_insert_with(Vec::new).push(stylemap);
}
pub fn stylemaps(&self) -> Option<&Vec<StyleMap>> {
self.stylemaps.as_ref()
}
pub fn stylemaps_mut(&mut self) -> &mut Vec<StyleMap> {
self.stylemaps.get_or_insert_with(Vec::new)
}
fo_break!(paragraphstyle_mut);
fo_keep_together!(paragraphstyle_mut);
fo_keep_with_next!(paragraphstyle_mut);
fo_margin!(paragraphstyle_mut);
paragraph!(paragraphstyle_mut);
text!(textstyle_mut);
fo_background_color!(cellstyle_mut);
fo_border!(cellstyle_mut);
fo_padding!(cellstyle_mut);
style_shadow!(cellstyle_mut);
style_writing_mode!(cellstyle_mut);
pub fn set_wrap_option(&mut self, wrap: WrapOption) {
self.cellstyle.set_attr("fo:wrap-option", wrap.to_string());
}
pub fn set_print_content(&mut self, print: bool) {
self.cellstyle
.set_attr("style:print-content", print.to_string());
}
pub fn set_repeat_content(&mut self, print: bool) {
self.cellstyle
.set_attr("style:repeat-content", print.to_string());
}
pub fn set_rotation_align(&mut self, align: RotationAlign) {
self.cellstyle
.set_attr("style:rotation-align", align.to_string());
}
pub fn set_rotation_angle(&mut self, angle: Angle) {
self.cellstyle
.set_attr("style:rotation-angle", angle.to_string());
}
pub fn set_shrink_to_fit(&mut self, shrink: bool) {
self.cellstyle
.set_attr("style:shrink-to-fit", shrink.to_string());
}
pub fn set_vertical_align(&mut self, align: CellAlignVertical) {
self.cellstyle
.set_attr("style:vertical-align", align.to_string());
}
pub fn set_diagonal_bl_tr(&mut self, width: Length, border: Border, color: Rgb<u8>) {
self.cellstyle
.set_attr("style:diagonal-bl-tr", border_string(width, border, color));
}
pub fn set_diagonal_bl_tr_widths(&mut self, inner: Length, spacing: Length, outer: Length) {
self.cellstyle.set_attr(
"style:diagonal-bl-tr-widths",
border_line_width_string(inner, spacing, outer),
);
}
pub fn set_diagonal_tl_br(&mut self, width: Length, border: Border, color: Rgb<u8>) {
self.cellstyle
.set_attr("style:diagonal-tl-br", border_string(width, border, color));
}
pub fn set_diagonal_tl_br_widths(&mut self, inner: Length, spacing: Length, outer: Length) {
self.cellstyle.set_attr(
"style:diagonal-tl-br-widths",
border_line_width_string(inner, spacing, outer),
);
}
}