Merge "Prevention for being assigned NULL value" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / layouts / layout-engine.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
20
21 // EXTERNAL INCLUDES
22 #include <limits>
23 #include <dali/integration-api/debug.h>
24 #include <dali/devel-api/text-abstraction/font-client.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
28 #include <dali-toolkit/internal/text/cursor-helper-functions.h>
29 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
30 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Text
39 {
40
41 namespace
42 {
43
44 #if defined(DEBUG_ENABLED)
45   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_LAYOUT");
46 #endif
47
48 const float MAX_FLOAT = std::numeric_limits<float>::max();
49 const bool RTL = true;
50 const float CURSOR_WIDTH = 1.f;
51 const float LINE_SPACING= 0.f;
52
53 } //namespace
54
55 /**
56  * @brief Stores temporary layout info of the line.
57  */
58 struct LineLayout
59 {
60   LineLayout()
61   : glyphIndex( 0u ),
62     characterIndex( 0u ),
63     numberOfGlyphs( 0u ),
64     numberOfCharacters( 0u ),
65     length( 0.f ),
66     extraBearing( 0.f ),
67     extraWidth( 0.f ),
68     wsLengthEndOfLine( 0.f ),
69     ascender( 0.f ),
70     descender( MAX_FLOAT )
71   {}
72
73   ~LineLayout()
74   {}
75
76   void Clear()
77   {
78     glyphIndex = 0u;
79     characterIndex = 0u;
80     numberOfGlyphs = 0u;
81     numberOfCharacters = 0u;
82     length = 0.f;
83     extraBearing = 0.f;
84     extraWidth = 0.f;
85     wsLengthEndOfLine = 0.f;
86     ascender = 0.f;
87     descender = MAX_FLOAT;
88   }
89
90   GlyphIndex     glyphIndex;         ///< Index of the first glyph to be laid-out.
91   CharacterIndex characterIndex;     ///< Index of the first character to be laid-out.
92   Length         numberOfGlyphs;     ///< The number of glyph which fit in one line.
93   Length         numberOfCharacters; ///< The number of characters which fit in one line.
94   float          length;             ///< The addition of the advance metric of all the glyphs which fit in one line.
95   float          extraBearing;       ///< The extra width to be added to the line's length when the bearing of the first glyph is negative.
96   float          extraWidth;         ///< The extra width to be added to the line's length when the bearing + width of the last glyph is greater than the advance.
97   float          wsLengthEndOfLine;  ///< The length of the white spaces at the end of the line.
98   float          ascender;           ///< The maximum ascender of all fonts in the line.
99   float          descender;          ///< The minimum descender of all fonts in the line.
100 };
101
102 struct LayoutEngine::Impl
103 {
104   Impl()
105   : mLayout( LayoutEngine::SINGLE_LINE_BOX ),
106     mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
107     mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ),
108     mCursorWidth( CURSOR_WIDTH ),
109     mDefaultLineSpacing( LINE_SPACING ),
110     mEllipsisEnabled( false )
111   {
112   }
113
114   /**
115    * @brief Updates the line ascender and descender with the metrics of a new font.
116    *
117    * @param[in] fontId The id of the new font.
118    * @param[in,out] lineLayout The line layout.
119    */
120   void UpdateLineHeight( FontId fontId, LineLayout& lineLayout )
121   {
122     Text::FontMetrics fontMetrics;
123     mMetrics->GetFontMetrics( fontId, fontMetrics );
124
125     // Sets the maximum ascender.
126     if( fontMetrics.ascender > lineLayout.ascender )
127     {
128       lineLayout.ascender = fontMetrics.ascender;
129     }
130
131     // Sets the minimum descender.
132     if( fontMetrics.descender < lineLayout.descender )
133     {
134       lineLayout.descender = fontMetrics.descender;
135     }
136   }
137
138   /**
139    * @brief Merges a temporary line layout into the line layout.
140    *
141    * @param[in,out] lineLayout The line layout.
142    * @param[in] tmpLineLayout A temporary line layout.
143    */
144   void MergeLineLayout( LineLayout& lineLayout,
145                         const LineLayout& tmpLineLayout )
146   {
147     lineLayout.numberOfCharacters += tmpLineLayout.numberOfCharacters;
148     lineLayout.numberOfGlyphs += tmpLineLayout.numberOfGlyphs;
149     lineLayout.length += tmpLineLayout.length;
150
151     if( 0.f < tmpLineLayout.length )
152     {
153       lineLayout.length += lineLayout.wsLengthEndOfLine;
154
155       lineLayout.wsLengthEndOfLine = tmpLineLayout.wsLengthEndOfLine;
156     }
157     else
158     {
159       lineLayout.wsLengthEndOfLine += tmpLineLayout.wsLengthEndOfLine;
160     }
161
162     if( tmpLineLayout.ascender > lineLayout.ascender )
163     {
164       lineLayout.ascender = tmpLineLayout.ascender;
165     }
166
167     if( tmpLineLayout.descender < lineLayout.descender )
168     {
169       lineLayout.descender = tmpLineLayout.descender;
170     }
171   }
172
173   /**
174    * Retrieves the line layout for a given box width.
175    *
176    * @note This method lais out text as it were left to right. At this point is not possible to reorder the line
177    *       because the number of characters of the line is not known (one of the responsabilities of this method
178    *       is calculate that). Due to glyph's 'x' bearing, width and advance, when right to left or mixed right to left
179    *       and left to right text is laid-out, it can be small differences in the line length. One solution is to
180    *       reorder and re-lay out the text after this method and add or remove one extra glyph if needed. However,
181    *       this method calculates which are the first and last glyphs of the line (the ones that causes the
182    *       differences). This is a good point to check if there is problems with the text exceeding the boundaries
183    *       of the control when there is right to left text.
184    *
185    * @param[in] parameters The layout parameters.
186    * @param[out] lineLayout The line layout.
187    * @param[in,out] paragraphDirection in: the current paragraph's direction, out: the next paragraph's direction. Is set after a must break.
188    * @param[in] completelyFill Whether to completely fill the line ( even if the last word exceeds the boundaries ).
189    */
190   void GetLineLayoutForBox( const LayoutParameters& parameters,
191                             LineLayout& lineLayout,
192                             CharacterDirection& paragraphDirection,
193                             bool completelyFill )
194   {
195     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->GetLineLayoutForBox\n" );
196     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  initial glyph index : %d\n", lineLayout.glyphIndex );
197     // Stores temporary line layout which has not been added to the final line layout.
198     LineLayout tmpLineLayout;
199
200     const bool isMultiline = mLayout == MULTI_LINE_BOX;
201
202     // The last glyph to be laid-out.
203     const GlyphIndex lastGlyphOfParagraphPlusOne = parameters.startGlyphIndex + parameters.numberOfGlyphs;
204
205     // If the first glyph has a negative bearing its absolute value needs to be added to the line length.
206     // In the case the line starts with a right to left character, if the width is longer than the advance,
207     // the difference needs to be added to the line length.
208
209     // Check whether the first glyph comes from a character that is shaped in multiple glyphs.
210     const Length numberOfGLyphsInGroup = GetNumberOfGlyphsOfGroup( lineLayout.glyphIndex,
211                                                                    lastGlyphOfParagraphPlusOne,
212                                                                    parameters.charactersPerGlyphBuffer );
213
214     GlyphMetrics glyphMetrics;
215     GetGlyphsMetrics( lineLayout.glyphIndex,
216                       numberOfGLyphsInGroup,
217                       glyphMetrics,
218                       parameters.glyphsBuffer,
219                       mMetrics );
220
221     // Set the direction of the first character of the line.
222     lineLayout.characterIndex = *( parameters.glyphsToCharactersBuffer + lineLayout.glyphIndex );
223     const CharacterDirection firstCharacterDirection = ( NULL == parameters.characterDirectionBuffer ) ? false : *( parameters.characterDirectionBuffer + lineLayout.characterIndex );
224     CharacterDirection previousCharacterDirection = firstCharacterDirection;
225
226     const float extraWidth = glyphMetrics.xBearing + glyphMetrics.width - glyphMetrics.advance;
227     float tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
228
229     float tmpExtraBearing = ( 0.f > glyphMetrics.xBearing ) ? -glyphMetrics.xBearing : 0.f;
230
231     tmpLineLayout.length += mCursorWidth; // Added to give some space to the cursor.
232
233     // Calculate the line height if there is no characters.
234     FontId lastFontId = glyphMetrics.fontId;
235     UpdateLineHeight( lastFontId, tmpLineLayout );
236
237     bool oneWordLaidOut = false;
238
239     for( GlyphIndex glyphIndex = lineLayout.glyphIndex;
240          glyphIndex < lastGlyphOfParagraphPlusOne; )
241     {
242       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  glyph index : %d\n", glyphIndex );
243
244       // Check whether this glyph comes from a character that is shaped in multiple glyphs.
245       const Length numberOfGLyphsInGroup = GetNumberOfGlyphsOfGroup( glyphIndex,
246                                                                      lastGlyphOfParagraphPlusOne,
247                                                                      parameters.charactersPerGlyphBuffer );
248
249       GlyphMetrics glyphMetrics;
250       GetGlyphsMetrics( glyphIndex,
251                         numberOfGLyphsInGroup,
252                         glyphMetrics,
253                         parameters.glyphsBuffer,
254                         mMetrics );
255
256       const bool isLastGlyph = glyphIndex + numberOfGLyphsInGroup  == parameters.totalNumberOfGlyphs;
257
258       // Check if the font of the current glyph is the same of the previous one.
259       // If it's different the ascender and descender need to be updated.
260       if( lastFontId != glyphMetrics.fontId )
261       {
262         UpdateLineHeight( glyphMetrics.fontId, tmpLineLayout );
263         lastFontId = glyphMetrics.fontId;
264       }
265
266       // Get the character indices for the current glyph. The last character index is needed
267       // because there are glyphs formed by more than one character but their break info is
268       // given only for the last character.
269       const Length charactersPerGlyph = *( parameters.charactersPerGlyphBuffer + glyphIndex + numberOfGLyphsInGroup - 1u );
270       const bool hasCharacters = charactersPerGlyph > 0u;
271       const CharacterIndex characterFirstIndex = *( parameters.glyphsToCharactersBuffer + glyphIndex );
272       const CharacterIndex characterLastIndex = characterFirstIndex + ( hasCharacters ? charactersPerGlyph - 1u : 0u );
273
274       // Get the line break info for the current character.
275       const LineBreakInfo lineBreakInfo = hasCharacters ? *( parameters.lineBreakInfoBuffer + characterLastIndex ) : TextAbstraction::LINE_NO_BREAK;
276
277       // Get the word break info for the current character.
278       const WordBreakInfo wordBreakInfo = *( parameters.wordBreakInfoBuffer + characterLastIndex );
279
280       // Increase the number of characters.
281       tmpLineLayout.numberOfCharacters += charactersPerGlyph;
282
283       // Increase the number of glyphs.
284       tmpLineLayout.numberOfGlyphs += numberOfGLyphsInGroup;
285
286       // Check whether is a white space.
287       const Character character = *( parameters.textBuffer + characterFirstIndex );
288       const bool isWhiteSpace = TextAbstraction::IsWhiteSpace( character );
289
290       // Used to restore the temporal line layout when a single word does not fit in the control's width and is split by character.
291       const float previousTmpLineLength = tmpLineLayout.length;
292       const float previousTmpExtraBearing = tmpExtraBearing;
293       const float previousTmpExtraWidth = tmpExtraWidth;
294
295       // Get the character's direction.
296       const CharacterDirection characterDirection = ( NULL == parameters.characterDirectionBuffer ) ? false : *( parameters.characterDirectionBuffer + characterFirstIndex );
297
298       // Increase the accumulated length.
299       if( isWhiteSpace )
300       {
301         // Add the length to the length of white spaces at the end of the line.
302         tmpLineLayout.wsLengthEndOfLine += glyphMetrics.advance; // The advance is used as the width is always zero for the white spaces.
303       }
304       else
305       {
306         // Add as well any previous white space length.
307         tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine + glyphMetrics.advance;
308
309         // An extra space may be added to the line for the first and last glyph of the line.
310         // If the bearing of the first glyph is negative, its positive value needs to be added.
311         // If the bearing plus the width of the last glyph is greater than the advance, the difference
312         // needs to be added.
313
314         if( characterDirection == paragraphDirection )
315         {
316           if( RTL == characterDirection )
317           {
318             //       <--
319             // |   Rrrrr|
320             // or
321             // |  Rllrrr|
322             // or
323             // |lllrrrrr|
324             // |     Rll|
325             //
326
327             tmpExtraBearing = ( 0.f > glyphMetrics.xBearing ) ? -glyphMetrics.xBearing : 0.f;
328           }
329           else // LTR
330           {
331             //  -->
332             // |lllL    |
333             // or
334             // |llrrL   |
335             // or
336             // |lllllrrr|
337             // |rrL     |
338             //
339
340             const float extraWidth = glyphMetrics.xBearing + glyphMetrics.width - glyphMetrics.advance;
341             tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
342           }
343         }
344         else
345         {
346           if( characterDirection != previousCharacterDirection )
347           {
348             if( RTL == characterDirection )
349             {
350               //  -->
351               // |lllR    |
352
353               const float extraWidth = glyphMetrics.xBearing + glyphMetrics.width - glyphMetrics.advance;
354               tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
355             }
356             else // LTR
357             {
358               //       <--
359               // |   Lrrrr|
360
361               tmpExtraBearing = ( 0.f > glyphMetrics.xBearing ) ? -glyphMetrics.xBearing : 0.f;
362             }
363           }
364           else if( characterDirection == firstCharacterDirection )
365           {
366             if( RTL == characterDirection )
367             {
368               //  -->
369               // |llllllrr|
370               // |Rr      |
371
372               tmpExtraBearing = ( 0.f > glyphMetrics.xBearing ) ? -glyphMetrics.xBearing : 0.f;
373             }
374             else // LTR
375             {
376               //       <--
377               // |llllrrrr|
378               // |     llL|
379
380               const float extraWidth = glyphMetrics.xBearing + glyphMetrics.width - glyphMetrics.advance;
381               tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
382             }
383           }
384         }
385
386         // Clear the white space length at the end of the line.
387         tmpLineLayout.wsLengthEndOfLine = 0.f;
388       }
389
390       // Check if the accumulated length fits in the width of the box.
391       if( ( completelyFill || isMultiline ) && !isWhiteSpace &&
392           ( tmpExtraBearing + lineLayout.length + lineLayout.wsLengthEndOfLine + tmpLineLayout.length + tmpExtraWidth > parameters.boundingBox.width ) )
393       {
394         // Current word does not fit in the box's width.
395         if( !oneWordLaidOut || completelyFill )
396         {
397           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  Break the word by character\n" );
398
399           // The word doesn't fit in the control's width. It needs to be split by character.
400           if( tmpLineLayout.numberOfGlyphs > 0u )
401           {
402             tmpLineLayout.numberOfCharacters -= charactersPerGlyph;
403             tmpLineLayout.numberOfGlyphs -= numberOfGLyphsInGroup;
404             tmpLineLayout.length = previousTmpLineLength;
405             tmpExtraBearing = previousTmpExtraBearing;
406             tmpExtraWidth = previousTmpExtraWidth;
407           }
408
409           // Add part of the word to the line layout.
410           MergeLineLayout( lineLayout, tmpLineLayout );
411         }
412         else
413         {
414           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  Current word does not fit.\n" );
415         }
416
417         lineLayout.extraBearing = tmpExtraBearing;
418         lineLayout.extraWidth = tmpExtraWidth;
419
420         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox.\n" );
421
422         return;
423       }
424
425       if( ( isMultiline || isLastGlyph ) &&
426           ( TextAbstraction::LINE_MUST_BREAK == lineBreakInfo ) )
427       {
428         // Must break the line. Update the line layout and return.
429         MergeLineLayout( lineLayout, tmpLineLayout );
430
431         // Set the next paragraph's direction.
432         if( !isLastGlyph &&
433             ( NULL != parameters.characterDirectionBuffer ) )
434         {
435           paragraphDirection = *( parameters.characterDirectionBuffer + 1u + characterLastIndex );
436         }
437
438         lineLayout.extraBearing = tmpExtraBearing;
439         lineLayout.extraWidth = tmpExtraWidth;
440
441         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  Must break\n" );
442         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
443
444         return;
445       }
446
447       if( isMultiline &&
448           ( TextAbstraction::WORD_BREAK == wordBreakInfo ) )
449       {
450         oneWordLaidOut = true;
451         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  One word laid-out\n" );
452
453         // Current glyph is the last one of the current word.
454         // Add the temporal layout to the current one.
455         MergeLineLayout( lineLayout, tmpLineLayout );
456
457         tmpLineLayout.Clear();
458       }
459
460       previousCharacterDirection = characterDirection;
461       glyphIndex += numberOfGLyphsInGroup;
462     }
463
464     lineLayout.extraBearing = tmpExtraBearing;
465     lineLayout.extraWidth = tmpExtraWidth;
466
467     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
468   }
469
470   void SetGlyphPositions( const GlyphInfo* const glyphsBuffer,
471                           Length numberOfGlyphs,
472                           Vector2* glyphPositionsBuffer )
473   {
474     // Traverse the glyphs and set the positions.
475
476     // Check if the x bearing of the first character is negative.
477     // If it has a negative x bearing, it will exceed the boundaries of the actor,
478     // so the penX position needs to be moved to the right.
479
480     const GlyphInfo& glyph = *glyphsBuffer;
481     float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
482
483     for( GlyphIndex i = 0u; i < numberOfGlyphs; ++i )
484     {
485       const GlyphInfo& glyph = *( glyphsBuffer + i );
486       Vector2& position = *( glyphPositionsBuffer + i );
487
488       position.x = penX + glyph.xBearing;
489       position.y = -glyph.yBearing;
490
491       penX += glyph.advance;
492     }
493   }
494
495   /**
496    * @brief Resizes the line buffer.
497    *
498    * @param[in,out] lines The vector of lines. Used when the layout is created from scratch.
499    * @param[in,out] newLines The vector of lines used instead of @p lines when the layout is updated.
500    * @param[in,out] linesCapacity The capacity of the vector (either lines or newLines).
501    * @param[in] updateCurrentBuffer Whether the layout is updated.
502    *
503    * @return Pointer to either lines or newLines.
504    */
505   LineRun* ResizeLinesBuffer( Vector<LineRun>& lines,
506                               Vector<LineRun>& newLines,
507                               Length& linesCapacity,
508                               bool updateCurrentBuffer )
509   {
510     LineRun* linesBuffer = NULL;
511     // Reserve more space for the next lines.
512     linesCapacity *= 2u;
513     if( updateCurrentBuffer )
514     {
515       newLines.Resize( linesCapacity );
516       linesBuffer = newLines.Begin();
517     }
518     else
519     {
520       lines.Resize( linesCapacity );
521       linesBuffer = lines.Begin();
522     }
523
524     return linesBuffer;
525   }
526
527   /**
528    * Ellipsis a line if it exceeds the width's of the bounding box.
529    *
530    * @param[in] layoutParameters The parameters needed to layout the text.
531    * @param[in] layout The line layout.
532    * @param[in,out] layoutSize The text's layout size.
533    * @param[in,out] linesBuffer Pointer to the line's buffer.
534    * @param[in,out] glyphPositionsBuffer Pointer to the position's buffer.
535    * @param[in,out] numberOfLines The number of laid-out lines.
536    * @param[in] penY The vertical layout position.
537    * @param[in] currentParagraphDirection The current paragraph's direction.
538    *
539    * return Whether the line is ellipsized.
540    */
541   bool EllipsisLine( const LayoutParameters& layoutParameters,
542                      const LineLayout& layout,
543                      Size& layoutSize,
544                      LineRun* linesBuffer,
545                      Vector2* glyphPositionsBuffer,
546                      Length& numberOfLines,
547                      float penY,
548                      CharacterDirection currentParagraphDirection )
549   {
550     const bool ellipsis = ( ( penY - layout.descender > layoutParameters.boundingBox.height ) ||
551                             ( ( mLayout == SINGLE_LINE_BOX ) &&
552                               ( layout.extraBearing + layout.length + layout.extraWidth > layoutParameters.boundingBox.width ) ) );
553
554     if( ellipsis )
555     {
556       // Do not layout more lines if ellipsis is enabled.
557
558       // The last line needs to be completely filled with characters.
559       // Part of a word may be used.
560
561       LineRun* lineRun = NULL;
562       LineLayout ellipsisLayout;
563       if( 0u != numberOfLines )
564       {
565         // Get the last line and layout it again with the 'completelyFill' flag to true.
566         lineRun = linesBuffer + ( numberOfLines - 1u );
567
568         penY -= layout.ascender - lineRun->descender;
569
570         ellipsisLayout.glyphIndex = lineRun->glyphRun.glyphIndex;
571       }
572       else
573       {
574         // At least there is space reserved for one line.
575         lineRun = linesBuffer;
576
577         lineRun->glyphRun.glyphIndex = 0u;
578         ellipsisLayout.glyphIndex = 0u;
579
580         ++numberOfLines;
581       }
582
583       GetLineLayoutForBox( layoutParameters,
584                            ellipsisLayout,
585                            currentParagraphDirection,
586                            true );
587
588       lineRun->glyphRun.numberOfGlyphs = ellipsisLayout.numberOfGlyphs;
589       lineRun->characterRun.characterIndex = ellipsisLayout.characterIndex;
590       lineRun->characterRun.numberOfCharacters = ellipsisLayout.numberOfCharacters;
591       lineRun->width = ellipsisLayout.length;
592       lineRun->extraLength =  ( ellipsisLayout.wsLengthEndOfLine > 0.f ) ? ellipsisLayout.wsLengthEndOfLine - ellipsisLayout.extraWidth : 0.f;
593       lineRun->ascender = ellipsisLayout.ascender;
594       lineRun->descender = ellipsisLayout.descender;
595       lineRun->direction = !RTL;
596       lineRun->ellipsis = true;
597
598       layoutSize.width = layoutParameters.boundingBox.width;
599       layoutSize.height += ( lineRun->ascender + -lineRun->descender );
600
601       SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun->glyphRun.glyphIndex,
602                          ellipsisLayout.numberOfGlyphs,
603                          glyphPositionsBuffer + lineRun->glyphRun.glyphIndex - layoutParameters.startGlyphIndex );
604     }
605
606     return ellipsis;
607   }
608
609   /**
610    * @brief Updates the text layout with a new laid-out line.
611    *
612    * @param[in] layoutParameters The parameters needed to layout the text.
613    * @param[in] layout The line layout.
614    * @param[in,out] layoutSize The text's layout size.
615    * @param[in,out] linesBuffer Pointer to the line's buffer.
616    * @param[in] index Index to the vector of glyphs.
617    * @param[in,out] numberOfLines The number of laid-out lines.
618    * @param[in] isLastLine Whether the laid-out line is the last one.
619    */
620   void UpdateTextLayout( const LayoutParameters& layoutParameters,
621                          const LineLayout& layout,
622                          Size& layoutSize,
623                          LineRun* linesBuffer,
624                          GlyphIndex index,
625                          Length& numberOfLines,
626                          bool isLastLine )
627   {
628     LineRun& lineRun = *( linesBuffer + numberOfLines );
629     ++numberOfLines;
630
631     lineRun.glyphRun.glyphIndex = index;
632     lineRun.glyphRun.numberOfGlyphs = layout.numberOfGlyphs;
633     lineRun.characterRun.characterIndex = layout.characterIndex;
634     lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters;
635     if( isLastLine && !layoutParameters.isLastNewParagraph )
636     {
637       const float width = layout.extraBearing + layout.length + layout.extraWidth + layout.wsLengthEndOfLine;
638       if( MULTI_LINE_BOX == mLayout )
639       {
640         lineRun.width = ( width > layoutParameters.boundingBox.width ) ? layoutParameters.boundingBox.width : width;
641       }
642       else
643       {
644         lineRun.width = width;
645       }
646
647       lineRun.extraLength = 0.f;
648     }
649     else
650     {
651       lineRun.width = layout.extraBearing + layout.length + layout.extraWidth;
652       lineRun.extraLength = ( layout.wsLengthEndOfLine > 0.f ) ? layout.wsLengthEndOfLine - layout.extraWidth : 0.f;
653     }
654     lineRun.ascender = layout.ascender;
655     lineRun.descender = layout.descender;
656     lineRun.direction = !RTL;
657     lineRun.ellipsis = false;
658
659     // Update the actual size.
660     if( lineRun.width > layoutSize.width )
661     {
662       layoutSize.width = lineRun.width;
663     }
664
665     layoutSize.height += ( lineRun.ascender + -lineRun.descender );
666   }
667
668   /**
669    * @brief Updates the text layout with the last laid-out line.
670    *
671    * @param[in] layoutParameters The parameters needed to layout the text.
672    * @param[in] characterIndex The character index of the line.
673    * @param[in] glyphIndex The glyph index of the line.
674    * @param[in,out] layoutSize The text's layout size.
675    * @param[in,out] linesBuffer Pointer to the line's buffer.
676    * @param[in,out] numberOfLines The number of laid-out lines.
677    */
678   void UpdateTextLayout( const LayoutParameters& layoutParameters,
679                          CharacterIndex characterIndex,
680                          GlyphIndex glyphIndex,
681                          Size& layoutSize,
682                          LineRun* linesBuffer,
683                          Length& numberOfLines )
684   {
685     // Need to add a new line with no characters but with height to increase the layoutSize.height
686     const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u );
687
688     Text::FontMetrics fontMetrics;
689     mMetrics->GetFontMetrics( glyphInfo.fontId, fontMetrics );
690
691     LineRun& lineRun = *( linesBuffer + numberOfLines );
692     ++numberOfLines;
693
694     lineRun.glyphRun.glyphIndex = glyphIndex;
695     lineRun.glyphRun.numberOfGlyphs = 0u;
696     lineRun.characterRun.characterIndex = characterIndex;
697     lineRun.characterRun.numberOfCharacters = 0u;
698     lineRun.width = 0.f;
699     lineRun.ascender = fontMetrics.ascender;
700     lineRun.descender = fontMetrics.descender;
701     lineRun.extraLength = 0.f;
702     lineRun.alignmentOffset = 0.f;
703     lineRun.direction = !RTL;
704     lineRun.ellipsis = false;
705
706     layoutSize.height += ( lineRun.ascender + -lineRun.descender );
707   }
708
709   /**
710    * @brief Updates the text's layout size adding the size of the previously laid-out lines.
711    *
712    * @param[in] lines The vector of lines (before the new laid-out lines are inserted).
713    * @param[in,out] layoutSize The text's layout size.
714    */
715   void UpdateLayoutSize( const Vector<LineRun>& lines,
716                          Size& layoutSize )
717   {
718     for( Vector<LineRun>::ConstIterator it = lines.Begin(),
719            endIt = lines.End();
720          it != endIt;
721          ++it )
722     {
723       const LineRun& line = *it;
724
725       if( line.width > layoutSize.width )
726       {
727         layoutSize.width = line.width;
728       }
729
730       layoutSize.height += ( line.ascender + -line.descender );
731     }
732   }
733
734   /**
735    * @brief Updates the indices of the character and glyph runs of the lines before the new lines are inserted.
736    *
737    * @param[in] layoutParameters The parameters needed to layout the text.
738    * @param[in,out] lines The vector of lines (before the new laid-out lines are inserted).
739    * @param[in] characterOffset The offset to be added to the runs of characters.
740    * @param[in] glyphOffset The offset to be added to the runs of glyphs.
741    */
742   void UpdateLineIndexOffsets( const LayoutParameters& layoutParameters,
743                                Vector<LineRun>& lines,
744                                Length characterOffset,
745                                Length glyphOffset )
746   {
747     // Update the glyph and character runs.
748     for( Vector<LineRun>::Iterator it = lines.Begin() + layoutParameters.startLineIndex,
749            endIt = lines.End();
750          it != endIt;
751          ++it )
752     {
753       LineRun& line = *it;
754
755       line.glyphRun.glyphIndex = glyphOffset;
756       line.characterRun.characterIndex = characterOffset;
757
758       glyphOffset += line.glyphRun.numberOfGlyphs;
759       characterOffset += line.characterRun.numberOfCharacters;
760     }
761   }
762
763   bool LayoutText( const LayoutParameters& layoutParameters,
764                    Vector<Vector2>& glyphPositions,
765                    Vector<LineRun>& lines,
766                    Size& layoutSize )
767   {
768     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->LayoutText\n" );
769     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  box size %f, %f\n", layoutParameters.boundingBox.width, layoutParameters.boundingBox.height );
770
771     if( 0u == layoutParameters.numberOfGlyphs )
772     {
773       // Add an extra line if the last character is a new paragraph character and the last line doesn't have zero characters.
774       if( layoutParameters.isLastNewParagraph )
775       {
776         Length numberOfLines = lines.Count();
777         if( 0u != numberOfLines )
778         {
779           const LineRun& lastLine = *( lines.End() - 1u );
780
781           if( 0u != lastLine.characterRun.numberOfCharacters )
782           {
783             // Need to add a new line with no characters but with height to increase the layoutSize.height
784             LineRun newLine;
785             Initialize( newLine );
786             lines.PushBack( newLine );
787
788             UpdateTextLayout( layoutParameters,
789                               lastLine.characterRun.characterIndex + lastLine.characterRun.numberOfCharacters,
790                               lastLine.glyphRun.glyphIndex + lastLine.glyphRun.numberOfGlyphs,
791                               layoutSize,
792                               lines.Begin(),
793                               numberOfLines );
794           }
795         }
796       }
797
798       // Nothing else do if there are no glyphs to layout.
799       return false;
800     }
801
802     const GlyphIndex lastGlyphPlusOne = layoutParameters.startGlyphIndex + layoutParameters.numberOfGlyphs;
803
804     // In a previous layout, an extra line with no characters may have been added if the text ended with a new paragraph character.
805     // This extra line needs to be removed.
806     if( 0u != lines.Count() )
807     {
808       Vector<LineRun>::Iterator lastLine = lines.End() - 1u;
809
810       if( ( 0u == lastLine->characterRun.numberOfCharacters ) &&
811           ( lastGlyphPlusOne == layoutParameters.totalNumberOfGlyphs ) )
812       {
813         lines.Remove( lastLine );
814       }
815     }
816
817     // Set the first paragraph's direction.
818     CharacterDirection paragraphDirection = ( NULL != layoutParameters.characterDirectionBuffer ) ? *layoutParameters.characterDirectionBuffer : !RTL;
819
820     // Whether the layout is being updated or set from scratch.
821     const bool updateCurrentBuffer = layoutParameters.numberOfGlyphs < layoutParameters.totalNumberOfGlyphs;
822
823     Vector2* glyphPositionsBuffer = NULL;
824     Vector<Vector2> newGlyphPositions;
825
826     LineRun* linesBuffer = NULL;
827     Vector<LineRun> newLines;
828
829     // Estimate the number of lines.
830     Length linesCapacity = std::max( 1u, layoutParameters.estimatedNumberOfLines );
831     Length numberOfLines = 0u;
832
833     if( updateCurrentBuffer )
834     {
835       newGlyphPositions.Resize( layoutParameters.numberOfGlyphs );
836       glyphPositionsBuffer = newGlyphPositions.Begin();
837
838       newLines.Resize( linesCapacity );
839       linesBuffer = newLines.Begin();
840     }
841     else
842     {
843       glyphPositionsBuffer = glyphPositions.Begin();
844
845       lines.Resize( linesCapacity );
846       linesBuffer = lines.Begin();
847     }
848
849     float penY = CalculateLineOffset( lines,
850                                       layoutParameters.startLineIndex );
851
852     for( GlyphIndex index = layoutParameters.startGlyphIndex; index < lastGlyphPlusOne; )
853     {
854       CharacterDirection currentParagraphDirection = paragraphDirection;
855
856       // Get the layout for the line.
857       LineLayout layout;
858       layout.glyphIndex = index;
859       GetLineLayoutForBox( layoutParameters,
860                            layout,
861                            paragraphDirection,
862                            false );
863
864       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "           glyph index %d\n", layout.glyphIndex );
865       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "       character index %d\n", layout.characterIndex );
866       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "      number of glyphs %d\n", layout.numberOfGlyphs );
867       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  number of characters %d\n", layout.numberOfCharacters );
868       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "                length %f\n", layout.length );
869
870       if( 0u == layout.numberOfGlyphs )
871       {
872         // The width is too small and no characters are laid-out.
873         DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--LayoutText width too small!\n\n" );
874
875         lines.Resize( numberOfLines );
876         return false;
877       }
878
879       // Set the line position. Discard if ellipsis is enabled and the position exceeds the boundaries
880       // of the box.
881       penY += layout.ascender;
882
883       DALI_LOG_INFO( gLogFilter, Debug::Verbose, "  pen y %f\n", penY );
884
885       bool ellipsis = false;
886       if( mEllipsisEnabled )
887       {
888         // Does the ellipsis of the last line.
889         ellipsis = EllipsisLine( layoutParameters,
890                                  layout,
891                                  layoutSize,
892                                  linesBuffer,
893                                  glyphPositionsBuffer,
894                                  numberOfLines,
895                                  penY,
896                                  currentParagraphDirection );
897       }
898
899       if( ellipsis )
900       {
901         // No more lines to layout.
902         break;
903       }
904       else
905       {
906         // Whether the last line has been laid-out.
907         const bool isLastLine = index + layout.numberOfGlyphs == layoutParameters.totalNumberOfGlyphs;
908
909         if( numberOfLines == linesCapacity )
910         {
911           // Reserve more space for the next lines.
912           linesBuffer = ResizeLinesBuffer( lines,
913                                            newLines,
914                                            linesCapacity,
915                                            updateCurrentBuffer );
916         }
917
918         // Updates the current text's layout with the line's layout.
919         UpdateTextLayout( layoutParameters,
920                           layout,
921                           layoutSize,
922                           linesBuffer,
923                           index,
924                           numberOfLines,
925                           isLastLine );
926
927         const GlyphIndex nextIndex = index + layout.numberOfGlyphs;
928
929         if( ( nextIndex == layoutParameters.totalNumberOfGlyphs ) &&
930             layoutParameters.isLastNewParagraph &&
931             ( mLayout == MULTI_LINE_BOX ) )
932         {
933           // The last character of the text is a new paragraph character.
934           // An extra line with no characters is added to increase the text's height
935           // in order to place the cursor.
936
937           if( numberOfLines == linesCapacity )
938           {
939             // Reserve more space for the next lines.
940             linesBuffer = ResizeLinesBuffer( lines,
941                                              newLines,
942                                              linesCapacity,
943                                              updateCurrentBuffer );
944           }
945
946           UpdateTextLayout( layoutParameters,
947                             layout.characterIndex + layout.numberOfCharacters,
948                             index + layout.numberOfGlyphs,
949                             layoutSize,
950                             linesBuffer,
951                             numberOfLines );
952         } // whether to add a last line.
953
954         // Sets the positions of the glyphs.
955         SetGlyphPositions( layoutParameters.glyphsBuffer + index,
956                            layout.numberOfGlyphs,
957                            glyphPositionsBuffer + index - layoutParameters.startGlyphIndex );
958
959         // Updates the vertical pen's position.
960         penY += -layout.descender;
961
962         // Increase the glyph index.
963         index = nextIndex;
964       } // no ellipsis
965     } // end for() traversing glyphs.
966
967     if( updateCurrentBuffer )
968     {
969       glyphPositions.Insert( glyphPositions.Begin() + layoutParameters.startGlyphIndex,
970                              newGlyphPositions.Begin(),
971                              newGlyphPositions.End() );
972       glyphPositions.Resize( layoutParameters.totalNumberOfGlyphs );
973
974       newLines.Resize( numberOfLines );
975
976       // Current text's layout size adds only the newly laid-out lines.
977       // Updates the layout size with the previously laid-out lines.
978       UpdateLayoutSize( lines,
979                         layoutSize );
980
981       if( 0u != newLines.Count() )
982       {
983         const LineRun& lastLine = *( newLines.End() - 1u );
984
985         const Length characterOffset = lastLine.characterRun.characterIndex + lastLine.characterRun.numberOfCharacters;
986         const Length glyphOffset = lastLine.glyphRun.glyphIndex + lastLine.glyphRun.numberOfGlyphs;
987
988         // Update the indices of the runs before the new laid-out lines are inserted.
989         UpdateLineIndexOffsets( layoutParameters,
990                                 lines,
991                                 characterOffset,
992                                 glyphOffset );
993
994         // Insert the lines.
995         lines.Insert( lines.Begin() + layoutParameters.startLineIndex,
996                       newLines.Begin(),
997                       newLines.End() );
998       }
999     }
1000     else
1001     {
1002       lines.Resize( numberOfLines );
1003     }
1004
1005     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--LayoutText\n\n" );
1006
1007     return true;
1008   }
1009
1010   void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
1011                                  CharacterIndex startIndex,
1012                                  Length numberOfCharacters,
1013                                  Vector<Vector2>& glyphPositions )
1014   {
1015     const CharacterIndex lastCharacterIndex = startIndex + numberOfCharacters;
1016
1017     // Traverses the paragraphs with right to left characters.
1018     for( LineIndex lineIndex = 0u; lineIndex < layoutParameters.numberOfBidirectionalInfoRuns; ++lineIndex )
1019     {
1020       const BidirectionalLineInfoRun& bidiLine = *( layoutParameters.lineBidirectionalInfoRunsBuffer + lineIndex );
1021
1022       if( startIndex >= bidiLine.characterRun.characterIndex + bidiLine.characterRun.numberOfCharacters )
1023       {
1024         // Do not reorder the line if it has been already reordered.
1025         continue;
1026       }
1027
1028       if( bidiLine.characterRun.characterIndex >= lastCharacterIndex )
1029       {
1030         // Do not reorder the lines after the last requested character.
1031         break;
1032       }
1033
1034       const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *bidiLine.visualToLogicalMap;
1035       const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) );
1036
1037       float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
1038
1039       Vector2* glyphPositionsBuffer = glyphPositions.Begin();
1040
1041       // Traverses the characters of the right to left paragraph.
1042       for( CharacterIndex characterLogicalIndex = 0u;
1043            characterLogicalIndex < bidiLine.characterRun.numberOfCharacters;
1044            ++characterLogicalIndex )
1045       {
1046         // Convert the character in the logical order into the character in the visual order.
1047         const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *( bidiLine.visualToLogicalMap + characterLogicalIndex );
1048
1049         // Get the number of glyphs of the character.
1050         const Length numberOfGlyphs = *( layoutParameters.glyphsPerCharacterBuffer + characterVisualIndex );
1051
1052         for( GlyphIndex index = 0u; index < numberOfGlyphs; ++index )
1053         {
1054           // Convert the character in the visual order into the glyph in the visual order.
1055           const GlyphIndex glyphIndex = *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) + index;
1056
1057           DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.totalNumberOfGlyphs );
1058
1059           const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex );
1060           Vector2& position = *( glyphPositionsBuffer + glyphIndex );
1061
1062           position.x = penX + glyph.xBearing;
1063           penX += glyph.advance;
1064         }
1065       }
1066     }
1067   }
1068
1069   void Align( const Size& size,
1070               CharacterIndex startIndex,
1071               Length numberOfCharacters,
1072               Vector<LineRun>& lines )
1073   {
1074     const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
1075
1076     // Traverse all lines and align the glyphs.
1077     for( Vector<LineRun>::Iterator it = lines.Begin(), endIt = lines.End();
1078          it != endIt;
1079          ++it )
1080     {
1081       LineRun& line = *it;
1082
1083       if( line.characterRun.characterIndex < startIndex )
1084       {
1085         // Do not align lines which have already been aligned.
1086         continue;
1087       }
1088
1089       if( line.characterRun.characterIndex >= lastCharacterPlusOne )
1090       {
1091         // Do not align lines beyond the last laid-out character.
1092         break;
1093       }
1094
1095       // Calculate the line's alignment offset accordingly with the align option,
1096       // the box width, line length, and the paragraph's direction.
1097       CalculateHorizontalAlignment( size.width,
1098                                     line );
1099     }
1100   }
1101
1102   void CalculateHorizontalAlignment( float boxWidth,
1103                                      LineRun& line )
1104   {
1105     line.alignmentOffset = 0.f;
1106     const bool isRTL = RTL == line.direction;
1107     float lineLength = line.width;
1108
1109     HorizontalAlignment alignment = mHorizontalAlignment;
1110     if( isRTL )
1111     {
1112       // Swap the alignment type if the line is right to left.
1113       switch( alignment )
1114       {
1115         case HORIZONTAL_ALIGN_BEGIN:
1116         {
1117           alignment = HORIZONTAL_ALIGN_END;
1118           break;
1119         }
1120         case HORIZONTAL_ALIGN_CENTER:
1121         {
1122           // Nothing to do.
1123           break;
1124         }
1125         case HORIZONTAL_ALIGN_END:
1126         {
1127           alignment = HORIZONTAL_ALIGN_BEGIN;
1128           break;
1129         }
1130       }
1131     }
1132
1133     // Calculate the horizontal line offset.
1134     switch( alignment )
1135     {
1136       case HORIZONTAL_ALIGN_BEGIN:
1137       {
1138         line.alignmentOffset = 0.f;
1139
1140         if( isRTL )
1141         {
1142           // 'Remove' the white spaces at the end of the line (which are at the beginning in visual order)
1143           line.alignmentOffset -= line.extraLength;
1144         }
1145         break;
1146       }
1147       case HORIZONTAL_ALIGN_CENTER:
1148       {
1149         line.alignmentOffset = 0.5f * ( boxWidth - lineLength );
1150
1151         if( isRTL )
1152         {
1153           line.alignmentOffset -= line.extraLength;
1154         }
1155
1156         line.alignmentOffset = floorf( line.alignmentOffset ); // try to avoid pixel alignment.
1157         break;
1158       }
1159       case HORIZONTAL_ALIGN_END:
1160       {
1161         if( isRTL )
1162         {
1163           lineLength += line.extraLength;
1164         }
1165
1166         line.alignmentOffset = boxWidth - lineLength;
1167         break;
1168       }
1169     }
1170   }
1171
1172   void Initialize( LineRun& line )
1173   {
1174     line.glyphRun.glyphIndex = 0u;
1175     line.glyphRun.numberOfGlyphs = 0u;
1176     line.characterRun.characterIndex = 0u;
1177     line.characterRun.numberOfCharacters = 0u;
1178     line.width = 0.f;
1179     line.ascender = 0.f;
1180     line.descender = 0.f;
1181     line.extraLength = 0.f;
1182     line.alignmentOffset = 0.f;
1183     line.direction = !RTL;
1184     line.ellipsis = false;
1185   }
1186
1187   LayoutEngine::Layout mLayout;
1188   LayoutEngine::HorizontalAlignment mHorizontalAlignment;
1189   LayoutEngine::VerticalAlignment mVerticalAlignment;
1190   float mCursorWidth;
1191   float mDefaultLineSpacing;
1192
1193   IntrusivePtr<Metrics> mMetrics;
1194
1195   bool mEllipsisEnabled:1;
1196 };
1197
1198 LayoutEngine::LayoutEngine()
1199 : mImpl( NULL )
1200 {
1201   mImpl = new LayoutEngine::Impl();
1202 }
1203
1204 LayoutEngine::~LayoutEngine()
1205 {
1206   delete mImpl;
1207 }
1208
1209 void LayoutEngine::SetMetrics( MetricsPtr& metrics )
1210 {
1211   mImpl->mMetrics = metrics;
1212 }
1213
1214 void LayoutEngine::SetLayout( Layout layout )
1215 {
1216   mImpl->mLayout = layout;
1217 }
1218
1219 LayoutEngine::Layout LayoutEngine::GetLayout() const
1220 {
1221   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetLayout[%d]\n", mImpl->mLayout);
1222   return mImpl->mLayout;
1223 }
1224
1225 void LayoutEngine::SetTextEllipsisEnabled( bool enabled )
1226 {
1227   DALI_LOG_INFO( gLogFilter, Debug::General, "-->LayoutEngine::SetTextEllipsisEnabled[%s]\n", (enabled)?"true":"false" );
1228   mImpl->mEllipsisEnabled = enabled;
1229 }
1230
1231 bool LayoutEngine::GetTextEllipsisEnabled() const
1232 {
1233   return mImpl->mEllipsisEnabled;
1234 }
1235
1236 void LayoutEngine::SetHorizontalAlignment( HorizontalAlignment alignment )
1237 {
1238   mImpl->mHorizontalAlignment = alignment;
1239 }
1240
1241 LayoutEngine::HorizontalAlignment LayoutEngine::GetHorizontalAlignment() const
1242 {
1243   return mImpl->mHorizontalAlignment;
1244 }
1245
1246 void LayoutEngine::SetVerticalAlignment( VerticalAlignment alignment )
1247 {
1248   mImpl->mVerticalAlignment = alignment;
1249 }
1250
1251 LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const
1252 {
1253   return mImpl->mVerticalAlignment;
1254 }
1255
1256 void LayoutEngine::SetCursorWidth( int width )
1257 {
1258   mImpl->mCursorWidth = static_cast<float>( width );
1259 }
1260
1261 int LayoutEngine::GetCursorWidth() const
1262 {
1263   return static_cast<int>( mImpl->mCursorWidth );
1264 }
1265
1266 bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters,
1267                                Vector<Vector2>& glyphPositions,
1268                                Vector<LineRun>& lines,
1269                                Size& layoutSize )
1270 {
1271   return mImpl->LayoutText( layoutParameters,
1272                             glyphPositions,
1273                             lines,
1274                             layoutSize );
1275 }
1276
1277 void LayoutEngine::ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
1278                                              CharacterIndex startIndex,
1279                                              Length numberOfCharacters,
1280                                              Vector<Vector2>& glyphPositions )
1281 {
1282   mImpl->ReLayoutRightToLeftLines( layoutParameters,
1283                                    startIndex,
1284                                    numberOfCharacters,
1285                                    glyphPositions );
1286 }
1287
1288 void LayoutEngine::Align( const Size& size,
1289                           CharacterIndex startIndex,
1290                           Length numberOfCharacters,
1291                           Vector<LineRun>& lines )
1292 {
1293   mImpl->Align( size,
1294                 startIndex,
1295                 numberOfCharacters,
1296                 lines );
1297 }
1298
1299 void LayoutEngine::SetDefaultLineSpacing( float lineSpacing )
1300 {
1301   mImpl->mDefaultLineSpacing = lineSpacing;
1302 }
1303
1304 float LayoutEngine::GetDefaultLineSpacing() const
1305 {
1306   return mImpl->mDefaultLineSpacing;
1307 }
1308
1309 } // namespace Text
1310
1311 } // namespace Toolkit
1312
1313 } // namespace Dali