+ // Get word before.
+ WordLayoutInfo& previousWordLayout( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex - 1u ) );
+ if( WordSeparator != previousWordLayout.mType )
+ {
+ // Previous word is not a word separator, so could be merged.
+ mergeFromBegin = true;
+ textInfoMergeIndicesBegin.mWordIndex = textInfoIndicesBegin.mWordIndex - 1u;
+ }
+ }
+
+ if( mergeFromBegin )
+ {
+ // First word (or previous one) could be merged. Check if last one could be merged as well.
+
+ if( textInfoIndicesEnd.mCharacterIndex + 1u < lastWordLayout.mCharactersLayoutInfo.size() )
+ {
+ // Last word is going to be split. It could be merged with the first word.
+ mergeToEnd = true;
+ textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesEnd.mWordIndex;
+ }
+ else if( ( textInfoIndicesEnd.mCharacterIndex + 1u == lastWordLayout.mCharactersLayoutInfo.size() ) && ( textInfoIndicesEnd.mWordIndex + 1u < lineLayout.mWordsLayoutInfo.size() ) )
+ {
+ // Last word is going to be removed completely.
+ // Check if the word after could be merged.
+
+ // Get word after.
+ WordLayoutInfo& afterWordLayout( *( lineLayout.mWordsLayoutInfo.begin() + textInfoIndicesEnd.mWordIndex + 1u ) );
+ if( WordSeparator != afterWordLayout.mType )
+ {
+ // The word after is not a word separator, so could be merged.
+ mergeToEnd = true;
+ textInfoMergeIndicesEnd.mWordIndex = textInfoIndicesEnd.mWordIndex + 1u;
+ }
+ }
+
+ // Merge words only if both words could be merged.
+ mergeWords = mergeFromBegin && mergeToEnd;
+ }
+
+ if( ( textInfoIndicesEnd.mCharacterIndex + 1u == lastWordLayout.mCharactersLayoutInfo.size() ) && ( textInfoIndicesEnd.mWordIndex + 1u == lineLayout.mWordsLayoutInfo.size() ) )
+ {
+ // Last word of the line is going to be removed completely.
+ // Check if it's a line separator.
+
+ if( LineSeparator == lastWordLayout.mType )
+ {
+ // The line separator is going to be removed.
+ if( textInfoIndicesBegin.mLineIndex + 1u < textLayoutInfo.mLinesLayoutInfo.size() )
+ {
+ // Line need to be merged.
+ textInfoMergeIndicesBegin.mLineIndex = textInfoIndicesBegin.mLineIndex;
+ textInfoMergeIndicesEnd.mLineIndex = textInfoIndicesBegin.mLineIndex + 1u;
+ mergeLines= true;
+
+ ++textInfoIndicesBegin.mLineIndex; // increase both indices,
+ textInfoIndicesEnd.mLineIndex +=2u; // will delete last line.
+ }
+ }
+ }
+
+ if( textInfoIndicesBegin.mCharacterIndex > 0u )
+ {
+ // First word needs to be split.
+
+ // Store text-actors before removing them.
+ CollectTextActors( removedTextActorsFromFirstWord, firstWordLayout, textInfoIndicesBegin.mCharacterIndex, firstWordLayout.mCharactersLayoutInfo.size() );
+
+ RemoveCharactersFromWord( textInfoIndicesBegin.mCharacterIndex,
+ firstWordLayout.mCharactersLayoutInfo.size() - textInfoIndicesBegin.mCharacterIndex,
+ firstWordLayout );
+
+ ++textInfoIndicesBegin.mWordIndex; // will delete from the word after.
+ }
+
+ if( textInfoIndicesEnd.mCharacterIndex + 1u < lastWordLayout.mCharactersLayoutInfo.size() )
+ {
+ // Last word needs to be split.
+
+ // Store text-actors before removing them.
+ CollectTextActors( removedTextActorsFromLastWord, lastWordLayout, 0u, textInfoIndicesEnd.mCharacterIndex + 1u );
+
+ RemoveCharactersFromWord( 0u,
+ textInfoIndicesEnd.mCharacterIndex + 1u,
+ lastWordLayout );
+
+ if( mergeWords )
+ {
+ // This word is going to be merged, so is not needed.
+ ++textInfoIndicesEnd.mWordIndex; // will delete the last word.
+ }
+ }
+ else if( textInfoIndicesEnd.mCharacterIndex + 1u == lastWordLayout.mCharactersLayoutInfo.size() )
+ {
+ // The whole last word is going to be removed.
+ ++textInfoIndicesEnd.mWordIndex; // will delete the last word.
+
+ if( ( WordSeparator == lastWordLayout.mType ) && mergeWords )
+ {
+ // The last word is a word separator and the word after is going to be merged so is not needed.
+ ++textInfoIndicesEnd.mWordIndex; // will delete the word after the last one.
+ }
+ }