Support the underline and its attributes in span tag
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextLabel-internal.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 #include <stdlib.h>
19 #include <iostream>
20
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
24 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
25 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
26 #include <dali-toolkit/internal/text/rendering/view-model.h>
27 #include <dali-toolkit/internal/text/text-controller-impl.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29
30 using namespace Dali;
31 using namespace Toolkit;
32 using namespace Text;
33
34 int UtcDaliTextLabelMarkupUnderline(void)
35 {
36   ToolkitTestApplication application;
37   tet_infoline(" UtcDaliTextLabelMarkupUnderline ");
38
39   TextLabel textLabel = TextLabel::New();
40
41   application.GetScene().Add(textLabel);
42
43   textLabel.SetProperty(TextLabel::Property::TEXT, "<u>ABC</u>EF<u>GH</u>");
44   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
45
46   application.SendNotification();
47   application.Render();
48
49   uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
50
51   Toolkit::Internal::TextLabel& textLabelImpl         = GetImpl(textLabel);
52   const Text::Length            numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
53
54   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
55
56   Vector<UnderlinedGlyphRun> underlineRuns;
57   underlineRuns.Resize(numberOfUnderlineRuns);
58   textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
59
60   //ABC are underlined
61   DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
62   DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 1u, TEST_LOCATION);
63   DALI_TEST_EQUALS(underlineRuns[2u].glyphRun.glyphIndex, 2u, TEST_LOCATION);
64
65   //GH are underlined
66   DALI_TEST_EQUALS(underlineRuns[3u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
67   DALI_TEST_EQUALS(underlineRuns[4u].glyphRun.glyphIndex, 6u, TEST_LOCATION);
68
69   END_TEST;
70 }
71
72 int UtcDaliTextLabelMarkupUnderlineAttributes(void)
73 {
74   ToolkitTestApplication application;
75   tet_infoline(" UtcDaliTextLabelMarkupUnderlineAttributes ");
76
77   TextLabel textLabel = TextLabel::New();
78
79   application.GetScene().Add(textLabel);
80
81   std::string testText =
82     "start<u>ABC1</u>then"
83     "<u type='solid'>ABC2</u>then"
84     "<u type='dashed'>ABC3</u>then"
85     "<u type='double'>ABC4</u>then"
86     "<u color='green'>ABC5</u>then"
87     "<u height='5.0f'>ABC6</u>then"
88     "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
89     "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
90     "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
91
92     ;
93
94   textLabel.SetProperty(TextLabel::Property::TEXT, testText);
95   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
96
97   application.SendNotification();
98   application.Render();
99
100   const uint32_t NUMBER_OF_CASES                  = 9u;
101   uint32_t       expectedNumberOfUnderlinedGlyphs = 36u;
102
103   Toolkit::Internal::TextLabel& textLabelImpl         = GetImpl(textLabel);
104   const Text::Length            numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
105
106   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
107
108   Vector<UnderlinedGlyphRun> underlineRuns;
109   underlineRuns.Resize(numberOfUnderlineRuns);
110   textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
111
112   struct DataOfCase
113   {
114     std::string              title;
115     uint32_t                 startIndex;
116     uint32_t                 endIndex;
117     GlyphIndex               startGlyphIndex;
118     GlyphIndex               endGlyphIndex;
119     UnderlineStyleProperties properties;
120   };
121   DataOfCase data[] =
122     {
123       //<u>ABC1</u>
124       {"<u>ABC1</u>",
125        0u,
126        3u,
127        5u,
128        8u,
129        {
130          Text::Underline::SOLID,
131          Color::BLACK,
132          0u,
133          1u,
134          2u,
135          false,
136          false,
137          false,
138          false,
139          false,
140        }},
141
142       //<u type='solid'>ABC2</u>
143       {"<u type='solid'>ABC2</u>",
144        4u,
145        7u,
146        13u,
147        16u,
148        {
149          Text::Underline::SOLID,
150          Color::BLACK,
151          0u,
152          1u,
153          2u,
154          true,
155          false,
156          false,
157          false,
158          false,
159        }},
160
161       //<u type='dashed'>ABC3</u>
162       {"<u type='dashed'>ABC3</u>",
163        8u,
164        11u,
165        21u,
166        24u,
167        {
168          Text::Underline::DASHED,
169          Color::BLACK,
170          0u,
171          1u,
172          2u,
173          true,
174          false,
175          false,
176          false,
177          false,
178        }},
179
180       //<u type='double'>ABC4</u>
181       {"<u type='double'>ABC4</u>",
182        12u,
183        15u,
184        29u,
185        32u,
186        {
187          Text::Underline::DOUBLE,
188          Color::BLACK,
189          0u,
190          1u,
191          2u,
192          true,
193          false,
194          false,
195          false,
196          false,
197        }},
198
199       //<u color='green'>ABC5</u>
200       {"<u color='green'>ABC5</u>",
201        16u,
202        19u,
203        37u,
204        40u,
205        {
206          Text::Underline::SOLID,
207          Color::GREEN,
208          0u,
209          1u,
210          2u,
211          false,
212          true,
213          false,
214          false,
215          false,
216        }},
217
218       //<u height='5.0f'>ABC6</u>
219       {"<u height='5.0f'>ABC6</u>",
220        20u,
221        23u,
222        45u,
223        48u,
224        {
225          Text::Underline::SOLID,
226          Color::BLACK,
227          5u,
228          1u,
229          2u,
230          false,
231          false,
232          true,
233          false,
234          false,
235        }},
236
237       //<u type='dashed' dash-gap='3.0f'>ABC7</u>
238       {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
239        24u,
240        27u,
241        53u,
242        56u,
243        {
244          Text::Underline::DASHED,
245          Color::BLACK,
246          0u,
247          3u,
248          2u,
249          true,
250          false,
251          false,
252          true,
253          false,
254        }},
255
256       //<u type='dashed' dash-width='4.0f'>ABC8</u>
257       {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
258        28u,
259        31u,
260        61u,
261        64u,
262        {
263          Text::Underline::DASHED,
264          Color::BLACK,
265          0u,
266          1u,
267          4u,
268          true,
269          false,
270          false,
271          false,
272          true,
273        }},
274
275       //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
276       {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
277        32u,
278        35u,
279        69u,
280        72u,
281        {
282          Text::Underline::DASHED,
283          Color::BLUE,
284          4u,
285          2u,
286          3u,
287          true,
288          true,
289          true,
290          true,
291          true,
292        }},
293
294     };
295
296   for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
297   {
298     tet_infoline(data[i].title.c_str());
299     DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
300     DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
301
302     DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
303     DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
304   }
305
306   END_TEST;
307 }
308
309 int UtcDaliTextLabelMarkupSpanUnderline(void)
310 {
311   ToolkitTestApplication application;
312   tet_infoline(" UtcDaliTextLabelMarkupSpanUnderline ");
313
314   TextLabel textLabel = TextLabel::New();
315
316   application.GetScene().Add(textLabel);
317
318   std::string testText =
319     "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
320     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>then"
321     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>then"
322     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>then"
323     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>then"
324     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
325     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>then"
326     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>then"
327     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>end"
328
329     ;
330
331   textLabel.SetProperty(TextLabel::Property::TEXT, testText);
332   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
333
334   application.SendNotification();
335   application.Render();
336
337   const uint32_t NUMBER_OF_CASES                  = 8u;
338   uint32_t       expectedNumberOfUnderlinedGlyphs = 32u;
339
340   Toolkit::Internal::TextLabel& textLabelImpl         = GetImpl(textLabel);
341   const Text::Length            numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
342
343   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
344
345   Vector<UnderlinedGlyphRun> underlineRuns;
346   underlineRuns.Resize(numberOfUnderlineRuns);
347   textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
348
349   struct DataOfCase
350   {
351     std::string              title;
352     uint32_t                 startIndex;
353     uint32_t                 endIndex;
354     GlyphIndex               startGlyphIndex;
355     GlyphIndex               endGlyphIndex;
356     UnderlineStyleProperties properties;
357   };
358   DataOfCase data[] =
359     {
360
361       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
362        0u,
363        3u,
364        13u,
365        16u,
366        {
367          Text::Underline::SOLID,
368          Color::BLACK,
369          0u,
370          1u,
371          2u,
372          true,
373          false,
374          false,
375          false,
376          false,
377        }},
378
379       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
380        4u,
381        7u,
382        21u,
383        24u,
384        {
385          Text::Underline::DASHED,
386          Color::BLACK,
387          0u,
388          1u,
389          2u,
390          true,
391          false,
392          false,
393          false,
394          false,
395        }},
396
397       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
398        8u,
399        11u,
400        29u,
401        32u,
402        {
403          Text::Underline::DOUBLE,
404          Color::BLACK,
405          0u,
406          1u,
407          2u,
408          true,
409          false,
410          false,
411          false,
412          false,
413        }},
414
415       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
416        12u,
417        15u,
418        37u,
419        40u,
420        {
421          Text::Underline::SOLID,
422          Color::GREEN,
423          0u,
424          1u,
425          2u,
426          false,
427          true,
428          false,
429          false,
430          false,
431        }},
432
433       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
434        16u,
435        19u,
436        45u,
437        48u,
438        {
439          Text::Underline::SOLID,
440          Color::BLACK,
441          5u,
442          1u,
443          2u,
444          false,
445          false,
446          true,
447          false,
448          false,
449        }},
450
451       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>",
452        20u,
453        23u,
454        53u,
455        56u,
456        {
457          Text::Underline::DASHED,
458          Color::BLACK,
459          0u,
460          3u,
461          2u,
462          true,
463          false,
464          false,
465          true,
466          false,
467        }},
468
469       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>",
470        24u,
471        27u,
472        61u,
473        64u,
474        {
475          Text::Underline::DASHED,
476          Color::BLACK,
477          0u,
478          1u,
479          4u,
480          true,
481          false,
482          false,
483          false,
484          true,
485        }},
486
487       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>",
488        28u,
489        31u,
490        69u,
491        72u,
492        {
493          Text::Underline::DASHED,
494          Color::BLUE,
495          4u,
496          2u,
497          3u,
498          true,
499          true,
500          true,
501          true,
502          true,
503        }},
504
505     };
506
507   for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
508   {
509     tet_infoline(data[i].title.c_str());
510     DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
511     DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
512
513     DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
514     DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
515   }
516
517   END_TEST;
518 }
519
520 int UtcDaliTextLabelBackgroundTag(void)
521 {
522   ToolkitTestApplication application;
523   tet_infoline("UtcDaliTextLabelBackgroundTag\n");
524
525   TextLabel label = TextLabel::New();
526   DALI_TEST_CHECK(label);
527
528   label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
529   label.SetProperty(TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
530   application.GetScene().Add(label);
531   application.SendNotification();
532   application.Render();
533
534   Toolkit::Internal::TextLabel& labelImpl                    = GetImpl(label);
535   const ColorIndex* const       backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
536
537   DALI_TEST_CHECK(backgroundColorIndicesBuffer);
538
539   //default color
540   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
541
542   //red color
543   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
544
545   //yellow color
546   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
547
548   END_TEST;
549 }
550
551 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
552 {
553   ToolkitTestApplication application;
554   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
555   TextLabel textLabel = TextLabel::New();
556
557   Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
558   const ModelInterface* const   textModel     = textLabelImpl.GetTextController()->GetTextModel();
559
560   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
561   textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
562   DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), false, TEST_LOCATION);
563   DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
564
565   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
566   textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
567   DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), true, TEST_LOCATION);
568   DALI_TEST_CHECK(textModel->IsTextElideEnabled());
569
570   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
571   DALI_TEST_EQUALS(textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
572
573   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
574   DALI_TEST_EQUALS(textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
575
576   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
577   DALI_TEST_EQUALS(textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
578
579   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
580   DALI_TEST_EQUALS(textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
581
582   // Tests the rendering controller has been created.
583   TypesetterPtr typesetter = Typesetter::New(textModel);
584   DALI_TEST_CHECK(typesetter);
585
586   // Tests the view model has been created.
587   ViewModel* model = typesetter->GetViewModel();
588
589   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
590   DALI_TEST_CHECK(model->IsTextElideEnabled());
591
592   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
593   DALI_TEST_EQUALS(model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
594
595   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
596   DALI_TEST_EQUALS(model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
597
598   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
599   DALI_TEST_EQUALS(model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
600
601   tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
602   DALI_TEST_EQUALS(model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
603
604   END_TEST;
605 }
606 int UtcDaliTextLabelTextWithSpan(void)
607 {
608   ToolkitTestApplication application;
609   tet_infoline("UtcDaliTextLabelTextWithSpan\n");
610
611   TextLabel label = TextLabel::New();
612   DALI_TEST_CHECK(label);
613
614   label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
615   label.SetProperty(TextLabel::Property::TEXT, "Hello Span");
616   application.GetScene().Add(label);
617
618   application.SendNotification();
619   application.Render();
620
621   Vector3 originalSize = label.GetNaturalSize();
622   label.SetProperty(TextLabel::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span");
623
624   application.SendNotification();
625   application.Render();
626
627   Vector3 spanSize = label.GetNaturalSize();
628
629   DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
630
631   Toolkit::Internal::TextLabel& labelImpl           = GetImpl(label);
632   const ColorIndex* const       colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
633
634   DALI_TEST_CHECK(colorIndicesBuffer1);
635
636   //default color
637   DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
638
639   //span color
640   DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
641
642   //default color
643   DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
644
645   label.SetProperty(TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
646
647   application.SendNotification();
648   application.Render();
649
650   const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
651
652   DALI_TEST_CHECK(colorIndicesBuffer2);
653
654   //default color
655   DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
656
657   //default color
658   DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
659
660   //span color
661   DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
662
663   //default color
664   DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
665
666   END_TEST;
667 }
668
669 int UtcDaliTextLabelMarkupStrikethrough(void)
670 {
671   ToolkitTestApplication application;
672   tet_infoline(" UtcDaliTextLabelMarkupStrikethrough ");
673
674   TextLabel textLabel = TextLabel::New();
675
676   application.GetScene().Add(textLabel);
677
678   textLabel.SetProperty(TextLabel::Property::TEXT, "<s color='red'>ABC</s>EF<s color='green'>GH</s>");
679   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
680
681   application.SendNotification();
682   application.Render();
683
684   uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
685
686   Toolkit::Internal::TextLabel& textLabelImpl             = GetImpl(textLabel);
687   const Text::Length            numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
688
689   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
690
691   Vector<StrikethroughGlyphRun> strikethroughRuns;
692   strikethroughRuns.Resize(numberOfStrikethroughRuns);
693   textLabelImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
694
695   //ABC have strikethrough
696   DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
697   DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
698   DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
699   DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
700   DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
701   DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
702
703   //GH have strikethrough
704   DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
705   DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
706   DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
707   DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
708   DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
709   DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);
710
711   END_TEST;
712 }
713
714 int UtcDaliTextLabelMarkupStrikethroughNoEndTag(void)
715 {
716   ToolkitTestApplication application;
717   tet_infoline(" UtcDaliTextLabelMarkupStrikethroughNoEndTag ");
718
719   TextLabel textLabel = TextLabel::New();
720
721   application.GetScene().Add(textLabel);
722
723   textLabel.SetProperty(TextLabel::Property::TEXT, "<s>ABC");
724   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
725
726   application.SendNotification();
727   application.Render();
728
729   uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
730
731   Toolkit::Internal::TextLabel& textLabelImpl             = GetImpl(textLabel);
732   Text::Length                  numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
733
734   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
735
736   END_TEST;
737 }
738
739 int UtcDaliTextLabelMarkupParagraphTag(void)
740
741 {
742   ToolkitTestApplication application;
743
744   tet_infoline(" UtcDaliTextLabelMarkupParagraphTag ");
745   TextLabel textLabel = TextLabel::New();
746
747   application.GetScene().Add(textLabel);
748
749   textLabel.SetProperty(TextLabel::Property::TEXT, "text one <p>Paragraph two</p> text three <p>Paragraph four</p> text five");
750   textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
751   textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true);
752
753   application.SendNotification();
754   application.Render();
755
756   uint32_t expectedNumberOfBoundedParagraphRuns = 2u;
757
758   Toolkit::Internal::TextLabel& textLabelImpl                = GetImpl(textLabel);
759   const Text::Length            numberOfBoundedParagraphRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
760   DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
761
762   const Vector<BoundedParagraphRun>& boundedParagraphRuns = textLabelImpl.GetTextController()->GetTextModel()->GetBoundedParagraphRuns();
763
764   //<p>Paragraph two</p>
765   DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.characterIndex, 10u, TEST_LOCATION);
766   DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.numberOfCharacters, 14u, TEST_LOCATION);
767
768   //<p>Paragraph four</p>
769   DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.characterIndex, 37u, TEST_LOCATION);
770   DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.numberOfCharacters, 15u, TEST_LOCATION);
771
772   END_TEST;
773 }
774
775 int UtcDaliTextLabelMarkupParagraphTagAlignAttribute(void)
776 {
777   ToolkitTestApplication application;
778   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute ");
779
780   // Apply alignment for each type on property level on three paragraphs and in-between text.
781   // Apply align in markup on the three paragraphs (each one a type).
782   // Using the same text to gain similar results from both the property level and the markup.
783   // Compare line alignment between the property level and the markup.
784
785   std::string textAlignOnPropertyLevel = "text outside<p>Paragraph end</p>text outside<p>Paragraph center</p>text outside<p>Paragraph begin</p><p>Paragraph property alignment</p>";
786   std::string textAlignInMarkup        = "text outside<p align='end'>Paragraph end</p>text outside<p align='center'>Paragraph center</p>text outside<p align='begin' >Paragraph begin</p><p>Paragraph property alignment</p>";
787
788   //Set size to avoid automatic eliding
789   Vector2 controllerSize = Vector2(1025, 1025);
790
791   TextLabel textLabelBeginAlign  = TextLabel::New();
792   TextLabel textLabelCenterAlign = TextLabel::New();
793   TextLabel textLabelEndAlign    = TextLabel::New();
794   TextLabel textLabelMultiAlign  = TextLabel::New();
795
796   application.GetScene().Add(textLabelBeginAlign);
797   application.GetScene().Add(textLabelCenterAlign);
798   application.GetScene().Add(textLabelEndAlign);
799   application.GetScene().Add(textLabelMultiAlign);
800
801   textLabelBeginAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
802   textLabelBeginAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
803   textLabelBeginAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
804   textLabelBeginAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
805   textLabelBeginAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::BEGIN);
806   textLabelBeginAlign.SetProperty(Actor::Property::SIZE, controllerSize);
807
808   textLabelCenterAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
809   textLabelCenterAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
810   textLabelCenterAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
811   textLabelCenterAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
812   textLabelCenterAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
813   textLabelCenterAlign.SetProperty(Actor::Property::SIZE, controllerSize);
814
815   textLabelEndAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
816   textLabelEndAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
817   textLabelEndAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
818   textLabelEndAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
819   textLabelEndAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::END);
820   textLabelEndAlign.SetProperty(Actor::Property::SIZE, controllerSize);
821
822   textLabelMultiAlign.SetProperty(TextLabel::Property::TEXT, textAlignInMarkup);
823   textLabelMultiAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
824   textLabelMultiAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
825   textLabelMultiAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
826   textLabelMultiAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
827   textLabelMultiAlign.SetProperty(Actor::Property::SIZE, controllerSize);
828
829   application.SendNotification();
830   application.Render();
831
832   uint32_t expectedNumberOfBoundedParagraphRuns = 4u;
833   uint32_t expectedNumberOfLines                = 7u;
834
835   Toolkit::Internal::TextLabel& textLabelMultiAlignImpl  = GetImpl(textLabelMultiAlign);
836   Toolkit::Internal::TextLabel& textLabelBeginAlignImpl  = GetImpl(textLabelBeginAlign);
837   Toolkit::Internal::TextLabel& textLabelCenterAlignImpl = GetImpl(textLabelCenterAlign);
838   Toolkit::Internal::TextLabel& textLabelEndAlignImpl    = GetImpl(textLabelEndAlign);
839
840   const Text::Length numberOfBoundedParagraphRuns = textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
841   DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
842
843   DALI_TEST_EQUALS(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
844   DALI_TEST_CHECK(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines());
845
846   DALI_TEST_EQUALS(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
847   DALI_TEST_CHECK(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetLines());
848
849   DALI_TEST_EQUALS(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
850   DALI_TEST_CHECK(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines());
851
852   DALI_TEST_EQUALS(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
853   DALI_TEST_CHECK(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetLines());
854
855   const uint32_t LINE_INDEX_ALIGN_END    = 1u;
856   const uint32_t LINE_INDEX_ALIGN_CENTER = 3u;
857   const uint32_t LINE_INDEX_ALIGN_BEGIN  = 5u;
858   const uint32_t LINE_INDEX_OUTSIDE_1    = 0u;
859   const uint32_t LINE_INDEX_OUTSIDE_2    = 2u;
860   const uint32_t LINE_INDEX_OUTSIDE_3    = 4u;
861   const uint32_t LINE_INDEX_PARAGRAPH    = 6u;
862
863   //<p align='end'>Paragraph end</p>
864   const LineRun& lineEndFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
865   const LineRun& lineEndFromEndAlign   = *(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
866   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='end'>Paragraph end</p>");
867   DALI_TEST_EQUALS(lineEndFromMultiAlign.alignmentOffset, lineEndFromEndAlign.alignmentOffset, TEST_LOCATION);
868   DALI_TEST_EQUALS(lineEndFromMultiAlign.width, lineEndFromEndAlign.width, TEST_LOCATION);
869
870   //<p align='center'>Paragraph center</p>
871   const LineRun& lineCenterFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
872   const LineRun& lineEndFromCenterAlign   = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
873   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='center'>Paragraph center</p>");
874   DALI_TEST_EQUALS(lineCenterFromMultiAlign.alignmentOffset, lineEndFromCenterAlign.alignmentOffset, TEST_LOCATION);
875   DALI_TEST_EQUALS(lineCenterFromMultiAlign.width, lineEndFromCenterAlign.width, TEST_LOCATION);
876
877   //<p align='begin' >Paragraph begin</p>
878   const LineRun& lineBeginFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
879   const LineRun& lineEndFromBeginAlign   = *(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
880   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='begin' >Paragraph begin</p>");
881   DALI_TEST_EQUALS(lineBeginFromMultiAlign.alignmentOffset, lineEndFromBeginAlign.alignmentOffset, TEST_LOCATION);
882   DALI_TEST_EQUALS(lineBeginFromMultiAlign.width, lineEndFromBeginAlign.width, TEST_LOCATION);
883
884   //text outside
885   const LineRun& lineOutsideOneFromMultiAlign  = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
886   const LineRun& lineOutsideOneFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
887   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside one");
888   DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.alignmentOffset, lineOutsideOneFromCenterAlign.alignmentOffset, TEST_LOCATION);
889   DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.width, lineOutsideOneFromCenterAlign.width, TEST_LOCATION);
890
891   const LineRun& lineOutsideTwoFromMultiAlign  = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
892   const LineRun& lineOutsideTwoFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
893   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside two");
894   DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.alignmentOffset, lineOutsideTwoFromCenterAlign.alignmentOffset, TEST_LOCATION);
895   DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.width, lineOutsideTwoFromCenterAlign.width, TEST_LOCATION);
896
897   const LineRun& lineOutsideThreeFromMultiAlign  = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
898   const LineRun& lineOutsideThreeFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
899   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside three");
900   DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.alignmentOffset, lineOutsideThreeFromCenterAlign.alignmentOffset, TEST_LOCATION);
901   DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.width, lineOutsideThreeFromCenterAlign.width, TEST_LOCATION);
902
903   const LineRun& lineParagraphFromMultiAlign  = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
904   const LineRun& lineParagraphFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
905   tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p>Paragraph property alignment</p>");
906   DALI_TEST_EQUALS(lineParagraphFromMultiAlign.alignmentOffset, lineParagraphFromCenterAlign.alignmentOffset, TEST_LOCATION);
907   DALI_TEST_EQUALS(lineParagraphFromMultiAlign.width, lineParagraphFromCenterAlign.width, TEST_LOCATION);
908
909   END_TEST;
910 }