+ const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
+ const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
+ const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
+ const CharacterIndex* const glyphsToCharactersBuffer = visualModel->mGlyphsToCharacters.Begin();
+ const Vector2* const glyphPositionsBuffer = visualModel->mGlyphPositions.Begin();
+ const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
+
+ // Convert the cursor position into the glyph position.
+ const GlyphIndex primaryGlyphIndex = *( charactersToGlyphBuffer + index );
+ const Length primaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
+ const Length primaryNumberOfCharacters = *( charactersPerGlyphBuffer + primaryGlyphIndex );
+
+ // Get the metrics for the group of glyphs.
+ GlyphMetrics glyphMetrics;
+ GetGlyphsMetrics( primaryGlyphIndex,
+ primaryNumberOfGlyphs,
+ glyphMetrics,
+ glyphInfoBuffer,
+ metrics );
+
+ // Whether to add the glyph's advance to the cursor position.
+ // i.e if the paragraph is left to right and the logical cursor is zero, the position is the position of the first glyph and the advance is not added,
+ // if the logical cursor is one, the position is the position of the first glyph and the advance is added.
+ // A 'truth table' was build and an online Karnaugh map tool was used to simplify the logic.
+ //
+ // FLCP A
+ // ------
+ // 0000 1
+ // 0001 1
+ // 0010 0
+ // 0011 0
+ // 0100 1
+ // 0101 0
+ // 0110 1
+ // 0111 0
+ // 1000 0
+ // 1001 1
+ // 1010 0
+ // 1011 1
+ // 1100 x
+ // 1101 x
+ // 1110 x
+ // 1111 x
+ //
+ // Where F -> isFirstPosition
+ // L -> isLastPosition
+ // C -> isCurrentRightToLeft
+ // P -> isRightToLeftParagraph
+ // A -> Whether to add the glyph's advance.
+
+ const bool addGlyphAdvance = ( ( isLastPositionOfLine && !isRightToLeftParagraph ) ||
+ ( isFirstPositionOfLine && isRightToLeftParagraph ) ||
+ ( !isFirstPositionOfLine && !isLastPosition && !isCurrentRightToLeft ) );
+
+ float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f;
+
+ if( !isLastPositionOfLine &&
+ ( primaryNumberOfCharacters > 1u ) )