+ // Do not reorder the lines after the last requested character.
+ break;
+ }
+
+ 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;
+
+ 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& size,
+ CharacterIndex startIndex,
+ Length numberOfCharacters,
+ Vector<LineRun>& lines )
+ {
+ const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters;
+
+ // Traverse all lines and align the glyphs.
+ for( Vector<LineRun>::Iterator it = lines.Begin(), endIt = lines.End();
+ it != endIt;
+ ++it )
+ {
+ LineRun& line = *it;
+
+ if( line.characterRun.characterIndex < startIndex )
+ {
+ // Do not align lines which have already been aligned.
+ continue;
+ }
+
+ if( line.characterRun.characterIndex >= lastCharacterPlusOne )
+ {
+ // Do not align lines beyond the last laid-out character.
+ break;
+ }
+
+ // Calculate the line's alignment offset accordingly with the align option,
+ // the box width, line length, and the paragraph's direction.
+ CalculateHorizontalAlignment( size.width,
+ line );
+ }
+ }
+
+ void CalculateHorizontalAlignment( float boxWidth,
+ LineRun& line )
+ {
+ line.alignmentOffset = 0.f;
+ const bool isRTL = RTL == line.direction;
+ float lineLength = line.width;
+
+ HorizontalAlignment alignment = mHorizontalAlignment;
+ if( isRTL )
+ {
+ // Swap the alignment type if the line is right to left.
+ switch( alignment )
+ {
+ case HORIZONTAL_ALIGN_BEGIN:
+ {
+ alignment = HORIZONTAL_ALIGN_END;
+ break;
+ }
+ case HORIZONTAL_ALIGN_CENTER:
+ {
+ // Nothing to do.
+ break;
+ }
+ case HORIZONTAL_ALIGN_END:
+ {
+ alignment = HORIZONTAL_ALIGN_BEGIN;
+ break;
+ }