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_size2::GetSize;
21use icu_locale_core::Locale;
22
23style_ref2!(CellStyleRef);
24
25#[derive(Debug, Clone, GetSize)]
51pub struct CellStyle {
52 origin: StyleOrigin,
54 styleuse: StyleUse,
56 name: String,
58 attr: AttrMap2,
60 cellstyle: AttrMap2,
62 paragraphstyle: AttrMap2,
64 textstyle: AttrMap2,
66 stylemaps: Option<Vec<StyleMap>>,
68}
69
70styles_styles2!(CellStyle, CellStyleRef);
71
72impl CellStyle {
73 pub fn new_empty() -> Self {
75 Self {
76 origin: Default::default(),
77 styleuse: Default::default(),
78 name: Default::default(),
79 attr: Default::default(),
80 cellstyle: Default::default(),
81 paragraphstyle: Default::default(),
82 textstyle: Default::default(),
83 stylemaps: None,
84 }
85 }
86
87 pub fn new<S: AsRef<str>>(name: S, value_format: &ValueFormatRef) -> Self {
90 let mut s = Self {
91 origin: Default::default(),
92 styleuse: Default::default(),
93 name: String::from(name.as_ref()),
94 attr: Default::default(),
95 cellstyle: Default::default(),
96 paragraphstyle: Default::default(),
97 textstyle: Default::default(),
98 stylemaps: None,
99 };
100 s.set_value_format(value_format);
101 s
102 }
103
104 pub fn value_format(&self) -> Option<&str> {
106 self.attr.attr("style:data-style-name")
107 }
108
109 pub fn set_value_format(&mut self, name: &ValueFormatRef) {
111 self.attr
112 .set_attr("style:data-style-name", name.as_ref().to_string());
113 }
114
115 pub fn attrmap(&self) -> &AttrMap2 {
117 &self.attr
118 }
119
120 pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
122 &mut self.attr
123 }
124
125 pub fn cellstyle(&self) -> &AttrMap2 {
127 &self.cellstyle
128 }
129
130 pub fn cellstyle_mut(&mut self) -> &mut AttrMap2 {
132 &mut self.cellstyle
133 }
134
135 pub fn paragraphstyle(&self) -> &AttrMap2 {
137 &self.paragraphstyle
138 }
139
140 pub fn paragraphstyle_mut(&mut self) -> &mut AttrMap2 {
142 &mut self.paragraphstyle
143 }
144
145 pub fn textstyle(&self) -> &AttrMap2 {
147 &self.textstyle
148 }
149
150 pub fn textstyle_mut(&mut self) -> &mut AttrMap2 {
152 &mut self.textstyle
153 }
154
155 pub fn push_stylemap(&mut self, stylemap: StyleMap) {
157 self.stylemaps.get_or_insert_with(Vec::new).push(stylemap);
158 }
159
160 pub fn stylemaps(&self) -> Option<&Vec<StyleMap>> {
162 self.stylemaps.as_ref()
163 }
164
165 pub fn stylemaps_mut(&mut self) -> &mut Vec<StyleMap> {
167 self.stylemaps.get_or_insert_with(Vec::new)
168 }
169
170 fo_background_color!(cellstyle);
172 fo_border!(cellstyle);
173 fo_padding!(cellstyle);
174 fo_wrap_option!(cellstyle);
175 fo_border_line_width!(cellstyle);
176 style_cell_protect!(cellstyle);
177 style_decimal_places!(cellstyle);
178 style_diagonal!(cellstyle);
179 style_direction!(cellstyle);
180 style_glyph_orientation_vertical!(cellstyle);
181 style_print_content!(cellstyle);
182 style_repeat_content!(cellstyle);
183 style_rotation_align!(cellstyle);
184 style_rotation_angle!(cellstyle);
185 style_shadow!(cellstyle);
186 style_shrink_to_fit!(cellstyle);
187 style_text_align_source!(cellstyle);
188 style_vertical_align!(cellstyle);
189 style_writing_mode!(cellstyle);
190
191 fo_break!(paragraphstyle);
200 fo_hyphenation!(paragraphstyle);
201 fo_keep_together!(paragraphstyle);
202 fo_keep_with_next!(paragraphstyle);
203 fo_line_height!(paragraphstyle);
204 fo_margin!(paragraphstyle);
205 fo_orphans!(paragraphstyle);
206 fo_text_align!(paragraphstyle);
208 fo_text_align_last!(paragraphstyle);
209 fo_text_indent!(paragraphstyle);
210 fo_widows!(paragraphstyle);
211 style_auto_text_indent!(paragraphstyle);
212 style_background_transparency!(paragraphstyle);
213 style_contextual_spacing!(paragraphstyle);
215 style_font_independent_line_spacing!(paragraphstyle);
216 style_join_border!(paragraphstyle);
217 style_justify_single_word!(paragraphstyle);
218 style_line_break!(paragraphstyle);
219 style_line_height_at_least!(paragraphstyle);
220 style_line_spacing!(paragraphstyle);
221 style_page_number!(paragraphstyle);
222 style_punctuation_wrap!(paragraphstyle);
223 style_register_true!(paragraphstyle);
224 style_snap_to_layout_grid!(paragraphstyle);
226 style_tab_stop_distance!(paragraphstyle);
227 style_text_autospace!(paragraphstyle);
228 style_vertical_align_para!(paragraphstyle);
229 style_writing_mode_automatic!(paragraphstyle);
231 style_line_number!(paragraphstyle);
232 style_number_lines!(paragraphstyle);
233
234 fo_color!(textstyle);
240 fo_locale!(textstyle);
241 style_font_name!(textstyle);
242 fo_font_size!(textstyle);
243 fo_font_size_rel!(textstyle);
244 fo_font_style!(textstyle);
245 fo_font_weight!(textstyle);
246 fo_font_variant!(textstyle);
247 fo_font_attr!(textstyle);
248 style_locale_asian!(textstyle);
249 style_font_name_asian!(textstyle);
250 style_font_size_asian!(textstyle);
251 style_font_size_rel_asian!(textstyle);
252 style_font_style_asian!(textstyle);
253 style_font_weight_asian!(textstyle);
254 style_font_attr_asian!(textstyle);
255 style_locale_complex!(textstyle);
256 style_font_name_complex!(textstyle);
257 style_font_size_complex!(textstyle);
258 style_font_size_rel_complex!(textstyle);
259 style_font_style_complex!(textstyle);
260 style_font_weight_complex!(textstyle);
261 style_font_attr_complex!(textstyle);
262 fo_hyphenate!(textstyle);
263 fo_hyphenation_push_char_count!(textstyle);
264 fo_hyphenation_remain_char_count!(textstyle);
265 fo_letter_spacing!(textstyle);
266 fo_text_shadow!(textstyle);
267 fo_text_transform!(textstyle);
268 style_font_relief!(textstyle);
269 style_text_position!(textstyle);
270 style_letter_kerning!(textstyle);
273 style_text_combine!(textstyle);
274 style_text_combine_start_char!(textstyle);
275 style_text_combine_end_char!(textstyle);
276 style_text_emphasize!(textstyle);
277 style_text_line_through!(textstyle);
278 style_text_outline!(textstyle);
279 style_text_overline!(textstyle);
280 style_text_underline!(textstyle);
281 style_use_window_font_color!(textstyle);
282 text_condition!(textstyle);
283 text_display!(textstyle);
284
285 }