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 "orcus/pstring.hpp"
12 #include "orcus/env.hpp"
13 #include "orcus/measurement.hpp"
14 #include "orcus/spreadsheet/types.hpp"
15 
16 #include <memory>
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 _alpha, color_elem_t _red, color_elem_t _green, color_elem_t _blue);
29 
30  void reset();
31 
32  bool operator==(const color_t& other) const;
33  bool operator!=(const color_t& other) const;
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  fill_pattern_t 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 ORCUS_SPM_DLLPUBLIC std::ostream& operator<< (std::ostream& os, const color_t& c);
148 
149 class ORCUS_SPM_DLLPUBLIC styles
150 {
151  struct impl;
152  std::unique_ptr<impl> mp_impl;
153 
154 public:
155  styles();
156  ~styles();
157 
158  void reserve_font_store(size_t n);
159  size_t append_font(const font_t& font);
160 
161  void reserve_fill_store(size_t n);
162  size_t append_fill(const fill_t& fill);
163 
164  void reserve_border_store(size_t n);
165  size_t append_border(const border_t& border);
166 
167  size_t append_protection(const protection_t& protection);
168 
169  void reserve_number_format_store(size_t n);
170  size_t append_number_format(const number_format_t& nf);
171 
172  void reserve_cell_style_format_store(size_t n);
173  size_t append_cell_style_format(const cell_format_t& cf);
174 
175  void reserve_cell_format_store(size_t n);
176  size_t append_cell_format(const cell_format_t& cf);
177 
178  void reserve_diff_cell_format_store(size_t n);
179  size_t append_diff_cell_format(const cell_format_t& cf);
180 
181  void reserve_cell_style_store(size_t n);
182  size_t append_cell_style(const cell_style_t& cs);
183 
184  const font_t* get_font(size_t index) const;
185  const fill_t* get_fill(size_t index) const;
186  const border_t* get_border(size_t index) const;
187  const protection_t* get_protection(size_t index) const;
188  const number_format_t* get_number_format(size_t index) const;
189  const cell_format_t* get_cell_format(size_t index) const;
190  const cell_format_t* get_cell_style_format(size_t index) const;
191  const cell_format_t* get_dxf_format(size_t index) const;
192  const cell_style_t* get_cell_style(size_t index) const;
193 
194  size_t get_font_count() const;
195  size_t get_fill_count() const;
196  size_t get_border_count() const;
197  size_t get_protection_count() const;
198  size_t get_number_format_count() const;
199  size_t get_cell_formats_count() const;
200  size_t get_cell_style_formats_count() const;
201  size_t get_dxf_count() const;
202  size_t get_cell_styles_count() const;
203 };
204 
205 }}
206 
207 #endif
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::spreadsheet::font_t
Definition: styles.hpp:37
orcus::spreadsheet::styles
Definition: styles.hpp:150
orcus::spreadsheet::border_t
Definition: styles.hpp:78
orcus::spreadsheet::cell_format_t
Definition: styles.hpp:116
orcus::spreadsheet::border_attrs_t
Definition: styles.hpp:68
orcus::spreadsheet::color_t
Definition: styles.hpp:21
orcus::spreadsheet::cell_format_t::style_xf
size_t style_xf
number format ID
Definition: styles.hpp:122
orcus::spreadsheet::cell_format_t::protection
size_t protection
border ID
Definition: styles.hpp:120
orcus::pstring
Definition: pstring.hpp:28
orcus::spreadsheet::cell_format_t::hor_align
hor_alignment_t hor_align
style XF ID (used only for cell format)
Definition: styles.hpp:123
orcus::spreadsheet::protection_t
Definition: styles.hpp:92
orcus::spreadsheet::cell_style_t
Definition: styles.hpp:137
orcus::spreadsheet::fill_t
Definition: styles.hpp:58
orcus::length_t
Definition: types.hpp:410
orcus::spreadsheet::cell_format_t::number_format
size_t number_format
protection ID
Definition: styles.hpp:121
orcus::spreadsheet::cell_format_t::fill
size_t fill
font ID
Definition: styles.hpp:118
orcus::spreadsheet::cell_format_t::border
size_t border
fill ID
Definition: styles.hpp:119
orcus::spreadsheet::number_format_t
Definition: styles.hpp:103