Merge "Dali-Text: Keyboard Shortcuts" into devel/master
[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) 2019 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
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 /**
37  * The input text's style.
38  */
39 struct InputStyle
40 {
41   enum Mask
42   {
43     NONE               = 0x0000,
44     INPUT_COLOR        = 0x0001,
45     INPUT_FONT_FAMILY  = 0x0002,
46     INPUT_POINT_SIZE   = 0x0004,
47     INPUT_FONT_WEIGHT  = 0x0008,
48     INPUT_FONT_WIDTH   = 0x0010,
49     INPUT_FONT_SLANT   = 0x0020,
50     INPUT_LINE_SPACING = 0x0040,
51     INPUT_UNDERLINE    = 0x0080,
52     INPUT_SHADOW       = 0x0100,
53     INPUT_EMBOSS       = 0x0200,
54     INPUT_OUTLINE      = 0x0400
55   };
56
57   InputStyle()
58   : textColor( Color::BLACK ),
59     familyName(),
60     weight( TextAbstraction::FontWeight::NORMAL ),
61     width( TextAbstraction::FontWidth::NORMAL ),
62     slant( TextAbstraction::FontSlant::NORMAL ),
63     size( 0.f ),
64     lineSpacing( 0.f ),
65     underlineProperties(),
66     shadowProperties(),
67     embossProperties(),
68     outlineProperties(),
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     {}
81
82   ~InputStyle()
83   {};
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
126   /**
127    * @brief
128    *
129    * Does not compare the font-style, underline, shadow, emboss and outline property strings.
130    */
131   bool Equal( const InputStyle& inputStyle ) const
132   {
133     if( ( isDefaultColor != inputStyle.isDefaultColor )             ||
134         ( isFamilyDefined != inputStyle.isFamilyDefined )           ||
135         ( isWeightDefined != inputStyle.isWeightDefined )           ||
136         ( isWidthDefined != inputStyle.isWidthDefined )             ||
137         ( isSlantDefined != inputStyle.isSlantDefined )             ||
138         ( isSizeDefined != inputStyle.isSizeDefined )               ||
139         ( isLineSpacingDefined != inputStyle.isLineSpacingDefined ) ||
140         ( isUnderlineDefined != inputStyle.isUnderlineDefined )     ||
141         ( isShadowDefined != inputStyle.isShadowDefined )           ||
142         ( isEmbossDefined != inputStyle.isEmbossDefined )           ||
143         ( isOutlineDefined != inputStyle.isOutlineDefined )         ||
144         ( textColor != inputStyle.textColor )                       ||
145         ( familyName != inputStyle.familyName )                     ||
146         ( weight != inputStyle.weight )                             ||
147         ( width != inputStyle.width )                               ||
148         ( slant != inputStyle.slant )                               ||
149         ( size != inputStyle.size )                                 ||
150         ( lineSpacing != inputStyle.lineSpacing )                   ||
151         ( underlineProperties != inputStyle.underlineProperties )   ||
152         ( shadowProperties != inputStyle.shadowProperties )         ||
153         ( embossProperties != inputStyle.embossProperties )         ||
154         ( outlineProperties != inputStyle.outlineProperties ) )
155     {
156       return false;
157     }
158
159     return true;
160   }
161
162   Mask GetInputStyleChangeMask( const InputStyle& inputStyle ) const
163   {
164     Mask mask = NONE;
165
166     if( textColor != inputStyle.textColor )
167     {
168       mask = static_cast<Mask>( mask | INPUT_COLOR );
169     }
170     if( familyName != inputStyle.familyName )
171     {
172       mask = static_cast<Mask>( mask | INPUT_FONT_FAMILY );
173     }
174     if( weight != inputStyle.weight )
175     {
176       mask = static_cast<Mask>( mask | INPUT_FONT_WEIGHT );
177     }
178     if( width != inputStyle.width )
179     {
180       mask = static_cast<Mask>( mask | INPUT_FONT_WIDTH );
181     }
182     if( slant != inputStyle.slant )
183     {
184       mask = static_cast<Mask>( mask | INPUT_FONT_SLANT );
185     }
186     if( size != inputStyle.size )
187     {
188       mask = static_cast<Mask>( mask | INPUT_POINT_SIZE );
189     }
190     if( lineSpacing != inputStyle.lineSpacing )
191     {
192       mask = static_cast<Mask>( mask | INPUT_LINE_SPACING );
193     }
194     if( underlineProperties != inputStyle.underlineProperties )
195     {
196       mask = static_cast<Mask>( mask | INPUT_UNDERLINE );
197     }
198     if( shadowProperties != inputStyle.shadowProperties )
199     {
200       mask = static_cast<Mask>( mask | INPUT_SHADOW );
201     }
202     if( embossProperties != inputStyle.embossProperties )
203     {
204       mask = static_cast<Mask>( mask | INPUT_EMBOSS );
205     }
206     if( outlineProperties != inputStyle.outlineProperties )
207     {
208       mask = static_cast<Mask>( mask | INPUT_OUTLINE );
209     }
210
211     return mask;
212   }
213
214   Vector4     textColor;           ///< The text's color.
215   std::string familyName;          ///< The font's family name.
216   FontWeight  weight;              ///< The font's weight.
217   FontWidth   width;               ///< The font's width.
218   FontSlant   slant;               ///< The font's slant.
219   float       size;                ///< The font's size.
220
221   float       lineSpacing;         ///< The line's spacing.
222
223   std::string underlineProperties; ///< The underline properties string.
224   std::string shadowProperties;    ///< The shadow properties string.
225   std::string embossProperties;    ///< The emboss properties string.
226   std::string outlineProperties;   ///< The outline properties string.
227
228   bool        isDefaultColor       : 1; ///< Whether the text's color is the default.
229   bool        isFamilyDefined      : 1; ///< Whether the font's family is defined.
230   bool        isWeightDefined      : 1; ///< Whether the font's weight is defined.
231   bool        isWidthDefined       : 1; ///< Whether the font's width is defined.
232   bool        isSlantDefined       : 1; ///< Whether the font's slant is defined.
233   bool        isSizeDefined        : 1; ///< Whether the font's size is defined.
234
235   bool        isLineSpacingDefined : 1; ///< Whether the line spacing is defined.
236   bool        isUnderlineDefined   : 1; ///< Whether the underline parameters are defined.
237   bool        isShadowDefined      : 1; ///< Whether the shadow parameters are defined.
238   bool        isEmbossDefined      : 1; ///< Whether the emboss parameters are defined.
239   bool        isOutlineDefined     : 1; ///< Whether the outline parameters are defined.
240 };
241
242 } // namespace Text
243
244 } // namespace Toolkit
245
246 } // namespace Dali
247
248 #endif // DALI_TOOLKIT_TEXT_INPUT_STYLE_H