15005cce26bdb9e9944407f4f436e7e076510764
[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/public-api/text/text.h>
24
25 namespace Dali
26 {
27
28 class TextStyle;
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 namespace TextProcessor
37 {
38 // Forward declarations.
39 struct BidirectionalParagraphInfo;
40 struct BidirectionalLineInfo;
41 } // namespace TextProcessor
42
43 namespace TextViewProcessor
44 {
45
46 /**
47  * Whether the text is a new paragraph character '\n', a white space or normal text.
48  */
49 enum TextSeparatorType
50 {
51   ParagraphSeparator,
52   WordSeparator,
53   NoSeparator
54 };
55
56 /**
57  * Whether to clear the text of the text-actors when text is removed.
58  */
59 enum TextOperationOnRemove
60 {
61   CLEAR_TEXT,
62   KEEP_TEXT
63 };
64
65
66 /**
67  * Stores text info indices.
68  */
69 struct TextInfoIndices
70 {
71   /**
72    * Default constructor.
73    *
74    * Initializes all members to their default values.
75    */
76   TextInfoIndices();
77
78   /**
79    * Constructor.
80    */
81   TextInfoIndices( std::size_t paragraphIndex,
82                    std::size_t wordIndex,
83                    std::size_t characterIndex );
84
85   /**
86    * Equality operator.
87    * @param [in] indices The text-info indices to be compared.
88    *
89    * @return \e true if both indices are equal.
90    */
91   bool operator==( const TextInfoIndices& indices ) const;
92
93   std::size_t mParagraphIndex;          ///< The paragraph index within the text.
94   std::size_t mWordIndex;               ///< The word index within the paragraph.
95   std::size_t mCharacterIndex;          ///< The character index within the word.
96   std::size_t mCharacterParagraphIndex; ///< The character index within the paragraph.
97 };
98
99 /**
100  * Stores gradient info.
101  *
102  * Used to fade in/out text-actors.
103  */
104 struct GradientInfo
105 {
106   /**
107    * Default constructor.
108    *
109    * Initializes all members to their default values.
110    */
111   GradientInfo();
112
113   /**
114    * Default destructor.
115    */
116   ~GradientInfo();
117
118   /**
119    * Copy constructor
120    */
121   GradientInfo( const GradientInfo& info );
122
123   /**
124    * Assignment operator.
125    */
126   GradientInfo& operator=( const GradientInfo& info );
127
128   Vector4                     mGradientColor;  ///< Gradient color.
129   Vector2                     mStartPoint;     ///< Gradient start point.
130   Vector2                     mEndPoint;       ///< Gradient end point.
131 };
132
133 /**
134  * Layout information for a character.
135  * It stores the position, size and ascender of its respective text-actor.
136  */
137 struct CharacterLayoutInfo
138 {
139   /**
140    * Default constructor.
141    *
142    * Initializes all members to their default values.
143    */
144   CharacterLayoutInfo();
145
146   /**
147    * Default destructor.
148    *
149    * Deletes the gradient info.
150    */
151   ~CharacterLayoutInfo();
152
153   /**
154    * Copy constructor.
155    */
156   CharacterLayoutInfo( const CharacterLayoutInfo& character );
157
158   /**
159    * Assignment operator.
160    */
161   CharacterLayoutInfo& operator=( const CharacterLayoutInfo& character );
162
163   // Metrics of the glyph.
164   Size        mSize;               ///< Height of the font and advance (the horizontal distance from the origin of the current character and the next one).
165   float       mBearing;            ///< Vertical distance from the baseline to the top of the glyph's boundary box.
166   float       mAscender;           ///< Distance from the base line to the top of the line.
167   float       mUnderlineThickness; ///< The underline's thickness.
168   float       mUnderlinePosition;  ///< The underline's position.
169
170   // Position and alignment offset. It depends on the lay-out.
171   Vector3     mPosition;           ///< Position within the text-view
172   Vector2     mOffset;             ///< Alignment and justification offset.
173
174   RenderableActor mGlyphActor;     ///< Handle to a text-actor.
175   float           mColorAlpha;     ///< Alpha component for the initial text color when text is faded.
176   GradientInfo*   mGradientInfo;   ///< Stores gradient info.
177
178   bool            mIsVisible:1;    ///< Whether the text-actor is visible.
179   bool            mSetText:1;      ///< Whether a new text needs to be set in the text-actor.
180   bool            mSetStyle:1;     ///< Whether a new style needs to be set in the text-actor.
181   bool            mIsColorGlyph:1; ///< Whether this character is an emoticon.
182 };
183 typedef std::vector<CharacterLayoutInfo> CharacterLayoutInfoContainer;
184
185 /**
186  * Layout information for a word.
187  */
188 struct WordLayoutInfo
189 {
190   /**
191    * Default constructor.
192    *
193    * Initializes all members to their default values.
194    */
195   WordLayoutInfo();
196
197   /**
198    * Default destructor.
199    *
200    * Clears all characters.
201    */
202   ~WordLayoutInfo();
203
204   /**
205    * Copy constructor.
206    */
207   WordLayoutInfo( const WordLayoutInfo& word );
208
209   /**
210    * Assignment operator.
211    */
212   WordLayoutInfo& operator=( const WordLayoutInfo& word );
213
214   Size                              mSize;                      ///< Size of the word.
215   float                             mAscender;                  ///< Max of all ascenders of all characters.
216   TextSeparatorType                 mType;                      ///< Whether this word is a word separator, a line separator or is not a separator.
217   std::size_t                       mFirstCharacter;            ///< Index to the first character of the word within the paragraph.
218   CharacterLayoutInfoContainer      mCharactersLayoutInfo;      ///< Layout info for all characters.
219 };
220 typedef std::vector<WordLayoutInfo> WordLayoutInfoContainer;
221
222 /**
223  * Stores the reordered layout for right to left text.
224  */
225 struct RightToLeftParagraphLayout
226 {
227   RightToLeftParagraphLayout()
228   : mWordsLayoutInfo(),
229     mText(),
230     mTextStyles(),
231     mPreviousLayoutCleared( false )
232   {
233   }
234
235   WordLayoutInfoContainer mWordsLayoutInfo;         ///< Layout info for all words.
236   Text                    mText;                    ///< Stores the text.
237   Vector<TextStyle*>      mTextStyles;              ///< Stores the style per each character.
238   bool                    mPreviousLayoutCleared:1; ///< Whether the previous right to left layout has been cleared.
239
240   /**
241    * Clears the word layout vector, the text and the vector of styles.
242    */
243   void Clear();
244 };
245
246 /**
247  * Layout information for a paragraph.
248  */
249 struct ParagraphLayoutInfo
250 {
251   /**
252    * Default constructor.
253    *
254    * Initializes all members to their default values.
255    */
256   ParagraphLayoutInfo();
257
258   /**
259    * Default destructor.
260    *
261    * Clears all words, deletes all text styles, the paragraph bidirectional info and all bidirectional infor for each line.
262    */
263   ~ParagraphLayoutInfo();
264
265   /**
266    * Copy constructor.
267    */
268   ParagraphLayoutInfo( const ParagraphLayoutInfo& paragraph );
269
270   /**
271    * Assignment operator.
272    */
273   ParagraphLayoutInfo& operator=( const ParagraphLayoutInfo& paragraph );
274
275   /**
276    * Deletes the bidirectional info for each line.
277    */
278   void ClearBidirectionalInfo();
279
280 private:
281
282   /**
283    * Deletes all text styles.
284    */
285   void ClearStyles();
286
287 public:
288   Size                                          mSize;                       ///< Size of the paragraph.
289   float                                         mAscender;                   ///< Max of all ascenders of all words.
290   float                                         mLineHeightOffset;           ///< Line height offset.
291   std::size_t                                   mFirstCharacter;             ///< Index to the first character of the paragraph.
292   std::size_t                                   mNumberOfCharacters;         ///< Stores the number of characters.
293   WordLayoutInfoContainer                       mWordsLayoutInfo;            ///< Layout info for all words.
294   Text                                          mText;                       ///< Stores the text.
295   Vector<TextStyle*>                            mTextStyles;                 ///< Stores the style per each character.
296   RightToLeftParagraphLayout*                   mRightToLeftLayout;          ///< Stores the reordered layout for the paragraph.
297   TextProcessor::BidirectionalParagraphInfo*    mBidirectionalParagraphInfo; ///< Contains bidirectional info for the whole paragraph. Set to NULL if the paragraph has left to right characters only.
298   Vector<TextProcessor::BidirectionalLineInfo*> mBidirectionalLinesInfo;     ///< Contains bidirectional info for each laid-out line.
299 };
300 typedef std::vector<ParagraphLayoutInfo> ParagraphLayoutInfoContainer;
301
302 /**
303  * Layout information for the whole text.
304  */
305 struct TextLayoutInfo
306 {
307   /**
308    * Default constructor.
309    *
310    * Initializes all members to their default values.
311    */
312   TextLayoutInfo();
313
314   /**
315    * Defualt destructor.
316    *
317    * Clears the paragraph vector, the ellipsis text and deletes all ellipsis styles.
318    */
319   ~TextLayoutInfo();
320
321   /**
322    * Copy constructor.
323    */
324   TextLayoutInfo( const TextLayoutInfo& text );
325
326   /**
327    * Assignment operator.
328    */
329   TextLayoutInfo& operator=( const TextLayoutInfo& text );
330
331 private:
332   /**
333    * Deletes all the ellipsis text styles.
334    */
335   void ClearStyles();
336
337 public:
338   Size                         mWholeTextSize;        ///< width and height of the whole text.
339   float                        mMaxWordWidth;         ///< maximum width between all words.
340   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.
341   std::size_t                  mNumberOfCharacters;   ///< Stores the number of characters.
342   ParagraphLayoutInfoContainer mParagraphsLayoutInfo; ///< Layout information for all paragraphs.
343   WordLayoutInfo               mEllipsizeLayoutInfo;  ///< Layout information for the ellipsize text.
344   Dali::Text                   mEllipsisText;         ///< The ellipsis text.
345   Vector<TextStyle*>           mEllipsisTextStyles;   ///< Stores the style per each character of the ellipsis text.
346 };
347
348 } // namespace TextViewProcessor
349
350 } // namespace Internal
351
352 } // namespace Toolkit
353
354 } // namespace Dali
355
356 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__