DALi Version 2.1.5
[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) 2021 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
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/text-definitions.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Text
32 {
33 /**
34  * The input text's style.
35  */
36 struct InputStyle
37 {
38   enum Mask
39   {
40     NONE                = 0x0000,
41     INPUT_COLOR         = 0x0001,
42     INPUT_FONT_FAMILY   = 0x0002,
43     INPUT_POINT_SIZE    = 0x0004,
44     INPUT_FONT_WEIGHT   = 0x0008,
45     INPUT_FONT_WIDTH    = 0x0010,
46     INPUT_FONT_SLANT    = 0x0020,
47     INPUT_LINE_SPACING  = 0x0040,
48     INPUT_UNDERLINE     = 0x0080,
49     INPUT_SHADOW        = 0x0100,
50     INPUT_EMBOSS        = 0x0200,
51     INPUT_OUTLINE       = 0x0400,
52     INPUT_STRIKETHROUGH = 0x0800
53   };
54
55   InputStyle()
56   : textColor(Color::BLACK),
57     familyName(),
58     weight(TextAbstraction::FontWeight::NORMAL),
59     width(TextAbstraction::FontWidth::NORMAL),
60     slant(TextAbstraction::FontSlant::NORMAL),
61     size(0.f),
62     lineSpacing(0.f),
63     underlineProperties(),
64     shadowProperties(),
65     embossProperties(),
66     outlineProperties(),
67     strikethroughProperties(),
68     isDefaultColor(true),
69     isFamilyDefined(false),
70     isWeightDefined(false),
71     isWidthDefined(false),
72     isSlantDefined(false),
73     isSizeDefined(false),
74     isLineSpacingDefined(false),
75     isUnderlineDefined(false),
76     isShadowDefined(false),
77     isEmbossDefined(false),
78     isOutlineDefined(false),
79     isStrikethroughDefined(false)
80   {
81   }
82
83   ~InputStyle(){};
84
85   /**
86    * @brief
87    *
88    * Does not copy the font-style, underline, shadow, emboss and outline property strings.
89    */
90   void Copy(const InputStyle& inputStyle)
91   {
92     isDefaultColor = inputStyle.isDefaultColor;
93     textColor      = inputStyle.textColor;
94
95     isFamilyDefined = inputStyle.isFamilyDefined;
96     familyName      = inputStyle.familyName;
97
98     isWeightDefined = inputStyle.isWeightDefined;
99     weight          = inputStyle.weight;
100
101     isWidthDefined = inputStyle.isWidthDefined;
102     width          = inputStyle.width;
103
104     isSlantDefined = inputStyle.isSlantDefined;
105     slant          = inputStyle.slant;
106
107     isSizeDefined = inputStyle.isSizeDefined;
108     size          = inputStyle.size;
109
110     isLineSpacingDefined = inputStyle.isLineSpacingDefined;
111     lineSpacing          = inputStyle.lineSpacing;
112
113     isUnderlineDefined  = inputStyle.isUnderlineDefined;
114     underlineProperties = inputStyle.underlineProperties;
115
116     isShadowDefined  = inputStyle.isShadowDefined;
117     shadowProperties = inputStyle.shadowProperties;
118
119     isEmbossDefined  = inputStyle.isEmbossDefined;
120     embossProperties = inputStyle.embossProperties;
121
122     isOutlineDefined  = inputStyle.isOutlineDefined;
123     outlineProperties = inputStyle.outlineProperties;
124
125     isStrikethroughDefined  = inputStyle.isStrikethroughDefined;
126     strikethroughProperties = inputStyle.strikethroughProperties;
127   }
128
129   /**
130    * @brief
131    *
132    * Does not compare the font-style, underline, shadow, emboss and outline property strings.
133    */
134   bool Equal(const InputStyle& inputStyle) const
135   {
136     if((isDefaultColor != inputStyle.isDefaultColor) ||
137        (isFamilyDefined != inputStyle.isFamilyDefined) ||
138        (isWeightDefined != inputStyle.isWeightDefined) ||
139        (isWidthDefined != inputStyle.isWidthDefined) ||
140        (isSlantDefined != inputStyle.isSlantDefined) ||
141        (isSizeDefined != inputStyle.isSizeDefined) ||
142        (isLineSpacingDefined != inputStyle.isLineSpacingDefined) ||
143        (isUnderlineDefined != inputStyle.isUnderlineDefined) ||
144        (isShadowDefined != inputStyle.isShadowDefined) ||
145        (isEmbossDefined != inputStyle.isEmbossDefined) ||
146        (isOutlineDefined != inputStyle.isOutlineDefined) ||
147        (textColor != inputStyle.textColor) ||
148        (familyName != inputStyle.familyName) ||
149        (weight != inputStyle.weight) ||
150        (width != inputStyle.width) ||
151        (slant != inputStyle.slant) ||
152        (size != inputStyle.size) ||
153        (lineSpacing != inputStyle.lineSpacing) ||
154        (underlineProperties != inputStyle.underlineProperties) ||
155        (shadowProperties != inputStyle.shadowProperties) ||
156        (embossProperties != inputStyle.embossProperties) ||
157        (outlineProperties != inputStyle.outlineProperties) ||
158        (isStrikethroughDefined != inputStyle.isStrikethroughDefined))
159     {
160       return false;
161     }
162
163     return true;
164   }
165
166   Mask GetInputStyleChangeMask(const InputStyle& inputStyle) const
167   {
168     Mask mask = NONE;
169
170     if(textColor != inputStyle.textColor)
171     {
172       mask = static_cast<Mask>(mask | INPUT_COLOR);
173     }
174     if(familyName != inputStyle.familyName)
175     {
176       mask = static_cast<Mask>(mask | INPUT_FONT_FAMILY);
177     }
178     if(weight != inputStyle.weight)
179     {
180       mask = static_cast<Mask>(mask | INPUT_FONT_WEIGHT);
181     }
182     if(width != inputStyle.width)
183     {
184       mask = static_cast<Mask>(mask | INPUT_FONT_WIDTH);
185     }
186     if(slant != inputStyle.slant)
187     {
188       mask = static_cast<Mask>(mask | INPUT_FONT_SLANT);
189     }
190     if(size != inputStyle.size)
191     {
192       mask = static_cast<Mask>(mask | INPUT_POINT_SIZE);
193     }
194     if(lineSpacing != inputStyle.lineSpacing)
195     {
196       mask = static_cast<Mask>(mask | INPUT_LINE_SPACING);
197     }
198     if(underlineProperties != inputStyle.underlineProperties)
199     {
200       mask = static_cast<Mask>(mask | INPUT_UNDERLINE);
201     }
202     if(shadowProperties != inputStyle.shadowProperties)
203     {
204       mask = static_cast<Mask>(mask | INPUT_SHADOW);
205     }
206     if(embossProperties != inputStyle.embossProperties)
207     {
208       mask = static_cast<Mask>(mask | INPUT_EMBOSS);
209     }
210     if(outlineProperties != inputStyle.outlineProperties)
211     {
212       mask = static_cast<Mask>(mask | INPUT_OUTLINE);
213     }
214     if(strikethroughProperties != inputStyle.strikethroughProperties)
215     {
216       mask = static_cast<Mask>(mask | INPUT_STRIKETHROUGH);
217     }
218
219     return mask;
220   }
221
222   Vector4     textColor;  ///< The text's color.
223   std::string familyName; ///< The font's family name.
224   FontWeight  weight;     ///< The font's weight.
225   FontWidth   width;      ///< The font's width.
226   FontSlant   slant;      ///< The font's slant.
227   float       size;       ///< The font's size.
228
229   float lineSpacing; ///< The line's spacing.
230
231   std::string underlineProperties;     ///< The underline properties string.
232   std::string shadowProperties;        ///< The shadow properties string.
233   std::string embossProperties;        ///< The emboss properties string.
234   std::string outlineProperties;       ///< The outline properties string.
235   std::string strikethroughProperties; ///< The strikethrough properties string.
236
237   bool isDefaultColor : 1;  ///< Whether the text's color is the default.
238   bool isFamilyDefined : 1; ///< Whether the font's family is defined.
239   bool isWeightDefined : 1; ///< Whether the font's weight is defined.
240   bool isWidthDefined : 1;  ///< Whether the font's width is defined.
241   bool isSlantDefined : 1;  ///< Whether the font's slant is defined.
242   bool isSizeDefined : 1;   ///< Whether the font's size is defined.
243
244   bool isLineSpacingDefined : 1;   ///< Whether the line spacing is defined.
245   bool isUnderlineDefined : 1;     ///< Whether the underline parameters are defined.
246   bool isShadowDefined : 1;        ///< Whether the shadow parameters are defined.
247   bool isEmbossDefined : 1;        ///< Whether the emboss parameters are defined.
248   bool isOutlineDefined : 1;       ///< Whether the outline parameters are defined.
249   bool isStrikethroughDefined : 1; ///< Whether the strikethrough parameters are defined.
250 };
251
252 } // namespace Text
253
254 } // namespace Toolkit
255
256 } // namespace Dali
257
258 #endif // DALI_TOOLKIT_TEXT_INPUT_STYLE_H