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