[dali_1.0.10] Merge branch 'tizen'
[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   bool            mIsRightToLeft:1; ///< Whether this character is right to left.
183 };
184 typedef std::vector<CharacterLayoutInfo> CharacterLayoutInfoContainer;
185
186 /**
187  * Layout information for a word.
188  */
189 struct WordLayoutInfo
190 {
191   /**
192    * Default constructor.
193    *
194    * Initializes all members to their default values.
195    */
196   WordLayoutInfo();
197
198   /**
199    * Default destructor.
200    *
201    * Clears all characters.
202    */
203   ~WordLayoutInfo();
204
205   /**
206    * Copy constructor.
207    */
208   WordLayoutInfo( const WordLayoutInfo& word );
209
210   /**
211    * Assignment operator.
212    */
213   WordLayoutInfo& operator=( const WordLayoutInfo& word );
214
215   Size                              mSize;                      ///< Size of the word.
216   float                             mAscender;                  ///< Max of all ascenders of all characters.
217   TextSeparatorType                 mType;                      ///< Whether this word is a word separator, a line separator or is not a separator.
218   std::size_t                       mFirstCharacter;            ///< Index to the first character of the word within the paragraph.
219   CharacterLayoutInfoContainer      mCharactersLayoutInfo;      ///< Layout info for all characters.
220 };
221 typedef std::vector<WordLayoutInfo> WordLayoutInfoContainer;
222
223 /**
224  * Stores the reordered layout for right to left text.
225  */
226 struct RightToLeftParagraphLayout
227 {
228   RightToLeftParagraphLayout()
229   : mWordsLayoutInfo(),
230     mText(),
231     mTextStyles(),
232     mPreviousLayoutCleared( false )
233   {
234   }
235
236   WordLayoutInfoContainer mWordsLayoutInfo;         ///< Layout info for all words.
237   Text                    mText;                    ///< Stores the text.
238   Vector<TextStyle*>      mTextStyles;              ///< Stores the style per each character.
239   bool                    mPreviousLayoutCleared:1; ///< Whether the previous right to left layout has been cleared.
240
241   /**
242    * Clears the word layout vector, the text and the vector of styles.
243    */
244   void Clear();
245 };
246
247 /**
248  * Layout information for a paragraph.
249  */
250 struct ParagraphLayoutInfo
251 {
252   /**
253    * Default constructor.
254    *
255    * Initializes all members to their default values.
256    */
257   ParagraphLayoutInfo();
258
259   /**
260    * Default destructor.
261    *
262    * Clears all words, deletes all text styles, the paragraph bidirectional info and all bidirectional infor for each line.
263    */
264   ~ParagraphLayoutInfo();
265
266   /**
267    * Copy constructor.
268    */
269   ParagraphLayoutInfo( const ParagraphLayoutInfo& paragraph );
270
271   /**
272    * Assignment operator.
273    */
274   ParagraphLayoutInfo& operator=( const ParagraphLayoutInfo& paragraph );
275
276   /**
277    * Deletes the bidirectional info for each line.
278    */
279   void ClearBidirectionalInfo();
280
281 private:
282
283   /**
284    * Deletes all text styles.
285    */
286   void ClearStyles();
287
288 public:
289   Size                                          mSize;                       ///< Size of the paragraph.
290   float                                         mAscender;                   ///< Max of all ascenders of all words.
291   float                                         mLineHeightOffset;           ///< Line height offset.
292   std::size_t                                   mFirstCharacter;             ///< Index to the first character of the paragraph.
293   std::size_t                                   mNumberOfCharacters;         ///< Stores the number of characters.
294   WordLayoutInfoContainer                       mWordsLayoutInfo;            ///< Layout info for all words.
295   Text                                          mText;                       ///< Stores the text.
296   Vector<TextStyle*>                            mTextStyles;                 ///< Stores the style per each character.
297   RightToLeftParagraphLayout*                   mRightToLeftLayout;          ///< Stores the reordered layout for the paragraph.
298   TextProcessor::BidirectionalParagraphInfo*    mBidirectionalParagraphInfo; ///< Contains bidirectional info for the whole paragraph. Set to NULL if the paragraph has left to right characters only.
299   Vector<TextProcessor::BidirectionalLineInfo*> mBidirectionalLinesInfo;     ///< Contains bidirectional info for each laid-out line.
300 };
301 typedef std::vector<ParagraphLayoutInfo> ParagraphLayoutInfoContainer;
302
303 /**
304  * Layout information for the whole text.
305  */
306 struct TextLayoutInfo
307 {
308   /**
309    * Default constructor.
310    *
311    * Initializes all members to their default values.
312    */
313   TextLayoutInfo();
314
315   /**
316    * Defualt destructor.
317    *
318    * Clears the paragraph vector, the ellipsis text and deletes all ellipsis styles.
319    */
320   ~TextLayoutInfo();
321
322   /**
323    * Copy constructor.
324    */
325   TextLayoutInfo( const TextLayoutInfo& text );
326
327   /**
328    * Assignment operator.
329    */
330   TextLayoutInfo& operator=( const TextLayoutInfo& text );
331
332 private:
333   /**
334    * Deletes all the ellipsis text styles.
335    */
336   void ClearStyles();
337
338 public:
339   Size                         mWholeTextSize;        ///< width and height of the whole text.
340   float                        mMaxWordWidth;         ///< maximum width between all words.
341   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.
342   std::size_t                  mNumberOfCharacters;   ///< Stores the number of characters.
343   ParagraphLayoutInfoContainer mParagraphsLayoutInfo; ///< Layout information for all paragraphs.
344   WordLayoutInfo               mEllipsizeLayoutInfo;  ///< Layout information for the ellipsize text.
345   Dali::Text                   mEllipsisText;         ///< The ellipsis text.
346   Vector<TextStyle*>           mEllipsisTextStyles;   ///< Stores the style per each character of the ellipsis text.
347 };
348
349 } // namespace TextViewProcessor
350
351 } // namespace Internal
352
353 } // namespace Toolkit
354
355 } // namespace Dali
356
357 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__