+ // Get the glyph info.
+ const GlyphInfo& glyphInfo = *( parameters.glyphsBuffer + glyphIndex );
+
+ // Get the character indices for the current glyph. The last character index is needed
+ // because there are glyphs formed by more than one character but their break info is
+ // given only for the last character.
+ const Length charactersPerGlyph = *( parameters.charactersPerGlyphBuffer + glyphIndex );
+ const CharacterIndex characterFirstIndex = *( parameters.glyphsToCharactersBuffer + glyphIndex );
+ const CharacterIndex characterLastIndex = characterFirstIndex + ( ( 1u > charactersPerGlyph ) ? 0u : charactersPerGlyph - 1u );
+
+ // Get the line break info for the current character.
+ const LineBreakInfo lineBreakInfo = *( parameters.lineBreakInfoBuffer + characterLastIndex );
+
+ // Get the word break info for the current character.
+ const WordBreakInfo wordBreakInfo = *( parameters.wordBreakInfoBuffer + characterLastIndex );
+
+ // Increase the number of characters.
+ tmpLineLayout.numberOfCharacters += charactersPerGlyph;
+
+ // Increase the number of glyphs.
+ tmpLineLayout.numberOfGlyphs++;
+
+ // Check whether is a white space.
+ const Character character = *( parameters.textBuffer + characterFirstIndex );
+ const bool isWhiteSpace = TextAbstraction::IsWhiteSpace( character );
+
+ // Increase the accumulated length.
+ if( isWhiteSpace )
+ {
+ // Add the length to the length of white spaces at the end of the line.
+ tmpLineLayout.wsLengthEndOfLine += glyphInfo.advance; // I use the advance as the width is always zero for the white spaces.
+ tmpLineLayout.widthAdvanceDiff = 0.f;
+ }
+ else
+ {
+ // Add as well any previous white space length.
+ tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine + glyphInfo.advance;
+ tmpLineLayout.widthAdvanceDiff = glyphInfo.width - glyphInfo.advance;
+
+ // Clear the white space length at the end of the line.
+ tmpLineLayout.wsLengthEndOfLine = 0.f;
+ }
+
+ // Check if the accumulated length fits in the width of the box.
+ if( lineLayout.length + tmpLineLayout.length + tmpLineLayout.widthAdvanceDiff + ( ( 0.f < tmpLineLayout.length ) ? lineLayout.wsLengthEndOfLine : 0.f ) > parameters.boundingBox.width )
+ {
+ // Current word does not fit in the box's width.
+ return;
+ }
+
+ if( TextAbstraction::LINE_MUST_BREAK == lineBreakInfo )
+ {
+ // Must break the line. Update the line layout and return.
+ lineLayout.numberOfCharacters += tmpLineLayout.numberOfCharacters;
+ lineLayout.numberOfGlyphs += tmpLineLayout.numberOfGlyphs;
+ lineLayout.length += tmpLineLayout.length;
+ lineLayout.widthAdvanceDiff = tmpLineLayout.widthAdvanceDiff;
+
+ if( 0.f < tmpLineLayout.length )
+ {
+ lineLayout.length += lineLayout.wsLengthEndOfLine;
+
+ lineLayout.wsLengthEndOfLine = tmpLineLayout.wsLengthEndOfLine;
+ }
+ else
+ {
+ lineLayout.wsLengthEndOfLine += tmpLineLayout.wsLengthEndOfLine;
+ }
+
+ if( tmpLineLayout.ascender > lineLayout.ascender )
+ {
+ lineLayout.ascender = tmpLineLayout.ascender;
+ }
+
+ if( tmpLineLayout.descender > lineLayout.descender )
+ {
+ lineLayout.descender = tmpLineLayout.descender;
+ }
+
+ tmpLineLayout.numberOfCharacters = 0u;
+ tmpLineLayout.numberOfGlyphs = 0u;
+ tmpLineLayout.length = 0u;
+ tmpLineLayout.widthAdvanceDiff = 0u;
+ tmpLineLayout.wsLengthEndOfLine = 0u;
+ tmpLineLayout.ascender = 0.f;
+ tmpLineLayout.descender = 0.f;
+ return;
+ }
+
+ if( TextAbstraction::WORD_BREAK == wordBreakInfo )
+ {
+ // Current glyph is the last one of the current word.
+ // Add the temporal layout to the current one.
+ lineLayout.numberOfCharacters += tmpLineLayout.numberOfCharacters;
+ lineLayout.numberOfGlyphs += tmpLineLayout.numberOfGlyphs;
+ lineLayout.length += tmpLineLayout.length;
+ lineLayout.widthAdvanceDiff = tmpLineLayout.widthAdvanceDiff;
+
+ if( 0.f < tmpLineLayout.length )
+ {
+ lineLayout.length += lineLayout.wsLengthEndOfLine;
+
+ lineLayout.wsLengthEndOfLine = tmpLineLayout.wsLengthEndOfLine;
+ }
+ else
+ {
+ lineLayout.wsLengthEndOfLine += tmpLineLayout.wsLengthEndOfLine;
+ }
+
+ if( tmpLineLayout.ascender > lineLayout.ascender )
+ {
+ lineLayout.ascender = tmpLineLayout.ascender;
+ }
+
+ if( tmpLineLayout.descender > lineLayout.descender )
+ {
+ lineLayout.descender = tmpLineLayout.descender;
+ }
+
+ tmpLineLayout.numberOfCharacters = 0u;
+ tmpLineLayout.numberOfGlyphs = 0u;
+ tmpLineLayout.length = 0u;
+ tmpLineLayout.widthAdvanceDiff = 0u;
+ tmpLineLayout.wsLengthEndOfLine = 0u;
+ tmpLineLayout.ascender = 0.f;
+ tmpLineLayout.descender = 0.f;
+ }
+
+ if( lastFontId != glyphInfo.fontId )
+ {
+ Text::FontMetrics fontMetrics;
+ mFontClient.GetFontMetrics( glyphInfo.fontId, fontMetrics );
+
+ // Sets the maximum ascender.
+ if( fontMetrics.ascender > tmpLineLayout.ascender )
+ {
+ tmpLineLayout.ascender = fontMetrics.ascender;
+ }
+
+ // Sets the maximum descender.
+ if( -fontMetrics.descender > tmpLineLayout.descender )
+ {
+ tmpLineLayout.descender = -fontMetrics.descender;
+ }
+
+ lastFontId = glyphInfo.fontId;
+ }