+ Character character = *( textBuffer + index );
+
+ // Get the script of the character.
+ Script script = TextAbstraction::GetCharacterScript( character );
+
+ // Some characters (like white spaces) are valid for many scripts. The rules to set a script
+ // for them are:
+ // - If they are at the begining of a paragraph they get the script of the first character with
+ // a defined script. If they are at the end, they get the script of the last one.
+ // - If they are between two scripts with the same direction, they get the script of the previous
+ // character with a defined script. If the two scripts have different directions, they get the
+ // script of the first character of the paragraph with a defined script.
+
+ // Skip those characters valid for many scripts like white spaces or '\n'.
+ bool endOfText = index == numberOfCharacters;
+ while( !endOfText &&
+ ( TextAbstraction::COMMON == script ) )
+ {
+ // Count all these characters to be added into a script.
+ ++numberOfAllScriptCharacters;
+
+ if( TextAbstraction::IsNewParagraph( character ) )
+ {
+ // The character is a new paragraph.
+ // To know when there is a new paragraph is needed because if there is a white space
+ // between two scripts with different directions, it is added to the script with
+ // the same direction than the first script of the paragraph.
+ isFirstScriptToBeSet = true;
+
+ // Characters common to all scripts at the end of the paragraph are added to the last script (if the last one is not unknown).
+ if( TextAbstraction::UNKNOWN != currentScriptRun.script )
+ {
+ currentScriptRun.characterRun.numberOfCharacters += numberOfAllScriptCharacters;
+ numberOfAllScriptCharacters = 0u;
+ }
+ }
+
+ // Get the next character.
+ ++index;
+ endOfText = index == numberOfCharacters;
+ if( !endOfText )
+ {
+ character = *( textBuffer + index );
+ script = TextAbstraction::GetCharacterScript( character );
+ }
+ }