Add api for get the internal media player handle of the VideoView
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / visual-model-impl.h
1 #ifndef DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H
2 #define DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H
3
4 /*
5  * Copyright (c) 2019 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/object/ref-object.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/internal/text/line-run.h>
30 #include <dali-toolkit/internal/text/color-run.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Text
39 {
40
41 class VisualModel;
42 typedef IntrusivePtr<VisualModel> VisualModelPtr;
43
44 /**
45  * @brief A visual text model contains layout specific information.
46  *
47  * This includes:
48  * - A series of glyphs in visual order i.e. after the bidirectional reordering.
49  * - The position of each glyph within a 2D bounding box.
50  */
51 class VisualModel : public RefObject
52 {
53 public:
54
55   /**
56    * @brief Create a new instance of a VisualModel.
57    *
58    * @return A pointer to a new VisualModel.
59    */
60   static VisualModelPtr New();
61
62   // Glyph interface.
63
64   /**
65    * @brief Creates the character to glyph conversion table.
66    *
67    * @pre The glyphs per character table needs to be created first.
68    *
69    * @param[in] startIndex The character from where the conversion table is created.
70    * @param[in] startGlyphIndex The glyph from where the conversion table is created.
71    * @param[in] numberOfCharacters The number of characters.
72    */
73   void CreateCharacterToGlyphTable( CharacterIndex startIndex,
74                                     GlyphIndex startGlyphIndex,
75                                     Length numberOfCharacters );
76
77   /**
78    * @brief Creates an array containing the number of glyphs per character.
79    *
80    * @param[in] startIndex The character from where the table is created.
81    * @param[in] startGlyphIndex The glyph from where the conversion table is created.
82    * @param[in] numberOfCharacters The number of characters.
83    */
84   void CreateGlyphsPerCharacterTable( CharacterIndex startIndex,
85                                       GlyphIndex startGlyphIndex,
86                                       Length numberOfCharacters );
87
88   /**
89    * @brief Retrieves glyphs in the given buffer.
90    *
91    * The size of the @p glyphs buffer needs to be big enough to copy the @p numberOfGlyphs.
92    * @param[out] glyphs Pointer to a buffer where the glyphs are copied.
93    * @param[in] glyphIndex Index to the first glyph.
94    * @param[in] numberOfGlyphs Number of glyphs to be copied.
95    */
96   void GetGlyphs( GlyphInfo* glyphs,
97                   GlyphIndex glyphIndex,
98                   Length numberOfGlyphs ) const;
99
100   // Position interface
101
102   /**
103    * @brief Retrieves the glyph positions.
104    *
105    * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
106    * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
107    * @param[in] glyphIndex Index to the first glyph position.
108    * @param[in] numberOfGlyphs The number of positions to be copied.
109    */
110   void GetGlyphPositions( Vector2* glyphPositions,
111                           GlyphIndex glyphIndex,
112                           Length numberOfGlyphs ) const;
113
114   // Line interface.
115
116   /**
117    * @brief Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
118    *
119    * @param[in] glyphIndex Index to the first glyph.
120    * @param[in] numberOfGlyphs The number of glyph.
121    * @param[out] firstLine Index to the line containing the glyph index.
122    * @param[out] numberOfLines The number of lines.
123    */
124   void GetNumberOfLines( GlyphIndex glyphIndex,
125                          Length numberOfGlyphs,
126                          LineIndex& firstLine,
127                          Length& numberOfLines ) const;
128
129   /**
130    * @brief Retrieves the lines where the given range of glyphs is laid out.
131    *
132    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
133    *
134    * @param[out] lines Pointer to a buffer where the lines are copied.
135    * @param[in] glyphIndex Index to the first glyphs of the range.
136    * @param[in] numberOfGlyphs Number of glyphs in the range.
137    */
138   void GetLinesOfGlyphRange( LineRun* lines,
139                              GlyphIndex glyphIndex,
140                              Length numberOfGlyphs ) const;
141
142   /**
143    * @brief Retrieves the line index where the character is laid-out.
144    *
145    * @param[in] characterIndex The character's index.
146    *
147    * @return The line index.
148    */
149   LineIndex GetLineOfCharacter( CharacterIndex characterIndex );
150
151   // Underline runs
152
153   /**
154    * @brief Retrieves the underline runs.
155    *
156    * @param[out] underlineRuns Pointer to a buffer where the underline runs are copied.
157    * @param[in] index Index of the first underline run to be copied.
158    * @param[in] numberOfRuns Number of underline runs to be copied.
159    */
160   void GetUnderlineRuns( GlyphRun* underlineRuns,
161                          UnderlineRunIndex index,
162                          Length numberOfRuns ) const;
163
164   // Size interface
165
166   /**
167    * @brief Sets the natural size.
168    *
169    * @param[in] size The text's natural size.
170    */
171   void SetNaturalSize( const Vector2& size  );
172
173   /**
174    * @brief Retrieves the natural size.
175    *
176    * @return The text's natural size.
177    */
178   const Vector2& GetNaturalSize() const;
179
180   /**
181    * @brief Sets the text's layout size.
182    *
183    * @param[in] size The text's size.
184    */
185   void SetLayoutSize( const Vector2& size );
186
187   /**
188    * @brief Retrieves the text's layout size.
189    *
190    * @return The text's size.
191    */
192   const Vector2& GetLayoutSize() const;
193
194   /**
195    * @brief Set the text's color
196    *
197    * @param[in] textColor The text's color
198    */
199   void SetTextColor( const Vector4& textColor );
200
201   /**
202    * @brief Retrieve the text's color
203    *
204    * @return The text's color
205    */
206   const Vector4& GetTextColor() const;
207
208   /**
209    * @brief Sets the text's shadow offset.
210    *
211    * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
212    */
213   void SetShadowOffset( const Vector2& shadowOffset );
214
215   /**
216    * @brief Retrieves the text's shadow offset.
217    *
218    * @return The text's shadow offset, 0,0 indicates no shadow.
219    */
220   const Vector2& GetShadowOffset() const;
221
222   /**
223    * @brief Sets the text's shadow color.
224    *
225    * @param[in] shadowColor The shadow color.
226    */
227   void SetShadowColor( const Vector4& shadowColor );
228
229   /**
230    * @brief Retrieves the text's shadow color.
231    *
232    * @return The text's shadow color.
233    */
234   const Vector4& GetShadowColor() const;
235
236   /**
237    * @brief Set the shadow blur radius.
238    *
239    * @param[in] shadowBlurRadius The shadow blur radius, 0,0 indicates no blur.
240    */
241   void SetShadowBlurRadius( const float& shadowBlurRadius );
242
243   /**
244    * @brief Retrieve the shadow blur radius.
245    *
246    * @return The shadow blur radius.
247    */
248   const float& GetShadowBlurRadius() const;
249
250   /**
251    * @brief Sets the text's underline color.
252    *
253    * @param[in] color The text's underline color.
254    */
255   void SetUnderlineColor( const Vector4& color );
256
257   /**
258    * @brief Retrieves the text's underline color.
259    *
260    * @return The text's underline color.
261    */
262   const Vector4& GetUnderlineColor() const;
263
264   /**
265    * @brief Sets the text underline flag.
266    *
267    * @param[in] enabled true if underlined.
268    */
269   void SetUnderlineEnabled( bool enabled );
270
271   /**
272    * @brief Returns whether the text is underlined or not.
273    *
274    * @return underline state.
275    */
276   bool IsUnderlineEnabled() const;
277
278   /**
279    * @brief Clear the caches.
280    */
281   void ClearCaches();
282
283   /**
284    * @brief Set the override used for underline height, 0 indicates height will be come from font metrics
285    *
286    * @param[in] height The height in pixels of the underline
287    */
288   void SetUnderlineHeight( float height );
289
290   /**
291    * @brief Retrieves the underline height override
292    *
293    * @return Returns the override height for an underline, 0 indicates that font metrics will determine the height
294    */
295   float GetUnderlineHeight() const;
296
297   /**
298    * @brief Retrieves the number of underline runs.
299    *
300    * @return The number of underline runs.
301    */
302   Length GetNumberOfUnderlineRuns() const;
303
304   /**
305    * @brief Set the outline color.
306    *
307    * @param[in] color color of outline.
308    */
309   void SetOutlineColor( const Vector4& color );
310
311   /**
312    * @brief Retrieve the outline color.
313    *
314    * @return The outline color.
315    */
316   const Vector4& GetOutlineColor() const;
317
318   /**
319    * @brief Set the outline width
320    *
321    * @param[in] width The width in pixels of the outline, 0 indicates no outline
322    */
323   void SetOutlineWidth( uint16_t width );
324
325   /**
326    * @brief Retrieves the width of an outline
327    *
328    * @return The width of the outline.
329    */
330   uint16_t GetOutlineWidth() const;
331
332   /**
333    * @brief Sets the text's background color.
334    *
335    * @param[in] color The text's background color.
336    */
337   void SetBackgroundColor( const Vector4& color );
338
339   /**
340    * @brief Retrieves the text's background color.
341    *
342    * @return The text's background color.
343    */
344   const Vector4& GetBackgroundColor() const;
345
346   /**
347    * @brief Sets whether the text has a background or not.
348    *
349    * @param[in] enabled true if the text has a background.
350    */
351   void SetBackgroundEnabled( bool enabled );
352
353   /**
354    * @brief Returns whether the text has a background or not.
355    *
356    * @return whether the text has a background or not.
357    */
358   bool IsBackgroundEnabled() const;
359
360 protected:
361
362   /**
363    * @brief A reference counted object may only be deleted by calling Unreference().
364    */
365   virtual ~VisualModel();
366
367 private:
368
369   /**
370    * @brief Private constructor.
371    */
372   VisualModel();
373
374   // Undefined
375   VisualModel( const VisualModel& handle );
376
377   // Undefined
378   VisualModel& operator=( const VisualModel& handle );
379
380 public:
381
382   Vector<GlyphInfo>      mGlyphs;               ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
383   Vector<CharacterIndex> mGlyphsToCharacters;   ///< For each glyph, the index of the first character.
384   Vector<GlyphIndex>     mCharactersToGlyph;    ///< For each character, the index of the first glyph.
385   Vector<Length>         mCharactersPerGlyph;   ///< For each glyph, the number of characters that form the glyph.
386   Vector<Length>         mGlyphsPerCharacter;   ///< For each character, the number of glyphs that are shaped.
387   Vector<Vector2>        mGlyphPositions;       ///< For each glyph, the position.
388   Vector<LineRun>        mLines;                ///< The laid out lines.
389   Vector<GlyphRun>       mUnderlineRuns;        ///< Runs of glyphs that are underlined.
390   Vector<Vector4>        mColors;               ///< Colors of the glyphs.
391   Vector<ColorIndex>     mColorIndices;         ///< Indices to the vector of colors for each glyphs.
392   Vector<Vector4>        mBackgroundColors;     ///< Background colors of the glyphs.
393   Vector<ColorIndex>     mBackgroundColorIndices; ///< Indices to the vector of background colors for each glyphs.
394
395   Vector4                mTextColor;            ///< The text color
396   Vector4                mShadowColor;          ///< Color of drop shadow
397   Vector4                mUnderlineColor;       ///< Color of underline
398   Vector4                mOutlineColor;         ///< Color of outline
399   Vector4                mBackgroundColor;      ///< Color of text background
400   Size                   mControlSize;          ///< The size of the UI control.
401   Vector2                mShadowOffset;         ///< Offset for drop shadow, 0 indicates no shadow
402   float                  mUnderlineHeight;      ///< Fixed height for underline to override font metrics.
403   float                  mShadowBlurRadius;     ///< Blur radius of shadow, 0 indicates no blur.
404   uint16_t               mOutlineWidth;         ///< Width of outline.
405
406 private:
407
408   Size                   mNaturalSize;        ///< Size of the text with no line wrapping.
409   Size                   mLayoutSize;         ///< Size of the laid-out text considering the layout properties set.
410
411   // Caches to increase performance in some consecutive operations.
412   LineIndex mCachedLineIndex; ///< Used to increase performance in consecutive calls to GetLineOfGlyph() or GetLineOfCharacter() with consecutive glyphs or characters.
413
414 public:
415
416   bool                   mUnderlineEnabled:1;   ///< Underline enabled flag
417   bool                   mUnderlineColorSet:1;  ///< Has the underline color been explicitly set?
418   bool                   mBackgroundEnabled:1;   ///< Background enabled flag
419 };
420
421 } // namespace Text
422
423 } // namespace Toolkit
424
425 } // namespace Dali
426
427 #endif // DALI_TOOLKIT_TEXT_VISUAL_MODEL_IMPL_H