Merge "fix linespacing calculation in TextLabel" into devel/master
[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 expectedNumberOfUnderlineRuns = 2u;
173
174   Toolkit::Internal::TextField& textFieldImpl         = GetImpl(textField);
175   const Text::Length            numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
176
177   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, 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[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
186
187   //GH are underlined
188   DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
189   DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
190
191   END_TEST;
192 }
193
194 int UtcDaliTextFieldMarkupUnderlineAttributes(void)
195 {
196   ToolkitTestApplication application;
197   tet_infoline(" UtcDaliTextFieldMarkupUnderlineAttributes ");
198
199   TextField textField = TextField::New();
200
201   application.GetScene().Add(textField);
202
203   std::string testText =
204     "start<u>ABC1</u>then"
205     "<u type='solid'>ABC2</u>then"
206     "<u type='dashed'>ABC3</u>then"
207     "<u type='double'>ABC4</u>then"
208     "<u color='green'>ABC5</u>then"
209     "<u height='5.0f'>ABC6</u>then"
210     "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
211     "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
212     "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
213
214     ;
215
216   textField.SetProperty(TextField::Property::TEXT, testText);
217   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
218
219   application.SendNotification();
220   application.Render();
221
222   const uint32_t expectedNumberOfUnderlineRuns = 9u;
223
224   Toolkit::Internal::TextField& textFieldImpl         = GetImpl(textField);
225   const Text::Length            numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
226
227   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
228
229   Vector<UnderlinedGlyphRun> underlineRuns;
230   underlineRuns.Resize(numberOfUnderlineRuns);
231   textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
232
233   struct DataOfCase
234   {
235     std::string              title;
236     GlyphIndex               glyphIndex;
237     Length                   numberOfGlyphs;
238     UnderlineStyleProperties properties;
239   };
240   DataOfCase data[] =
241     {
242       //<u>ABC1</u>
243       {"<u>ABC1</u>",
244        5u,
245        4u,
246        {
247          Text::Underline::SOLID,
248          Color::BLACK,
249          0u,
250          1u,
251          2u,
252          false,
253          false,
254          false,
255          false,
256          false,
257        }},
258
259       //<u type='solid'>ABC2</u>
260       {"<u type='solid'>ABC2</u>",
261        13u,
262        4u,
263        {
264          Text::Underline::SOLID,
265          Color::BLACK,
266          0u,
267          1u,
268          2u,
269          true,
270          false,
271          false,
272          false,
273          false,
274        }},
275
276       //<u type='dashed'>ABC3</u>
277       {"<u type='dashed'>ABC3</u>",
278        21u,
279        4u,
280        {
281          Text::Underline::DASHED,
282          Color::BLACK,
283          0u,
284          1u,
285          2u,
286          true,
287          false,
288          false,
289          false,
290          false,
291        }},
292
293       //<u type='double'>ABC4</u>
294       {"<u type='double'>ABC4</u>",
295        29u,
296        4u,
297        {
298          Text::Underline::DOUBLE,
299          Color::BLACK,
300          0u,
301          1u,
302          2u,
303          true,
304          false,
305          false,
306          false,
307          false,
308        }},
309
310       //<u color='green'>ABC5</u>
311       {"<u color='green'>ABC5</u>",
312        37u,
313        4u,
314        {
315          Text::Underline::SOLID,
316          Color::GREEN,
317          0u,
318          1u,
319          2u,
320          false,
321          true,
322          false,
323          false,
324          false,
325        }},
326
327       //<u height='5.0f'>ABC6</u>
328       {"<u height='5.0f'>ABC6</u>",
329        45u,
330        4u,
331        {
332          Text::Underline::SOLID,
333          Color::BLACK,
334          5u,
335          1u,
336          2u,
337          false,
338          false,
339          true,
340          false,
341          false,
342        }},
343
344       //<u type='dashed' dash-gap='3.0f'>ABC7</u>
345       {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
346        53u,
347        4u,
348        {
349          Text::Underline::DASHED,
350          Color::BLACK,
351          0u,
352          3u,
353          2u,
354          true,
355          false,
356          false,
357          true,
358          false,
359        }},
360
361       //<u type='dashed' dash-width='4.0f'>ABC8</u>
362       {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
363        61u,
364        4u,
365        {
366          Text::Underline::DASHED,
367          Color::BLACK,
368          0u,
369          1u,
370          4u,
371          true,
372          false,
373          false,
374          false,
375          true,
376        }},
377
378       //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
379       {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
380        69u,
381        4u,
382        {
383          Text::Underline::DASHED,
384          Color::BLUE,
385          4u,
386          2u,
387          3u,
388          true,
389          true,
390          true,
391          true,
392          true,
393        }},
394
395     };
396
397   for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
398   {
399     tet_infoline(data[i].title.c_str());
400     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
401     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
402     DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
403   }
404
405   END_TEST;
406 }
407
408 int UtcDaliTextFieldMarkupSpanUnderline(void)
409 {
410   ToolkitTestApplication application;
411   tet_infoline(" UtcDaliTextFieldMarkupSpanUnderline ");
412
413   TextField textField = TextField::New();
414
415   application.GetScene().Add(textField);
416
417   std::string testText =
418     "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
419     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>then"
420     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>then"
421     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>then"
422     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>then"
423     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
424     "<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"
425     "<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"
426     "<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";
427
428   textField.SetProperty(TextField::Property::TEXT, testText);
429   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
430
431   application.SendNotification();
432   application.Render();
433
434   const uint32_t expectedNumberOfUnderlineRuns = 8u;
435
436   Toolkit::Internal::TextField& textFieldImpl         = GetImpl(textField);
437   const Text::Length            numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
438
439   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
440
441   Vector<UnderlinedGlyphRun> underlineRuns;
442   underlineRuns.Resize(numberOfUnderlineRuns);
443   textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
444
445   struct DataOfCase
446   {
447     std::string              title;
448     GlyphIndex               glyphIndex;
449     Length                   numberOfGlyphs;
450     UnderlineStyleProperties properties;
451   };
452   DataOfCase data[] =
453     {
454       //<u type='solid'>ABC2</u>
455       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
456        13u,
457        4u,
458        {
459          Text::Underline::SOLID,
460          Color::BLACK,
461          0u,
462          1u,
463          2u,
464          true,
465          false,
466          false,
467          false,
468          false,
469        }},
470
471       //<u type='dashed'>ABC3</u>
472       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
473        21u,
474        4u,
475        {
476          Text::Underline::DASHED,
477          Color::BLACK,
478          0u,
479          1u,
480          2u,
481          true,
482          false,
483          false,
484          false,
485          false,
486        }},
487
488       //<u type='double'>ABC4</u>
489       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
490        29u,
491        4u,
492        {
493          Text::Underline::DOUBLE,
494          Color::BLACK,
495          0u,
496          1u,
497          2u,
498          true,
499          false,
500          false,
501          false,
502          false,
503        }},
504
505       //<u color='green'>ABC5</u>
506       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
507        37u,
508        4u,
509        {
510          Text::Underline::SOLID,
511          Color::GREEN,
512          0u,
513          1u,
514          2u,
515          false,
516          true,
517          false,
518          false,
519          false,
520        }},
521
522       //<u height='5.0f'>ABC6</u>
523       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
524        45u,
525        4u,
526        {
527          Text::Underline::SOLID,
528          Color::BLACK,
529          5u,
530          1u,
531          2u,
532          false,
533          false,
534          true,
535          false,
536          false,
537        }},
538
539       //<u type='dashed' dash-gap='3.0f'>ABC7</u>
540       {"<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>",
541        53u,
542        4u,
543        {
544          Text::Underline::DASHED,
545          Color::BLACK,
546          0u,
547          3u,
548          2u,
549          true,
550          false,
551          false,
552          true,
553          false,
554        }},
555
556       //<u type='dashed' dash-width='4.0f'>ABC8</u>
557       {"<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>",
558        61u,
559        4u,
560        {
561          Text::Underline::DASHED,
562          Color::BLACK,
563          0u,
564          1u,
565          4u,
566          true,
567          false,
568          false,
569          false,
570          true,
571        }},
572
573       //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
574       {"<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>",
575        69u,
576        4u,
577        {
578          Text::Underline::DASHED,
579          Color::BLUE,
580          4u,
581          2u,
582          3u,
583          true,
584          true,
585          true,
586          true,
587          true,
588        }},
589
590     };
591
592   for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
593   {
594     tet_infoline(data[i].title.c_str());
595     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
596     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
597     DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
598   }
599
600   END_TEST;
601 }
602
603 int UtcDaliTextFieldMarkupNestedUnderlineTags(void)
604 {
605   ToolkitTestApplication application;
606   tet_infoline(" UtcDaliTextFieldMarkupNestedUnderlineTags ");
607
608   TextField textField = TextField::New();
609
610   application.GetScene().Add(textField);
611
612   std::string testText = "start<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>end";
613
614   textField.SetProperty(TextField::Property::TEXT, testText);
615   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
616
617   application.SendNotification();
618   application.Render();
619
620   const uint32_t expectedNumberOfUnderlineRuns = 2u;
621
622   Toolkit::Internal::TextField& textFieldImpl         = GetImpl(textField);
623   const Text::Length            numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
624
625   DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
626
627   Vector<UnderlinedGlyphRun> underlineRuns;
628   underlineRuns.Resize(numberOfUnderlineRuns);
629   textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
630
631   struct DataOfCase
632   {
633     std::string              title;
634     GlyphIndex               glyphIndex;
635     Length                   numberOfGlyphs;
636     UnderlineStyleProperties properties;
637   };
638   DataOfCase data[] =
639     {
640       //Outter
641       {"<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>",
642        5u,
643        8u,
644        {
645          Text::Underline::SOLID,
646          Color::GREEN,
647          5u,
648          1u,
649          2u,
650          false,
651          true,
652          true,
653          false,
654          false,
655        }},
656
657       //Inner
658       {"<u color='blue' >XYZ</u>",
659        7u,
660        3u,
661        {
662          Text::Underline::SOLID,
663          Color::BLUE,
664          5u,
665          1u,
666          2u,
667          false,
668          true,
669          true,
670          false,
671          false,
672        }},
673
674     };
675
676   for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
677   {
678     tet_infoline(data[i].title.c_str());
679     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
680     DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
681     DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
682   }
683
684   END_TEST;
685 }
686
687 int UtcDaliTextFieldMarkupNestedStrikethroughTags(void)
688 {
689   ToolkitTestApplication application;
690   tet_infoline(" UtcDaliTextFieldMarkupNestedStrikethroughTags ");
691
692   TextField textField = TextField::New();
693
694   application.GetScene().Add(textField);
695
696   std::string testText = "start<s height='5.0f' color='green' >AB<s color='blue' >XYZ</s>CDE</s>end";
697
698   textField.SetProperty(TextField::Property::TEXT, testText);
699   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
700
701   application.SendNotification();
702   application.Render();
703
704   const uint32_t expectedNumberOfStrikethroughRuns = 2u;
705
706   Toolkit::Internal::TextField& textFieldImpl             = GetImpl(textField);
707   const Text::Length            numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
708
709   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
710
711   Vector<StrikethroughGlyphRun> strikethroughRuns;
712   strikethroughRuns.Resize(numberOfStrikethroughRuns);
713   textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
714
715   struct DataOfCase
716   {
717     std::string                  title;
718     GlyphIndex                   glyphIndex;
719     Length                       numberOfGlyphs;
720     StrikethroughStyleProperties properties;
721   };
722   DataOfCase data[] =
723     {
724       //Outter
725       {"<s height='5.0f' color='green' >AB<s color='blue' >XYZ</s>CDE</s>",
726        5u,
727        8u,
728        {
729          Color::GREEN,
730          5.0f,
731          true,
732          true,
733        }},
734
735       //Inner
736       {"<s color='blue' >XYZ</s>",
737        7u,
738        3u,
739        {
740          Color::BLUE,
741          5.0f,
742          true,
743          true,
744        }},
745
746     };
747
748   for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
749   {
750     tet_infoline(data[i].title.c_str());
751     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
752     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
753     DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
754   }
755
756   END_TEST;
757 }
758
759 int UtcDaliTextFieldMarkupStrikethroughAttributes(void)
760 {
761   ToolkitTestApplication application;
762   tet_infoline(" UtcDaliTextFieldMarkupStrikethroughAttributes ");
763
764   TextField textField = TextField::New();
765
766   application.GetScene().Add(textField);
767
768   std::string testText =
769     "start<s>ABC1</s>then"
770     "<s color='green'>ABC2</s>then"
771     "<s height='5.0f'>ABC3</s>then"
772     "<s color='blue' height='4.0f' >ABC4</s>end";
773
774   textField.SetProperty(TextField::Property::TEXT, testText);
775   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
776
777   application.SendNotification();
778   application.Render();
779
780   const uint32_t expectedNumberOfStrikethroughRuns = 4u;
781
782   Toolkit::Internal::TextField& textFieldImpl             = GetImpl(textField);
783   const Text::Length            numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
784
785   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
786
787   Vector<StrikethroughGlyphRun> strikethroughRuns;
788   strikethroughRuns.Resize(numberOfStrikethroughRuns);
789   textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
790
791   struct DataOfCase
792   {
793     std::string                  title;
794     GlyphIndex                   glyphIndex;
795     Length                       numberOfGlyphs;
796     StrikethroughStyleProperties properties;
797   };
798   DataOfCase data[] =
799     {
800
801       {"<s>ABC1</s>",
802        5u,
803        4u,
804        {Color::BLACK,
805         0.0f,
806         false,
807         false}},
808
809       {"<s color='green'>ABC2</s>",
810        13u,
811        4u,
812        {Color::GREEN,
813         0.0f,
814         true,
815         false}},
816
817       {"<s height='5.0f'>ABC3</s>",
818        21u,
819        4u,
820        {Color::BLACK,
821         5.0f,
822         false,
823         true}},
824
825       {"<s color='blue' height='4.0f' >ABC4</s>",
826        29u,
827        4u,
828        {Color::BLUE,
829         4.0f,
830         true,
831         true}},
832
833     };
834
835   for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
836   {
837     tet_infoline(data[i].title.c_str());
838     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
839     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
840     DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
841   }
842
843   END_TEST;
844 }
845
846 int UtcDaliTextFieldMarkupSpanStrikethrough(void)
847 {
848   ToolkitTestApplication application;
849   tet_infoline(" UtcDaliTextFieldMarkupSpanStrikethrough ");
850
851   TextField textField = TextField::New();
852
853   application.GetScene().Add(textField);
854
855   std::string testText =
856     "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
857     "<span s-color='blue'>ABC2</span>then"
858     "<span s-height='2.0f'>ABC3</span>then"
859     "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' s-color='green' s-height='5.0f'>ABC4</span>end";
860
861   textField.SetProperty(TextField::Property::TEXT, testText);
862   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
863
864   application.SendNotification();
865   application.Render();
866
867   const uint32_t expectedNumberOfStrikethroughRuns = 3u;
868
869   Toolkit::Internal::TextField& textFieldImpl             = GetImpl(textField);
870   const Text::Length            numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
871
872   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
873
874   Vector<StrikethroughGlyphRun> strikethroughRuns;
875   strikethroughRuns.Resize(numberOfStrikethroughRuns);
876   textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
877
878   struct DataOfCase
879   {
880     std::string                  title;
881     GlyphIndex                   glyphIndex;
882     Length                       numberOfGlyphs;
883     StrikethroughStyleProperties properties;
884   };
885   DataOfCase data[] =
886     {
887
888       {"<span s-color='blue'>ABC2</span>then",
889        13u,
890        4u,
891        {Color::BLUE,
892         0.0f,
893         true,
894         false}},
895
896       {"<span s-height='2.0f'>ABC3</span>then",
897        21u,
898        4u,
899        {Color::BLACK,
900         2.0f,
901         false,
902         true}},
903
904       {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' s-color='green' s-height='5.0f'>ABC4</span>",
905        29u,
906        4u,
907        {Color::GREEN,
908         5.0f,
909         true,
910         true}},
911
912     };
913
914   for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
915   {
916     tet_infoline(data[i].title.c_str());
917     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
918     DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
919     DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
920   }
921
922   END_TEST;
923 }
924
925 int UtcDaliTextFieldFontPointSizeLargerThanAtlas(void)
926 {
927   ToolkitTestApplication application;
928   tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlas ");
929
930   // Create a Text field
931   TextField textField = TextField::New();
932   //Set size to avoid automatic eliding
933   textField.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
934   //Set very large font-size using point-size
935   textField.SetProperty(TextField::Property::POINT_SIZE, 1000);
936   //Specify font-family
937   textField.SetProperty(TextField::Property::FONT_FAMILY, "DejaVu Sans");
938   //Set text to check if appear or not
939   textField.SetProperty(TextField::Property::TEXT, "A");
940
941   application.GetScene().Add(textField);
942
943   application.SendNotification();
944   application.Render();
945
946   //Check if Glyph is added to AtlasGlyphManger or not
947   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
948   DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
949
950   END_TEST;
951 }
952
953 int UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase(void)
954 {
955   ToolkitTestApplication application;
956   tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase ");
957
958   //Set Map of placeholder: text, font-family and point-size
959   Property::Map placeholderMapSet;
960   placeholderMapSet["text"]       = "A";
961   placeholderMapSet["fontFamily"] = "DejaVu Sans";
962   placeholderMapSet["pixelSize"]  = 1000.0f;
963
964   // Create a text editor
965   TextField textField = TextField::New();
966   //Set size to avoid automatic eliding
967   textField.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
968   //Set placeholder
969   textField.SetProperty(TextField::Property::PLACEHOLDER, placeholderMapSet);
970
971   application.GetScene().Add(textField);
972
973   application.SendNotification();
974   application.Render();
975
976   //Check if Glyph is added to AtlasGlyphManger or not
977   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
978   DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
979
980   END_TEST;
981 }
982
983 int UtcDaliTextFieldBackgroundTag(void)
984 {
985   ToolkitTestApplication application;
986   tet_infoline("UtcDaliTextFieldBackgroundTag\n");
987
988   TextField field = TextField::New();
989   DALI_TEST_CHECK(field);
990
991   field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
992   field.SetProperty(TextField::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
993   application.GetScene().Add(field);
994   application.SendNotification();
995   application.Render();
996
997   Toolkit::Internal::TextField& fieldImpl                    = GetImpl(field);
998   const ColorIndex* const       backgroundColorIndicesBuffer = fieldImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
999
1000   DALI_TEST_CHECK(backgroundColorIndicesBuffer);
1001
1002   //default color
1003   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
1004
1005   //red color
1006   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
1007
1008   //yellow color
1009   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
1010
1011   END_TEST;
1012 }
1013
1014 int UtcDaliTextFieldSpanBackgroundTag(void)
1015 {
1016   ToolkitTestApplication application;
1017   tet_infoline("UtcDaliTextFieldSpanBackgroundTag\n");
1018
1019   TextField field = TextField::New();
1020   DALI_TEST_CHECK(field);
1021
1022   field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1023   field.SetProperty(TextField::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
1024   application.GetScene().Add(field);
1025   application.SendNotification();
1026   application.Render();
1027
1028   Toolkit::Internal::TextField& fieldImpl                    = GetImpl(field);
1029   const ColorIndex* const       backgroundColorIndicesBuffer = fieldImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
1030
1031   DALI_TEST_CHECK(backgroundColorIndicesBuffer);
1032
1033   //default color
1034   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
1035
1036   //red color
1037   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
1038
1039   //yellow color
1040   DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
1041
1042   END_TEST;
1043 }
1044
1045 int UtcDaliToolkitTextFieldEllipsisInternalAPIs(void)
1046 {
1047   ToolkitTestApplication application;
1048   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs ");
1049   TextField textField = TextField::New();
1050
1051   Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
1052   Text::ViewInterface&          view          = textFieldImpl.GetTextController()->GetView();
1053
1054   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - ELLIPSIS Disabled");
1055   textField.SetProperty(DevelTextField::Property::ELLIPSIS, false);
1056   DALI_TEST_EQUALS(textField.GetProperty<bool>(DevelTextField::Property::ELLIPSIS), false, TEST_LOCATION);
1057   DALI_TEST_CHECK(!(view.IsTextElideEnabled()));
1058
1059   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - ELLIPSIS Enabled");
1060   textField.SetProperty(DevelTextField::Property::ELLIPSIS, true);
1061   DALI_TEST_EQUALS(textField.GetProperty<bool>(DevelTextField::Property::ELLIPSIS), true, TEST_LOCATION);
1062   DALI_TEST_CHECK(view.IsTextElideEnabled());
1063
1064   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
1065   DALI_TEST_EQUALS(view.GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1066
1067   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
1068   DALI_TEST_EQUALS(view.GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1069
1070   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
1071   DALI_TEST_EQUALS(view.GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1072
1073   tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
1074   DALI_TEST_EQUALS(view.GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1075
1076   END_TEST;
1077 }
1078 int UtcDaliTextFieldTextWithSpan(void)
1079 {
1080   ToolkitTestApplication application;
1081   tet_infoline("UtcDaliTextFieldTextWithSpan\n");
1082
1083   TextField field = TextField::New();
1084   DALI_TEST_CHECK(field);
1085
1086   field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1087   field.SetProperty(TextField::Property::TEXT, "Hello Span");
1088   application.GetScene().Add(field);
1089
1090   application.SendNotification();
1091   application.Render();
1092
1093   Vector3 originalSize = field.GetNaturalSize();
1094   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");
1095
1096   application.SendNotification();
1097   application.Render();
1098
1099   Vector3 spanSize = field.GetNaturalSize();
1100
1101   DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
1102
1103   Toolkit::Internal::TextField& fieldImpl           = GetImpl(field);
1104   const ColorIndex* const       colorIndicesBuffer1 = fieldImpl.GetTextController()->GetTextModel()->GetColorIndices();
1105
1106   DALI_TEST_CHECK(colorIndicesBuffer1);
1107
1108   //default color
1109   DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
1110
1111   //span color
1112   DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
1113
1114   //default color
1115   DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
1116
1117   field.SetProperty(TextField::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
1118
1119   application.SendNotification();
1120   application.Render();
1121
1122   const ColorIndex* const colorIndicesBuffer2 = fieldImpl.GetTextController()->GetTextModel()->GetColorIndices();
1123
1124   DALI_TEST_CHECK(colorIndicesBuffer2);
1125
1126   //default color
1127   DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
1128
1129   //default color
1130   DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
1131
1132   //span color
1133   DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
1134
1135   //default color
1136   DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
1137
1138   END_TEST;
1139 }
1140
1141 int UtcDaliTextFieldControlBackgroundColor(void)
1142 {
1143   ToolkitTestApplication application;
1144   tet_infoline(" UtcDaliTextFieldControlBackgroundColor\n");
1145
1146   TextField field = TextField::New();
1147   DALI_TEST_CHECK(field);
1148
1149   Vector4 backgroundColor;
1150
1151   field.SetProperty(TextField::Property::TEXT, "Background Color");
1152   application.GetScene().Add(field);
1153   application.SendNotification();
1154   application.Render();
1155
1156   Toolkit::Internal::TextField& fieldImpl      = GetImpl(field);
1157   ControllerPtr                 controller     = fieldImpl.GetTextController();
1158   Controller::Impl&             controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
1159
1160   // Default color is transparent
1161   controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
1162   DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
1163
1164   // Set background color to red
1165   field.SetBackgroundColor(Color::RED);
1166   application.SendNotification();
1167   application.Render();
1168
1169   // Should be red
1170   controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
1171   DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
1172
1173   END_TEST;
1174 }
1175
1176 int UtcDaliTextFieldMarkupStrikethrough(void)
1177 {
1178   ToolkitTestApplication application;
1179   tet_infoline(" UtcDaliTextFieldMarkupStrikethrough ");
1180
1181   TextField textField = TextField::New();
1182
1183   application.GetScene().Add(textField);
1184
1185   textField.SetProperty(TextField::Property::TEXT, "<s>ABC</s>EF<s color='red'>GH</s>");
1186   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1187
1188   application.SendNotification();
1189   application.Render();
1190
1191   uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
1192
1193   Toolkit::Internal::TextField& textFieldImpl             = GetImpl(textField);
1194   const Text::Length            numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1195
1196   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
1197
1198   Vector<StrikethroughGlyphRun> strikethroughRuns;
1199   strikethroughRuns.Resize(numberOfStrikethroughRuns);
1200   textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
1201
1202   //ABC have strikethrough
1203   DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
1204   DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
1205   DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
1206
1207   //GH have strikethrough
1208   DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
1209   DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
1210   DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
1211
1212   END_TEST;
1213 }
1214
1215 int UtcDaliTextFieldMarkupStrikethroughNoEndTag(void)
1216 {
1217   ToolkitTestApplication application;
1218   tet_infoline(" UtcDaliTextFieldMarkupStrikethroughNoEndTag ");
1219
1220   TextField textField = TextField::New();
1221
1222   application.GetScene().Add(textField);
1223
1224   textField.SetProperty(TextField::Property::TEXT, "<s>ABC");
1225   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1226
1227   application.SendNotification();
1228   application.Render();
1229
1230   uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
1231
1232   Toolkit::Internal::TextField& textFieldImpl             = GetImpl(textField);
1233   Text::Length                  numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1234
1235   DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
1236
1237   END_TEST;
1238 }
1239
1240 int UtcDaliTextFieldMarkupCharacterSpacingTag(void)
1241 {
1242   ToolkitTestApplication application;
1243   tet_infoline(" UtcDaliTextFieldMarkupCharacterSpacingTag ");
1244
1245   const Length EXPECTED_NUMBER_OF_GLYPHS = 21u;
1246
1247   const float expandedCharSpacing  = 10.0f;
1248   const float condensedCharSpacing = -5.0f;
1249
1250   TextField textField = TextField::New();
1251
1252   textField.SetProperty(TextField::Property::TEXT, "ABC EF\n<char-spacing value='-5.0f'>ABC EF\n</char-spacing><char-spacing value='10.0f'>ABC EF\n</char-spacing>");
1253   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1254
1255   application.GetScene().Add(textField);
1256
1257   application.SendNotification();
1258   application.Render();
1259
1260   Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
1261   Text::ViewInterface&          view          = textFieldImpl.GetTextController()->GetView();
1262
1263   Length numberOfGlyphs = view.GetNumberOfGlyphs();
1264
1265   DALI_TEST_EQUALS(numberOfGlyphs, EXPECTED_NUMBER_OF_GLYPHS, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1266
1267   Vector<GlyphInfo> glyphs;
1268   glyphs.Resize(numberOfGlyphs);
1269
1270   Vector<Vector2> positions;
1271   positions.Resize(numberOfGlyphs);
1272
1273   float alignmentOffset = 0u;
1274   numberOfGlyphs        = view.GetGlyphs(glyphs.Begin(),
1275                                   positions.Begin(),
1276                                   alignmentOffset,
1277                                   0u,
1278                                   numberOfGlyphs);
1279
1280   const Length numberOfGlyphsOneLine = 7u;
1281   for(Length i = 0; i < numberOfGlyphsOneLine - 1u; i++)
1282   {
1283     float diffLineNoCharSpacing = positions[i + 1].x - positions[i].x;
1284
1285     float diffLineCondensedCharSpacing = positions[numberOfGlyphsOneLine + i + 1].x - positions[numberOfGlyphsOneLine + i].x;
1286     DALI_TEST_EQUALS(diffLineCondensedCharSpacing, diffLineNoCharSpacing + condensedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1287
1288     float diffLineExpandedCharSpacing = positions[2u * numberOfGlyphsOneLine + i + 1].x - positions[2u * numberOfGlyphsOneLine + i].x;
1289     DALI_TEST_EQUALS(diffLineExpandedCharSpacing, diffLineNoCharSpacing + expandedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1290   }
1291
1292   END_TEST;
1293 }
1294
1295 int UtcDaliTextFieldMarkupSpanCharacterSpacing(void)
1296 {
1297   ToolkitTestApplication application;
1298   tet_infoline(" UtcDaliTextFieldMarkupSpanCharacterSpacing ");
1299
1300   const Length EXPECTED_NUMBER_OF_GLYPHS = 21u;
1301
1302   const float expandedCharSpacing  = 10.0f;
1303   const float condensedCharSpacing = -5.0f;
1304
1305   std::string testText =
1306     "<span font-size='20' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='blue' >ABC EF\n</span>"
1307     "<span font-size='20' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' char-space-value='-5.0f'>ABC EF\n</span>"
1308     "<span font-size='20' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='green' char-space-value='10.0f'>ABC EF\n</span>";
1309
1310   TextField textField = TextField::New();
1311
1312   textField.SetProperty(TextField::Property::TEXT, testText);
1313   textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1314
1315   application.GetScene().Add(textField);
1316
1317   application.SendNotification();
1318   application.Render();
1319
1320   Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
1321   Text::ViewInterface&          view          = textFieldImpl.GetTextController()->GetView();
1322
1323   Length numberOfGlyphs = view.GetNumberOfGlyphs();
1324
1325   DALI_TEST_EQUALS(numberOfGlyphs, EXPECTED_NUMBER_OF_GLYPHS, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1326
1327   Vector<GlyphInfo> glyphs;
1328   glyphs.Resize(numberOfGlyphs);
1329
1330   Vector<Vector2> positions;
1331   positions.Resize(numberOfGlyphs);
1332
1333   float alignmentOffset = 0u;
1334   numberOfGlyphs        = view.GetGlyphs(glyphs.Begin(),
1335                                   positions.Begin(),
1336                                   alignmentOffset,
1337                                   0u,
1338                                   numberOfGlyphs);
1339
1340   const Length numberOfGlyphsOneLine = 7u;
1341   for(Length i = 0; i < numberOfGlyphsOneLine - 1u; i++)
1342   {
1343     float diffLineNoCharSpacing = positions[i + 1].x - positions[i].x;
1344
1345     float diffLineCondensedCharSpacing = positions[numberOfGlyphsOneLine + i + 1].x - positions[numberOfGlyphsOneLine + i].x;
1346     DALI_TEST_EQUALS(diffLineCondensedCharSpacing, diffLineNoCharSpacing + condensedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1347
1348     float diffLineExpandedCharSpacing = positions[2u * numberOfGlyphsOneLine + i + 1].x - positions[2u * numberOfGlyphsOneLine + i].x;
1349     DALI_TEST_EQUALS(diffLineExpandedCharSpacing, diffLineNoCharSpacing + expandedCharSpacing, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1350   }
1351
1352   END_TEST;
1353 }