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