[dali_1.0.7] 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/dali.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 direction is Right To Left or Left To Right.
39  */
40 enum Direction
41 {
42   LTR, ///< Left To Right direction.
43   RTL  ///< Right To Left direction.
44 };
45
46 /**
47  * Whether the text is a new line character, a white space or normal text.
48  */
49 enum TextSeparatorType
50 {
51   LineSeparator,
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   TextInfoIndices();
75
76   /**
77    * Constructor.
78    */
79   TextInfoIndices( std::size_t lineIndex,
80                    std::size_t groupIndex,
81                    std::size_t wordIndex,
82                    std::size_t characterIndex );
83
84   /**
85    * Equality operator.
86    * @param [in] indices The text-info indices to be compared.
87    *
88    * @return \e true if both indices are equal.
89    */
90   bool operator==( const TextInfoIndices& indices ) const;
91
92   std::size_t mLineIndex;
93   std::size_t mGroupIndex;
94   std::size_t mWordIndex;
95   std::size_t mCharacterIndex;
96 };
97
98 /**
99  * Layout information for a character.
100  * It stores the position, size and ascender of its respective text-actor.
101  */
102 struct CharacterLayoutInfo
103 {
104   /**
105    * Default constructor.
106    *
107    * Initializes all members to their default values.
108    */
109   CharacterLayoutInfo();
110
111   /**
112    * Copy constructor.
113    */
114   CharacterLayoutInfo( const CharacterLayoutInfo& character );
115
116   /**
117    * Assignment operator.
118    */
119   CharacterLayoutInfo& operator=( const CharacterLayoutInfo& character );
120
121   // Natural size (metrics) of the glyph.
122   float       mHeight;             ///< Natural height of the character.
123   float       mAdvance;            ///< Natural horizontal distance from origin of current character and the next one.
124   float       mBearing;            ///< Natural vertical distance from the baseline to the top of the glyph's bbox.
125
126   // Size of the text-actor (may be modified by a scale factor).
127   Vector3     mPosition;           ///< Position within the text-view
128   Vector2     mOffset;             ///< Alignment and justification offset.
129   Size        mSize;               ///< Size of this character.
130   float       mAscender;           ///< Distance from the base line to the top of the line.
131   float       mUnderlineThickness; ///< The underline's thickness.
132   float       mUnderlinePosition;  ///< The underline's position.
133
134   RenderableActor             mGlyphActor;     ///< Handle to a text-actor.
135   MarkupProcessor::StyledText mStyledText;     ///< Stores the text and its style.
136   float                       mColorAlpha;     ///< Alpha component for the initial text color when text is faded.
137   Vector4                     mGradientColor;  ///< Gradient color.
138   Vector2                     mStartPoint;     ///< Gradient start point.
139   Vector2                     mEndPoint;       ///< Gradient end point.
140
141   bool                        mIsVisible:1;    ///< Whether the text-actor is visible.
142   bool                        mSetText:1;      ///< Whether a new text needs to be set in the text-actor.
143   bool                        mSetStyle:1;     ///< Whether a new style needs to be set in the text-actor.
144   bool                        mIsColorGlyph:1; ///< Whether this character is an emoticon.
145 };
146 typedef std::vector<CharacterLayoutInfo> CharacterLayoutInfoContainer;
147
148 /**
149  * Layout information for a word.
150  */
151 struct WordLayoutInfo
152 {
153   /**
154    * Default constructor.
155    *
156    * Initializes all members to their default values.
157    */
158   WordLayoutInfo();
159
160   /**
161    * Copy constructor.
162    */
163   WordLayoutInfo( const WordLayoutInfo& word );
164
165   /**
166    * Assignment operator.
167    */
168   WordLayoutInfo& operator=( const WordLayoutInfo& word );
169
170   Size                              mSize;                      ///< Size of the word.
171   float                             mAscender;                  ///< Max of all ascenders of all characters.
172   TextSeparatorType                 mType;                      ///< Whether this word is a word separator, a line separator or is not a separator.
173   CharacterLayoutInfoContainer      mCharactersLayoutInfo;      ///< Layout info for all characters.
174 };
175 typedef std::vector<WordLayoutInfo> WordLayoutInfoContainer;
176
177 /**
178  * Layout information for a group of words.
179  */
180 struct WordGroupLayoutInfo
181 {
182   /**
183    * Default constructor.
184    *
185    * Initializes all members to their default values.
186    */
187   WordGroupLayoutInfo();
188
189   /**
190    * Copy constructor.
191    */
192   WordGroupLayoutInfo( const WordGroupLayoutInfo& group );
193
194   /**
195    * Assignment operator.
196    */
197   WordGroupLayoutInfo& operator=( const WordGroupLayoutInfo& group );
198
199   Size                    mSize;               ///< Size of the group of words.
200   float                   mAscender;           ///< Max of all ascenders of all words.
201   Direction               mDirection;          ///< Whether this group of words is Right To Left or Left To Right.
202   WordLayoutInfoContainer mWordsLayoutInfo;    ///< Layout info for all words.
203   std::size_t             mNumberOfCharacters; ///< Stores the number of characters.
204 };
205 typedef std::vector<WordGroupLayoutInfo> WordGroupLayoutInfoContainer;
206
207 /**
208  * Layout information for a line.
209  */
210 struct LineLayoutInfo
211 {
212   /**
213    * Default constructor.
214    *
215    * Initializes all members to their default values.
216    */
217   LineLayoutInfo();
218
219   /**
220    * Copy constructor.
221    */
222   LineLayoutInfo( const LineLayoutInfo& line );
223
224   /**
225    * Assignment operator.
226    */
227   LineLayoutInfo& operator=( const LineLayoutInfo& line );
228
229   Size                         mSize;                 ///< Size of the line.
230   float                        mAscender;             ///< Max of all ascenders of all groups of words.
231   float                        mLineHeightOffset;     ///< Line height offset.
232   WordGroupLayoutInfoContainer mWordGroupsLayoutInfo; ///< Layout info for all groups of words.
233   std::size_t                  mNumberOfCharacters;   ///< Stores the number of characters.
234 };
235 typedef std::vector<LineLayoutInfo> LineLayoutInfoContainer;
236
237 /**
238  * Layout information for the whole text.
239  */
240 struct TextLayoutInfo
241 {
242   /**
243    * Default constructor.
244    *
245    * Initializes all members to their default values.
246    */
247   TextLayoutInfo();
248
249   /**
250    * Copy constructor.
251    */
252   TextLayoutInfo( const TextLayoutInfo& text );
253
254   /**
255    * Assignment operator.
256    */
257   TextLayoutInfo& operator=( const TextLayoutInfo& text );
258
259   Size                    mWholeTextSize;                 ///< width and height of the whole text.
260   float                   mMaxWordWidth;                  ///< maximum width between all words.
261   LineLayoutInfoContainer mLinesLayoutInfo;               ///< Layout information for all lines.
262   std::size_t             mNumberOfCharacters;            ///< Stores the number of characters.
263   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.
264   WordLayoutInfo          mEllipsizeLayoutInfo;           ///< Layout information for the ellipsize text.
265 };
266
267 } // namespace TextViewProcessor
268
269 } // namespace Internal
270
271 } // namespace Toolkit
272
273 } // namespace Dali
274
275 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__