TextView - Rename Line to Paragraph.
[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  * Layout information for a character.
91  * It stores the position, size and ascender of its respective text-actor.
92  */
93 struct CharacterLayoutInfo
94 {
95   /**
96    * Default constructor.
97    *
98    * Initializes all members to their default values.
99    */
100   CharacterLayoutInfo();
101
102   /**
103    * Default destructor.
104    *
105    * Deletes the gradient info.
106    */
107   ~CharacterLayoutInfo();
108
109   /**
110    * Copy constructor.
111    */
112   CharacterLayoutInfo( const CharacterLayoutInfo& character );
113
114   /**
115    * Assignment operator.
116    */
117   CharacterLayoutInfo& operator=( const CharacterLayoutInfo& character );
118
119   // Natural size (metrics) of the glyph.
120   float       mHeight;             ///< Natural height of the character.
121   float       mAdvance;            ///< Natural horizontal distance from origin of current character and the next one.
122   float       mBearing;            ///< Natural vertical distance from the baseline to the top of the glyph's bbox.
123
124   // Size of the text-actor (may be modified by a scale factor).
125   Vector3     mPosition;           ///< Position within the text-view
126   Vector2     mOffset;             ///< Alignment and justification offset.
127   Size        mSize;               ///< Size of this character.
128   float       mAscender;           ///< Distance from the base line to the top of the line.
129   float       mUnderlineThickness; ///< The underline's thickness.
130   float       mUnderlinePosition;  ///< The underline's position.
131
132   RenderableActor             mGlyphActor;     ///< Handle to a text-actor.
133   MarkupProcessor::StyledText mStyledText;     ///< Stores the text and its style.
134   float                       mColorAlpha;     ///< Alpha component for the initial text color when text is faded.
135   Vector4                     mGradientColor;  ///< Gradient color.
136   Vector2                     mStartPoint;     ///< Gradient start point.
137   Vector2                     mEndPoint;       ///< Gradient end point.
138
139   bool                        mIsVisible:1;    ///< Whether the text-actor is visible.
140   bool                        mSetText:1;      ///< Whether a new text needs to be set in the text-actor.
141   bool                        mSetStyle:1;     ///< Whether a new style needs to be set in the text-actor.
142   bool                        mIsColorGlyph:1; ///< Whether this character is an emoticon.
143 };
144 typedef std::vector<CharacterLayoutInfo> CharacterLayoutInfoContainer;
145
146 /**
147  * Layout information for a word.
148  */
149 struct WordLayoutInfo
150 {
151   /**
152    * Default constructor.
153    *
154    * Initializes all members to their default values.
155    */
156   WordLayoutInfo();
157
158   /**
159    * Default destructor.
160    *
161    * Clears all characters.
162    */
163   ~WordLayoutInfo();
164
165   /**
166    * Copy constructor.
167    */
168   WordLayoutInfo( const WordLayoutInfo& word );
169
170   /**
171    * Assignment operator.
172    */
173   WordLayoutInfo& operator=( const WordLayoutInfo& word );
174
175   Size                              mSize;                      ///< Size of the word.
176   float                             mAscender;                  ///< Max of all ascenders of all characters.
177   TextSeparatorType                 mType;                      ///< Whether this word is a word separator, a line separator or is not a separator.
178   CharacterLayoutInfoContainer      mCharactersLayoutInfo;      ///< Layout info for all characters.
179 };
180 typedef std::vector<WordLayoutInfo> WordLayoutInfoContainer;
181
182 /**
183  * Layout information for a paragraph.
184  */
185 struct ParagraphLayoutInfo
186 {
187   /**
188    * Default constructor.
189    *
190    * Initializes all members to their default values.
191    */
192   ParagraphLayoutInfo();
193
194   /**
195    * Default destructor.
196    *
197    * Clears all words and deletes all text styles.
198    */
199   ~ParagraphLayoutInfo();
200
201   /**
202    * Copy constructor.
203    */
204   ParagraphLayoutInfo( const ParagraphLayoutInfo& paragraph );
205
206   /**
207    * Assignment operator.
208    */
209   ParagraphLayoutInfo& operator=( const ParagraphLayoutInfo& paragraph );
210
211   Size                                          mSize;                       ///< Size of the paragraph.
212   float                                         mAscender;                   ///< Max of all ascenders of all words.
213   float                                         mLineHeightOffset;           ///< Line height offset.
214   std::size_t                                   mNumberOfCharacters;         ///< Stores the number of characters.
215   WordLayoutInfoContainer                       mWordsLayoutInfo;            ///< Layout info for all words.
216 };
217 typedef std::vector<ParagraphLayoutInfo> ParagraphLayoutInfoContainer;
218
219 /**
220  * Layout information for the whole text.
221  */
222 struct TextLayoutInfo
223 {
224   /**
225    * Default constructor.
226    *
227    * Initializes all members to their default values.
228    */
229   TextLayoutInfo();
230
231   /**
232    * Copy constructor.
233    */
234   TextLayoutInfo( const TextLayoutInfo& text );
235
236   /**
237    * Assignment operator.
238    */
239   TextLayoutInfo& operator=( const TextLayoutInfo& text );
240
241   Size                         mWholeTextSize;        ///< width and height of the whole text.
242   float                        mMaxWordWidth;         ///< maximum width between all words.
243   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.
244   std::size_t                  mNumberOfCharacters;   ///< Stores the number of characters.
245   ParagraphLayoutInfoContainer mParagraphsLayoutInfo; ///< Layout information for all paragraphs.
246   WordLayoutInfo               mEllipsizeLayoutInfo;  ///< Layout information for the ellipsize text.
247 };
248
249 } // namespace TextViewProcessor
250
251 } // namespace Internal
252
253 } // namespace Toolkit
254
255 } // namespace Dali
256
257 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_PROCESSOR_TYPES_H__