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 "types.hpp"
14 
15 #include <memory>
16 #include <string_view>
17 
18 namespace orcus { namespace spreadsheet {
19 
20 struct ORCUS_SPM_DLLPUBLIC color_t
21 {
22  color_elem_t alpha;
23  color_elem_t red;
24  color_elem_t green;
25  color_elem_t blue;
26 
27  color_t();
28  color_t(color_elem_t _red, color_elem_t _green, color_elem_t _blue);
29  color_t(color_elem_t _alpha, color_elem_t _red, color_elem_t _green, color_elem_t _blue);
30 
31  void reset();
32 
33  bool operator==(const color_t& other) const;
34  bool operator!=(const color_t& other) const;
35 };
36 
37 struct ORCUS_SPM_DLLPUBLIC font_t
38 {
39  std::string_view name;
40  double size;
41  bool bold:1;
42  bool italic:1;
43  underline_t underline_style;
44  underline_width_t underline_width;
45  underline_mode_t underline_mode;
46  underline_type_t underline_type;
47  color_t underline_color;
48  color_t color;
49  strikethrough_style_t strikethrough_style;
50  strikethrough_width_t strikethrough_width;
51  strikethrough_type_t strikethrough_type;
52  strikethrough_text_t strikethrough_text;
53 
54  font_t();
55  void reset();
56 };
57 
61 struct ORCUS_SPM_DLLPUBLIC font_active_t
62 {
63  bool name = false;
64  bool size = false;
65  bool bold = false;
66  bool italic = false;
67  bool underline_style = false;
68  bool underline_width = false;
69  bool underline_mode = false;
70  bool underline_type = false;
71  bool underline_color = false;
72  bool color = false;
73  bool strikethrough_style = false;
74  bool strikethrough_width = false;
75  bool strikethrough_type = false;
76  bool strikethrough_text = false;
77 
78  void set() noexcept;
79  void reset();
80 
81  bool operator== (const font_active_t& other) const noexcept;
82  bool operator!= (const font_active_t& other) const noexcept;
83 };
84 
85 struct ORCUS_SPM_DLLPUBLIC fill_t
86 {
87  fill_pattern_t pattern_type;
88  color_t fg_color;
89  color_t bg_color;
90 
91  fill_t();
92  void reset();
93 };
94 
98 struct ORCUS_SPM_DLLPUBLIC fill_active_t
99 {
100  bool pattern_type = false;
101  bool fg_color = false;
102  bool bg_color = false;
103 
104  void set() noexcept;
105  void reset();
106 
107  bool operator== (const fill_active_t& other) const noexcept;
108  bool operator!= (const fill_active_t& other) const noexcept;
109 };
110 
111 struct ORCUS_SPM_DLLPUBLIC border_attrs_t
112 {
113  border_style_t style;
114  color_t border_color;
115  length_t border_width;
116 
117  border_attrs_t();
118  void reset();
119 };
120 
124 struct ORCUS_SPM_DLLPUBLIC border_attrs_active_t
125 {
126  bool style = false;
127  bool border_color = false;
128  bool border_width = false;
129 
130  void set() noexcept;
131  void reset();
132 
133  bool operator== (const border_attrs_active_t& other) const noexcept;
134  bool operator!= (const border_attrs_active_t& other) const noexcept;
135 };
136 
137 struct ORCUS_SPM_DLLPUBLIC border_t
138 {
139  border_attrs_t top;
140  border_attrs_t bottom;
141  border_attrs_t left;
142  border_attrs_t right;
143  border_attrs_t diagonal;
144  border_attrs_t diagonal_bl_tr;
145  border_attrs_t diagonal_tl_br;
146 
147  border_t();
148  void reset();
149 };
150 
154 struct ORCUS_SPM_DLLPUBLIC border_active_t
155 {
157  border_attrs_active_t bottom;
159  border_attrs_active_t right;
160  border_attrs_active_t diagonal;
161  border_attrs_active_t diagonal_bl_tr;
162  border_attrs_active_t diagonal_tl_br;
163 
164  void set() noexcept;
165  void reset();
166 
167  bool operator== (const border_active_t& other) const noexcept;
168  bool operator!= (const border_active_t& other) const noexcept;
169 };
170 
171 struct ORCUS_SPM_DLLPUBLIC protection_t
172 {
173  bool locked;
174  bool hidden;
175  bool print_content;
176  bool formula_hidden;
177 
178  protection_t();
179  void reset();
180 };
181 
185 struct ORCUS_SPM_DLLPUBLIC protection_active_t
186 {
187  bool locked = false;
188  bool hidden = false;
189  bool print_content = false;
190  bool formula_hidden = false;
191 
192  void set() noexcept;
193  void reset();
194 
195  bool operator== (const protection_active_t& other) const noexcept;
196  bool operator!= (const protection_active_t& other) const noexcept;
197 };
198 
199 struct ORCUS_SPM_DLLPUBLIC number_format_t
200 {
201  size_t identifier;
202  std::string_view format_string;
203 
204  number_format_t();
205  void reset();
206 
207  bool operator== (const number_format_t& other) const; // TODO:API: noexcept
208  bool operator!= (const number_format_t& other) const; // TODO:API: noexcept
209 };
210 
214 struct ORCUS_SPM_DLLPUBLIC number_format_active_t
215 {
216  bool identifier = false;
217  bool format_string = false;
218 
219  void set() noexcept;
220  void reset();
221 
222  bool operator== (const number_format_active_t& other) const noexcept;
223  bool operator!= (const number_format_active_t& other) const noexcept;
224 };
225 
229 struct ORCUS_SPM_DLLPUBLIC cell_format_t
230 {
231  size_t font;
232  size_t fill;
233  size_t border;
234  size_t protection;
235  size_t number_format;
236  size_t style_xf;
237  hor_alignment_t hor_align;
238  ver_alignment_t ver_align;
239  bool apply_num_format:1;
240  bool apply_font:1;
241  bool apply_fill:1;
242  bool apply_border:1;
243  bool apply_alignment:1;
244  bool apply_protection:1;
245 
246  cell_format_t();
247  void reset();
248 };
249 
250 struct ORCUS_SPM_DLLPUBLIC cell_style_t
251 {
252  std::string_view name;
253  size_t xf;
254  size_t builtin;
255  std::string_view parent_name;
256 
257  cell_style_t();
258  void reset();
259 };
260 
261 namespace detail {
262 
263 template<typename T>
265 
266 template<> struct to_active_type<font_t> { using type = font_active_t; };
267 template<> struct to_active_type<fill_t> { using type = fill_active_t; };
268 template<> struct to_active_type<border_t> { using type = border_active_t; };
269 template<> struct to_active_type<protection_t> { using type = protection_active_t; };
271 
272 } // namespace detail
273 
274 template<typename T>
275 using style_attrs_t = std::pair<T, typename detail::to_active_type<T>::type>;
276 
277 ORCUS_SPM_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const color_t& c);
278 
279 class ORCUS_SPM_DLLPUBLIC styles
280 {
281  struct impl;
282  std::unique_ptr<impl> mp_impl;
283 
284 public:
285  styles();
286  ~styles();
287 
288  void reserve_font_store(size_t n);
289  size_t append_font(const font_t& font);
290  size_t append_font(const font_t& value, const font_active_t& active);
291 
292  void reserve_fill_store(size_t n);
293  size_t append_fill(const fill_t& fill);
294  size_t append_fill(const fill_t& value, const fill_active_t& active);
295 
296  void reserve_border_store(size_t n);
297  size_t append_border(const border_t& border);
298  size_t append_border(const border_t& value, const border_active_t& active);
299 
300  size_t append_protection(const protection_t& protection);
301  size_t append_protection(const protection_t& value, const protection_active_t& active);
302 
303  void reserve_number_format_store(size_t n);
304  size_t append_number_format(const number_format_t& nf);
305  size_t append_number_format(const number_format_t& value, const number_format_active_t& active);
306 
307  void reserve_cell_style_format_store(size_t n);
308  size_t append_cell_style_format(const cell_format_t& cf);
309 
310  void reserve_cell_format_store(size_t n);
311  size_t append_cell_format(const cell_format_t& cf);
312 
313  void reserve_diff_cell_format_store(size_t n);
314  size_t append_diff_cell_format(const cell_format_t& cf);
315 
316  void reserve_cell_style_store(size_t n);
317  size_t append_cell_style(const cell_style_t& cs);
318 
319  const font_t* get_font(size_t index) const;
320  const style_attrs_t<font_t>* get_font_state(size_t index) const;
321 
322  const fill_t* get_fill(size_t index) const;
323  const style_attrs_t<fill_t>* get_fill_state(size_t index) const;
324 
325  const border_t* get_border(size_t index) const;
326  const style_attrs_t<border_t>* get_border_state(size_t index) const;
327 
328  const protection_t* get_protection(size_t index) const;
329  const style_attrs_t<protection_t>* get_protection_state(size_t index) const;
330 
331  const number_format_t* get_number_format(size_t index) const;
332  const style_attrs_t<number_format_t>* get_number_format_state(size_t index) const;
333 
334  const cell_format_t* get_cell_format(size_t index) const;
335  const cell_format_t* get_cell_style_format(size_t index) const;
336  const cell_format_t* get_dxf_format(size_t index) const;
337  const cell_style_t* get_cell_style(size_t index) const;
338 
339  size_t get_font_count() const;
340  size_t get_fill_count() const;
341  size_t get_border_count() const;
342  size_t get_protection_count() const;
343  size_t get_number_format_count() const;
344  size_t get_cell_formats_count() const;
345  size_t get_cell_style_formats_count() const;
346  size_t get_dxf_count() const;
347  size_t get_cell_styles_count() const;
348 
349  void clear();
350 };
351 
352 }}
353 
354 #endif
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: styles.hpp:280
Definition: types.hpp:447
Definition: styles.hpp:155
Definition: styles.hpp:112
Definition: styles.hpp:138
Definition: styles.hpp:230
size_t fill
font ID
Definition: styles.hpp:232
size_t protection
border ID
Definition: styles.hpp:234
size_t border
fill ID
Definition: styles.hpp:233
hor_alignment_t hor_align
style XF ID (used only for cell format)
Definition: styles.hpp:237
size_t number_format
protection ID
Definition: styles.hpp:235
size_t style_xf
number format ID
Definition: styles.hpp:236
Definition: styles.hpp:251
Definition: styles.hpp:21
Definition: styles.hpp:99
Definition: styles.hpp:86
Definition: styles.hpp:62
Definition: styles.hpp:38
Definition: styles.hpp:200
Definition: styles.hpp:186
Definition: styles.hpp:172