1 // Copyright (c) 2014-2020 Thomas Fussell
2 // Copyright (c) 2010-2015 openpyxl
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <xlnt/xlnt_config.hpp>
28 #include <xlnt/utils/optional.hpp>
29 
30 namespace xlnt {
31 
32 /// <summary>
33 /// Text can be aligned horizontally within a cell in these enumerated ways.
34 /// </summary>
35 enum class XLNT_API horizontal_alignment
36 {
37     general,
38     left,
39     center,
40     right,
41     fill,
42     justify,
43     center_continuous,
44     distributed
45 };
46 
47 /// <summary>
48 /// Text can be aligned vertically within a cell in these enumerated ways.
49 /// </summary>
50 enum class XLNT_API vertical_alignment
51 {
52     top,
53     center,
54     bottom,
55     justify,
56     distributed
57 };
58 
59 /// <summary>
60 /// Alignment options that determine how text should be displayed within a cell.
61 /// </summary>
62 class XLNT_API alignment
63 {
64 public:
65     /// <summary>
66     /// Returns true if shrink-to-fit has been enabled.
67     /// </summary>
68     bool shrink() const;
69 
70     /// <summary>
71     /// Sets whether the font size should be reduced until all of the text fits in a cell without wrapping.
72     /// </summary>
73     alignment &shrink(bool shrink_to_fit);
74 
75     /// <summary>
76     /// Returns true if text-wrapping has been enabled.
77     /// </summary>
78     bool wrap() const;
79 
80     /// <summary>
81     /// Sets whether text in a cell should continue to multiple lines if it doesn't fit in one line.
82     /// </summary>
83     alignment &wrap(bool wrap_text);
84 
85     /// <summary>
86     /// Returns the optional value of indentation width in number of spaces.
87     /// </summary>
88     optional<int> indent() const;
89 
90     /// <summary>
91     /// Sets the indent size in number of spaces from the side of the cell. This will only
92     /// take effect when left or right horizontal alignment has also been set.
93     /// </summary>
94     alignment &indent(int indent_size);
95 
96     /// <summary>
97     /// Returns the optional value of rotation for text in the cell in degrees.
98     /// </summary>
99     optional<int> rotation() const;
100 
101     /// <summary>
102     /// Sets the rotation for text in the cell in degrees.
103     /// </summary>
104     alignment &rotation(int text_rotation);
105 
106     /// <summary>
107     /// Returns the optional horizontal alignment.
108     /// </summary>
109     optional<horizontal_alignment> horizontal() const;
110 
111     /// <summary>
112     /// Sets the horizontal alignment.
113     /// </summary>
114     alignment &horizontal(horizontal_alignment horizontal);
115 
116     /// <summary>
117     /// Returns the optional vertical alignment.
118     /// </summary>
119     optional<vertical_alignment> vertical() const;
120 
121     /// <summary>
122     /// Sets the vertical alignment.
123     /// </summary>
124     alignment &vertical(vertical_alignment vertical);
125 
126     /// <summary>
127     /// Returns true if this alignment is equivalent to other.
128     /// </summary>
129     bool operator==(const alignment &other) const;
130 
131     /// <summary>
132     /// Returns true if this alignment is not equivalent to other.
133     /// </summary>
134     bool operator!=(const alignment &other) const;
135 
136 private:
137     /// <summary>
138     /// Whether or not to shrink font size until it fits on one line
139     /// </summary>
140     bool shrink_to_fit_ = false;
141 
142     /// <summary>
143     /// Whether or not to wrap text to the next line
144     /// </summary>
145     bool wrap_text_ = false;
146 
147     /// <summary>
148     /// The indent in number of spaces from the side
149     /// </summary>
150     optional<int> indent_;
151 
152     /// <summary>
153     /// The text roation in degrees
154     /// </summary>
155     optional<int> text_rotation_;
156 
157     /// <summary>
158     /// The horizontal alignment
159     /// </summary>
160     optional<horizontal_alignment> horizontal_;
161 
162     /// <summary>
163     /// The vertical alignment
164     /// </summary>
165     optional<vertical_alignment> vertical_;
166 };
167 
168 } // namespace xlnt
169