a4d18738aee3cfbc809ad8f2bbb5c8872fc5e41d
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-view / text-view-processor-types.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__
3
4 /*
5  * Copyright (c) 2014 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 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/renderable-actor.h>
23 #include <dali-toolkit/public-api/markup-processor/markup-processor.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 namespace TextViewProcessor
35 {
36
37 /**
38  * Whether the text is a new paragraph character '\n', a white space or normal text.
39  */
40 enum TextSeparatorType
41 {
42   ParagraphSeparator,
43   WordSeparator,
44   NoSeparator
45 };
46
47 /**
48  * Whether to clear the text of the text-actors when text is removed.
49  */
50 enum TextOperationOnRemove
51 {
52   CLEAR_TEXT,
53   KEEP_TEXT
54 };
55
56
57 /**
58  * Stores text info indices.
59  */
60 struct TextInfoIndices
61 {
62   /**
63    * Default constructor.
64    *
65    * Initializes all members to their default values.
66    */
67   TextInfoIndices();
68
69   /**
70    * Constructor.
71    */
72   TextInfoIndices( std::size_t paragraphIndex,
73                    std::size_t wordIndex,
74                    std::size_t characterIndex );
75
76   /**
77    * Equality operator.
78    * @param [in] indices The text-info indices to be compared.
79    *
80    * @return \e true if both indices are equal.
81    */
82   bool operator==( const TextInfoIndices& indices ) const;
83
84   std::size_t mParagraphIndex;          ///< The paragraph index within the text.
85   std::size_t mWordIndex;               ///< The word index within the paragraph.
86   std::size_t mCharacterIndex;          ///< The character index within the word.
87 };
88
89 /**
90  * Stores gradient info.
91  *
92  * Used to fade in/out text-actors.
93  */
94 struct GradientInfo
95 {
96   /**
97    * Default constructor.
98    *
99    * Initializes all members to their default values.
100    */
101   GradientInfo();
102
103   /**
104    * Default destructor.
105    */
106   ~GradientInfo();
107
108   /**
109    * Copy constructor
110    */
111   GradientInfo( const GradientInfo& info );
112
113   /**
114    * Assignment operator.
115    */
116   GradientInfo& operator=( const GradientInfo& info );
117
118   Vector4                     mGradientColor;  ///< Gradient color.
119   Vector2                     mStartPoint;     ///< Gradient start point.
120   Vector2                     mEndPoint;       ///< Gradient end point.
121 };
122
123 /**
124  * Layout information for a character.
125  * It stores the position, size and ascender of its respective text-actor.
126  */
127 struct CharacterLayoutInfo
128 {
129   /**
130    * Default constructor.
131    *
132    * Initializes all members to their default values.
133    */
134   CharacterLayoutInfo();
135
136   /**
137    * Default destructor.
138    *
139    * Deletes the gradient info.
140    */
141   ~CharacterLayoutInfo();
142
143   /**
144    * Copy constructor.
145    */
146   CharacterLayoutInfo( const CharacterLayoutInfo& character );
147
148   /**
149    * Assignment operator.
150    */
151   CharacterLayoutInfo& operator=( const CharacterLayoutInfo& character );
152
153   // Metrics of the glyph.
154   Size        mSize;               ///< Height of the font and advance (the horizontal distance from the origin of the current character and the next one).
155   float       mBearing;            ///< Vertical distance from the baseline to the top of the glyph's boundary box.
156   float       mAscender;           ///< Distance from the base line to the top of the line.
157   float       mUnderlineThickness; ///< The underline's thickness.
158   float       mUnderlinePosition;  ///< The underline's position.
159
160   // Position and alignment offset. It depends on the lay-out.
161   Vector3     mPosition;           ///< Position within the text-view
162   Vector2     mOffset;             ///< Alignment and justification offset.
163
164   RenderableActor             mGlyphActor;   ///< Handle to a text-actor.
165   MarkupProcessor::StyledText mStyledText;   ///< Stores the text and its style.
166   float                       mColorAlpha;   ///< Alpha component for the initial text color when text is faded.
167   GradientInfo*               mGradientInfo; ///< Stores gradient info.
168
169   bool            mIsVisible:1;    ///< Whether the text-actor is visible.
170   bool            mSetText:1;      ///< Whether a new text needs to be set in the text-actor.
171   bool            mSetStyle:1;     ///< Whether a new style needs to be set in the text-actor.
172   bool            mIsColorGlyph:1; ///< Whether this character is an emoticon.
173 };
174 typedef std::vector<CharacterLayoutInfo> CharacterLayoutInfoContainer;
175
176 /**
177  * Layout information for a word.
178  */
179 struct WordLayoutInfo
180 {
181   /**
182    * Default constructor.
183    *
184    * Initializes all members to their default values.
185    */
186   WordLayoutInfo();
187
188   /**
189    * Default destructor.
190    *
191    * Clears all characters.
192    */
193   ~WordLayoutInfo();
194
195   /**
196    * Copy constructor.
197    */
198   WordLayoutInfo( const WordLayoutInfo& word );
199
200   /**
201    * Assignment operator.
202    */
203   WordLayoutInfo& operator=( const WordLayoutInfo& word );
204
205   Size                              mSize;                      ///< Size of the word.
206   float                             mAscender;                  ///< Max of all ascenders of all characters.
207   TextSeparatorType                 mType;                      ///< Whether this word is a word separator, a line separator or is not a separator.
208   CharacterLayoutInfoContainer      mCharactersLayoutInfo;      ///< Layout info for all characters.
209 };
210 typedef std::vector<WordLayoutInfo> WordLayoutInfoContainer;
211
212 /**
213  * Layout information for a paragraph.
214  */
215 struct ParagraphLayoutInfo
216 {
217   /**
218    * Default constructor.
219    *
220    * Initializes all members to their default values.
221    */
222   ParagraphLayoutInfo();
223
224   /**
225    * Default destructor.
226    *
227    * Clears all words.
228    */
229   ~ParagraphLayoutInfo();
230
231   /**
232    * Copy constructor.
233    */
234   ParagraphLayoutInfo( const ParagraphLayoutInfo& paragraph );
235
236   /**
237    * Assignment operator.
238    */
239   ParagraphLayoutInfo& operator=( const ParagraphLayoutInfo& paragraph );
240
241   Size                                          mSize;                       ///< Size of the paragraph.
242   float                                         mAscender;                   ///< Max of all ascenders of all words.
243   float                                         mLineHeightOffset;           ///< Line height offset.
244   std::size_t                                   mNumberOfCharacters;         ///< Stores the number of characters.
245   WordLayoutInfoContainer                       mWordsLayoutInfo;            ///< Layout info for all words.
246 };
247 typedef std::vector<ParagraphLayoutInfo> ParagraphLayoutInfoContainer;
248
249 /**
250  * Layout information for the whole text.
251  */
252 struct TextLayoutInfo
253 {
254   /**
255    * Default constructor.
256    *
257    * Initializes all members to their default values.
258    */
259   TextLayoutInfo();
260
261   /**
262    * Copy constructor.
263    */
264   TextLayoutInfo( const TextLayoutInfo& text );
265
266   /**
267    * Assignment operator.
268    */
269   TextLayoutInfo& operator=( const TextLayoutInfo& text );
270
271   Size                         mWholeTextSize;        ///< width and height of the whole text.
272   float                        mMaxWordWidth;         ///< maximum width between all words.
273   float                        mMaxItalicsOffset;     ///< When rendering text-view in offscreen an extra width offset is needed to prevent italic characters to be cut if they are in the right edge.
274   std::size_t                  mNumberOfCharacters;   ///< Stores the number of characters.
275   ParagraphLayoutInfoContainer mParagraphsLayoutInfo; ///< Layout information for all paragraphs.
276   WordLayoutInfo               mEllipsizeLayoutInfo;  ///< Layout information for the ellipsize text.
277 };
278
279 } // namespace TextViewProcessor
280
281 } // namespace Internal
282
283 } // namespace Toolkit
284
285 } // namespace Dali
286
287 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__