+ // If the first glyph has a negative bearing its absolute value needs to be added to the line length.
+ // In the case the line starts with a right to left character the bearing needs to be substracted to the line length.
+ const GlyphInfo& glyphInfo = *( parameters.glyphsBuffer + lineLayout.glyphIndex );
+ float initialHorizontalBearing = glyphInfo.xBearing;
+
+ lineLayout.characterIndex = *( parameters.glyphsToCharactersBuffer + lineLayout.glyphIndex );
+ const CharacterDirection firstCharacterDirection = ( NULL == parameters.characterDirectionBuffer ) ? false : *( parameters.characterDirectionBuffer + lineLayout.characterIndex );
+
+ if( RTL == firstCharacterDirection )
+ {
+ initialHorizontalBearing = -initialHorizontalBearing;
+
+ if( 0.f < glyphInfo.xBearing )
+ {
+ tmpLineLayout.length = glyphInfo.xBearing;
+ initialHorizontalBearing = 0.f;
+ }
+ }
+ else
+ {
+ if( 0.f > glyphInfo.xBearing )
+ {
+ tmpLineLayout.length = -glyphInfo.xBearing;
+ initialHorizontalBearing = 0.f;
+ }
+ }
+
+ // Calculate the line height if there is no characters.
+ FontId lastFontId = glyphInfo.fontId;
+ UpdateLineHeight( lastFontId, tmpLineLayout );
+
+ const float boundingBoxWidth = parameters.boundingBox.width - initialHorizontalBearing;
+
+ bool oneWordLaidOut = false;
+