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