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 
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;
43  color_t color;
44 
45  font_t();
46  void reset();
47 };
48 
49 struct ORCUS_SPM_DLLPUBLIC fill_t
50 {
51  pstring pattern_type;
52  color_t fg_color;
53  color_t bg_color;
54 
55  fill_t();
56  void reset();
57 };
58 
59 struct ORCUS_SPM_DLLPUBLIC border_attrs_t
60 {
61  border_style_t style;
62  color_t border_color;
63 
65  void reset();
66 };
67 
68 struct ORCUS_SPM_DLLPUBLIC border_t
69 {
70  border_attrs_t top;
71  border_attrs_t bottom;
72  border_attrs_t left;
73  border_attrs_t right;
74  border_attrs_t diagonal;
75 
76  border_t();
77  void reset();
78 };
79 
80 struct ORCUS_SPM_DLLPUBLIC protection_t
81 {
82  bool locked;
83  bool hidden;
84 
85  protection_t();
86  void reset();
87 };
88 
89 struct ORCUS_SPM_DLLPUBLIC number_format_t
90 {
91  size_t identifier;
92  pstring format_string;
93 
95  void reset();
96  bool operator== (const number_format_t& r) const;
97 };
98 
102 struct ORCUS_SPM_DLLPUBLIC cell_format_t
103 {
104  size_t font;
105  size_t fill;
106  size_t border;
107  size_t protection;
108  size_t number_format;
109  size_t style_xf;
110  hor_alignment_t hor_align;
111  ver_alignment_t ver_align;
112  bool apply_num_format:1;
113  bool apply_font:1;
114  bool apply_fill:1;
115  bool apply_border:1;
116  bool apply_alignment:1;
117 
118  cell_format_t();
119  void reset();
120 };
121 
122 struct ORCUS_SPM_DLLPUBLIC cell_style_t
123 {
124  pstring name;
125  size_t xf;
126  size_t builtin;
127  pstring parent_name;
128 
129  cell_style_t();
130  void reset();
131 };
132 
133 class ORCUS_SPM_DLLPUBLIC import_styles : public iface::import_styles
134 {
135 public:
136 
138  virtual ~import_styles();
139 
140  virtual void set_font_count(size_t n);
141  virtual void set_font_bold(bool b);
142  virtual void set_font_italic(bool b);
143  virtual void set_font_name(const char* s, size_t n);
144  virtual void set_font_size(double point);
145  virtual void set_font_underline(underline_t e);
146  virtual void set_font_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
147  virtual size_t commit_font();
148 
149  virtual void set_fill_count(size_t n);
150  virtual void set_fill_pattern_type(const char* s, size_t n);
151  virtual void set_fill_fg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
152  virtual void set_fill_bg_color(color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
153  virtual size_t commit_fill();
154 
155  virtual void set_border_count(size_t n);
156  virtual void set_border_style(border_direction_t dir, const char* s, size_t n);
157  virtual void set_border_style(border_direction_t dir, border_style_t style);
158  virtual void set_border_color(
159  border_direction_t dir, color_elem_t alpha, color_elem_t red, color_elem_t green, color_elem_t blue);
160  virtual size_t commit_border();
161 
162  virtual void set_cell_hidden(bool b);
163  virtual void set_cell_locked(bool b);
164  virtual size_t commit_cell_protection();
165 
166  virtual void set_number_format_count(size_t n);
167  virtual void set_number_format_identifier(size_t id);
168  virtual void set_number_format_code(const char* s, size_t n);
169  virtual size_t commit_number_format();
170 
171  virtual void set_cell_style_xf_count(size_t n);
172  virtual size_t commit_cell_style_xf();
173 
174  virtual void set_cell_xf_count(size_t n);
175  virtual size_t commit_cell_xf();
176 
177  virtual void set_dxf_count(size_t n);
178  virtual size_t commit_dxf();
179 
180  virtual void set_xf_font(size_t index);
181  virtual void set_xf_fill(size_t index);
182  virtual void set_xf_border(size_t index);
183  virtual void set_xf_protection(size_t index);
184  virtual void set_xf_number_format(size_t index);
185  virtual void set_xf_style_xf(size_t index);
186  virtual void set_xf_apply_alignment(bool b);
187  virtual void set_xf_horizontal_alignment(orcus::spreadsheet::hor_alignment_t align);
188  virtual void set_xf_vertical_alignment(orcus::spreadsheet::ver_alignment_t align);
189 
190  virtual void set_cell_style_count(size_t n);
191  virtual void set_cell_style_name(const char* s, size_t n);
192  virtual void set_cell_style_xf(size_t index);
193  virtual void set_cell_style_builtin(size_t index);
194  virtual void set_cell_style_parent_name(const char* s, size_t n);
195  virtual size_t commit_cell_style();
196 
197  const font_t* get_font(size_t index) const;
198  const fill_t* get_fill(size_t index) const;
199  const border_t* get_border(size_t index) const;
200  const protection_t* get_protection(size_t index) const;
201  const number_format_t* get_number_format(size_t index) const;
202  const cell_format_t* get_cell_format(size_t index) const;
203  const cell_format_t* get_cell_style_format(size_t index) const;
204  const cell_format_t* get_dxf_format(size_t index) const;
205  const cell_style_t* get_cell_style(size_t index) const;
206 
207  size_t get_font_count() const;
208  size_t get_fill_count() const;
209  size_t get_border_count() const;
210  size_t get_protection_count() const;
211  size_t get_number_format_count() const;
212  size_t get_cell_formats_count() const;
213  size_t get_cell_style_formats_count() const;
214  size_t get_dxf_count() const;
215  size_t get_cell_styles_count() const;
216 
217 private:
218  string_pool& m_string_pool;
219 
220  font_t m_cur_font;
221  fill_t m_cur_fill;
222  border_t m_cur_border;
223  protection_t m_cur_protection;
224  number_format_t m_cur_number_format;
225  cell_format_t m_cur_cell_format;
226  cell_style_t m_cur_cell_style;
227 
228  ::std::vector<font_t> m_fonts;
229  ::std::vector<fill_t> m_fills;
230  ::std::vector<border_t> m_borders;
231  ::std::vector<protection_t> m_protections;
232  ::std::vector<number_format_t> m_number_formats;
233  ::std::vector<cell_format_t> m_cell_style_formats;
234  ::std::vector<cell_format_t> m_cell_formats;
235  ::std::vector<cell_format_t> m_dxf_formats;
236  ::std::vector<cell_style_t> m_cell_styles;
237 };
238 
239 }}
240 
241 #endif
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
hor_alignment_t hor_align
style XF ID (used only for cell format)
Definition: styles.hpp:110
Definition: styles.hpp:36
size_t protection
border ID
Definition: styles.hpp:107
Definition: styles.hpp:68
Definition: pstring.hpp:24
Definition: import_interface.hpp:80
Definition: styles.hpp:59
Definition: styles.hpp:89
size_t number_format
protection ID
Definition: styles.hpp:108
size_t fill
font ID
Definition: styles.hpp:105
Definition: styles.hpp:80
Definition: styles.hpp:23
size_t border
fill ID
Definition: styles.hpp:106
Definition: styles.hpp:122
Definition: styles.hpp:133
Definition: string_pool.hpp:22
Definition: styles.hpp:49
Definition: base64.hpp:15
size_t style_xf
number format ID
Definition: styles.hpp:109
Definition: styles.hpp:102