Remove Geometry::QUAD() usage in Toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / cursor-helper-functions.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // FILE HEADER
19 #include <dali-toolkit/internal/text/cursor-helper-functions.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
26
27 namespace
28 {
29
30 #if defined(DEBUG_ENABLED)
31   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
32 #endif
33
34 const Dali::Toolkit::Text::CharacterDirection LTR = false; ///< Left To Right direction.
35
36 } //namespace
37
38 namespace Dali
39 {
40
41 namespace Toolkit
42 {
43
44 namespace Text
45 {
46
47 LineIndex GetClosestLine( VisualModelPtr visualModel,
48                           float visualY )
49 {
50   float totalHeight = 0.f;
51   LineIndex lineIndex = 0u;
52
53   const Vector<LineRun>& lines = visualModel->mLines;
54
55   for( Vector<LineRun>::ConstIterator it = lines.Begin(),
56          endIt = lines.End();
57        it != endIt;
58        ++it, ++lineIndex )
59   {
60     const LineRun& lineRun = *it;
61
62     // The line height is the addition of the line ascender and the line descender.
63     // However, the line descender has a negative value, hence the subtraction.
64     totalHeight += lineRun.ascender - lineRun.descender;
65
66     if( visualY < totalHeight )
67     {
68       return lineIndex;
69     }
70   }
71
72   if( lineIndex == 0u )
73   {
74     return 0;
75   }
76
77   return lineIndex-1;
78 }
79
80 float CalculateLineOffset( const Vector<LineRun>& lines,
81                            LineIndex lineIndex )
82 {
83   float offset = 0.f;
84
85   for( Vector<LineRun>::ConstIterator it = lines.Begin(),
86          endIt = lines.Begin() + lineIndex;
87        it != endIt;
88        ++it )
89   {
90     const LineRun& lineRun = *it;
91
92     // The line height is the addition of the line ascender and the line descender.
93     // However, the line descender has a negative value, hence the subtraction.
94     offset += lineRun.ascender - lineRun.descender;
95   }
96
97   return offset;
98 }
99
100 CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
101                                       LogicalModelPtr logicalModel,
102                                       MetricsPtr metrics,
103                                       float visualX,
104                                       float visualY )
105 {
106   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex, closest visualX %f visualY %f\n", visualX, visualY );
107
108   CharacterIndex logicalIndex = 0u;
109
110   const Length numberOfGlyphs = visualModel->mGlyphs.Count();
111   const Length numberOfLines  = visualModel->mLines.Count();
112   if( ( 0 == numberOfGlyphs ) ||
113       ( 0 == numberOfLines ) )
114   {
115     return logicalIndex;
116   }
117
118   // Find which line is closest.
119   const LineIndex lineIndex = Text::GetClosestLine( visualModel,
120                                                     visualY );
121
122   // Convert from text's coords to line's coords.
123   const LineRun& line = *( visualModel->mLines.Begin() + lineIndex );
124
125   // Transform the tap point from text's coords to line's coords.
126   visualX -= line.alignmentOffset;
127
128   // Get the positions of the glyphs.
129   const Vector2* const positionsBuffer = visualModel->mGlyphPositions.Begin();
130
131   // Get the character to glyph conversion table.
132   const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
133
134   // Get the glyphs per character table.
135   const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
136
137   // Get the characters per glyph table.
138   const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
139
140   // Get the glyph's info buffer.
141   const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
142
143   const CharacterIndex startCharacter = line.characterRun.characterIndex;
144   const CharacterIndex endCharacter   = line.characterRun.characterIndex + line.characterRun.numberOfCharacters;
145   DALI_ASSERT_DEBUG( endCharacter <= logicalModel->mText.Count() && "Invalid line info" );
146
147   // Whether this line is a bidirectional line.
148   const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( startCharacter );
149
150   // The character's direction buffer.
151   const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
152
153   // Whether there is a hit on a glyph.
154   bool matched = false;
155
156   // Traverses glyphs in visual order. To do that use the visual to logical conversion table.
157   CharacterIndex visualIndex = startCharacter;
158   Length numberOfVisualCharacters = 0u;
159   for( ; visualIndex < endCharacter; ++visualIndex )
160   {
161     // The character in logical order.
162     const CharacterIndex characterLogicalOrderIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( visualIndex ) : visualIndex );
163     const CharacterDirection direction = ( bidiLineFetched ? *( directionsBuffer + characterLogicalOrderIndex ) : LTR );
164
165     // The number of glyphs for that character
166     const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterLogicalOrderIndex );
167     ++numberOfVisualCharacters;
168
169     if( 0u != numberOfGlyphs )
170     {
171       // Get the first character/glyph of the group of glyphs.
172       const CharacterIndex firstVisualCharacterIndex = 1u + visualIndex - numberOfVisualCharacters;
173       const CharacterIndex firstLogicalCharacterIndex = ( bidiLineFetched ? logicalModel->GetLogicalCharacterIndex( firstVisualCharacterIndex ) : firstVisualCharacterIndex );
174       const GlyphIndex firstLogicalGlyphIndex = *( charactersToGlyphBuffer + firstLogicalCharacterIndex );
175
176       // Get the metrics for the group of glyphs.
177       GlyphMetrics glyphMetrics;
178       GetGlyphsMetrics( firstLogicalGlyphIndex,
179                         numberOfGlyphs,
180                         glyphMetrics,
181                         glyphInfoBuffer,
182                         metrics );
183
184       // Get the position of the first glyph.
185       const Vector2& position = *( positionsBuffer + firstLogicalGlyphIndex );
186
187       // Whether the glyph can be split, like Latin ligatures fi, ff or Arabic ï»».
188       const Length numberOfCharacters = *( charactersPerGlyphBuffer + firstLogicalGlyphIndex );
189       if( direction != LTR )
190       {
191         // As characters are being traversed in visual order,
192         // for right to left ligatures, the character which contains the
193         // number of glyphs in the table is found first.
194         // Jump the number of characters to the next glyph is needed.
195         visualIndex += numberOfCharacters - 1u;
196       }
197
198       // Get the script of the character.
199       const Script script = logicalModel->GetScript( characterLogicalOrderIndex );
200
201       const bool isInterglyphIndex = ( numberOfCharacters > numberOfGlyphs ) && HasLigatureMustBreak( script );
202       const Length numberOfBlocks = isInterglyphIndex ? numberOfCharacters : 1u;
203       const float glyphAdvance = glyphMetrics.advance / static_cast<float>( numberOfBlocks );
204
205       CharacterIndex index = 0u;
206       for( ; index < numberOfBlocks; ++index )
207       {
208         // Find the mid-point of the area containing the glyph
209         const float glyphCenter = -glyphMetrics.xBearing + position.x + ( static_cast<float>( index ) + 0.5f ) * glyphAdvance;
210
211         if( visualX < glyphCenter )
212         {
213           matched = true;
214           break;
215         }
216       }
217
218       if( matched )
219       {
220         // If the glyph is shaped from more than one character, it matches the character of the glyph.
221         visualIndex = firstVisualCharacterIndex + index;
222         break;
223       }
224
225       numberOfVisualCharacters = 0u;
226     }
227   }
228
229   // The number of characters of the whole text.
230   const Length totalNumberOfCharacters = logicalModel->mText.Count();
231
232   // Return the logical position of the cursor in characters.
233
234   if( !matched )
235   {
236     // If no character is matched, then the last character (in visual order) of the line is used.
237     visualIndex = endCharacter;
238   }
239
240   // Get the paragraph direction.
241   const CharacterDirection paragraphDirection = line.direction;
242
243   if( totalNumberOfCharacters != visualIndex )
244   {
245     // The visual index is not at the end of the text.
246
247     if( LTR == paragraphDirection )
248     {
249       // The paragraph direction is left to right.
250
251       if( visualIndex == endCharacter )
252       {
253         // It places the cursor just before the last character in visual order.
254         // i.e. it places the cursor just before the '\n' or before the last character
255         // if there is a long line with no word breaks which is wrapped.
256
257         // It doesn't check if the closest line is the last one like the RTL branch below
258         // because the total number of characters is different than the visual index and
259         // the visual index is the last character of the line.
260         --visualIndex;
261       }
262     }
263     else
264     {
265       // The paragraph direction is right to left.
266
267       if( ( lineIndex != numberOfLines - 1u ) && // is not the last line.
268           ( visualIndex == startCharacter ) )
269       {
270         // It places the cursor just after the first character in visual order.
271         // i.e. it places the cursor just after the '\n' or after the last character
272         // if there is a long line with no word breaks which is wrapped.
273
274         // If the last line doesn't end with '\n' it won't increase the visual index
275         // placing the cursor at the beginning of the line (in visual order).
276         ++visualIndex;
277       }
278     }
279   }
280   else
281   {
282     // The visual index is at the end of text.
283
284     // 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.
285     // This branch checks if the closest line is the one with the last '\n'. If it is, it decrements the visual index to place
286     // the cursor just before the last '\n'.
287
288     if( ( lineIndex != numberOfLines - 1u ) &&
289         TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + visualIndex - 1u ) ) )
290     {
291       --visualIndex;
292     }
293   }
294
295   logicalIndex = ( bidiLineFetched ? logicalModel->GetLogicalCursorIndex( visualIndex ) : visualIndex );
296
297   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "closest visualIndex %d logicalIndex %d\n", visualIndex, logicalIndex );
298
299   DALI_ASSERT_DEBUG( ( logicalIndex <= logicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" );
300
301   return logicalIndex;
302 }
303
304
305 void GetCursorPosition( VisualModelPtr visualModel,
306                         LogicalModelPtr logicalModel,
307                         MetricsPtr metrics,
308                         CharacterIndex logical,
309                         CursorInfo& cursorInfo )
310 {
311   // Whether the logical cursor position is at the end of the whole text.
312   const bool isLastPosition = logicalModel->mText.Count() == logical;
313
314   // Get the line where the character is laid-out.
315   const CharacterIndex characterOfLine = isLastPosition ? ( logical - 1u ) : logical;
316
317   // Whether the cursor is in the last position and the last position is a new paragraph character.
318   const bool isLastNewParagraph = isLastPosition && TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + characterOfLine ) );
319
320   const LineRun* const modelLines = visualModel->mLines.Begin();
321
322   const LineIndex lineIndex = visualModel->GetLineOfCharacter( characterOfLine );
323   const LineRun& line = *( modelLines + lineIndex );
324
325   if( isLastNewParagraph )
326   {
327     // The cursor is in a new line with no characters. Place the cursor in that line.
328     const LineIndex newLineIndex = lineIndex + 1u;
329     const LineRun& newLine = *( modelLines + newLineIndex );
330
331     cursorInfo.isSecondaryCursor = false;
332
333     // Set the line offset and height.
334     cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
335                                                  newLineIndex );
336
337     // The line height is the addition of the line ascender and the line descender.
338     // However, the line descender has a negative value, hence the subtraction.
339     cursorInfo.lineHeight = newLine.ascender - newLine.descender;
340
341     // Set the primary cursor's height.
342     cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
343
344     // Set the primary cursor's position.
345     cursorInfo.primaryPosition.x = 0.f;
346     cursorInfo.primaryPosition.y = cursorInfo.lineOffset;
347
348     // Transform the cursor info from line's coords to text's coords.
349     cursorInfo.primaryPosition.x += ( LTR == line.direction ) ? 0.f : visualModel->mControlSize.width;
350   }
351   else
352   {
353     // Whether this line is a bidirectional line.
354     const bool bidiLineFetched = logicalModel->FetchBidirectionalLineInfo( characterOfLine );
355
356     // Check if the logical position is the first or the last one of the line.
357     const bool isFirstPositionOfLine = line.characterRun.characterIndex == logical;
358     const bool isLastPositionOfLine = line.characterRun.characterIndex + line.characterRun.numberOfCharacters == logical;
359
360     // 'logical' is the logical 'cursor' index.
361     // Get the next and current logical 'character' index.
362     const CharacterIndex characterIndex = isFirstPositionOfLine ? logical : logical - 1u;
363     const CharacterIndex nextCharacterIndex = isLastPositionOfLine ? characterIndex : logical;
364
365     // The character's direction buffer.
366     const CharacterDirection* const directionsBuffer = bidiLineFetched ? logicalModel->mCharacterDirections.Begin() : NULL;
367
368     CharacterDirection isCurrentRightToLeft = false;
369     CharacterDirection isNextRightToLeft = false;
370     if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
371     {
372       isCurrentRightToLeft = *( directionsBuffer + characterIndex );
373       isNextRightToLeft = *( directionsBuffer + nextCharacterIndex );
374     }
375
376     // Get the paragraph's direction.
377     const CharacterDirection isRightToLeftParagraph = line.direction;
378
379     // Check whether there is an alternative position:
380     cursorInfo.isSecondaryCursor = ( ( !isLastPositionOfLine && ( isCurrentRightToLeft != isNextRightToLeft ) )     ||
381                                      ( isLastPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) ||
382                                      ( isFirstPositionOfLine && ( isRightToLeftParagraph != isCurrentRightToLeft ) ) );
383
384     // Set the line offset and height.
385     cursorInfo.lineOffset = CalculateLineOffset( visualModel->mLines,
386                                                  lineIndex );
387
388     // The line height is the addition of the line ascender and the line descender.
389     // However, the line descender has a negative value, hence the subtraction.
390     cursorInfo.lineHeight = line.ascender - line.descender;
391
392     // Calculate the primary cursor.
393
394     CharacterIndex index = characterIndex;
395     if( cursorInfo.isSecondaryCursor )
396     {
397       // If there is a secondary position, the primary cursor may be in a different place than the logical index.
398
399       if( isLastPositionOfLine )
400       {
401         // The position of the cursor after the last character needs special
402         // care depending on its direction and the direction of the paragraph.
403
404         // Need to find the first character after the last character with the paragraph's direction.
405         // i.e l0 l1 l2 r0 r1 should find r0.
406
407         index = isRightToLeftParagraph ? line.characterRun.characterIndex : line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u;
408         if( bidiLineFetched )
409         {
410           index = logicalModel->GetLogicalCharacterIndex( index );
411         }
412       }
413       else if( isFirstPositionOfLine )
414       {
415         index = isRightToLeftParagraph ? line.characterRun.characterIndex + line.characterRun.numberOfCharacters - 1u : line.characterRun.characterIndex;
416         if( bidiLineFetched )
417         {
418           index = logicalModel->GetLogicalCharacterIndex( index );
419         }
420       }
421       else
422       {
423         index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? characterIndex : nextCharacterIndex;
424       }
425     }
426
427     const GlyphIndex* const charactersToGlyphBuffer = visualModel->mCharactersToGlyph.Begin();
428     const Length* const glyphsPerCharacterBuffer = visualModel->mGlyphsPerCharacter.Begin();
429     const Length* const charactersPerGlyphBuffer = visualModel->mCharactersPerGlyph.Begin();
430     const CharacterIndex* const glyphsToCharactersBuffer = visualModel->mGlyphsToCharacters.Begin();
431     const Vector2* const glyphPositionsBuffer = visualModel->mGlyphPositions.Begin();
432     const GlyphInfo* const glyphInfoBuffer = visualModel->mGlyphs.Begin();
433
434     // Convert the cursor position into the glyph position.
435     const GlyphIndex primaryGlyphIndex = *( charactersToGlyphBuffer + index );
436     const Length primaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
437     const Length primaryNumberOfCharacters = *( charactersPerGlyphBuffer + primaryGlyphIndex );
438
439     // Get the metrics for the group of glyphs.
440     GlyphMetrics glyphMetrics;
441     GetGlyphsMetrics( primaryGlyphIndex,
442                       primaryNumberOfGlyphs,
443                       glyphMetrics,
444                       glyphInfoBuffer,
445                       metrics );
446
447     // Whether to add the glyph's advance to the cursor position.
448     // 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,
449     //     if the logical cursor is one, the position is the position of the first glyph and the advance is added.
450     // A 'truth table' was build and an online Karnaugh map tool was used to simplify the logic.
451     //
452     // FLCP A
453     // ------
454     // 0000 1
455     // 0001 1
456     // 0010 0
457     // 0011 0
458     // 0100 1
459     // 0101 0
460     // 0110 1
461     // 0111 0
462     // 1000 0
463     // 1001 1
464     // 1010 0
465     // 1011 1
466     // 1100 x
467     // 1101 x
468     // 1110 x
469     // 1111 x
470     //
471     // Where F -> isFirstPosition
472     //       L -> isLastPosition
473     //       C -> isCurrentRightToLeft
474     //       P -> isRightToLeftParagraph
475     //       A -> Whether to add the glyph's advance.
476
477     const bool addGlyphAdvance = ( ( isLastPositionOfLine && !isRightToLeftParagraph ) ||
478                                    ( isFirstPositionOfLine && isRightToLeftParagraph ) ||
479                                    ( !isFirstPositionOfLine && !isLastPosition && !isCurrentRightToLeft ) );
480
481     float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f;
482
483     if( !isLastPositionOfLine &&
484         ( primaryNumberOfCharacters > 1u ) )
485     {
486       const CharacterIndex firstIndex = *( glyphsToCharactersBuffer + primaryGlyphIndex );
487
488       bool isCurrentRightToLeft = false;
489       if( bidiLineFetched ) // If bidiLineFetched is false, it means the whole text is left to right.
490       {
491         isCurrentRightToLeft = *( directionsBuffer + index );
492       }
493
494       Length numberOfGlyphAdvance = ( isFirstPositionOfLine ? 0u : 1u ) + characterIndex - firstIndex;
495       if( isCurrentRightToLeft )
496       {
497         numberOfGlyphAdvance = primaryNumberOfCharacters - numberOfGlyphAdvance;
498       }
499
500       glyphAdvance = static_cast<float>( numberOfGlyphAdvance ) * glyphMetrics.advance / static_cast<float>( primaryNumberOfCharacters );
501     }
502
503     // Get the glyph position and x bearing (in the line's coords).
504     const Vector2& primaryPosition = *( glyphPositionsBuffer + primaryGlyphIndex );
505
506     // Set the primary cursor's height.
507     cursorInfo.primaryCursorHeight = cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight;
508
509     // Set the primary cursor's position.
510     cursorInfo.primaryPosition.x = -glyphMetrics.xBearing + primaryPosition.x + glyphAdvance;
511     cursorInfo.primaryPosition.y = cursorInfo.lineOffset + line.ascender - glyphMetrics.ascender;
512
513     // Transform the cursor info from line's coords to text's coords.
514     cursorInfo.primaryPosition.x += line.alignmentOffset;
515
516     // Calculate the secondary cursor.
517     if( cursorInfo.isSecondaryCursor )
518     {
519       // Set the secondary cursor's height.
520       cursorInfo.secondaryCursorHeight = 0.5f * glyphMetrics.fontHeight;
521
522       CharacterIndex index = characterIndex;
523       if( !isLastPositionOfLine )
524       {
525         index = ( isRightToLeftParagraph == isCurrentRightToLeft ) ? nextCharacterIndex : characterIndex;
526       }
527
528       const GlyphIndex secondaryGlyphIndex = *( charactersToGlyphBuffer + index );
529       const Length secondaryNumberOfGlyphs = *( glyphsPerCharacterBuffer + index );
530
531       const Vector2& secondaryPosition = *( glyphPositionsBuffer + secondaryGlyphIndex );
532
533       GetGlyphsMetrics( secondaryGlyphIndex,
534                         secondaryNumberOfGlyphs,
535                         glyphMetrics,
536                         glyphInfoBuffer,
537                         metrics );
538
539       // Set the secondary cursor's position.
540
541       // FCP A
542       // ------
543       // 000 1
544       // 001 x
545       // 010 0
546       // 011 0
547       // 100 x
548       // 101 0
549       // 110 1
550       // 111 x
551       //
552       // Where F -> isFirstPosition
553       //       C -> isCurrentRightToLeft
554       //       P -> isRightToLeftParagraph
555       //       A -> Whether to add the glyph's advance.
556
557       const bool addGlyphAdvance = ( ( !isFirstPositionOfLine && !isCurrentRightToLeft ) ||
558                                      ( isFirstPositionOfLine && !isRightToLeftParagraph ) );
559
560       cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + ( addGlyphAdvance ? glyphMetrics.advance : 0.f );
561       cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight - line.descender - ( glyphMetrics.fontHeight - glyphMetrics.ascender );
562
563       // Transform the cursor info from line's coords to text's coords.
564       cursorInfo.secondaryPosition.x += line.alignmentOffset;
565     }
566   }
567 }
568
569 void FindSelectionIndices( VisualModelPtr visualModel,
570                            LogicalModelPtr logicalModel,
571                            MetricsPtr metrics,
572                            float visualX,
573                            float visualY,
574                            CharacterIndex& startIndex,
575                            CharacterIndex& endIndex )
576 {
577   CharacterIndex hitCharacter = Text::GetClosestCursorIndex( visualModel,
578                                                              logicalModel,
579                                                              metrics,
580                                                              visualX,
581                                                              visualY );
582   DALI_ASSERT_DEBUG( hitCharacter <= logicalModel->mText.Count() && "GetClosestCursorIndex returned out of bounds index" );
583
584   if( logicalModel->mText.Count() == 0 )
585   {
586     return;  // if model empty
587   }
588
589   if( hitCharacter >= logicalModel->mText.Count() )
590   {
591     // Closest hit character is the last character.
592     if( hitCharacter ==  logicalModel->mText.Count() )
593     {
594       hitCharacter--; //Hit character index set to last character in logical model
595     }
596     else
597     {
598       // hitCharacter is out of bounds
599       return;
600     }
601   }
602
603   startIndex = hitCharacter;
604   endIndex = hitCharacter;
605   bool isHitCharacterWhitespace = TextAbstraction::IsWhiteSpace( logicalModel->mText[hitCharacter] );
606
607   // Find the start and end of the text
608   for( startIndex = hitCharacter; startIndex > 0; --startIndex )
609   {
610     if( isHitCharacterWhitespace != TextAbstraction::IsWhiteSpace( logicalModel->mText[ startIndex-1 ] ) )
611     {
612       break;
613     }
614   }
615   const CharacterIndex pastTheEnd = logicalModel->mText.Count();
616   for( endIndex = hitCharacter + 1u; endIndex < pastTheEnd; ++endIndex )
617   {
618     if( isHitCharacterWhitespace != TextAbstraction::IsWhiteSpace( logicalModel->mText[ endIndex ] ) )
619     {
620       break;
621     }
622   }
623 }
624
625 } // namespace Text
626
627 } // namespace Toolkit
628
629 } // namespace Dali