Platform SDK: International Features

Displaying the Caret in Bidirectional Strings

In unidirectional text, there is no ambiguity in the caret position because the leading edge of a character is at the same place as the trailing edge of the previous character. However, in bidirectional text, the caret position between runs of opposing direction is ambiguous. For example, in the LTR paragraph "helloMAALAS", the last letter of "hello" immediately precedes the first letter of "salaam". The best position in which to display the caret depends on whether it is considered to follow the "o" of "hello" or to precede the "s" of "salaam".

Uniscribe uses the following caret positioning conventions.

Situation Visual caret placement
Typing Trailing edge of last character typed.
Pasting Trailing edge of last character pasted.
Caret advancing Trailing edge of last character passed over.
Caret retiring Leading edge of last character passed over.
Home Leading edge of line.
End Trailing edge of line.

The caret may be positioned as follows:

if (advancing) {
    ScriptCPtoX(iCharPos-1, TRUE, ..., &iCaretX);
} else {
    ScriptCPtoX(iCharPos, FALSE, ..., &iCaretX);
}

Or, more simply, given an fAdvancing BOOL restricted to TRUE or FALSE:

ScriptCPtoX(iCharPos-fAdvancing, fAdvancing, ..., &iCaretX);

ScriptCPtoX handles out-of-range positions logically: It returns the leading edge of the run for iCharPos <0, and the trailing edge of the run for iCharPos =length.