Orcus
styles.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef INCLUDED_ORCUS_SPREADSHEET_STYLES_HPP
9 #define INCLUDED_ORCUS_SPREADSHEET_STYLES_HPP
10 
11 #include "../env.hpp"
12 #include "../measurement.hpp"
13 #include "document_types.hpp"
14 
15 #include <memory>
16 #include <string_view>
17 #include <optional>
18 
19 namespace orcus { namespace spreadsheet {
20 
21 class document;
22 
26 struct ORCUS_SPM_DLLPUBLIC font_t
27 {
28  std::optional<std::string_view> name;
29  std::optional<std::string_view> name_asian;
30  std::optional<std::string_view> name_complex;
31  std::optional<double> size;
32  std::optional<double> size_asian;
33  std::optional<double> size_complex;
34  std::optional<bool> bold;
35  std::optional<bool> bold_asian;
36  std::optional<bool> bold_complex;
37  std::optional<bool> italic;
38  std::optional<bool> italic_asian;
39  std::optional<bool> italic_complex;
40  std::optional<underline_t> underline_style;
41  std::optional<underline_width_t> underline_width;
42  std::optional<underline_mode_t> underline_mode;
43  std::optional<underline_type_t> underline_type;
44  std::optional<color_t> underline_color;
45  std::optional<color_t> color;
46  std::optional<strikethrough_style_t> strikethrough_style;
47  std::optional<strikethrough_width_t> strikethrough_width;
48  std::optional<strikethrough_type_t> strikethrough_type;
49  std::optional<strikethrough_text_t> strikethrough_text;
50 
51  font_t();
52  void reset();
53 };
54 
58 struct ORCUS_SPM_DLLPUBLIC fill_t
59 {
60  std::optional<fill_pattern_t> pattern_type;
61  std::optional<color_t> fg_color;
62  std::optional<color_t> bg_color;
63 
64  fill_t();
65  void reset();
66 };
67 
71 struct ORCUS_SPM_DLLPUBLIC border_attrs_t
72 {
73  std::optional<border_style_t> style;
74  std::optional<color_t> border_color;
75  std::optional<length_t> border_width;
76 
78  void reset();
79 };
80 
84 struct ORCUS_SPM_DLLPUBLIC border_t
85 {
86  border_attrs_t top;
87  border_attrs_t bottom;
88  border_attrs_t left;
89  border_attrs_t right;
90  border_attrs_t diagonal;
91  border_attrs_t diagonal_bl_tr;
92  border_attrs_t diagonal_tl_br;
93 
94  border_t();
95  void reset();
96 };
97 
101 struct ORCUS_SPM_DLLPUBLIC protection_t
102 {
103  std::optional<bool> locked;
104  std::optional<bool> hidden;
105  std::optional<bool> print_content;
106  std::optional<bool> formula_hidden;
107 
108  protection_t();
109  void reset();
110 };
111 
115 struct ORCUS_SPM_DLLPUBLIC number_format_t
116 {
117  std::optional<std::size_t> identifier;
118  std::optional<std::string_view> format_string;
119 
120  number_format_t();
121  void reset();
122 
123  bool operator== (const number_format_t& other) const noexcept;
124  bool operator!= (const number_format_t& other) const noexcept;
125 };
126 
131 struct ORCUS_SPM_DLLPUBLIC cell_format_t
132 {
134  std::size_t font;
136  std::size_t fill;
138  std::size_t border;
140  std::size_t protection;
142  std::size_t number_format;
144  std::size_t style_xf;
146  hor_alignment_t hor_align;
148  ver_alignment_t ver_align;
150  std::optional<bool> wrap_text;
152  std::optional<bool> shrink_to_fit;
153  bool apply_num_format:1;
154  bool apply_font:1;
155  bool apply_fill:1;
156  bool apply_border:1;
157  bool apply_alignment:1;
158  bool apply_protection:1;
159 
160  cell_format_t();
161  void reset();
162 };
163 
170 struct ORCUS_SPM_DLLPUBLIC cell_style_t
171 {
172  std::string_view name;
173  std::string_view display_name;
174  std::size_t xf;
175  std::size_t builtin;
176  std::string_view parent_name;
177 
178  cell_style_t();
179  void reset();
180 };
181 
182 ORCUS_SPM_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const color_t& c);
183 
188 class ORCUS_SPM_DLLPUBLIC styles
189 {
190  friend class document;
191 
192  struct impl;
193  std::unique_ptr<impl> mp_impl;
194 
195 public:
196  styles();
197  ~styles();
198 
199  void reserve_font_store(size_t n);
200  std::size_t append_font(const font_t& font);
201 
202  void reserve_fill_store(size_t n);
203  std::size_t append_fill(const fill_t& fill);
204 
205  void reserve_border_store(size_t n);
206  std::size_t append_border(const border_t& border);
207 
208  std::size_t append_protection(const protection_t& protection);
209 
210  void reserve_number_format_store(size_t n);
211  std::size_t append_number_format(const number_format_t& nf);
212 
213  void reserve_cell_style_format_store(size_t n);
214  size_t append_cell_style_format(const cell_format_t& cf);
215 
216  void reserve_cell_format_store(size_t n);
217  size_t append_cell_format(const cell_format_t& cf);
218 
219  void reserve_diff_cell_format_store(size_t n);
220  size_t append_diff_cell_format(const cell_format_t& cf);
221 
222  void reserve_cell_style_store(size_t n);
223  void append_cell_style(const cell_style_t& cs);
224 
225  const font_t* get_font(size_t index) const;
226  const fill_t* get_fill(size_t index) const;
227  const border_t* get_border(size_t index) const;
228  const protection_t* get_protection(size_t index) const;
229  const number_format_t* get_number_format(size_t index) const;
230  const cell_format_t* get_cell_format(size_t index) const;
231  const cell_format_t* get_cell_style_format(size_t index) const;
232  const cell_format_t* get_dxf_format(size_t index) const;
233  const cell_style_t* get_cell_style(size_t index) const;
234  const cell_style_t* get_cell_style_by_xf(size_t xfid) const;
235 
236  size_t get_font_count() const;
237  size_t get_fill_count() const;
238  size_t get_border_count() const;
239  size_t get_protection_count() const;
240  size_t get_number_format_count() const;
241  size_t get_cell_formats_count() const;
242  size_t get_cell_style_formats_count() const;
243  size_t get_dxf_count() const;
244  size_t get_cell_styles_count() const;
245 
246  void clear();
247 
248 private:
249  void finalize_import();
250 };
251 
252 }}
253 
254 #endif
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: document.hpp:54
Definition: styles.hpp:189
Definition: styles.hpp:72
Definition: styles.hpp:85
Definition: styles.hpp:132
std::size_t fill
Definition: styles.hpp:136
ver_alignment_t ver_align
Definition: styles.hpp:148
std::size_t style_xf
Definition: styles.hpp:144
std::size_t font
Definition: styles.hpp:134
std::size_t border
Definition: styles.hpp:138
hor_alignment_t hor_align
Definition: styles.hpp:146
std::optional< bool > shrink_to_fit
Definition: styles.hpp:152
std::size_t number_format
Definition: styles.hpp:142
std::optional< bool > wrap_text
Definition: styles.hpp:150
std::size_t protection
Definition: styles.hpp:140
Definition: styles.hpp:171
Definition: document_types.hpp:20
Definition: styles.hpp:59
Definition: styles.hpp:27
Definition: styles.hpp:116
Definition: styles.hpp:102