xlnt
font.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 // Copyright (c) 2024 xlnt-community
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE
22 //
23 // @license: http://www.opensource.org/licenses/mit-license.php
24 // @author: see AUTHORS file
25 
26 #pragma once
27 
28 #include <string>
29 
30 #include <xlnt/xlnt_config.hpp>
31 #include <xlnt/styles/color.hpp>
32 #include <xlnt/utils/optional.hpp>
33 
34 namespace xlnt {
35 
36 class style;
37 
41 class XLNT_API font
42 {
43 public:
47  enum class underline_style
48  {
49  none,
50  double_,
51  double_accounting,
52  single,
53  single_accounting
54  };
55 
59  font();
60 
64  font &bold(bool bold);
65 
69  bool bold() const;
70 
74  font &subscript(bool value);
75 
79  bool subscript() const;
80 
84  font &superscript(bool value);
85 
89  bool superscript() const;
90 
94  font &italic(bool italic);
95 
99  bool italic() const;
100 
104  font &strikethrough(bool strikethrough);
105 
109  bool strikethrough() const;
110 
114  font &outline(bool outline);
115 
119  bool outline() const;
120 
124  font &shadow(bool shadow);
125 
129  bool shadow() const;
130 
134  font &underline(underline_style new_underline);
135 
139  bool underlined() const;
140 
144  underline_style underline() const;
145 
149  bool has_size() const;
150 
154  font &size(double size);
155 
159  double size() const;
160 
164  bool has_name() const;
165 
169  font &name(const std::string &name);
170 
174  const std::string &name() const;
175 
179  bool has_color() const;
180 
184  font &color(const color &c);
185 
189  xlnt::color color() const;
190 
194  bool has_family() const;
195 
199  font &family(std::size_t family);
200 
204  std::size_t family() const;
205 
209  bool has_charset() const;
210 
211  // TODO: charset should be an enum, not a number
212 
216  font &charset(std::size_t charset);
217 
221  std::size_t charset() const;
222 
226  bool has_scheme() const;
227 
231  font &scheme(const std::string &scheme);
232 
236  const std::string &scheme() const;
237 
241  bool operator==(const font &other) const;
242 
246  bool operator!=(const font &other) const
247  {
248  return !operator==(other);
249  }
250 
251 private:
252  friend class style;
253 
257  optional<std::string> name_;
258 
262  optional<double> size_;
263 
267  bool bold_ = false;
268 
272  bool italic_ = false;
273 
277  bool superscript_ = false;
278 
282  bool subscript_ = false;
283 
287  bool strikethrough_ = false;
288 
292  bool outline_ = false;
293 
297  bool shadow_ = false;
298 
302  underline_style underline_ = underline_style::none;
303 
307  optional<xlnt::color> color_;
308 
312  optional<std::size_t> family_;
313 
317  optional<std::size_t> charset_;
318 
322  optional<std::string> scheme_;
323 };
324 
325 } // namespace xlnt
underline_style
Text can be underlined in the enumerated ways
Definition: font.hpp:47
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
Describes the font style of a particular cell.
Definition: font.hpp:41
Colors can be applied to many parts of a cell&#39;s style.
Definition: color.hpp:165
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
bool operator!=(const font &other) const
Returns true if left is not exactly equal to right.
Definition: font.hpp:246
Describes a style which has a name and can be applied to multiple individual formats. In Excel this is a "Cell Style".
Definition: style.hpp:56