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