Orcus
Loading...
Searching...
No Matches
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
19namespace orcus { namespace spreadsheet {
20
21class document;
22
26struct 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 font_t(const font_t& other);
53 ~font_t();
54
55 font_t& operator=(const font_t& other);
56
57 bool operator==(const font_t& other) const;
58 bool operator!=(const font_t& other) const;
59
60 void reset();
61
62 struct ORCUS_SPM_DLLPUBLIC hash
63 {
64 std::size_t operator()(const font_t& v) const;
65 };
66};
67
71struct ORCUS_SPM_DLLPUBLIC fill_t
72{
73 std::optional<fill_pattern_t> pattern_type;
74 std::optional<color_t> fg_color;
75 std::optional<color_t> bg_color;
76
77 fill_t();
78 void reset();
79};
80
84struct ORCUS_SPM_DLLPUBLIC border_attrs_t
85{
86 std::optional<border_style_t> style;
87 std::optional<color_t> border_color;
88 std::optional<length_t> border_width;
89
90 border_attrs_t();
91 void reset();
92};
93
97struct ORCUS_SPM_DLLPUBLIC border_t
98{
100 border_attrs_t bottom;
101 border_attrs_t left;
102 border_attrs_t right;
103 border_attrs_t diagonal;
104 border_attrs_t diagonal_bl_tr;
105 border_attrs_t diagonal_tl_br;
106
107 border_t();
108 void reset();
109};
110
114struct ORCUS_SPM_DLLPUBLIC protection_t
115{
116 std::optional<bool> locked;
117 std::optional<bool> hidden;
118 std::optional<bool> print_content;
119 std::optional<bool> formula_hidden;
120
121 protection_t();
122 void reset();
123};
124
128struct ORCUS_SPM_DLLPUBLIC number_format_t
129{
130 std::optional<std::size_t> identifier;
131 std::optional<std::string_view> format_string;
132
133 number_format_t();
134 void reset();
135
136 bool operator== (const number_format_t& other) const noexcept;
137 bool operator!= (const number_format_t& other) const noexcept;
138};
139
144struct ORCUS_SPM_DLLPUBLIC cell_format_t
145{
147 std::size_t font;
149 std::size_t fill;
151 std::size_t border;
153 std::size_t protection;
155 std::size_t number_format;
157 std::size_t style_xf;
159 hor_alignment_t hor_align;
161 ver_alignment_t ver_align;
163 std::optional<bool> wrap_text;
165 std::optional<bool> shrink_to_fit;
166 bool apply_num_format:1;
167 bool apply_font:1;
168 bool apply_fill:1;
169 bool apply_border:1;
170 bool apply_alignment:1;
171 bool apply_protection:1;
172
173 cell_format_t();
174 void reset();
175};
176
183struct ORCUS_SPM_DLLPUBLIC cell_style_t
184{
185 std::string_view name;
186 std::string_view display_name;
187 std::size_t xf;
188 std::size_t builtin;
189 std::string_view parent_name;
190
191 cell_style_t();
192 void reset();
193};
194
195ORCUS_SPM_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const color_t& c);
196
201class ORCUS_SPM_DLLPUBLIC styles
202{
203 friend class document;
204
205 struct impl;
206 std::unique_ptr<impl> mp_impl;
207
208public:
209 styles();
210 ~styles();
211
212 void reserve_font_store(size_t n);
213 std::size_t append_font(const font_t& font);
214
215 void reserve_fill_store(size_t n);
216 std::size_t append_fill(const fill_t& fill);
217
218 void reserve_border_store(size_t n);
219 std::size_t append_border(const border_t& border);
220
221 std::size_t append_protection(const protection_t& protection);
222
223 void reserve_number_format_store(size_t n);
224 std::size_t append_number_format(const number_format_t& nf);
225
226 void reserve_cell_style_format_store(size_t n);
227 size_t append_cell_style_format(const cell_format_t& cf);
228
229 void reserve_cell_format_store(size_t n);
230 size_t append_cell_format(const cell_format_t& cf);
231
232 void reserve_diff_cell_format_store(size_t n);
233 size_t append_diff_cell_format(const cell_format_t& cf);
234
235 void reserve_cell_style_store(size_t n);
236 void append_cell_style(const cell_style_t& cs);
237
238 const font_t* get_font(size_t index) const;
239 const fill_t* get_fill(size_t index) const;
240 const border_t* get_border(size_t index) const;
241 const protection_t* get_protection(size_t index) const;
242 const number_format_t* get_number_format(size_t index) const;
243 const cell_format_t* get_cell_format(size_t index) const;
244 const cell_format_t* get_cell_style_format(size_t index) const;
245 const cell_format_t* get_dxf_format(size_t index) const;
246 const cell_style_t* get_cell_style(size_t index) const;
247 const cell_style_t* get_cell_style_by_xf(size_t xfid) const;
248
249 size_t get_font_count() const;
250 size_t get_fill_count() const;
251 size_t get_border_count() const;
252 size_t get_protection_count() const;
253 size_t get_number_format_count() const;
254 size_t get_cell_formats_count() const;
255 size_t get_cell_style_formats_count() const;
256 size_t get_dxf_count() const;
257 size_t get_cell_styles_count() const;
258
259 void clear();
260
261private:
262 void finalize_import();
263};
264
265}}
266
267#endif
268/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition document.hpp:54
Definition styles.hpp:85
Definition styles.hpp:98
Definition styles.hpp:145
std::size_t fill
Definition styles.hpp:149
ver_alignment_t ver_align
Definition styles.hpp:161
std::size_t style_xf
Definition styles.hpp:157
std::size_t font
Definition styles.hpp:147
std::size_t border
Definition styles.hpp:151
hor_alignment_t hor_align
Definition styles.hpp:159
std::optional< bool > shrink_to_fit
Definition styles.hpp:165
std::size_t number_format
Definition styles.hpp:155
std::optional< bool > wrap_text
Definition styles.hpp:163
std::size_t protection
Definition styles.hpp:153
Definition styles.hpp:184
Definition document_types.hpp:20
Definition styles.hpp:72
Definition styles.hpp:63
Definition styles.hpp:27
Definition styles.hpp:129
Definition styles.hpp:115