+ 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 == lastCharacter;
+ while( !endOfText &&
+ ( TextAbstraction::COMMON == script ) )
+ {
+ if( TextAbstraction::EMOJI == currentScriptRun.script )
+ {
+ // Emojis doesn't mix well with characters common to all scripts. Insert the emoji run.
+ scripts.Insert( scripts.Begin() + scriptIndex, currentScriptRun );
+ ++scriptIndex;
+
+ // Initialize the new one.
+ currentScriptRun.characterRun.characterIndex = currentScriptRun.characterRun.characterIndex + currentScriptRun.characterRun.numberOfCharacters;
+ currentScriptRun.characterRun.numberOfCharacters = 0u;
+ currentScriptRun.script = TextAbstraction::UNKNOWN;
+ numberOfAllScriptCharacters = 0u;
+ }
+
+ // 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;