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 __ORCUS_SPREADSHEET_STYLES_HPP__
9 #define __ORCUS_SPREADSHEET_STYLES_HPP__
10 
11 #include "orcus/spreadsheet/import_interface.hpp"
12 #include "orcus/pstring.hpp"
13 #include "orcus/env.hpp"
14 #include <orcus/measurement.hpp>
15 #include <vector>
16 
17 namespace orcus {
18 
19 class string_pool;
20 
21 namespace spreadsheet {
22 
23 struct ORCUS_SPM_DLLPUBLIC color_t
24 {
25  color_elem_t alpha;
26  color_elem_t red;
27  color_elem_t green;
28  color_elem_t blue;
29 
30  color_t();
31  color_t(color_elem_t _alpha, color_elem_t _red, color_elem_t _green, color_elem_t _blue);
32 
33  void reset();
34 };
35 
36 struct ORCUS_SPM_DLLPUBLIC font_t
37 {
38  pstring name;
39  double size;
40  bool bold:1;
41  bool italic:1;
42  underline_t underline_style;
43  underline_width_t underline_width;
44  underline_mode_t underline_mode;
45  underline_type_t underline_type;
46  color_t underline_color;
47  color_t color;
48  strikethrough_style_t strikethrough_style;
49  strikethrough_width_t strikethrough_width;
50  strikethrough_type_t strikethrough_type;
51  strikethrough_text_t strikethrough_text;
52 
53  font_t();
54  void reset();
55 };
56 
57 struct ORCUS_SPM_DLLPUBLIC fill_t
58 {
59  pstring pattern_type;
60  color_t fg_color;
61  color_t bg_color;
62 
63  fill_t();
64  void reset();
65 };
66 
67 struct ORCUS_SPM_DLLPUBLIC border_attrs_t
68 {
69  border_style_t style;
70  color_t border_color;
71  length_t border_width;
72 
74  void reset();
75 };
76 
77 struct ORCUS_SPM_DLLPUBLIC border_t
78 {
79  border_attrs_t top;
80  border_attrs_t bottom;
81  border_attrs_t left;
82  border_attrs_t right;
83  border_attrs_t diagonal;
84  border_attrs_t diagonal_bl_tr;
85  border_attrs_t diagonal_tl_br;
86 
87  border_t();
88  void reset();
89 };
90 
91 struct ORCUS_SPM_DLLPUBLIC protection_t
92 {
93  bool locked;
94  bool hidden;
95  bool print_content;
96  bool formula_hidden;
97 
98  protection_t();
99  void reset();
100 };
101 
102 struct ORCUS_SPM_DLLPUBLIC number_format_t
103 {
104  size_t identifier;
105  pstring format_string;
106 
107  number_format_t();
108  void reset();
109  bool operator== (const number_format_t& r) const;
110 };
111 
115 struct ORCUS_SPM_DLLPUBLIC cell_format_t
116 {
117  size_t font;
118  size_t fill;
119  size_t border;
120  size_t protection;
121  size_t number_format;
122  size_t style_xf;
123  hor_alignment_t hor_align;
124  ver_alignment_t ver_align;
125  bool apply_num_format:1;
126  bool apply_font:1;
127  bool apply_fill:1;
128  bool apply_border:1;
129  bool apply_alignment:1;
130  bool apply_protection:1;
131 
132  cell_format_t();
133  void reset();
134 };
135 
136 struct ORCUS_SPM_DLLPUBLIC cell_style_t
137 {
138  pstring name;
139  size_t xf;
140  size_t builtin;
141  pstring parent_name;
142 
143  cell_style_t();
144  void reset();
145 };
146 
147 class ORCUS_SPM_DLLPUBLIC import_styles : public iface::import_styles
148 {
149 public:
150 
152  virtual ~import_styles();
153 
154  virtual void set_font_count(size_t n);
155  virtual void set_font_bold(bool b);
156  virtual void set_font_italic(bool b);
157  virtual void set_font_name(const char* s, size_t n);
158  virtual void set_font_size(double point);
159  virtual void set_font_underline(underline_t e);
160  virtual void set_font_underline_width(underline_width_t e);
161  virtual void set_font_underline_mode(underline_mode_t e);
162  virtual void set_font_underline_type(underline_type_t e);
163  virtual void set_font_underline_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
164  virtual void set_font_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
165  virtual void set_strikethrough_style(strikethrough_style_t s);
166  virtual void set_strikethrough_type(strikethrough_type_t s);
167  virtual void set_strikethrough_width(strikethrough_width_t s);
168  virtual void set_strikethrough_text(strikethrough_text_t s);
169  virtual size_t commit_font();
170 
171  virtual void set_fill_count(size_t n);
172  virtual void set_fill_pattern_type(const char* s, size_t n);
173  virtual void set_fill_fg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
174  virtual void set_fill_bg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
175  virtual size_t commit_fill();
176 
177  virtual void set_border_count(size_t n);
178  virtual void set_border_style(border_direction_t dir, const char* s, size_t n);
179  virtual void set_border_style(border_direction_t dir, border_style_t style);
180  virtual void set_border_color(
181  border_direction_t dir, color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
182  virtual void set_border_width(border_direction_t dir, double width, orcus::length_unit_t unit);
183  virtual size_t commit_border();
184 
185  virtual void set_cell_hidden(bool b);
186  virtual void set_cell_locked(bool b);
187  virtual void set_cell_print_content(bool b);
188  virtual void set_cell_formula_hidden(bool b);
189  virtual size_t commit_cell_protection();
190 
191  virtual void set_number_format_count(size_t n);
192  virtual void set_number_format_identifier(size_t id);
193  virtual void set_number_format_code(const char* s, size_t n);
194  virtual size_t commit_number_format();
195 
196  virtual void set_cell_style_xf_count(size_t n);
197  virtual size_t commit_cell_style_xf();
198 
199  virtual void set_cell_xf_count(size_t n);
200  virtual size_t commit_cell_xf();
201 
202  virtual void set_dxf_count(size_t n);
203  virtual size_t commit_dxf();
204 
205  virtual void set_xf_font(size_t index);
206  virtual void set_xf_fill(size_t index);
207  virtual void set_xf_border(size_t index);
208  virtual void set_xf_protection(size_t index);
209  virtual void set_xf_number_format(size_t index);
210  virtual void set_xf_style_xf(size_t index);
211  virtual void set_xf_apply_alignment(bool b);
212  virtual void set_xf_horizontal_alignment(orcus::spreadsheet::hor_alignment_t align);
213  virtual void set_xf_vertical_alignment(orcus::spreadsheet::ver_alignment_t align);
214 
215  virtual void set_cell_style_count(size_t n);
216  virtual void set_cell_style_name(const char* s, size_t n);
217  virtual void set_cell_style_xf(size_t index);
218  virtual void set_cell_style_builtin(size_t index);
219  virtual void set_cell_style_parent_name(const char* s, size_t n);
220  virtual size_t commit_cell_style();
221 
222  const font_t* get_font(size_t index) const;
223  const fill_t* get_fill(size_t index) const;
224  const border_t* get_border(size_t index) const;
225  const protection_t* get_protection(size_t index) const;
226  const number_format_t* get_number_format(size_t index) const;
227  const cell_format_t* get_cell_format(size_t index) const;
228  const cell_format_t* get_cell_style_format(size_t index) const;
229  const cell_format_t* get_dxf_format(size_t index) const;
230  const cell_style_t* get_cell_style(size_t index) const;
231 
232  size_t get_font_count() const;
233  size_t get_fill_count() const;
234  size_t get_border_count() const;
235  size_t get_protection_count() const;
236  size_t get_number_format_count() const;
237  size_t get_cell_formats_count() const;
238  size_t get_cell_style_formats_count() const;
239  size_t get_dxf_count() const;
240  size_t get_cell_styles_count() const;
241 
242 private:
243  string_pool& m_string_pool;
244 
245  font_t m_cur_font;
246  fill_t m_cur_fill;
247  border_t m_cur_border;
248  protection_t m_cur_protection;
249  number_format_t m_cur_number_format;
250  cell_format_t m_cur_cell_format;
251  cell_style_t m_cur_cell_style;
252 
253  ::std::vector<font_t> m_fonts;
254  ::std::vector<fill_t> m_fills;
255  ::std::vector<border_t> m_borders;
256  ::std::vector<protection_t> m_protections;
257  ::std::vector<number_format_t> m_number_formats;
258  ::std::vector<cell_format_t> m_cell_style_formats;
259  ::std::vector<cell_format_t> m_cell_formats;
260  ::std::vector<cell_format_t> m_dxf_formats;
261  ::std::vector<cell_style_t> m_cell_styles;
262 };
263 
264 }}
265 
266 #endif
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
hor_alignment_t hor_align
style XF ID (used only for cell format)
Definition: styles.hpp:123
Definition: styles.hpp:36
size_t protection
border ID
Definition: styles.hpp:120
Definition: styles.hpp:77
Definition: pstring.hpp:24
Definition: import_interface.hpp:80
Definition: styles.hpp:67
Definition: styles.hpp:102
size_t number_format
protection ID
Definition: styles.hpp:121
size_t fill
font ID
Definition: styles.hpp:118
Definition: styles.hpp:91
Definition: styles.hpp:23
size_t border
fill ID
Definition: styles.hpp:119
Definition: styles.hpp:136
Definition: types.hpp:97
Definition: styles.hpp:147
Definition: string_pool.hpp:22
Definition: styles.hpp:57
Definition: base64.hpp:15
size_t style_xf
number format ID
Definition: styles.hpp:122
Definition: styles.hpp:115