spreadsheet_ods/style/
textstyle.rs

1use crate::attrmap2::AttrMap2;
2use crate::color::Rgb;
3use crate::style::units::{
4    Angle, FontSize, FontStyle, FontVariant, FontWeight, Length, LetterSpacing, LineMode,
5    LineStyle, LineType, LineWidth, Percent, RotationScale, TextCombine, TextCondition,
6    TextDisplay, TextEmphasize, TextEmphasizePosition, TextPosition, TextRelief, TextTransform,
7};
8use crate::style::AnyStyleRef;
9use crate::style::{color_string, shadow_string, text_position, StyleOrigin, StyleUse};
10use core::borrow::Borrow;
11use get_size::GetSize;
12use get_size_derive::GetSize;
13use icu_locid::Locale;
14
15style_ref2!(TextStyleRef);
16
17/// Text style.
18/// This is not used for cell-formatting. Use CellStyle instead.
19///
20#[derive(Debug, Clone, GetSize)]
21pub struct TextStyle {
22    /// From where did we get this style.
23    origin: StyleOrigin,
24    /// Which tag contains this style.
25    styleuse: StyleUse,
26    /// Style name
27    name: String,
28    /// General attributes
29    attr: AttrMap2,
30    /// Specific attributes
31    textstyle: AttrMap2,
32}
33
34styles_styles2!(TextStyle, TextStyleRef);
35
36impl TextStyle {
37    /// Empty.
38    pub fn new_empty() -> Self {
39        Self {
40            origin: Default::default(),
41            styleuse: Default::default(),
42            name: Default::default(),
43            attr: Default::default(),
44            textstyle: Default::default(),
45        }
46    }
47
48    /// A new named style.
49    pub fn new<S: AsRef<str>>(name: S) -> Self {
50        Self {
51            origin: Default::default(),
52            styleuse: Default::default(),
53            name: name.as_ref().to_string(),
54            attr: Default::default(),
55            textstyle: Default::default(),
56        }
57    }
58
59    /// General attributes for the style.
60    pub fn attrmap(&self) -> &AttrMap2 {
61        &self.attr
62    }
63
64    /// General attributes for the style.
65    pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
66        &mut self.attr
67    }
68
69    /// All text-attributes for the style.
70    pub fn textstyle(&self) -> &AttrMap2 {
71        &self.textstyle
72    }
73
74    /// All text-attributes for the style.
75    pub fn textstyle_mut(&mut self) -> &mut AttrMap2 {
76        &mut self.textstyle
77    }
78
79    fo_background_color!(textstyle);
80    fo_color!(textstyle);
81    fo_locale!(textstyle);
82    style_font_name!(textstyle);
83    fo_font_size!(textstyle);
84    fo_font_size_rel!(textstyle);
85    fo_font_style!(textstyle);
86    fo_font_weight!(textstyle);
87    fo_font_variant!(textstyle);
88    fo_font_attr!(textstyle);
89    style_locale_asian!(textstyle);
90    style_font_name_asian!(textstyle);
91    style_font_size_asian!(textstyle);
92    style_font_size_rel_asian!(textstyle);
93    style_font_style_asian!(textstyle);
94    style_font_weight_asian!(textstyle);
95    style_font_attr_asian!(textstyle);
96    style_locale_complex!(textstyle);
97    style_font_name_complex!(textstyle);
98    style_font_size_complex!(textstyle);
99    style_font_size_rel_complex!(textstyle);
100    style_font_style_complex!(textstyle);
101    style_font_weight_complex!(textstyle);
102    style_font_attr_complex!(textstyle);
103    fo_hyphenate!(textstyle);
104    fo_hyphenation_push_char_count!(textstyle);
105    fo_hyphenation_remain_char_count!(textstyle);
106    fo_letter_spacing!(textstyle);
107    fo_text_shadow!(textstyle);
108    fo_text_transform!(textstyle);
109    style_font_relief!(textstyle);
110    style_text_position!(textstyle);
111    style_rotation_angle!(textstyle);
112    style_rotation_scale!(textstyle);
113    style_letter_kerning!(textstyle);
114    style_text_combine!(textstyle);
115    style_text_combine_start_char!(textstyle);
116    style_text_combine_end_char!(textstyle);
117    style_text_emphasize!(textstyle);
118    style_text_line_through!(textstyle);
119    style_text_outline!(textstyle);
120    style_text_overline!(textstyle);
121    style_text_underline!(textstyle);
122    style_use_window_font_color!(textstyle);
123    text_condition!(textstyle);
124    text_display!(textstyle);
125}