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