2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/cursor-helper-functions.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
30 #if defined(DEBUG_ENABLED)
31 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
34 const Dali::Toolkit::Text::CharacterDirection LTR = false; ///< Left To Right direction.
38 FindWordData( const Dali::Toolkit::Text::Character* const textBuffer,
39 Dali::Toolkit::Text::Length totalNumberOfCharacters,
40 Dali::Toolkit::Text::CharacterIndex hitCharacter,
43 : textBuffer( textBuffer ),
44 totalNumberOfCharacters( totalNumberOfCharacters ),
45 hitCharacter( hitCharacter ),
47 isWhiteSpace( isWhiteSpace ),
48 isNewParagraph( isNewParagraph )
54 const Dali::Toolkit::Text::Character* const textBuffer;
55 Dali::Toolkit::Text::Length totalNumberOfCharacters;
56 Dali::Toolkit::Text::CharacterIndex hitCharacter;
57 Dali::Toolkit::Text::CharacterIndex foundIndex;
58 bool isWhiteSpace : 1u;
59 bool isNewParagraph : 1u;
62 bool IsWhiteSpaceOrNewParagraph( Dali::Toolkit::Text::Character character,
64 bool isHitWhiteSpaceOrNewParagraph )
66 bool isWhiteSpaceOrNewParagraph = false;
67 if( isHitWhiteSpaceOrNewParagraph )
71 // Whether the current character is a white space. Note a new paragraph character is a white space as well but here is not wanted.
72 isWhiteSpaceOrNewParagraph = Dali::TextAbstraction::IsWhiteSpace( character ) && !Dali::TextAbstraction::IsNewParagraph( character );
76 // Whether the current character is a new paragraph character.
77 isWhiteSpaceOrNewParagraph = Dali::TextAbstraction::IsNewParagraph( character );
82 // Whether the current character is a white space or a new paragraph character (note the new paragraph character is a white space as well).
83 isWhiteSpaceOrNewParagraph = Dali::TextAbstraction::IsWhiteSpace( character );
86 return isWhiteSpaceOrNewParagraph;
89 void FindStartOfWord( FindWordData& data )
91 const bool isHitWhiteSpaceOrNewParagraph = data.isWhiteSpace || data.isNewParagraph;
93 for( data.foundIndex = data.hitCharacter; data.foundIndex > 0; --data.foundIndex )
95 const Dali::Toolkit::Text::Character character = *( data.textBuffer + data.foundIndex - 1u );
97 const bool isWhiteSpaceOrNewParagraph = IsWhiteSpaceOrNewParagraph( character,
99 isHitWhiteSpaceOrNewParagraph );
101 if( isHitWhiteSpaceOrNewParagraph != isWhiteSpaceOrNewParagraph )
108 void FindEndOfWord( FindWordData& data )
110 const bool isHitWhiteSpaceOrNewParagraph = data.isWhiteSpace || data.isNewParagraph;
112 for( data.foundIndex = data.hitCharacter + 1u; data.foundIndex < data.totalNumberOfCharacters; ++data.foundIndex )
114 const Dali::Toolkit::Text::Character character = *( data.textBuffer + data.foundIndex );
116 const bool isWhiteSpaceOrNewParagraph = IsWhiteSpaceOrNewParagraph( character,
118 isHitWhiteSpaceOrNewParagraph );
120 if( isHitWhiteSpaceOrNewParagraph != isWhiteSpaceOrNewParagraph )
138 LineIndex GetClosestLine( VisualModelPtr visualModel,
141 float totalHeight = 0.f;
142 LineIndex lineIndex = 0u;
144 const Vector<LineRun>& lines = visualModel->mLines;
146 for( Vector<LineRun>::ConstIterator it = lines.Begin(),
151 const LineRun& lineRun = *it;
153 // The line height is the addition of the line ascender and the line descender.
154 // However, the line descender has a negative value, hence the subtraction.
155 totalHeight += lineRun.ascender - lineRun.descender;
157 if( visualY < totalHeight )
163 if( lineIndex == 0u )
171 float CalculateLineOffset( const Vector<LineRun>& lines,
172 LineIndex lineIndex )
176 for( Vector<LineRun>::ConstIterator it = lines.Begin(),
177 endIt = lines.Begin() + lineIndex;
181 const LineRun& lineRun = *it;
183 // The line height is the addition of the line ascender and the line descender.
184 // However, the line descender has a negative value, hence the subtraction.
185 offset += lineRun.ascender - lineRun.descender;
191 CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
192 LogicalModelPtr logicalModel,
197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex, closest visualX %f visualY %f\n", visualX, visualY );
199 CharacterIndex logicalIndex = 0u;
201 const Length numberOfGlyphs = visualModel->mGlyphs.Count();
202 const Length numberOfLines = visualModel->mLines.Count();
203 if( ( 0 == numberOfGlyphs ) ||
204 ( 0 == numberOfLines ) )
209 // Find which line is closest.
210 const LineIndex lineIndex = Text::GetClosestLine( visualModel,
213 // Convert from text's coords to line's coords.
214 const LineRun& line = *( visualModel->mLines.Begin() + lineIndex );
216 // Transform the tap point from text's coords to line's coords.
217 visualX -= line.alignmentOffset;
219 // Get the positions of the glyphs.
220 const Vector2* const positionsBuffer = visualModel->mGlyphPositions.Begin();
222 // Get the character to glyph conversion table.
223 const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
225 // Get the glyphs per character table.
226 const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
228 // Get the characters per glyph table.
229 const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
231 // Get the glyph's info buffer.
232 const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
234 const CharacterIndex startCharacter = line.characterRun.characterIndex;
235 const CharacterIndex endCharacter = line.characterRun.characterIndex + line.characterRun.numberOfCharacters;
236 DALI_ASSERT_DEBUG( endCharacter <= logicalModel->mText.Count() && "Invalid line info" );
238 // Whether this line is a bidirectional line.
239 const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( startCharacter );
241 // The character's direction buffer.
242 const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
244 // Whether there is a hit on a glyph.
245 bool matched = false;
247 // Traverses glyphs in visual order. To do that use the visual to logical conversion table.
248 CharacterIndex visualIndex = startCharacter;
249 Length numberOfVisualCharacters = 0u;
250 for( ; visualIndex < endCharacter; ++visualIndex )
252 // The character in logical order.
253 const CharacterIndex characterLogicalOrderIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( visualIndex ) : visualIndex );
254 const CharacterDirection direction = ( bidiLineFetched ? *( directionsBuffer + characterLogicalOrderIndex ) : LTR );
256 // The number of glyphs for that character
257 const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex );
258 ++numberOfVisualCharacters;
260 if( 0u != numberOfGlyphs )
262 // Get the first character/glyph of the group of glyphs.
263 const CharacterIndex firstVisualCharacterIndex = 1u + visualIndex - numberOfVisualCharacters;
264 const CharacterIndex firstLogicalCharacterIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( firstVisualCharacterIndex ) : firstVisualCharacterIndex );
265 const GlyphIndex firstLogicalGlyphIndex = *( charactersToGlyphBuffer + firstLogicalCharacterIndex );
267 // Get the metrics for the group of glyphs.
268 GlyphMetrics glyphMetrics;
269 GetGlyphsMetrics( firstLogicalGlyphIndex,
275 // Get the position of the first glyph.
276 const Vector2& position = *( positionsBuffer + firstLogicalGlyphIndex );
278 // Whether the glyph can be split, like Latin ligatures fi, ff or Arabic ï»».
279 const Length numberOfCharacters = *( charactersPerGlyphBuffer + firstLogicalGlyphIndex );
280 if( direction != LTR )
282 // As characters are being traversed in visual order,
283 // for right to left ligatures, the character which contains the
284 // number of glyphs in the table is found first.
285 // Jump the number of characters to the next glyph is needed.
286 visualIndex += numberOfCharacters - 1u;
289 // Get the script of the character.
290 const Script script = logicalModel->GetScript( characterLogicalOrderIndex );
292 const bool isInterglyphIndex = ( numberOfCharacters > numberOfGlyphs ) && HasLigatureMustBreak( script );
293 const Length numberOfBlocks = isInterglyphIndex ? numberOfCharacters : 1u;
294 const float glyphAdvance = glyphMetrics.advance / static_cast<float>( numberOfBlocks );
296 CharacterIndex index = 0u;
297 for( ; index < numberOfBlocks; ++index )
299 // Find the mid-point of the area containing the glyph
300 const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast<float>( index ) + 0.5f ) * glyphAdvance;
302 if( visualX < glyphCenter )
311 // If the glyph is shaped from more than one character, it matches the character of the glyph.
312 visualIndex = firstVisualCharacterIndex + index;
316 numberOfVisualCharacters = 0u;
320 // The number of characters of the whole text.
321 const Length totalNumberOfCharacters = logicalModel->mText.Count();
323 // Return the logical position of the cursor in characters.
327 // If no character is matched, then the last character (in visual order) of the line is used.
328 visualIndex = endCharacter;
331 // Get the paragraph direction.
332 const CharacterDirection paragraphDirection = line.direction;
334 if( totalNumberOfCharacters != visualIndex )
336 // The visual index is not at the end of the text.
338 if( LTR == paragraphDirection )
340 // The paragraph direction is left to right.
342 if( visualIndex == endCharacter )
344 // It places the cursor just before the last character in visual order.
345 // i.e. it places the cursor just before the '\n' or before the last character
346 // if there is a long line with no word breaks which is wrapped.
348 // It doesn't check if the closest line is the last one like the RTL branch below
349 // because the total number of characters is different than the visual index and
350 // the visual index is the last character of the line.
356 // The paragraph direction is right to left.
358 if( ( lineIndex != numberOfLines - 1u ) && // is not the last line.
359 ( visualIndex == startCharacter ) )
361 // It places the cursor just after the first character in visual order.
362 // i.e. it places the cursor just after the '\n' or after the last character
363 // if there is a long line with no word breaks which is wrapped.
365 // If the last line doesn't end with '\n' it won't increase the visual index
366 // placing the cursor at the beginning of the line (in visual order).
373 // The visual index is at the end of text.
375 // If the text ends with a new paragraph character i.e. a '\n', an extra line with no characters is added at the end of the text.
376 // This branch checks if the closest line is the one with the last '\n'. If it is, it decrements the visual index to place
377 // the cursor just before the last '\n'.
379 if( ( lineIndex != numberOfLines - 1u ) &&
380 TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + visualIndex - 1u ) ) )
386 logicalIndex = ( bidiLineFetched ? logicalModel->GetLogicalCursorIndex( visualIndex ) : visualIndex );
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "closest visualIndex %d logicalIndex %d\n", visualIndex, logicalIndex );
390 DALI_ASSERT_DEBUG( ( logicalIndex <= logicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" );
396 void GetCursorPosition( VisualModelPtr visualModel,
397 LogicalModelPtr logicalModel,
399 CharacterIndex logical,
400 CursorInfo& cursorInfo )
402 // Whether the logical cursor position is at the end of the whole text.
403 const bool isLastPosition = logicalModel->mText.Count() == logical;
405 // Get the line where the character is laid-out.
406 const CharacterIndex characterOfLine = isLastPosition ? ( logical - 1u ) : logical;
408 // Whether the cursor is in the last position and the last position is a new paragraph character.
409 const bool isLastNewParagraph = isLastPosition && TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + characterOfLine ) );
411 const LineRun* const modelLines = visualModel->mLines.Begin();
413 const LineIndex lineIndex = visualModel->GetLineOfCharacter( characterOfLine );
414 const LineRun& line = *( modelLines + lineIndex );
416 if( isLastNewParagraph )
418 // The cursor is in a new line with no characters. Place the cursor in that line.
419 const LineIndex newLineIndex = lineIndex + 1u;
420 const LineRun& newLine = *( modelLines + newLineIndex );
422 cursorInfo.isSecondaryCursor = false;
424 // Set the line offset and height.
425 cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
428 // The line height is the addition of the line ascender and the line descender.
429 // However, the line descender has a negative value, hence the subtraction.
430 cursorInfo.lineHeight = newLine.ascender - newLine.descender;
432 // Set the primary cursor's height.
433 cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
435 // Set the primary cursor's position.
436 cursorInfo.primaryPosition.x = 0.f;
437 cursorInfo.primaryPosition.y = cursorInfo.lineOffset;
439 // Transform the cursor info from line's coords to text's coords.
440 cursorInfo.primaryPosition.x += ( LTR == line.direction ) ? 0.f : visualModel->mControlSize.width;
444 // Whether this line is a bidirectional line.
445 const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( characterOfLine );
447 // Check if the logical position is the first or the last one of the line.
448 const bool isFirstPositionOfLine = line.characterRun.characterIndex == logical;
449 const bool isLastPositionOfLine = line.characterRun.characterIndex + line.characterRun.numberOfCharacters == logical;
451 // 'logical' is the logical 'cursor' index.
452 // Get the next and current logical 'character' index.
453 const CharacterIndex characterIndex = isFirstPositionOfLine ? logical : logical - 1u;
454 const CharacterIndex nextCharacterIndex = isLastPositionOfLine ? characterIndex : logical;
456 // The character's direction buffer.
457 const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
459 CharacterDirection isCurrentRightToLeft = false;
460 CharacterDirection isNextRightToLeft = false;
461 if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
463 isCurrentRightToLeft = *( directionsBuffer + characterIndex );
464 isNextRightToLeft = *( directionsBuffer + nextCharacterIndex );
467 // Get the paragraph's direction.
468 const CharacterDirection isRightToLeftParagraph = line.direction;
470 // Check whether there is an alternative position:
471 cursorInfo.isSecondaryCursor = ( ( !isLastPositionOfLine && ( isCurrentRightToLeft != isNextRightToLeft ) ) ||
472 ( isLastPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) ||
473 ( isFirstPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) );
475 // Set the line offset and height.
476 cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
479 // The line height is the addition of the line ascender and the line descender.
480 // However, the line descender has a negative value, hence the subtraction.
481 cursorInfo.lineHeight = line.ascender - line.descender;
483 // Calculate the primary cursor.
485 CharacterIndex index = characterIndex;
486 if( cursorInfo.isSecondaryCursor )
488 // If there is a secondary position, the primary cursor may be in a different place than the logical index.
490 if( isLastPositionOfLine )
492 // The position of the cursor after the last character needs special
493 // care depending on its direction and the direction of the paragraph.
495 // Need to find the first character after the last character with the paragraph's direction.
496 // i.e l0 l1 l2 r0 r1 should find r0.
498 index = isRightToLeftParagraph ? line.characterRun.characterIndex : line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u;
499 if( bidiLineFetched )
501 index = logicalModel->GetLogicalCharacterIndex( index );
504 else if( isFirstPositionOfLine )
506 index = isRightToLeftParagraph ? line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u : line.characterRun.characterIndex;
507 if( bidiLineFetched )
509 index = logicalModel->GetLogicalCharacterIndex( index );
514 index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? characterIndex : nextCharacterIndex;
518 const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
519 const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
520 const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
521 const CharacterIndex* const glyphsToCharactersBuffer = visualModel->mGlyphsToCharacters.Begin();
522 const Vector2* const glyphPositionsBuffer = visualModel->mGlyphPositions.Begin();
523 const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
525 // Convert the cursor position into the glyph position.
526 const GlyphIndex primaryGlyphIndex = *( charactersToGlyphBuffer + index );
527 const Length primaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
528 const Length primaryNumberOfCharacters = *( charactersPerGlyphBuffer + primaryGlyphIndex );
530 // Get the metrics for the group of glyphs.
531 GlyphMetrics glyphMetrics;
532 GetGlyphsMetrics( primaryGlyphIndex,
533 primaryNumberOfGlyphs,
538 // Whether to add the glyph's advance to the cursor position.
539 // 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,
540 // if the logical cursor is one, the position is the position of the first glyph and the advance is added.
541 // A 'truth table' was build and an online Karnaugh map tool was used to simplify the logic.
562 // Where F -> isFirstPosition
563 // L -> isLastPosition
564 // C -> isCurrentRightToLeft
565 // P -> isRightToLeftParagraph
566 // A -> Whether to add the glyph's advance.
568 const bool addGlyphAdvance = ( ( isLastPositionOfLine && !isRightToLeftParagraph ) ||
569 ( isFirstPositionOfLine && isRightToLeftParagraph ) ||
570 ( !isFirstPositionOfLine && !isLastPosition && !isCurrentRightToLeft ) );
572 float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f;
574 if( !isLastPositionOfLine &&
575 ( primaryNumberOfCharacters > 1u ) )
577 const CharacterIndex firstIndex = *( glyphsToCharactersBuffer + primaryGlyphIndex );
579 bool isCurrentRightToLeft = false;
580 if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
582 isCurrentRightToLeft = *( directionsBuffer + index );
585 Length numberOfGlyphAdvance = ( isFirstPositionOfLine ? 0u : 1u ) + characterIndex - firstIndex;
586 if( isCurrentRightToLeft )
588 numberOfGlyphAdvance = primaryNumberOfCharacters - numberOfGlyphAdvance;
591 glyphAdvance = static_cast<float>( numberOfGlyphAdvance ) * glyphMetrics.advance / static_cast<float>( primaryNumberOfCharacters );
594 // Get the glyph position and x bearing (in the line's coords).
595 const Vector2& primaryPosition = *( glyphPositionsBuffer + primaryGlyphIndex );
597 // Set the primary cursor's height.
598 cursorInfo.primaryCursorHeight = cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight;
600 // Set the primary cursor's position.
601 cursorInfo.primaryPosition.x = -glyphMetrics.xBearing + primaryPosition.x + glyphAdvance;
602 cursorInfo.primaryPosition.y = cursorInfo.lineOffset + line.ascender - glyphMetrics.ascender;
604 // Transform the cursor info from line's coords to text's coords.
605 cursorInfo.primaryPosition.x += line.alignmentOffset;
607 // Calculate the secondary cursor.
608 if( cursorInfo.isSecondaryCursor )
610 // Set the secondary cursor's height.
611 cursorInfo.secondaryCursorHeight = 0.5f * glyphMetrics.fontHeight;
613 CharacterIndex index = characterIndex;
614 if( !isLastPositionOfLine )
616 index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? nextCharacterIndex : characterIndex;
619 const GlyphIndex secondaryGlyphIndex = *( charactersToGlyphBuffer + index );
620 const Length secondaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
622 const Vector2& secondaryPosition = *( glyphPositionsBuffer + secondaryGlyphIndex );
624 GetGlyphsMetrics( secondaryGlyphIndex,
625 secondaryNumberOfGlyphs,
630 // Set the secondary cursor's position.
643 // Where F -> isFirstPosition
644 // C -> isCurrentRightToLeft
645 // P -> isRightToLeftParagraph
646 // A -> Whether to add the glyph's advance.
648 const bool addGlyphAdvance = ( ( !isFirstPositionOfLine && !isCurrentRightToLeft ) ||
649 ( isFirstPositionOfLine && !isRightToLeftParagraph ) );
651 cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( addGlyphAdvance ? glyphMetrics.advance : 0.f );
652 cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight;
654 // Transform the cursor info from line's coords to text's coords.
655 cursorInfo.secondaryPosition.x += line.alignmentOffset;
660 bool FindSelectionIndices( VisualModelPtr visualModel,
661 LogicalModelPtr logicalModel,
665 CharacterIndex& startIndex,
666 CharacterIndex& endIndex )
671 |-------------------------------------------------------|------------------------------------------|
672 | On a word | The word |
673 | On a single white space between words | The word before or after the white space |
674 | On one of the multiple contiguous white spaces | The white spaces |
675 | On a single white space which is in the position zero | The white space and the next word |
676 | On a new paragraph character | The word or group of white spaces before |
677 |-------------------------------------------------------|------------------------------------------|
680 CharacterIndex hitCharacter = Text::GetClosestCursorIndex( visualModel,
686 const Length totalNumberOfCharacters = logicalModel->mText.Count();
688 DALI_ASSERT_DEBUG( ( hitCharacter <= totalNumberOfCharacters ) && "GetClosestCursorIndex returned out of bounds index" );
690 if( 0u == totalNumberOfCharacters )
692 // Nothing to do if the model is empty.
696 if( hitCharacter >= totalNumberOfCharacters )
698 // Closest hit character is the last character.
699 if( hitCharacter == totalNumberOfCharacters )
701 hitCharacter--; //Hit character index set to last character in logical model
705 // hitCharacter is out of bounds
710 const Character* const textBuffer = logicalModel->mText.Begin();
712 startIndex = hitCharacter;
713 endIndex = hitCharacter;
715 // Whether the hit character is a new paragraph character.
716 const bool isHitCharacterNewParagraph = TextAbstraction::IsNewParagraph( *( textBuffer + hitCharacter ) );
718 // Whether the hit character is a white space. Note a new paragraph character is a white space as well but here is not wanted.
719 const bool isHitCharacterWhiteSpace = TextAbstraction::IsWhiteSpace( *( textBuffer + hitCharacter ) ) && !isHitCharacterNewParagraph;
721 FindWordData data( textBuffer,
722 totalNumberOfCharacters,
724 isHitCharacterWhiteSpace,
725 isHitCharacterNewParagraph );
727 if( isHitCharacterNewParagraph )
729 // Find the first character before the hit one which is not a new paragraph character.
731 if( hitCharacter > 0u )
733 endIndex = hitCharacter - 1u;
734 for( ; endIndex > 0; --endIndex )
736 const Dali::Toolkit::Text::Character character = *( data.textBuffer + endIndex );
738 if( !Dali::TextAbstraction::IsNewParagraph( character ) )
745 data.hitCharacter = endIndex;
746 data.isNewParagraph = false;
747 data.isWhiteSpace = TextAbstraction::IsWhiteSpace( *( textBuffer + data.hitCharacter ) );
750 // Find the start of the word.
751 FindStartOfWord( data );
752 startIndex = data.foundIndex;
754 // Find the end of the word.
755 FindEndOfWord( data );
756 endIndex = data.foundIndex;
758 if( 1u == ( endIndex - startIndex ) )
760 if( isHitCharacterWhiteSpace )
762 // Select the word before or after the white space
764 if( 0u == hitCharacter )
766 data.isWhiteSpace = false;
767 FindEndOfWord( data );
768 endIndex = data.foundIndex;
770 else if( hitCharacter > 0u )
772 // Find the start of the word.
773 data.hitCharacter = hitCharacter - 1u;
774 data.isWhiteSpace = false;
775 FindStartOfWord( data );
776 startIndex = data.foundIndex;
788 } // namespace Toolkit