+ // Continue in the second half of line, because in it the first index of character that is not WhiteSpace.
+ if(!extendedToSecondHalf &&
+ bidirectionalLineInfo.characterRunForSecondHalfLine.numberOfCharacters > 0u)
+ {
+ for(; characterLogicalIndex < bidirectionalLineInfo.characterRunForSecondHalfLine.numberOfCharacters;)
+ {
+ // Convert the character in the logical order into the character in the visual order.
+ const CharacterIndex characterVisualIndex = bidirectionalLineInfo.characterRunForSecondHalfLine.characterIndex + *(bidirectionalLineInfo.visualToLogicalMapSecondHalf + characterLogicalIndex);
+ const bool isWhiteSpace = TextAbstraction::IsWhiteSpace(*(textBuffer + characterVisualIndex));
+
+ const GlyphIndex glyphIndex = *(charactersToGlyphsBuffer + characterVisualIndex);
+
+ // Check whether this glyph comes from a character that is shaped in multiple glyphs.
+ const Length numberOfGLyphsInGroup = GetNumberOfGlyphsOfGroup(glyphIndex,
+ lastGlyphOfParagraphPlusOne,
+ charactersPerGlyphBuffer);
+
+ characterLogicalIndex += *(charactersPerGlyphBuffer + glyphIndex + numberOfGLyphsInGroup - 1u);
+
+ GlyphMetrics glyphMetrics;
+ GetGlyphsMetrics(glyphIndex,
+ numberOfGLyphsInGroup,
+ glyphMetrics,
+ glyphsBuffer,
+ mMetrics);
+
+ if(isWhiteSpace)
+ {
+ // If glyph is WhiteSpace then:
+ // For RTL it is whitespace but not at endOfLine. Use "advance" to accumulate length and shift penX.
+ // the endOfLine in RTL was the headOfLine for layouting.
+ // But for LTR added it to the endOfLine and use "advance" to accumulate length.
+ if(RTL == bidirectionalLineInfo.direction)
+ {
+ length += glyphMetrics.advance;
+ }
+ else
+ {
+ whiteSpaceLengthEndOfLine += glyphMetrics.advance;
+ }
+ penX += glyphMetrics.advance;
+ }
+ else
+ {
+ // If glyph is not whiteSpace then:
+ // Reset endOfLine for LTR because there is a non-whiteSpace so the tail of line is not whiteSpaces
+ // Use "advance" and "interGlyphExtraAdvance" to shift penX.
+ // Set length to the maximum possible length, of the current glyph "xBearing" and "width" are shifted penX to length greater than current lenght.
+ // Otherwise the current length is maximum.
+ if(LTR == bidirectionalLineInfo.direction)
+ {
+ whiteSpaceLengthEndOfLine = 0.f;
+ }
+ length = std::max(length, penX + glyphMetrics.xBearing + glyphMetrics.width);
+ penX += (glyphMetrics.advance + parameters.interGlyphExtraAdvance);
+ }
+ }
+ }
+
+ // Continue traversing in the first half of line or in the whole line.
+ // If the second half of line was extended then continue from logical index in the first half of line
+ // Also this is valid when the line was not splitted and there were WhiteSpace.
+ // Otherwise start from first logical index in line.
+ characterLogicalIndex = extendedToSecondHalf ? characterLogicalIndex : 0u;
+ for(; characterLogicalIndex < bidirectionalLineInfo.characterRun.numberOfCharacters;)