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