Minor coverity issue fixes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / underline-style-properties.h
1 #ifndef DALI_TOOLKIT_TEXT_UNDERLINE_STYLE_PROPERTIES_H
2 #define DALI_TOOLKIT_TEXT_UNDERLINE_STYLE_PROPERTIES_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 #include <dali/public-api/math/vector4.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/text/text-enumerations.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 /**
36  * @brief Properties of underline style.
37  */
38 struct UnderlineStyleProperties
39 {
40   // Constructors
41
42   /**
43    * Default constructor to set the default values of bitfields
44    */
45   UnderlineStyleProperties()
46   : type{Text::Underline::SOLID},
47     color{Color::BLACK},
48     height{0u},
49     dashGap{1u},
50     dashWidth{2u},
51     typeDefined{false},
52     colorDefined{false},
53     heightDefined{false},
54     dashGapDefined{false},
55     dashWidthDefined{false}
56   {
57   }
58
59   UnderlineStyleProperties(Text::Underline::Type type,
60                            Vector4               color,
61                            float                 height,
62                            float                 dashGap,
63                            float                 dashWidth,
64                            bool                  typeDefined,
65                            bool                  colorDefined,
66                            bool                  heightDefined,
67                            bool                  dashGapDefined,
68                            bool                  dashWidthDefined)
69   : type{type},
70     color{color},
71     height{height},
72     dashGap{dashGap},
73     dashWidth{dashWidth},
74     typeDefined{typeDefined},
75     colorDefined{colorDefined},
76     heightDefined{heightDefined},
77     dashGapDefined{dashGapDefined},
78     dashWidthDefined{dashWidthDefined}
79   {
80   }
81
82   // Overloading operators
83
84   bool operator==(const UnderlineStyleProperties& other) const
85   {
86     //The property is similar when both are not defined or when both are defined and have the same value.
87     return ((!typeDefined && !other.typeDefined) || ((typeDefined && other.typeDefined) && (type == other.type))) &&
88            ((!colorDefined && !other.colorDefined) || ((colorDefined && other.colorDefined) && (color == other.color))) &&
89            ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (Dali::Equals(height, other.height)))) &&
90            ((!dashGapDefined && !other.dashGapDefined) || ((dashGapDefined && other.dashGapDefined) && (Dali::Equals(dashGap, other.dashGap)))) &&
91            ((!dashWidthDefined && !other.dashWidthDefined) || ((dashWidthDefined && other.dashWidthDefined) && (Dali::Equals(dashWidth, other.dashWidth))));
92   }
93
94   bool operator!=(const UnderlineStyleProperties& other) const
95   {
96     return !(*this == other);
97   }
98
99   bool IsHeightEqualTo(const UnderlineStyleProperties& other) const
100   {
101     return ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (Dali::Equals(height, other.height))));
102   }
103
104   UnderlineStyleProperties& CopyIfNotDefined(const UnderlineStyleProperties& other)
105   {
106     //Copy only the defined properties in other and not defined in this from other to this
107     if(!typeDefined && other.typeDefined)
108     {
109       type        = other.type;
110       typeDefined = true;
111     }
112
113     if(!heightDefined && other.heightDefined)
114     {
115       height        = other.height;
116       heightDefined = true;
117     }
118
119     if(!colorDefined && other.colorDefined)
120     {
121       color        = other.color;
122       colorDefined = true;
123     }
124
125     if(!dashGapDefined && other.dashGapDefined)
126     {
127       dashGap        = other.dashGap;
128       dashGapDefined = true;
129     }
130
131     if(!dashWidthDefined && other.dashWidthDefined)
132     {
133       dashWidth        = other.dashWidth;
134       dashWidthDefined = true;
135     }
136
137     // to chain this method
138     return *this;
139   }
140
141   UnderlineStyleProperties& OverrideByDefinedProperties(const UnderlineStyleProperties& other)
142   {
143     //Copy only the defined properties in other from other to this
144     if(other.typeDefined)
145     {
146       type        = other.type;
147       typeDefined = true;
148     }
149
150     if(other.heightDefined)
151     {
152       height        = other.height;
153       heightDefined = true;
154     }
155
156     if(other.colorDefined)
157     {
158       color        = other.color;
159       colorDefined = true;
160     }
161
162     if(other.dashGapDefined)
163     {
164       dashGap        = other.dashGap;
165       dashGapDefined = true;
166     }
167
168     if(other.dashWidthDefined)
169     {
170       dashWidth        = other.dashWidth;
171       dashWidthDefined = true;
172     }
173
174     // to chain this method
175     return *this;
176   }
177
178   //Attributes
179   Text::Underline::Type type;      ///< The type of underline.
180   Vector4               color;     ///< The color of underline.
181   float                 height;    ///< The height of underline.
182   float                 dashGap;   ///< The dash-gap of underline.
183   float                 dashWidth; ///< The height of underline.
184
185   bool typeDefined : 1;      ///< Whether the type is defined.
186   bool colorDefined : 1;     ///< Whether the color is defined.
187   bool heightDefined : 1;    ///< Whether the height is defined.
188   bool dashGapDefined : 1;   ///< Whether the dash-gap is defined.
189   bool dashWidthDefined : 1; ///< Whether the dash-width is defined.
190 };
191
192 } // namespace Text
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197
198 #endif // DALI_TOOLKIT_TEXT_UNDERLINE_STYLE_PROPERTIES_H