spreadsheet_ods/style/
paragraphstyle.rs

1use crate::attrmap2::AttrMap2;
2use crate::color::Rgb;
3use crate::style::tabstop::TabStop;
4use crate::style::units::{
5    Border, FontSize, FontStyle, FontVariant, FontWeight, Hyphenation, HyphenationLadderCount,
6    Indent, Length, LetterSpacing, LineBreak, LineHeight, LineMode, LineStyle, LineType, LineWidth,
7    Margin, PageBreak, PageNumber, ParaAlignVertical, Percent, PunctuationWrap, RotationScale,
8    TextAlign, TextAlignLast, TextAutoSpace, TextCombine, TextCondition, TextDisplay,
9    TextEmphasize, TextEmphasizePosition, TextKeep, TextPosition, TextRelief, TextTransform,
10    WritingMode,
11};
12use crate::style::AnyStyleRef;
13use crate::style::MasterPageRef;
14use crate::style::{
15    border_line_width_string, border_string, color_string, shadow_string, text_position,
16    StyleOrigin, StyleUse, TextStyleRef,
17};
18use get_size::GetSize;
19use get_size_derive::GetSize;
20use icu_locid::Locale;
21use std::borrow::Borrow;
22
23style_ref2!(ParagraphStyleRef);
24
25/// Paragraph style.
26///
27/// This is not used for cell-formatting. Use [crate::style::CellStyle] instead.
28/// This kind of style is used for complex text formatting. See [crate::text].
29///
30#[derive(Debug, Clone, GetSize)]
31pub struct ParagraphStyle {
32    /// From where did we get this style.
33    origin: StyleOrigin,
34    /// Which tag contains this style.
35    styleuse: StyleUse,
36    /// Style name
37    name: String,
38    /// General attributes
39    attr: AttrMap2,
40    /// Paragraph attributes
41    paragraphstyle: AttrMap2,
42    /// Text attributes
43    textstyle: AttrMap2,
44    /// Tabstop data.
45    tabstops: Option<Vec<TabStop>>,
46}
47
48styles_styles2!(ParagraphStyle, ParagraphStyleRef);
49
50impl ParagraphStyle {
51    /// Empty
52    pub fn new_empty() -> Self {
53        Self {
54            origin: Default::default(),
55            styleuse: Default::default(),
56            name: Default::default(),
57            attr: Default::default(),
58            paragraphstyle: Default::default(),
59            textstyle: Default::default(),
60            tabstops: None,
61        }
62    }
63
64    /// New style.
65    pub fn new<S: AsRef<str>>(name: S) -> Self {
66        Self {
67            origin: Default::default(),
68            styleuse: Default::default(),
69            name: name.as_ref().to_string(),
70            attr: Default::default(),
71            paragraphstyle: Default::default(),
72            textstyle: Default::default(),
73            tabstops: None,
74        }
75    }
76
77    /// General attributes.
78    pub fn attrmap(&self) -> &AttrMap2 {
79        &self.attr
80    }
81
82    /// General attributes.
83    pub fn attrmap_mut(&mut self) -> &mut AttrMap2 {
84        &mut self.attr
85    }
86
87    /// Paragraph style attributes.
88    pub fn paragraphstyle(&self) -> &AttrMap2 {
89        &self.paragraphstyle
90    }
91
92    /// Paragraph style attributes.
93    pub fn paragraphstyle_mut(&mut self) -> &mut AttrMap2 {
94        &mut self.paragraphstyle
95    }
96
97    /// Text style attributes.
98    pub fn textstyle(&self) -> &AttrMap2 {
99        &self.textstyle
100    }
101
102    /// Text style attributes.
103    pub fn textstyle_mut(&mut self) -> &mut AttrMap2 {
104        &mut self.textstyle
105    }
106
107    style_default_outline_level!(attr);
108    style_master_page!(attr);
109    style_next_style!(attr);
110
111    /// Tabstops.
112    pub fn add_tabstop(&mut self, ts: TabStop) {
113        let tabstops = self.tabstops.get_or_insert_with(Vec::new);
114        tabstops.push(ts);
115    }
116
117    /// Tabstops.
118    pub fn tabstops(&self) -> Option<&Vec<TabStop>> {
119        self.tabstops.as_ref()
120    }
121
122    fo_background_color!(paragraphstyle);
123    fo_border!(paragraphstyle);
124    fo_break!(paragraphstyle);
125    fo_hyphenation!(paragraphstyle);
126    fo_keep_together!(paragraphstyle);
127    fo_keep_with_next!(paragraphstyle);
128    fo_line_height!(paragraphstyle);
129    fo_margin!(paragraphstyle);
130    fo_orphans!(paragraphstyle);
131    fo_padding!(paragraphstyle);
132    fo_text_align!(paragraphstyle);
133    fo_text_align_last!(paragraphstyle);
134    fo_text_indent!(paragraphstyle);
135    fo_widows!(paragraphstyle);
136    style_auto_text_indent!(paragraphstyle);
137    style_background_transparency!(paragraphstyle);
138    fo_border_line_width!(paragraphstyle);
139    style_contextual_spacing!(paragraphstyle);
140    style_font_independent_line_spacing!(paragraphstyle);
141    style_join_border!(paragraphstyle);
142    style_justify_single_word!(paragraphstyle);
143    style_line_break!(paragraphstyle);
144    style_line_height_at_least!(paragraphstyle);
145    style_line_spacing!(paragraphstyle);
146    style_page_number!(paragraphstyle);
147    style_punctuation_wrap!(paragraphstyle);
148    style_register_true!(paragraphstyle);
149    style_shadow!(paragraphstyle);
150    style_snap_to_layout_grid!(paragraphstyle);
151    style_tab_stop_distance!(paragraphstyle);
152    style_text_autospace!(paragraphstyle);
153    style_vertical_align_para!(paragraphstyle);
154    style_writing_mode!(paragraphstyle);
155    style_writing_mode_automatic!(paragraphstyle);
156    style_line_number!(paragraphstyle);
157    style_number_lines!(paragraphstyle);
158
159    // TODO: background-image
160    // TODO: drop-cap
161
162    // fo_background_color!(textstyle);
163    fo_color!(textstyle);
164    fo_locale!(textstyle);
165    style_font_name!(textstyle);
166    fo_font_size!(textstyle);
167    fo_font_size_rel!(textstyle);
168    fo_font_style!(textstyle);
169    fo_font_weight!(textstyle);
170    fo_font_variant!(textstyle);
171    fo_font_attr!(textstyle);
172    style_locale_asian!(textstyle);
173    style_font_name_asian!(textstyle);
174    style_font_size_asian!(textstyle);
175    style_font_size_rel_asian!(textstyle);
176    style_font_style_asian!(textstyle);
177    style_font_weight_asian!(textstyle);
178    style_font_attr_asian!(textstyle);
179    style_locale_complex!(textstyle);
180    style_font_name_complex!(textstyle);
181    style_font_size_complex!(textstyle);
182    style_font_size_rel_complex!(textstyle);
183    style_font_style_complex!(textstyle);
184    style_font_weight_complex!(textstyle);
185    style_font_attr_complex!(textstyle);
186    fo_hyphenate!(textstyle);
187    fo_hyphenation_push_char_count!(textstyle);
188    fo_hyphenation_remain_char_count!(textstyle);
189    fo_letter_spacing!(textstyle);
190    fo_text_shadow!(textstyle);
191    fo_text_transform!(textstyle);
192    style_font_relief!(textstyle);
193    style_text_position!(textstyle);
194    // style_rotation_angle!(textstyle);
195    style_rotation_scale!(textstyle);
196    style_letter_kerning!(textstyle);
197    style_text_combine!(textstyle);
198    style_text_combine_start_char!(textstyle);
199    style_text_combine_end_char!(textstyle);
200    style_text_emphasize!(textstyle);
201    style_text_line_through!(textstyle);
202    style_text_outline!(textstyle);
203    style_text_overline!(textstyle);
204    style_text_underline!(textstyle);
205    style_use_window_font_color!(textstyle);
206    text_condition!(textstyle);
207    text_display!(textstyle);
208}