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