spreadsheet_ods/style/
cellstyle.rs1use crate::attrmap2::AttrMap2;
2use crate::color::Rgb;
3use crate::format::ValueFormatRef;
4use crate::style::stylemap::StyleMap;
5use crate::style::units::{
6 Angle, Border, CellAlignVertical, CellProtect, FontSize, FontStyle, FontVariant, FontWeight,
7 GlyphOrientation, Hyphenation, HyphenationLadderCount, Indent, Length, LetterSpacing,
8 LineBreak, LineHeight, LineMode, LineStyle, LineType, LineWidth, Margin, PageBreak, PageNumber,
9 ParaAlignVertical, Percent, PunctuationWrap, RotationAlign, TextAlign, TextAlignLast,
10 TextAlignSource, TextAutoSpace, TextCombine, TextCondition, TextDisplay, TextEmphasize,
11 TextEmphasizePosition, TextKeep, TextPosition, TextRelief, TextTransform, WrapOption,
12 WritingDirection, WritingMode,
13};
14use crate::style::AnyStyleRef;
15use crate::style::{
16 border_line_width_string, border_string, color_string, shadow_string, text_position,
17 StyleOrigin, StyleUse, TextStyleRef,
18};
19use core::borrow::Borrow;
20use get_size::GetSize;
21use get_size_derive::GetSize;
22use icu_locid::Locale;
23
24style_ref2!(CellStyleRef);
25
26#[derive(Debug, Clone, GetSize)]
52pub struct CellStyle {
53 origin: StyleOrigin,
55 styleuse: StyleUse,
57 name: String,
59 attr: AttrMap2,
61 cellstyle: AttrMap2,
63 paragraphstyle: AttrMap2,
65 textstyle: AttrMap2,
67 stylemaps: Option<Vec<StyleMap>>,
69}
70
71styles_styles2!(CellStyle, CellStyleRef);
72
73impl CellStyle {
74 pub fn new_empty() -> Self {
76 Self {
77 origin: Default::default(),
78 styleuse: Default::default(),
79 name: Default::default(),
80 attr: Default::default(),
81 cellstyle: Default::default(),
82 paragraphstyle: Default::default(),
83 textstyle: Default::default(),
84 stylemaps: None,
85 }
86 }
87
88 pub fn new<S: AsRef<str>>(name: S, value_format: &ValueFormatRef) -> Self {
91 let mut s = Self {
92 origin: Default::default(),
93 styleuse: Default::default(),
94 name: String::from(name.as_ref()),
95 attr: Default::default(),
96 cellstyle: Default::default(),
97 paragraphstyle: Default::default(),
98 textstyle: Default::default(),
99 stylemaps: None,
100 };
101 s.set_value_format(value_format);
102 s
103 }
104
105 pub fn value_format(&self) -> Option<&str> {
107 self.attr.attr("style:data-style-name")
108 }
109
110 pub fn set_value_format(&mut self, name: &ValueFormatRef) {
112 self.attr
113 .set_attr("style:data-style-name", name.as_ref().to_string());
114 }
115
116 pub fn attrmap(&self) -> &AttrMap2 {
118 &self.attr
119 }
120
121 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
123 &mut self.attr
124 }
125
126 pub fn cellstyle(&self) -> &AttrMap2 {
128 &self.cellstyle
129 }
130
131 pub fn cellstyle_mut(&mut self) -> &mut AttrMap2 {
133 &mut self.cellstyle
134 }
135
136 pub fn paragraphstyle(&self) -> &AttrMap2 {
138 &self.paragraphstyle
139 }
140
141 pub fn paragraphstyle_mut(&mut self) -> &mut AttrMap2 {
143 &mut self.paragraphstyle
144 }
145
146 pub fn textstyle(&self) -> &AttrMap2 {
148 &self.textstyle
149 }
150
151 pub fn textstyle_mut(&mut self) -> &mut AttrMap2 {
153 &mut self.textstyle
154 }
155
156 pub fn push_stylemap(&mut self, stylemap: StyleMap) {
158 self.stylemaps.get_or_insert_with(Vec::new).push(stylemap);
159 }
160
161 pub fn stylemaps(&self) -> Option<&Vec<StyleMap>> {
163 self.stylemaps.as_ref()
164 }
165
166 pub fn stylemaps_mut(&mut self) -> &mut Vec<StyleMap> {
168 self.stylemaps.get_or_insert_with(Vec::new)
169 }
170
171 fo_background_color!(cellstyle);
173 fo_border!(cellstyle);
174 fo_padding!(cellstyle);
175 fo_wrap_option!(cellstyle);
176 fo_border_line_width!(cellstyle);
177 style_cell_protect!(cellstyle);
178 style_decimal_places!(cellstyle);
179 style_diagonal!(cellstyle);
180 style_direction!(cellstyle);
181 style_glyph_orientation_vertical!(cellstyle);
182 style_print_content!(cellstyle);
183 style_repeat_content!(cellstyle);
184 style_rotation_align!(cellstyle);
185 style_rotation_angle!(cellstyle);
186 style_shadow!(cellstyle);
187 style_shrink_to_fit!(cellstyle);
188 style_text_align_source!(cellstyle);
189 style_vertical_align!(cellstyle);
190 style_writing_mode!(cellstyle);
191
192 fo_break!(paragraphstyle);
201 fo_hyphenation!(paragraphstyle);
202 fo_keep_together!(paragraphstyle);
203 fo_keep_with_next!(paragraphstyle);
204 fo_line_height!(paragraphstyle);
205 fo_margin!(paragraphstyle);
206 fo_orphans!(paragraphstyle);
207 fo_text_align!(paragraphstyle);
209 fo_text_align_last!(paragraphstyle);
210 fo_text_indent!(paragraphstyle);
211 fo_widows!(paragraphstyle);
212 style_auto_text_indent!(paragraphstyle);
213 style_background_transparency!(paragraphstyle);
214 style_contextual_spacing!(paragraphstyle);
216 style_font_independent_line_spacing!(paragraphstyle);
217 style_join_border!(paragraphstyle);
218 style_justify_single_word!(paragraphstyle);
219 style_line_break!(paragraphstyle);
220 style_line_height_at_least!(paragraphstyle);
221 style_line_spacing!(paragraphstyle);
222 style_page_number!(paragraphstyle);
223 style_punctuation_wrap!(paragraphstyle);
224 style_register_true!(paragraphstyle);
225 style_snap_to_layout_grid!(paragraphstyle);
227 style_tab_stop_distance!(paragraphstyle);
228 style_text_autospace!(paragraphstyle);
229 style_vertical_align_para!(paragraphstyle);
230 style_writing_mode_automatic!(paragraphstyle);
232 style_line_number!(paragraphstyle);
233 style_number_lines!(paragraphstyle);
234
235 fo_color!(textstyle);
241 fo_locale!(textstyle);
242 style_font_name!(textstyle);
243 fo_font_size!(textstyle);
244 fo_font_size_rel!(textstyle);
245 fo_font_style!(textstyle);
246 fo_font_weight!(textstyle);
247 fo_font_variant!(textstyle);
248 fo_font_attr!(textstyle);
249 style_locale_asian!(textstyle);
250 style_font_name_asian!(textstyle);
251 style_font_size_asian!(textstyle);
252 style_font_size_rel_asian!(textstyle);
253 style_font_style_asian!(textstyle);
254 style_font_weight_asian!(textstyle);
255 style_font_attr_asian!(textstyle);
256 style_locale_complex!(textstyle);
257 style_font_name_complex!(textstyle);
258 style_font_size_complex!(textstyle);
259 style_font_size_rel_complex!(textstyle);
260 style_font_style_complex!(textstyle);
261 style_font_weight_complex!(textstyle);
262 style_font_attr_complex!(textstyle);
263 fo_hyphenate!(textstyle);
264 fo_hyphenation_push_char_count!(textstyle);
265 fo_hyphenation_remain_char_count!(textstyle);
266 fo_letter_spacing!(textstyle);
267 fo_text_shadow!(textstyle);
268 fo_text_transform!(textstyle);
269 style_font_relief!(textstyle);
270 style_text_position!(textstyle);
271 style_letter_kerning!(textstyle);
274 style_text_combine!(textstyle);
275 style_text_combine_start_char!(textstyle);
276 style_text_combine_end_char!(textstyle);
277 style_text_emphasize!(textstyle);
278 style_text_line_through!(textstyle);
279 style_text_outline!(textstyle);
280 style_text_overline!(textstyle);
281 style_text_underline!(textstyle);
282 style_use_window_font_color!(textstyle);
283 text_condition!(textstyle);
284 text_display!(textstyle);
285
286 }