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