Minor coverity issue fixes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / input-style.h
1 #ifndef DALI_TOOLKIT_TEXT_INPUT_STYLE_H
2 #define DALI_TOOLKIT_TEXT_INPUT_STYLE_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/math/math-utils.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/text-definitions.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Text
33 {
34 /**
35  * The input text's style.
36  */
37 struct InputStyle
38 {
39   enum Mask
40   {
41     NONE                = 0x0000,
42     INPUT_COLOR         = 0x0001,
43     INPUT_FONT_FAMILY   = 0x0002,
44     INPUT_POINT_SIZE    = 0x0004,
45     INPUT_FONT_WEIGHT   = 0x0008,
46     INPUT_FONT_WIDTH    = 0x0010,
47     INPUT_FONT_SLANT    = 0x0020,
48     INPUT_LINE_SPACING  = 0x0040,
49     INPUT_UNDERLINE     = 0x0080,
50     INPUT_SHADOW        = 0x0100,
51     INPUT_EMBOSS        = 0x0200,
52     INPUT_OUTLINE       = 0x0400,
53     INPUT_STRIKETHROUGH = 0x0800
54   };
55
56   InputStyle()
57   : textColor(Color::BLACK),
58     familyName(),
59     weight(TextAbstraction::FontWeight::NORMAL),
60     width(TextAbstraction::FontWidth::NORMAL),
61     slant(TextAbstraction::FontSlant::NORMAL),
62     size(0.f),
63     lineSpacing(0.f),
64     underlineProperties(),
65     shadowProperties(),
66     embossProperties(),
67     outlineProperties(),
68     strikethroughProperties(),
69     isDefaultColor(true),
70     isFamilyDefined(false),
71     isWeightDefined(false),
72     isWidthDefined(false),
73     isSlantDefined(false),
74     isSizeDefined(false),
75     isLineSpacingDefined(false),
76     isUnderlineDefined(false),
77     isShadowDefined(false),
78     isEmbossDefined(false),
79     isOutlineDefined(false),
80     isStrikethroughDefined(false)
81   {
82   }
83
84   ~InputStyle(){};
85
86   /**
87    * @brief
88    *
89    * Does not copy the font-style, underline, shadow, emboss and outline property strings.
90    */
91   void Copy(const InputStyle& inputStyle)
92   {
93     isDefaultColor = inputStyle.isDefaultColor;
94     textColor      = inputStyle.textColor;
95
96     isFamilyDefined = inputStyle.isFamilyDefined;
97     familyName      = inputStyle.familyName;
98
99     isWeightDefined = inputStyle.isWeightDefined;
100     weight          = inputStyle.weight;
101
102     isWidthDefined = inputStyle.isWidthDefined;
103     width          = inputStyle.width;
104
105     isSlantDefined = inputStyle.isSlantDefined;
106     slant          = inputStyle.slant;
107
108     isSizeDefined = inputStyle.isSizeDefined;
109     size          = inputStyle.size;
110
111     isLineSpacingDefined = inputStyle.isLineSpacingDefined;
112     lineSpacing          = inputStyle.lineSpacing;
113
114     isUnderlineDefined  = inputStyle.isUnderlineDefined;
115     underlineProperties = inputStyle.underlineProperties;
116
117     isShadowDefined  = inputStyle.isShadowDefined;
118     shadowProperties = inputStyle.shadowProperties;
119
120     isEmbossDefined  = inputStyle.isEmbossDefined;
121     embossProperties = inputStyle.embossProperties;
122
123     isOutlineDefined  = inputStyle.isOutlineDefined;
124     outlineProperties = inputStyle.outlineProperties;
125
126     isStrikethroughDefined  = inputStyle.isStrikethroughDefined;
127     strikethroughProperties = inputStyle.strikethroughProperties;
128   }
129
130   /**
131    * @brief
132    *
133    * Does not compare the font-style, underline, shadow, emboss and outline property strings.
134    */
135   bool Equal(const InputStyle& inputStyle) const
136   {
137     if((isDefaultColor != inputStyle.isDefaultColor) ||
138        (isFamilyDefined != inputStyle.isFamilyDefined) ||
139        (isWeightDefined != inputStyle.isWeightDefined) ||
140        (isWidthDefined != inputStyle.isWidthDefined) ||
141        (isSlantDefined != inputStyle.isSlantDefined) ||
142        (isSizeDefined != inputStyle.isSizeDefined) ||
143        (isLineSpacingDefined != inputStyle.isLineSpacingDefined) ||
144        (isUnderlineDefined != inputStyle.isUnderlineDefined) ||
145        (isShadowDefined != inputStyle.isShadowDefined) ||
146        (isEmbossDefined != inputStyle.isEmbossDefined) ||
147        (isOutlineDefined != inputStyle.isOutlineDefined) ||
148        (textColor != inputStyle.textColor) ||
149        (familyName != inputStyle.familyName) ||
150        (weight != inputStyle.weight) ||
151        (width != inputStyle.width) ||
152        (slant != inputStyle.slant) ||
153        (!Dali::Equals(size, inputStyle.size)) ||
154        (!Dali::Equals(lineSpacing, inputStyle.lineSpacing)) ||
155        (underlineProperties != inputStyle.underlineProperties) ||
156        (shadowProperties != inputStyle.shadowProperties) ||
157        (embossProperties != inputStyle.embossProperties) ||
158        (outlineProperties != inputStyle.outlineProperties) ||
159        (isStrikethroughDefined != inputStyle.isStrikethroughDefined))
160     {
161       return false;
162     }
163
164     return true;
165   }
166
167   Mask GetInputStyleChangeMask(const InputStyle& inputStyle) const
168   {
169     Mask mask = NONE;
170
171     if(textColor != inputStyle.textColor)
172     {
173       mask = static_cast<Mask>(mask | INPUT_COLOR);
174     }
175     if(familyName != inputStyle.familyName)
176     {
177       mask = static_cast<Mask>(mask | INPUT_FONT_FAMILY);
178     }
179     if(weight != inputStyle.weight)
180     {
181       mask = static_cast<Mask>(mask | INPUT_FONT_WEIGHT);
182     }
183     if(width != inputStyle.width)
184     {
185       mask = static_cast<Mask>(mask | INPUT_FONT_WIDTH);
186     }
187     if(slant != inputStyle.slant)
188     {
189       mask = static_cast<Mask>(mask | INPUT_FONT_SLANT);
190     }
191     if(!Dali::Equals(size, inputStyle.size))
192     {
193       mask = static_cast<Mask>(mask | INPUT_POINT_SIZE);
194     }
195     if(!Dali::Equals(lineSpacing, inputStyle.lineSpacing))
196     {
197       mask = static_cast<Mask>(mask | INPUT_LINE_SPACING);
198     }
199     if(underlineProperties != inputStyle.underlineProperties)
200     {
201       mask = static_cast<Mask>(mask | INPUT_UNDERLINE);
202     }
203     if(shadowProperties != inputStyle.shadowProperties)
204     {
205       mask = static_cast<Mask>(mask | INPUT_SHADOW);
206     }
207     if(embossProperties != inputStyle.embossProperties)
208     {
209       mask = static_cast<Mask>(mask | INPUT_EMBOSS);
210     }
211     if(outlineProperties != inputStyle.outlineProperties)
212     {
213       mask = static_cast<Mask>(mask | INPUT_OUTLINE);
214     }
215     if(strikethroughProperties != inputStyle.strikethroughProperties)
216     {
217       mask = static_cast<Mask>(mask | INPUT_STRIKETHROUGH);
218     }
219
220     return mask;
221   }
222
223   Vector4     textColor;  ///< The text's color.
224   std::string familyName; ///< The font's family name.
225   FontWeight  weight;     ///< The font's weight.
226   FontWidth   width;      ///< The font's width.
227   FontSlant   slant;      ///< The font's slant.
228   float       size;       ///< The font's size.
229
230   float lineSpacing; ///< The line's spacing.
231
232   std::string underlineProperties;     ///< The underline properties string.
233   std::string shadowProperties;        ///< The shadow properties string.
234   std::string embossProperties;        ///< The emboss properties string.
235   std::string outlineProperties;       ///< The outline properties string.
236   std::string strikethroughProperties; ///< The strikethrough properties string.
237
238   bool isDefaultColor : 1;  ///< Whether the text's color is the default.
239   bool isFamilyDefined : 1; ///< Whether the font's family is defined.
240   bool isWeightDefined : 1; ///< Whether the font's weight is defined.
241   bool isWidthDefined : 1;  ///< Whether the font's width is defined.
242   bool isSlantDefined : 1;  ///< Whether the font's slant is defined.
243   bool isSizeDefined : 1;   ///< Whether the font's size is defined.
244
245   bool isLineSpacingDefined : 1;   ///< Whether the line spacing is defined.
246   bool isUnderlineDefined : 1;     ///< Whether the underline parameters are defined.
247   bool isShadowDefined : 1;        ///< Whether the shadow parameters are defined.
248   bool isEmbossDefined : 1;        ///< Whether the emboss parameters are defined.
249   bool isOutlineDefined : 1;       ///< Whether the outline parameters are defined.
250   bool isStrikethroughDefined : 1; ///< Whether the strikethrough parameters are defined.
251 };
252
253 } // namespace Text
254
255 } // namespace Toolkit
256
257 } // namespace Dali
258
259 #endif // DALI_TOOLKIT_TEXT_INPUT_STYLE_H