[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / view-model.cpp
1 /*
2  * Copyright (c) 2022 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 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/view-model.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/font-client.h>
23 #include <memory.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/glyph-metrics-helper.h>
27 #include <dali-toolkit/internal/text/line-run.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 ViewModel::ViewModel(const ModelInterface* const model)
36 : mModel(model),
37   mElidedGlyphs(),
38   mElidedLayout(),
39   mIsTextElided(false),
40   mStartIndexOfElidedGlyphs(0u),
41   mEndIndexOfElidedGlyphs(0u),
42   mFirstMiddleIndexOfElidedGlyphs(0u),
43   mSecondMiddleIndexOfElidedGlyphs(0u)
44 {
45 }
46
47 ViewModel::~ViewModel()
48 {
49 }
50
51 const Size& ViewModel::GetControlSize() const
52 {
53   return mModel->GetControlSize();
54 }
55
56 const Size& ViewModel::GetLayoutSize() const
57 {
58   return mModel->GetLayoutSize();
59 }
60
61 const Vector2& ViewModel::GetScrollPosition() const
62 {
63   return mModel->GetScrollPosition();
64 }
65
66 HorizontalAlignment::Type ViewModel::GetHorizontalAlignment() const
67 {
68   return mModel->GetHorizontalAlignment();
69 }
70
71 VerticalAlignment::Type ViewModel::GetVerticalAlignment() const
72 {
73   return mModel->GetVerticalAlignment();
74 }
75
76 DevelText::VerticalLineAlignment::Type ViewModel::GetVerticalLineAlignment() const
77 {
78   return mModel->GetVerticalLineAlignment();
79 }
80
81 DevelText::EllipsisPosition::Type ViewModel::GetEllipsisPosition() const
82 {
83   return mModel->GetEllipsisPosition();
84 }
85
86 bool ViewModel::IsTextElideEnabled() const
87 {
88   return mModel->IsTextElideEnabled();
89 }
90
91 Length ViewModel::GetNumberOfLines() const
92 {
93   return mModel->GetNumberOfLines();
94 }
95
96 const LineRun* const ViewModel::GetLines() const
97 {
98   return mModel->GetLines();
99 }
100
101 Length ViewModel::GetNumberOfScripts() const
102 {
103   return mModel->GetNumberOfScripts();
104 }
105
106 const ScriptRun* const ViewModel::GetScriptRuns() const
107 {
108   return mModel->GetScriptRuns();
109 }
110
111 Length ViewModel::GetNumberOfGlyphs() const
112 {
113   if(mIsTextElided && mModel->IsTextElideEnabled())
114   {
115     return mElidedGlyphs.Count();
116   }
117   else
118   {
119     return mModel->GetNumberOfGlyphs();
120   }
121
122   return 0u;
123 }
124
125 GlyphIndex ViewModel::GetStartIndexOfElidedGlyphs() const
126 {
127   if(mIsTextElided && mModel->IsTextElideEnabled())
128   {
129     return mStartIndexOfElidedGlyphs;
130   }
131
132   return mModel->GetStartIndexOfElidedGlyphs();
133 }
134
135 GlyphIndex ViewModel::GetEndIndexOfElidedGlyphs() const
136 {
137   if(mIsTextElided && mModel->IsTextElideEnabled())
138   {
139     return mEndIndexOfElidedGlyphs;
140   }
141
142   return mModel->GetEndIndexOfElidedGlyphs();
143 }
144
145 GlyphIndex ViewModel::GetFirstMiddleIndexOfElidedGlyphs() const
146 {
147   if(mIsTextElided && mModel->IsTextElideEnabled())
148   {
149     return mFirstMiddleIndexOfElidedGlyphs;
150   }
151
152   return mModel->GetFirstMiddleIndexOfElidedGlyphs();
153 }
154
155 GlyphIndex ViewModel::GetSecondMiddleIndexOfElidedGlyphs() const
156 {
157   if(mIsTextElided && mModel->IsTextElideEnabled())
158   {
159     return mSecondMiddleIndexOfElidedGlyphs;
160   }
161
162   return mModel->GetSecondMiddleIndexOfElidedGlyphs();
163 }
164
165 const GlyphInfo* const ViewModel::GetGlyphs() const
166 {
167   if(mIsTextElided && mModel->IsTextElideEnabled())
168   {
169     return mElidedGlyphs.Begin();
170   }
171   else
172   {
173     return mModel->GetGlyphs();
174   }
175
176   return NULL;
177 }
178
179 const Vector2* const ViewModel::GetLayout() const
180 {
181   if(mIsTextElided && mModel->IsTextElideEnabled())
182   {
183     return mElidedLayout.Begin();
184   }
185   else
186   {
187     return mModel->GetLayout();
188   }
189
190   return NULL;
191 }
192
193 const Vector4* const ViewModel::GetColors() const
194 {
195   return mModel->GetColors();
196 }
197
198 const ColorIndex* const ViewModel::GetColorIndices() const
199 {
200   return mModel->GetColorIndices();
201 }
202
203 const Vector4* const ViewModel::GetBackgroundColors() const
204 {
205   return mModel->GetBackgroundColors();
206 }
207
208 const ColorIndex* const ViewModel::GetBackgroundColorIndices() const
209 {
210   return mModel->GetBackgroundColorIndices();
211 }
212
213 bool const ViewModel::IsMarkupBackgroundColorSet() const
214 {
215   return mModel->IsMarkupBackgroundColorSet();
216 }
217
218 const Vector4& ViewModel::GetDefaultColor() const
219 {
220   return mModel->GetDefaultColor();
221 }
222
223 const Vector2& ViewModel::GetShadowOffset() const
224 {
225   return mModel->GetShadowOffset();
226 }
227
228 const Vector4& ViewModel::GetShadowColor() const
229 {
230   return mModel->GetShadowColor();
231 }
232
233 const float& ViewModel::GetShadowBlurRadius() const
234 {
235   return mModel->GetShadowBlurRadius();
236 }
237
238 const Vector4& ViewModel::GetUnderlineColor() const
239 {
240   return mModel->GetUnderlineColor();
241 }
242
243 bool ViewModel::IsUnderlineEnabled() const
244 {
245   return mModel->IsUnderlineEnabled();
246 }
247
248 float ViewModel::GetUnderlineHeight() const
249 {
250   return mModel->GetUnderlineHeight();
251 }
252
253 Text::Underline::Type ViewModel::GetUnderlineType() const
254 {
255   return mModel->GetUnderlineType();
256 }
257
258 float ViewModel::GetDashedUnderlineWidth() const
259 {
260   return mModel->GetDashedUnderlineWidth();
261 }
262
263 float ViewModel::GetDashedUnderlineGap() const
264 {
265   return mModel->GetDashedUnderlineGap();
266 }
267
268 Length ViewModel::GetNumberOfUnderlineRuns() const
269 {
270   return mModel->GetNumberOfUnderlineRuns();
271 }
272
273 void ViewModel::GetUnderlineRuns(UnderlinedGlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns) const
274 {
275   mModel->GetUnderlineRuns(underlineRuns, index, numberOfRuns);
276 }
277
278 const Vector4& ViewModel::GetOutlineColor() const
279 {
280   return mModel->GetOutlineColor();
281 }
282
283 uint16_t ViewModel::GetOutlineWidth() const
284 {
285   return mModel->GetOutlineWidth();
286 }
287
288 const Vector4& ViewModel::GetBackgroundColor() const
289 {
290   return mModel->GetBackgroundColor();
291 }
292
293 bool ViewModel::IsBackgroundEnabled() const
294 {
295   return mModel->IsBackgroundEnabled();
296 }
297
298 bool ViewModel::IsMarkupProcessorEnabled() const
299 {
300   return mModel->IsMarkupProcessorEnabled();
301 }
302
303 const GlyphInfo* ViewModel::GetHyphens() const
304 {
305   return mModel->GetHyphens();
306 }
307
308 const Length* ViewModel::GetHyphenIndices() const
309 {
310   return mModel->GetHyphenIndices();
311 }
312
313 Length ViewModel::GetHyphensCount() const
314 {
315   return mModel->GetHyphensCount();
316 }
317
318 const float ViewModel::GetCharacterSpacing() const
319 {
320   return mModel->GetCharacterSpacing();
321 }
322
323 const Character* ViewModel::GetTextBuffer() const
324 {
325   return mModel->GetTextBuffer();
326 }
327
328 const Vector<CharacterIndex>& ViewModel::GetGlyphsToCharacters() const
329 {
330   return mModel->GetGlyphsToCharacters();
331 }
332
333 void ViewModel::ElideGlyphs()
334 {
335   mIsTextElided             = false;
336   mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = 0;
337   mEndIndexOfElidedGlyphs                                                                        = mModel->GetNumberOfGlyphs() - 1u;
338
339   auto                          ellipsisPosition          = GetEllipsisPosition();
340   auto                          characterSpacing          = GetCharacterSpacing();
341   const Character*              textBuffer                = GetTextBuffer();
342   const Vector<CharacterIndex>& glyphToCharacterMap       = GetGlyphsToCharacters();
343   const CharacterIndex*         glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
344   float                         calculatedAdvance         = 0.f;
345
346   if(IsTextElideEnabled())
347   {
348     const Length numberOfLines = mModel->GetNumberOfLines();
349     if(0u != numberOfLines)
350     {
351       const LineRun* const lines = mModel->GetLines();
352
353       //Get line of ellipsis
354       const LineRun* ellipsisLine     = nullptr;
355       const LineRun* ellipsisNextLine = nullptr;
356
357       for(Length lineIndex = 0; lineIndex < numberOfLines; lineIndex++)
358       {
359         const LineRun* line = (lines + lineIndex);
360         if(line->ellipsis)
361         {
362           ellipsisLine = line;
363           if(lineIndex < numberOfLines - 1u)
364           {
365             ellipsisNextLine = (lines + lineIndex + 1u);
366           }
367           break;
368         }
369       }
370
371       // Check if there is a line contains Ellipsis.
372       // Then find total number of glyphs and total number of laid out glyphs.
373       // Check where to set Ellipsis glyph in line.
374       // Determine index of Ellipsis glyph and how many glyphs should be replaced by Ellipsis glyph, according to width of Ellipsis glyph.
375       if(ellipsisLine != nullptr)
376       {
377         // Total number of glyphs.
378         const Length numberOfGlyphs = mModel->GetNumberOfGlyphs();
379         // Total number of laid out glyphs.
380         Length numberOfActualLaidOutGlyphs = 0u;
381
382         // Accumulate laid out glyphs for each line to find total number of laid out glyphs.
383         for(Length lineIndex = 0u; lineIndex < numberOfLines; lineIndex++)
384         {
385           numberOfActualLaidOutGlyphs += lines[lineIndex].glyphRun.numberOfGlyphs + lines[lineIndex].glyphRunSecondHalf.numberOfGlyphs;
386         }
387
388         // Make sure there are laid out glyphs.
389         if(0u != numberOfActualLaidOutGlyphs)
390         {
391           // There are elided glyphs.
392           mIsTextElided                          = true;
393           TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
394
395           // Retrieve the whole glyphs and their positions.
396           const GlyphInfo* const glyphs    = mModel->GetGlyphs();
397           const Vector2* const   positions = mModel->GetLayout();
398
399           // Copy the glyphs to be elided.
400           mElidedGlyphs.Resize(numberOfGlyphs);
401           mElidedLayout.Resize(numberOfGlyphs);
402           GlyphInfo* elidedGlyphsBuffer    = mElidedGlyphs.Begin();
403           Vector2*   elidedPositionsBuffer = mElidedLayout.Begin();
404
405           memcpy(elidedGlyphsBuffer, glyphs, numberOfGlyphs * sizeof(GlyphInfo));
406           memcpy(elidedPositionsBuffer, positions, numberOfGlyphs * sizeof(Vector2));
407
408           const Size& controlSize = mModel->GetControlSize();
409
410           // Set index where to set Ellipsis according to the selected position of Ellipsis.
411           // Start with this index to replace its glyph by Ellipsis, if the width  is not enough, then remove more glyphs.
412           GlyphIndex startIndexOfEllipsis = 0u;
413           if(ellipsisPosition == DevelText::EllipsisPosition::START)
414           {
415             // It's the fisrt glyph in line.
416             startIndexOfEllipsis = ellipsisLine->glyphRun.glyphIndex;
417           }
418           else if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE)
419           {
420             // It's the second middle of the line in case the line split to two halves.
421             // Otherwise it's It's the last glyph in line (line before all removed lines).
422             startIndexOfEllipsis = ellipsisLine->isSplitToTwoHalves ? (ellipsisLine->glyphRunSecondHalf.glyphIndex) : (ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u);
423           }
424           else // DevelText::EllipsisPosition::END
425           {
426             // It's the last glyph in line.
427             startIndexOfEllipsis = ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u;
428           }
429
430           // When the hight is not enough then show one glyph and that should be the first laid out glyph.
431           if((1u == numberOfLines) &&
432              (ellipsisLine->ascender - ellipsisLine->descender > controlSize.height))
433           {
434             // Replace the first glyph with ellipsis glyph
435             auto indexOfFirstGlyph = (ellipsisPosition == DevelText::EllipsisPosition::START) ? startIndexOfEllipsis : 0u;
436
437             // Regardless where the location of ellipsis,in-case the hight of line is greater than control's height
438             // then replace the first glyph with ellipsis glyph.
439
440             // Get the first glyph which is going to be replaced and the ellipsis glyph.
441             GlyphInfo&       glyphToRemove = *(elidedGlyphsBuffer + indexOfFirstGlyph);
442             const GlyphInfo& ellipsisGlyph = fontClient.GetEllipsisGlyph(fontClient.GetPointSize(glyphToRemove.fontId));
443
444             // Change the 'x' and 'y' position of the ellipsis glyph.
445             Vector2& position = *(elidedPositionsBuffer + indexOfFirstGlyph);
446
447             position.x = ellipsisGlyph.xBearing;
448             position.y = -ellipsisLine->ascender + controlSize.height - ellipsisGlyph.yBearing;
449
450             // Replace the glyph by the ellipsis glyph and resize the buffers.
451             glyphToRemove = ellipsisGlyph;
452
453             mElidedGlyphs.Resize(1u);
454             mElidedLayout.Resize(1u);
455
456             mEndIndexOfElidedGlyphs = mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = indexOfFirstGlyph;
457
458             return;
459           }
460
461           // firstPenX, penY and firstPenSet are used to position the ellipsis glyph if needed.
462           float firstPenX   = 0.f; // Used if rtl text is elided.
463           float penY        = 0.f;
464           bool  firstPenSet = false;
465
466           // Add the ellipsis glyph.
467           bool       inserted              = false;
468           float      removedGlypsWidth     = 0.f;
469           Length     numberOfRemovedGlyphs = 0u;
470           GlyphIndex indexOfEllipsis       = startIndexOfEllipsis;
471
472           // Tail Mode: start by the end of line.
473           bool isTailMode = (ellipsisPosition == DevelText::EllipsisPosition::END) ||
474                             (ellipsisPosition == DevelText::EllipsisPosition::MIDDLE && numberOfLines != 1u);
475
476           // The ellipsis glyph has to fit in the place where the last glyph(s) is(are) removed.
477           while(!inserted)
478           {
479             const GlyphInfo& glyphToRemove = *(elidedGlyphsBuffer + indexOfEllipsis);
480
481             if(0u != glyphToRemove.fontId)
482             {
483               // i.e. The font id of the glyph shaped from the '\n' character is zero.
484
485               // Need to reshape the glyph as the font may be different in size.
486               const GlyphInfo& ellipsisGlyph = fontClient.GetEllipsisGlyph(fontClient.GetPointSize(glyphToRemove.fontId));
487
488               if(!firstPenSet || EqualsZero(glyphToRemove.advance))
489               {
490                 const Vector2& position = *(elidedPositionsBuffer + indexOfEllipsis);
491
492                 // Calculates the penY of the current line. It will be used to position the ellipsis glyph.
493                 penY = position.y + glyphToRemove.yBearing;
494
495                 // Calculates the first penX which will be used if rtl text is elided.
496                 firstPenX = position.x - glyphToRemove.xBearing;
497                 if(firstPenX < -ellipsisGlyph.xBearing)
498                 {
499                   // Avoids to exceed the bounding box when rtl text is elided.
500                   firstPenX = -ellipsisGlyph.xBearing;
501                 }
502
503                 removedGlypsWidth = -ellipsisGlyph.xBearing;
504
505                 firstPenSet = true;
506               }
507
508               calculatedAdvance = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + indexOfEllipsis))), characterSpacing, glyphToRemove.advance);
509               removedGlypsWidth += std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width));
510
511               // Calculate the width of the ellipsis glyph and check if it fits.
512               const float ellipsisGlyphWidth = ellipsisGlyph.width + ellipsisGlyph.xBearing;
513
514               // If it is the last glyph to remove, add the ellipsis glyph without checking its width.
515               if((ellipsisGlyphWidth < removedGlypsWidth) || (isTailMode ? (indexOfEllipsis == 0u) : (indexOfEllipsis == numberOfGlyphs - 1u)))
516               {
517                 GlyphInfo& glyphInfo = *(elidedGlyphsBuffer + indexOfEllipsis);
518                 Vector2&   position  = *(elidedPositionsBuffer + indexOfEllipsis);
519                 position.x -= (0.f > glyphInfo.xBearing) ? glyphInfo.xBearing : 0.f;
520
521                 // Replace the glyph by the ellipsis glyph.
522                 glyphInfo = ellipsisGlyph;
523
524                 // Change the 'x' and 'y' position of the ellipsis glyph.
525                 if(position.x > firstPenX)
526                 {
527                   if(isTailMode)
528                   {
529                     // To handle case of the mixed languages (LTR then RTL) with
530                     // EllipsisPosition::END and the LayoutDirection::RIGHT_TO_LEFT
531                     float nextXPositions = ellipsisLine->width;
532                     if(indexOfEllipsis + 1u < numberOfGlyphs)
533                     {
534                       Vector2& positionOfNextGlyph = *(elidedPositionsBuffer + indexOfEllipsis + 1u);
535                       nextXPositions               = positionOfNextGlyph.x;
536                     }
537
538                     if(position.x > nextXPositions) // RTL language
539                     {
540                       if((indexOfEllipsis > 0u) && ((position.x - nextXPositions) > removedGlypsWidth))
541                       {
542                         // To handle mixed directions
543                         // Re-calculates the first penX which will be used if rtl text is elided.
544                         firstPenX = position.x - glyphToRemove.xBearing;
545                         if(firstPenX < -ellipsisGlyph.xBearing)
546                         {
547                           // Avoids to exceed the bounding box when rtl text is elided.
548                           firstPenX = -ellipsisGlyph.xBearing;
549                         }
550                         //Reset the width of removed glyphs
551                         removedGlypsWidth = std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width)) - ellipsisGlyph.xBearing;
552
553                         --indexOfEllipsis;
554                         continue;
555                       }
556                       else
557                       {
558                         // To handle the case of RTL language with EllipsisPosition::END
559                         position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
560                       }
561                     }
562                   }
563                   else
564                   {
565                     // To handle the case of LTR language with EllipsisPosition::START
566                     position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
567                   }
568                 }
569                 else
570                 {
571                   if(!isTailMode)
572                   {
573                     // To handle case of the mixed languages (RTL then LTR) with
574                     // EllipsisPosition::START and the LayoutDirection::RIGHT_TO_LEFT
575                     float nextXPositions = ellipsisLine->width;
576                     if(indexOfEllipsis + 1u < numberOfGlyphs)
577                     {
578                       Vector2& positionOfNextGlyph = *(elidedPositionsBuffer + indexOfEllipsis + 1u);
579                       nextXPositions               = positionOfNextGlyph.x;
580                     }
581
582                     if(position.x < nextXPositions) // LTR language
583                     {
584                       position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
585
586                       if((position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) > nextXPositions)
587                       {
588                         position.x -= (position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) - nextXPositions;
589                       }
590                     }
591                   }
592                 }
593
594                 position.x += ellipsisGlyph.xBearing;
595                 position.y = penY - ellipsisGlyph.yBearing;
596
597                 inserted = true;
598               }
599             }
600
601             if(!inserted)
602             {
603               if(!isTailMode && indexOfEllipsis < numberOfGlyphs - 1u)
604               {
605                 // Tail Mode: remove glyphs from startIndexOfEllipsis then decrement indexOfEllipsis, until arrive to index zero.
606                 ++indexOfEllipsis;
607               }
608               else if(isTailMode && indexOfEllipsis > 0u)
609               {
610                 // Not Tail Mode: remove glyphs from startIndexOfEllipsis then increase indexOfEllipsis, until arrive to last index (numberOfGlyphs - 1u).
611                 --indexOfEllipsis;
612               }
613               else
614               {
615                 // No space for the ellipsis.
616                 inserted = true;
617               }
618               ++numberOfRemovedGlyphs;
619             }
620           } // while( !inserted )
621
622           //Reduce size, shift glyphs and start from ellipsis glyph
623           Length numberOfElidedGlyphs = numberOfActualLaidOutGlyphs - numberOfRemovedGlyphs;
624           mElidedGlyphs.Resize(numberOfElidedGlyphs);
625           mElidedLayout.Resize(numberOfElidedGlyphs);
626
627           if(ellipsisPosition == DevelText::EllipsisPosition::START)
628           {
629             // 'Shifts' glyphs after ellipsis glyph and 'Removes' before ellipsis glyph
630             memcpy(elidedGlyphsBuffer, elidedGlyphsBuffer + indexOfEllipsis, numberOfElidedGlyphs * sizeof(GlyphInfo));
631             memcpy(elidedPositionsBuffer, elidedPositionsBuffer + indexOfEllipsis, numberOfElidedGlyphs * sizeof(Vector2));
632
633             mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = indexOfEllipsis;
634           }
635           else if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE)
636           {
637             // 'Shifts and connects' glyphs before and after ellipsis glyph and 'Removes' in-between.
638             bool isOnlySecondHalf = false;
639
640             if(isTailMode)
641             {
642               mFirstMiddleIndexOfElidedGlyphs = indexOfEllipsis;
643               if(ellipsisNextLine != nullptr)
644               {
645                 mSecondMiddleIndexOfElidedGlyphs = ellipsisNextLine->glyphRun.glyphIndex;
646               }
647               else
648               {
649                 mEndIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs;
650               }
651             }
652             else
653             {
654               mFirstMiddleIndexOfElidedGlyphs  = (ellipsisLine->glyphRun.numberOfGlyphs > 0u) ? (ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u) : (ellipsisLine->glyphRun.glyphIndex);
655               mSecondMiddleIndexOfElidedGlyphs = indexOfEllipsis;
656               isOnlySecondHalf                 = ellipsisLine->glyphRun.numberOfGlyphs == 0u && ellipsisLine->glyphRunSecondHalf.numberOfGlyphs > 0u;
657             }
658
659             if(isOnlySecondHalf)
660             {
661               Length numberOfSecondHalfGlyphs = numberOfElidedGlyphs - mFirstMiddleIndexOfElidedGlyphs;
662
663               //Copy elided glyphs after the ellipsis glyph.
664               memcpy(elidedGlyphsBuffer + mFirstMiddleIndexOfElidedGlyphs, elidedGlyphsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(GlyphInfo));
665               memcpy(elidedPositionsBuffer + mFirstMiddleIndexOfElidedGlyphs, elidedPositionsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(Vector2));
666             }
667             else
668             {
669               Length numberOfSecondHalfGlyphs = numberOfElidedGlyphs - mFirstMiddleIndexOfElidedGlyphs + 1u;
670
671               //Copy elided glyphs after the ellipsis glyph.
672               memcpy(elidedGlyphsBuffer + mFirstMiddleIndexOfElidedGlyphs + 1u, elidedGlyphsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(GlyphInfo));
673               memcpy(elidedPositionsBuffer + mFirstMiddleIndexOfElidedGlyphs + 1u, elidedPositionsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(Vector2));
674             }
675           }
676           else // DevelText::EllipsisPosition::END
677           {
678             // 'Removes' all the glyphs after the ellipsis glyph.
679             mEndIndexOfElidedGlyphs = indexOfEllipsis;
680           }
681         }
682       }
683     }
684   }
685 }
686
687 float ViewModel::GetStrikethroughHeight() const
688 {
689   return mModel->GetStrikethroughHeight();
690 }
691
692 const Vector4& ViewModel::GetStrikethroughColor() const
693 {
694   return mModel->GetStrikethroughColor();
695 }
696
697 bool ViewModel::IsStrikethroughEnabled() const
698 {
699   return mModel->IsStrikethroughEnabled();
700 }
701
702 Length ViewModel::GetNumberOfStrikethroughRuns() const
703 {
704   return mModel->GetNumberOfStrikethroughRuns();
705 }
706
707 void ViewModel::GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const
708 {
709   mModel->GetStrikethroughRuns(strikethroughRuns, index, numberOfRuns);
710 }
711
712 Length ViewModel::GetNumberOfBoundedParagraphRuns() const
713 {
714   return mModel->GetNumberOfBoundedParagraphRuns();
715 }
716
717 const Vector<BoundedParagraphRun>& ViewModel::GetBoundedParagraphRuns() const
718 {
719   return mModel->GetBoundedParagraphRuns();
720 }
721
722 Length ViewModel::GetNumberOfCharacterSpacingGlyphRuns() const
723 {
724   return mModel->GetNumberOfCharacterSpacingGlyphRuns();
725 }
726
727 const Vector<CharacterSpacingGlyphRun>& ViewModel::GetCharacterSpacingGlyphRuns() const
728 {
729   return mModel->GetCharacterSpacingGlyphRuns();
730 }
731
732 } // namespace Text
733
734 } // namespace Toolkit
735
736 } // namespace Dali