3404be236f080af780c56b9dedcdfbad170b77ad
[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 Vector2& ViewModel::GetOutlineOffset() const
289 {
290   return mModel->GetOutlineOffset();
291 }
292
293 const Vector4& ViewModel::GetOutlineColor() const
294 {
295   return mModel->GetOutlineColor();
296 }
297
298 uint16_t ViewModel::GetOutlineWidth() const
299 {
300   return mModel->GetOutlineWidth();
301 }
302
303 const float& ViewModel::GetOutlineBlurRadius() const
304 {
305   return mModel->GetOutlineBlurRadius();
306 }
307
308 const Vector4& ViewModel::GetBackgroundColor() const
309 {
310   return mModel->GetBackgroundColor();
311 }
312
313 bool ViewModel::IsBackgroundEnabled() const
314 {
315   return mModel->IsBackgroundEnabled();
316 }
317
318 bool ViewModel::IsMarkupProcessorEnabled() const
319 {
320   return mModel->IsMarkupProcessorEnabled();
321 }
322
323 bool ViewModel::IsSpannedTextPlaced() const
324 {
325   return mModel->IsSpannedTextPlaced();
326 }
327
328 const GlyphInfo* ViewModel::GetHyphens() const
329 {
330   return mModel->GetHyphens();
331 }
332
333 const Length* ViewModel::GetHyphenIndices() const
334 {
335   return mModel->GetHyphenIndices();
336 }
337
338 Length ViewModel::GetHyphensCount() const
339 {
340   return mModel->GetHyphensCount();
341 }
342
343 float ViewModel::GetCharacterSpacing() const
344 {
345   return mModel->GetCharacterSpacing();
346 }
347
348 const Character* ViewModel::GetTextBuffer() const
349 {
350   return mModel->GetTextBuffer();
351 }
352
353 const Vector<CharacterIndex>& ViewModel::GetGlyphsToCharacters() const
354 {
355   return mModel->GetGlyphsToCharacters();
356 }
357
358 void ViewModel::ElideGlyphs()
359 {
360   mIsTextElided             = false;
361   mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = 0;
362   mEndIndexOfElidedGlyphs                                                                        = mModel->GetNumberOfGlyphs() - 1u;
363
364   auto                          ellipsisPosition          = GetEllipsisPosition();
365   auto                          characterSpacing          = GetCharacterSpacing();
366   const Character*              textBuffer                = GetTextBuffer();
367   const Vector<CharacterIndex>& glyphToCharacterMap       = GetGlyphsToCharacters();
368   const CharacterIndex*         glyphToCharacterMapBuffer = glyphToCharacterMap.Begin();
369   float                         calculatedAdvance         = 0.f;
370
371   if(IsTextElideEnabled())
372   {
373     const Length numberOfLines = mModel->GetNumberOfLines();
374     if(0u != numberOfLines)
375     {
376       const LineRun* const lines = mModel->GetLines();
377
378       //Get line of ellipsis
379       const LineRun* ellipsisLine     = nullptr;
380       const LineRun* ellipsisNextLine = nullptr;
381
382       for(Length lineIndex = 0; lineIndex < numberOfLines; lineIndex++)
383       {
384         const LineRun* line = (lines + lineIndex);
385         if(line->ellipsis)
386         {
387           ellipsisLine = line;
388           if(lineIndex < numberOfLines - 1u)
389           {
390             ellipsisNextLine = (lines + lineIndex + 1u);
391           }
392           break;
393         }
394       }
395
396       // Check if there is a line contains Ellipsis.
397       // Then find total number of glyphs and total number of laid out glyphs.
398       // Check where to set Ellipsis glyph in line.
399       // Determine index of Ellipsis glyph and how many glyphs should be replaced by Ellipsis glyph, according to width of Ellipsis glyph.
400       if(ellipsisLine != nullptr)
401       {
402         // Total number of glyphs.
403         const Length numberOfGlyphs = mModel->GetNumberOfGlyphs();
404         // Total number of laid out glyphs.
405         Length numberOfActualLaidOutGlyphs = 0u;
406
407         // Accumulate laid out glyphs for each line to find total number of laid out glyphs.
408         for(Length lineIndex = 0u; lineIndex < numberOfLines; lineIndex++)
409         {
410           numberOfActualLaidOutGlyphs += lines[lineIndex].glyphRun.numberOfGlyphs + lines[lineIndex].glyphRunSecondHalf.numberOfGlyphs;
411         }
412
413         // Make sure there are laid out glyphs.
414         if(0u != numberOfActualLaidOutGlyphs)
415         {
416           // There are elided glyphs.
417           mIsTextElided                          = true;
418           TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
419
420           // Retrieve the whole glyphs and their positions.
421           const GlyphInfo* const glyphs    = mModel->GetGlyphs();
422           const Vector2* const   positions = mModel->GetLayout();
423
424           // Copy the glyphs to be elided.
425           mElidedGlyphs.Resize(numberOfGlyphs);
426           mElidedLayout.Resize(numberOfGlyphs);
427           GlyphInfo* elidedGlyphsBuffer    = mElidedGlyphs.Begin();
428           Vector2*   elidedPositionsBuffer = mElidedLayout.Begin();
429
430           memcpy(elidedGlyphsBuffer, glyphs, numberOfGlyphs * sizeof(GlyphInfo));
431           memcpy(elidedPositionsBuffer, positions, numberOfGlyphs * sizeof(Vector2));
432
433           const Size& controlSize = mModel->GetControlSize();
434
435           // Set index where to set Ellipsis according to the selected position of Ellipsis.
436           // Start with this index to replace its glyph by Ellipsis, if the width  is not enough, then remove more glyphs.
437           GlyphIndex startIndexOfEllipsis = 0u;
438           if(ellipsisPosition == DevelText::EllipsisPosition::START)
439           {
440             // It's the fisrt glyph in line.
441             startIndexOfEllipsis = ellipsisLine->glyphRun.glyphIndex;
442           }
443           else if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE)
444           {
445             // It's the second middle of the line in case the line split to two halves.
446             // Otherwise it's It's the last glyph in line (line before all removed lines).
447             startIndexOfEllipsis = ellipsisLine->isSplitToTwoHalves ? (ellipsisLine->glyphRunSecondHalf.glyphIndex) : (ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u);
448           }
449           else // DevelText::EllipsisPosition::END
450           {
451             // It's the last glyph in line.
452             startIndexOfEllipsis = ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u;
453           }
454
455           // When the hight is not enough then show one glyph and that should be the first laid out glyph.
456           if((1u == numberOfLines) &&
457              (ellipsisLine->ascender - ellipsisLine->descender > controlSize.height))
458           {
459             // Replace the first glyph with ellipsis glyph
460             auto indexOfFirstGlyph = (ellipsisPosition == DevelText::EllipsisPosition::START) ? startIndexOfEllipsis : 0u;
461
462             // Regardless where the location of ellipsis,in-case the hight of line is greater than control's height
463             // then replace the first glyph with ellipsis glyph.
464
465             // Get the first glyph which is going to be replaced and the ellipsis glyph.
466             GlyphInfo&       glyphToRemove = *(elidedGlyphsBuffer + indexOfFirstGlyph);
467             const GlyphInfo& ellipsisGlyph = fontClient.GetEllipsisGlyph(fontClient.GetPointSize(glyphToRemove.fontId));
468
469             // Change the 'x' and 'y' position of the ellipsis glyph.
470             Vector2& position = *(elidedPositionsBuffer + indexOfFirstGlyph);
471
472             position.x = ellipsisGlyph.xBearing;
473             position.y = -ellipsisLine->ascender + controlSize.height - ellipsisGlyph.yBearing;
474
475             // Replace the glyph by the ellipsis glyph and resize the buffers.
476             glyphToRemove = ellipsisGlyph;
477
478             mElidedGlyphs.Resize(1u);
479             mElidedLayout.Resize(1u);
480
481             mEndIndexOfElidedGlyphs = mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = indexOfFirstGlyph;
482
483             return;
484           }
485
486           // firstPenX, penY and firstPenSet are used to position the ellipsis glyph if needed.
487           float firstPenX   = 0.f; // Used if rtl text is elided.
488           float penY        = 0.f;
489           bool  firstPenSet = false;
490
491           // Add the ellipsis glyph.
492           bool       inserted              = false;
493           float      removedGlypsWidth     = 0.f;
494           Length     numberOfRemovedGlyphs = 0u;
495           GlyphIndex indexOfEllipsis       = startIndexOfEllipsis;
496
497           // Tail Mode: start by the end of line.
498           bool isTailMode = (ellipsisPosition == DevelText::EllipsisPosition::END) ||
499                             (ellipsisPosition == DevelText::EllipsisPosition::MIDDLE && numberOfLines != 1u);
500
501           // The ellipsis glyph has to fit in the place where the last glyph(s) is(are) removed.
502           while(!inserted)
503           {
504             const GlyphInfo& glyphToRemove = *(elidedGlyphsBuffer + indexOfEllipsis);
505
506             if(0u != glyphToRemove.fontId)
507             {
508               // i.e. The font id of the glyph shaped from the '\n' character is zero.
509
510               // Need to reshape the glyph as the font may be different in size.
511               const GlyphInfo& ellipsisGlyph = fontClient.GetEllipsisGlyph(fontClient.GetPointSize(glyphToRemove.fontId));
512
513               if(!firstPenSet || EqualsZero(glyphToRemove.advance))
514               {
515                 const Vector2& position = *(elidedPositionsBuffer + indexOfEllipsis);
516
517                 // Calculates the penY of the current line. It will be used to position the ellipsis glyph.
518                 penY = position.y + glyphToRemove.yBearing;
519
520                 // Calculates the first penX which will be used if rtl text is elided.
521                 firstPenX = position.x - glyphToRemove.xBearing;
522                 if(firstPenX < -ellipsisGlyph.xBearing)
523                 {
524                   // Avoids to exceed the bounding box when rtl text is elided.
525                   firstPenX = -ellipsisGlyph.xBearing;
526                 }
527
528                 removedGlypsWidth = -ellipsisGlyph.xBearing;
529
530                 firstPenSet = true;
531               }
532
533               calculatedAdvance = GetCalculatedAdvance(*(textBuffer + (*(glyphToCharacterMapBuffer + indexOfEllipsis))), characterSpacing, glyphToRemove.advance);
534               removedGlypsWidth += std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width));
535
536               // Calculate the width of the ellipsis glyph and check if it fits.
537               const float ellipsisGlyphWidth = ellipsisGlyph.width + ellipsisGlyph.xBearing;
538
539               // If it is the last glyph to remove, add the ellipsis glyph without checking its width.
540               if((ellipsisGlyphWidth < removedGlypsWidth) || (isTailMode ? (indexOfEllipsis == 0u) : (indexOfEllipsis == numberOfGlyphs - 1u)))
541               {
542                 GlyphInfo& glyphInfo = *(elidedGlyphsBuffer + indexOfEllipsis);
543                 Vector2&   position  = *(elidedPositionsBuffer + indexOfEllipsis);
544                 position.x -= (0.f > glyphInfo.xBearing) ? glyphInfo.xBearing : 0.f;
545
546                 // Replace the glyph by the ellipsis glyph.
547                 glyphInfo = ellipsisGlyph;
548
549                 // Change the 'x' and 'y' position of the ellipsis glyph.
550                 if(position.x > firstPenX)
551                 {
552                   if(isTailMode)
553                   {
554                     // To handle case of the mixed languages (LTR then RTL) with
555                     // EllipsisPosition::END and the LayoutDirection::RIGHT_TO_LEFT
556                     float nextXPositions = ellipsisLine->width;
557                     if(indexOfEllipsis + 1u < numberOfGlyphs)
558                     {
559                       Vector2& positionOfNextGlyph = *(elidedPositionsBuffer + indexOfEllipsis + 1u);
560                       nextXPositions               = positionOfNextGlyph.x;
561                     }
562
563                     if(position.x > nextXPositions) // RTL language
564                     {
565                       if((indexOfEllipsis > 0u) && ((position.x - nextXPositions) > removedGlypsWidth))
566                       {
567                         // To handle mixed directions
568                         // Re-calculates the first penX which will be used if rtl text is elided.
569                         firstPenX = position.x - glyphToRemove.xBearing;
570                         if(firstPenX < -ellipsisGlyph.xBearing)
571                         {
572                           // Avoids to exceed the bounding box when rtl text is elided.
573                           firstPenX = -ellipsisGlyph.xBearing;
574                         }
575                         //Reset the width of removed glyphs
576                         removedGlypsWidth = std::min(calculatedAdvance, (glyphToRemove.xBearing + glyphToRemove.width)) - ellipsisGlyph.xBearing;
577
578                         --indexOfEllipsis;
579                         continue;
580                       }
581                       else
582                       {
583                         // To handle the case of RTL language with EllipsisPosition::END
584                         position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
585                       }
586                     }
587                   }
588                   else
589                   {
590                     // To handle the case of LTR language with EllipsisPosition::START
591                     position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
592                   }
593                 }
594                 else
595                 {
596                   if(!isTailMode)
597                   {
598                     // To handle case of the mixed languages (RTL then LTR) with
599                     // EllipsisPosition::START and the LayoutDirection::RIGHT_TO_LEFT
600                     float nextXPositions = ellipsisLine->width;
601                     if(indexOfEllipsis + 1u < numberOfGlyphs)
602                     {
603                       Vector2& positionOfNextGlyph = *(elidedPositionsBuffer + indexOfEllipsis + 1u);
604                       nextXPositions               = positionOfNextGlyph.x;
605                     }
606
607                     if(position.x < nextXPositions) // LTR language
608                     {
609                       position.x = firstPenX + removedGlypsWidth - ellipsisGlyphWidth;
610
611                       if((position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) > nextXPositions)
612                       {
613                         position.x -= (position.x + ellipsisGlyphWidth + ellipsisGlyph.xBearing) - nextXPositions;
614                       }
615                     }
616                   }
617                 }
618
619                 position.x += ellipsisGlyph.xBearing;
620                 position.y = penY - ellipsisGlyph.yBearing;
621
622                 inserted = true;
623               }
624             }
625
626             if(!inserted)
627             {
628               if(!isTailMode && indexOfEllipsis < numberOfGlyphs - 1u)
629               {
630                 // Tail Mode: remove glyphs from startIndexOfEllipsis then decrement indexOfEllipsis, until arrive to index zero.
631                 ++indexOfEllipsis;
632               }
633               else if(isTailMode && indexOfEllipsis > 0u)
634               {
635                 // Not Tail Mode: remove glyphs from startIndexOfEllipsis then increase indexOfEllipsis, until arrive to last index (numberOfGlyphs - 1u).
636                 --indexOfEllipsis;
637               }
638               else
639               {
640                 // No space for the ellipsis.
641                 inserted = true;
642               }
643               ++numberOfRemovedGlyphs;
644             }
645           } // while( !inserted )
646
647           //Reduce size, shift glyphs and start from ellipsis glyph
648           Length numberOfElidedGlyphs = numberOfActualLaidOutGlyphs - numberOfRemovedGlyphs;
649           mElidedGlyphs.Resize(numberOfElidedGlyphs);
650           mElidedLayout.Resize(numberOfElidedGlyphs);
651
652           if(ellipsisPosition == DevelText::EllipsisPosition::START)
653           {
654             // 'Shifts' glyphs after ellipsis glyph and 'Removes' before ellipsis glyph
655             memcpy(elidedGlyphsBuffer, elidedGlyphsBuffer + indexOfEllipsis, numberOfElidedGlyphs * sizeof(GlyphInfo));
656             memcpy(elidedPositionsBuffer, elidedPositionsBuffer + indexOfEllipsis, numberOfElidedGlyphs * sizeof(Vector2));
657
658             mStartIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = indexOfEllipsis;
659           }
660           else if(ellipsisPosition == DevelText::EllipsisPosition::MIDDLE)
661           {
662             // 'Shifts and connects' glyphs before and after ellipsis glyph and 'Removes' in-between.
663             bool isOnlySecondHalf = false;
664
665             if(isTailMode)
666             {
667               mFirstMiddleIndexOfElidedGlyphs = indexOfEllipsis;
668               if(ellipsisNextLine != nullptr)
669               {
670                 mSecondMiddleIndexOfElidedGlyphs = ellipsisNextLine->glyphRun.glyphIndex;
671               }
672               else
673               {
674                 mEndIndexOfElidedGlyphs = mSecondMiddleIndexOfElidedGlyphs = mFirstMiddleIndexOfElidedGlyphs;
675               }
676             }
677             else
678             {
679               mFirstMiddleIndexOfElidedGlyphs  = (ellipsisLine->glyphRun.numberOfGlyphs > 0u) ? (ellipsisLine->glyphRun.glyphIndex + ellipsisLine->glyphRun.numberOfGlyphs - 1u) : (ellipsisLine->glyphRun.glyphIndex);
680               mSecondMiddleIndexOfElidedGlyphs = indexOfEllipsis;
681               isOnlySecondHalf                 = ellipsisLine->glyphRun.numberOfGlyphs == 0u && ellipsisLine->glyphRunSecondHalf.numberOfGlyphs > 0u;
682             }
683
684             if(isOnlySecondHalf)
685             {
686               Length numberOfSecondHalfGlyphs = numberOfElidedGlyphs - mFirstMiddleIndexOfElidedGlyphs;
687
688               //Copy elided glyphs after the ellipsis glyph.
689               memcpy(elidedGlyphsBuffer + mFirstMiddleIndexOfElidedGlyphs, elidedGlyphsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(GlyphInfo));
690               memcpy(elidedPositionsBuffer + mFirstMiddleIndexOfElidedGlyphs, elidedPositionsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(Vector2));
691             }
692             else
693             {
694               Length numberOfSecondHalfGlyphs = numberOfElidedGlyphs - mFirstMiddleIndexOfElidedGlyphs + 1u;
695
696               //Copy elided glyphs after the ellipsis glyph.
697               memcpy(elidedGlyphsBuffer + mFirstMiddleIndexOfElidedGlyphs + 1u, elidedGlyphsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(GlyphInfo));
698               memcpy(elidedPositionsBuffer + mFirstMiddleIndexOfElidedGlyphs + 1u, elidedPositionsBuffer + mSecondMiddleIndexOfElidedGlyphs, numberOfSecondHalfGlyphs * sizeof(Vector2));
699             }
700           }
701           else // DevelText::EllipsisPosition::END
702           {
703             // 'Removes' all the glyphs after the ellipsis glyph.
704             mEndIndexOfElidedGlyphs = indexOfEllipsis;
705           }
706         }
707       }
708     }
709   }
710 }
711
712 float ViewModel::GetStrikethroughHeight() const
713 {
714   return mModel->GetStrikethroughHeight();
715 }
716
717 const Vector4& ViewModel::GetStrikethroughColor() const
718 {
719   return mModel->GetStrikethroughColor();
720 }
721
722 bool ViewModel::IsStrikethroughEnabled() const
723 {
724   return mModel->IsStrikethroughEnabled();
725 }
726
727 bool ViewModel::IsMarkupStrikethroughSet() const
728 {
729   return mModel->IsMarkupStrikethroughSet();
730 }
731
732 Length ViewModel::GetNumberOfStrikethroughRuns() const
733 {
734   return mModel->GetNumberOfStrikethroughRuns();
735 }
736
737 void ViewModel::GetStrikethroughRuns(StrikethroughGlyphRun* strikethroughRuns, StrikethroughRunIndex index, Length numberOfRuns) const
738 {
739   mModel->GetStrikethroughRuns(strikethroughRuns, index, numberOfRuns);
740 }
741
742 Length ViewModel::GetNumberOfBoundedParagraphRuns() const
743 {
744   return mModel->GetNumberOfBoundedParagraphRuns();
745 }
746
747 const Vector<BoundedParagraphRun>& ViewModel::GetBoundedParagraphRuns() const
748 {
749   return mModel->GetBoundedParagraphRuns();
750 }
751
752 Length ViewModel::GetNumberOfCharacterSpacingGlyphRuns() const
753 {
754   return mModel->GetNumberOfCharacterSpacingGlyphRuns();
755 }
756
757 const Vector<CharacterSpacingGlyphRun>& ViewModel::GetCharacterSpacingGlyphRuns() const
758 {
759   return mModel->GetCharacterSpacingGlyphRuns();
760 }
761
762 const Vector<FontRun>& ViewModel::GetFontRuns() const
763 {
764   return mModel->GetFontRuns();
765 }
766
767 const Vector<FontDescriptionRun>& ViewModel::GetFontDescriptionRuns() const
768 {
769   return mModel->GetFontDescriptionRuns();
770 }
771
772 } // namespace Text
773
774 } // namespace Toolkit
775
776 } // namespace Dali