+ actualSize.width = lineRun.width;
+ }
+
+ actualSize.height += ( lineRun.ascender + -lineRun.descender );
+
+ SetGlyphPositions( layoutParameters.glyphsBuffer + index,
+ layout.numberOfGlyphs,
+ penY,
+ glyphPositions.Begin() + index );
+
+ penY += -layout.descender;
+
+ // Increase the glyph index.
+ index += layout.numberOfGlyphs;
+
+ if( isLastLine &&
+ layoutParameters.isLastNewParagraph &&
+ ( mLayout == MULTI_LINE_BOX ) )
+ {
+ // Need to add a new line with no characters but with height to increase the actualSize.height
+ const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u );
+
+ Text::FontMetrics fontMetrics;
+ mFontClient.GetFontMetrics( glyphInfo.fontId, fontMetrics );
+
+ LineRun lineRun;
+ lineRun.glyphIndex = 0u;
+ lineRun.numberOfGlyphs = 0u;
+ lineRun.characterRun.characterIndex = 0u;
+ lineRun.characterRun.numberOfCharacters = 0u;
+ lineRun.width = 0.f;
+ lineRun.ascender = fontMetrics.ascender;
+ lineRun.descender = fontMetrics.descender;
+ lineRun.extraLength = 0.f;
+ lineRun.alignmentOffset = 0.f;
+ lineRun.direction = !RTL;
+ lineRun.ellipsis = false;
+
+ actualSize.height += ( lineRun.ascender + -lineRun.descender );
+
+ lines.PushBack( lineRun );
+ }
+ }
+ } // end for() traversing glyphs.
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--LayoutText\n\n" );
+
+ return true;
+ }
+
+ void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
+ Vector<Vector2>& glyphPositions )
+ {
+ // Traverses the paragraphs with right to left characters.
+ for( LineIndex lineIndex = 0u; lineIndex < layoutParameters.numberOfBidirectionalInfoRuns; ++lineIndex )
+ {
+ const BidirectionalLineInfoRun& bidiLine = *( layoutParameters.lineBidirectionalInfoRunsBuffer + lineIndex );
+
+ const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *bidiLine.visualToLogicalMap;
+ const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) );
+
+ float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
+ penX += 1.f; // Added one unit to give some space to the cursor.
+
+ Vector2* glyphPositionsBuffer = glyphPositions.Begin();
+
+ // Traverses the characters of the right to left paragraph.
+ for( CharacterIndex characterLogicalIndex = 0u;
+ characterLogicalIndex < bidiLine.characterRun.numberOfCharacters;
+ ++characterLogicalIndex )
+ {
+ // Convert the character in the logical order into the character in the visual order.
+ const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *( bidiLine.visualToLogicalMap + characterLogicalIndex );
+
+ // Get the number of glyphs of the character.
+ const Length numberOfGlyphs = *( layoutParameters.glyphsPerCharacterBuffer + characterVisualIndex );
+
+ for( GlyphIndex index = 0u; index < numberOfGlyphs; ++index )
+ {
+ // Convert the character in the visual order into the glyph in the visual order.
+ const GlyphIndex glyphIndex = *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) + index;
+
+ DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.totalNumberOfGlyphs );
+
+ const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex );
+ Vector2& position = *( glyphPositionsBuffer + glyphIndex );
+
+ position.x = penX + glyph.xBearing;
+ penX += glyph.advance;
+ }
+ }
+ }
+ }
+
+ void Align( const Size& layoutSize,
+ Vector<LineRun>& lines )
+ {
+ // Traverse all lines and align the glyphs.
+
+ for( Vector<LineRun>::Iterator it = lines.Begin(), endIt = lines.End();
+ it != endIt;
+ ++it )
+ {
+ LineRun& line = *it;
+ const bool isLastLine = lines.End() == it + 1u;
+
+ // Calculate the alignment offset accordingly with the align option,
+ // the box width, line length, and the paragraphs direction.
+ CalculateHorizontalAlignment( layoutSize.width,
+ line,
+ isLastLine );
+ }
+ }
+
+ void CalculateHorizontalAlignment( float boxWidth,
+ LineRun& line,
+ bool isLastLine )
+ {
+ line.alignmentOffset = 0.f;
+ const bool isRTL = RTL == line.direction;
+ float lineLength = line.width;
+
+ HorizontalAlignment alignment = mHorizontalAlignment;
+ if( isRTL &&
+ ( HORIZONTAL_ALIGN_CENTER != alignment ) )
+ {
+ if( HORIZONTAL_ALIGN_BEGIN == alignment )
+ {
+ alignment = HORIZONTAL_ALIGN_END;
+ }
+ else
+ {
+ alignment = HORIZONTAL_ALIGN_BEGIN;
+ }
+ }
+
+ switch( alignment )
+ {
+ case HORIZONTAL_ALIGN_BEGIN:
+ {
+ line.alignmentOffset = 0.f;