xlnt
fill.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 <unordered_map>
29 
30 #include <xlnt/xlnt_config.hpp>
31 #include <xlnt/styles/color.hpp>
32 #include <xlnt/utils/optional.hpp>
33 
34 namespace xlnt {
35 
39 enum class XLNT_API pattern_fill_type
40 {
41  none,
42  solid,
43  mediumgray,
44  darkgray,
45  lightgray,
46  darkhorizontal,
47  darkvertical,
48  darkdown,
49  darkup,
50  darkgrid,
51  darktrellis,
52  lighthorizontal,
53  lightvertical,
54  lightdown,
55  lightup,
56  lightgrid,
57  lighttrellis,
58  gray125,
59  gray0625
60 };
61 
66 class XLNT_API pattern_fill
67 {
68 public:
72  pattern_fill();
73 
77  pattern_fill_type type() const;
78 
82  pattern_fill &type(pattern_fill_type new_type);
83 
87  optional<color> foreground() const;
88 
92  pattern_fill &foreground(const color &foreground);
93 
97  optional<color> background() const;
98 
102  pattern_fill &background(const color &background);
103 
107  bool operator==(const pattern_fill &other) const;
108 
112  bool operator!=(const pattern_fill &other) const;
113 
114 private:
118  pattern_fill_type type_ = pattern_fill_type::none;
119 
123  optional<color> foreground_;
124 
128  optional<color> background_;
129 };
130 
134 enum class XLNT_API gradient_fill_type
135 {
136  linear,
137  path
138 };
139 
143 class XLNT_API gradient_fill
144 {
145 public:
149  gradient_fill();
150 
154  gradient_fill_type type() const;
155 
156  // Type
157 
161  gradient_fill &type(gradient_fill_type new_type);
162 
163  // Degree
164 
168  gradient_fill &degree(double degree);
169 
173  double degree() const;
174 
175  // Left
176 
180  double left() const;
181 
185  gradient_fill &left(double value);
186 
187  // Right
188 
192  double right() const;
193 
197  gradient_fill &right(double value);
198 
199  // Top
200 
204  double top() const;
205 
209  gradient_fill &top(double value);
210 
211  // Bottom
212 
216  double bottom() const;
217 
221  gradient_fill &bottom(double value);
222 
223  // Stops
224 
228  gradient_fill &add_stop(double position, color stop_color);
229 
233  gradient_fill &clear_stops();
234 
238  std::unordered_map<double, color> stops() const;
239 
243  bool operator==(const gradient_fill &other) const;
244 
248  bool operator!=(const gradient_fill &right) const;
249 
250 private:
254  gradient_fill_type type_ = gradient_fill_type::linear;
255 
259  double degree_ = 0;
260 
264  double left_ = 0;
265 
269  double right_ = 0;
270 
274  double top_ = 0;
275 
279  double bottom_ = 0;
280 
284  std::unordered_map<double, color> stops_;
285 };
286 
290 enum class XLNT_API fill_type
291 {
292  pattern,
293  gradient
294 };
295 
299 class XLNT_API fill
300 {
301 public:
308  static fill solid(const color &fill_color);
309 
314  fill();
315 
319  fill(const pattern_fill &pattern);
320 
324  fill(const gradient_fill &gradient);
325 
329  fill_type type() const;
330 
335  class gradient_fill gradient_fill() const;
336 
341  class pattern_fill pattern_fill() const;
342 
346  bool operator==(const fill &other) const;
347 
351  bool operator!=(const fill &other) const;
352 
353 private:
357  fill_type type_ = fill_type::pattern;
358 
362  xlnt::gradient_fill gradient_;
363 
367  xlnt::pattern_fill pattern_;
368 };
369 
370 } // namespace xlnt
pattern_fill_type
The pattern of pixels upon which the corresponding pattern fill will be displayed ...
Definition: fill.hpp:39
Encapsulates a fill which transitions between colors at particular "stops".
Definition: fill.hpp:143
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
Colors can be applied to many parts of a cell&#39;s style.
Definition: color.hpp:165
Describes the fill style of a particular cell.
Definition: fill.hpp:299
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Represents a fill which colors the cell based on a foreground and background color and a pattern...
Definition: fill.hpp:66
Encapsulates a path that points to location in a filesystem.
Definition: path.hpp:38
fill_type
Enumerates the possible fill types
Definition: fill.hpp:290
Many settings in xlnt are allowed to not have a value set. This class encapsulates a value which may ...
Definition: format.hpp:44
gradient_fill_type
Enumerates the types of gradient fills
Definition: fill.hpp:134
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.