2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
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>
30 using namespace Toolkit;
33 int UtcDaliTextEditorSelectText(void)
35 ToolkitTestApplication application;
36 tet_infoline("UtcDaliTextEditorSelectText");
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");
43 // Add the text editor to the stage
44 application.GetScene().Add(textEditor);
46 application.SendNotification();
49 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
51 application.SendNotification();
54 // Highlight the whole text
55 textEditorImpl.SelectWholeText();
57 application.SendNotification();
60 std::string selectedText = textEditorImpl.GetSelectedText();
61 DALI_TEST_CHECK(selectedText == "Hello World");
64 textEditorImpl.SelectNone();
66 application.SendNotification();
69 selectedText = textEditorImpl.GetSelectedText();
70 DALI_TEST_CHECK(selectedText == "");
75 int UtcDaliTextEditorMarkupUnderline(void)
77 ToolkitTestApplication application;
78 tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
80 TextEditor textEditor = TextEditor::New();
82 application.GetScene().Add(textEditor);
84 textEditor.SetProperty(TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>");
85 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
87 application.SendNotification();
90 uint32_t expectedNumberOfUnderlineRuns = 2u;
92 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
93 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
95 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
97 Vector<UnderlinedGlyphRun> underlineRuns;
98 underlineRuns.Resize(numberOfUnderlineRuns);
99 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
102 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
103 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
106 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
107 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
112 int UtcDaliTextEditorMarkupUnderlineAttributes(void)
114 ToolkitTestApplication application;
115 tet_infoline(" UtcDaliTextEditorMarkupUnderlineAttributes ");
117 TextEditor textEditor = TextEditor::New();
119 application.GetScene().Add(textEditor);
121 std::string testText =
122 "start<u>ABC1</u>then"
123 "<u type='solid'>ABC2</u>then"
124 "<u type='dashed'>ABC3</u>then"
125 "<u type='double'>ABC4</u>then"
126 "<u color='green'>ABC5</u>then"
127 "<u height='5.0f'>ABC6</u>then"
128 "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
129 "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
130 "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end";
132 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
133 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
135 application.SendNotification();
136 application.Render();
138 const uint32_t expectedNumberOfUnderlineRuns = 9u;
140 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
141 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
143 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
145 Vector<UnderlinedGlyphRun> underlineRuns;
146 underlineRuns.Resize(numberOfUnderlineRuns);
147 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
152 GlyphIndex glyphIndex;
153 Length numberOfGlyphs;
154 UnderlineStyleProperties properties;
163 Text::Underline::SOLID,
175 //<u type='solid'>ABC2</u>
176 {"<u type='solid'>ABC2</u>",
180 Text::Underline::SOLID,
192 //<u type='dashed'>ABC3</u>
193 {"<u type='dashed'>ABC3</u>",
197 Text::Underline::DASHED,
209 //<u type='double'>ABC4</u>
210 {"<u type='double'>ABC4</u>",
214 Text::Underline::DOUBLE,
226 //<u color='green'>ABC5</u>
227 {"<u color='green'>ABC5</u>",
231 Text::Underline::SOLID,
243 //<u height='5.0f'>ABC6</u>
244 {"<u height='5.0f'>ABC6</u>",
248 Text::Underline::SOLID,
260 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
261 {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
265 Text::Underline::DASHED,
277 //<u type='dashed' dash-width='4.0f'>ABC8</u>
278 {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
282 Text::Underline::DASHED,
294 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
295 {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
299 Text::Underline::DASHED,
313 for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
315 tet_infoline(data[i].title.c_str());
316 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
317 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
318 DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
324 int UtcDaliTextEditorMarkupSpanUnderline(void)
326 ToolkitTestApplication application;
327 tet_infoline(" UtcDaliTextEditorMarkupSpanUnderline ");
329 TextEditor textEditor = TextEditor::New();
331 application.GetScene().Add(textEditor);
333 std::string testText =
334 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
335 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>then"
336 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>then"
337 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>then"
338 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>then"
339 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
340 "<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"
341 "<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"
342 "<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";
344 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
345 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
347 application.SendNotification();
348 application.Render();
350 const uint32_t expectedNumberOfUnderlineRuns = 8u;
352 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
353 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
355 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
357 Vector<UnderlinedGlyphRun> underlineRuns;
358 underlineRuns.Resize(numberOfUnderlineRuns);
359 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
364 GlyphIndex glyphIndex;
365 Length numberOfGlyphs;
366 UnderlineStyleProperties properties;
370 //<u type='solid'>ABC2</u>
371 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
375 Text::Underline::SOLID,
387 //<u type='dashed'>ABC3</u>
388 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
392 Text::Underline::DASHED,
404 //<u type='double'>ABC4</u>
405 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
409 Text::Underline::DOUBLE,
421 //<u color='green'>ABC5</u>
422 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
426 Text::Underline::SOLID,
438 //<u height='5.0f'>ABC6</u>
439 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
443 Text::Underline::SOLID,
455 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
456 {"<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>",
460 Text::Underline::DASHED,
472 //<u type='dashed' dash-width='4.0f'>ABC8</u>
473 {"<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>",
477 Text::Underline::DASHED,
489 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
490 {"<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>",
494 Text::Underline::DASHED,
508 for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
510 tet_infoline(data[i].title.c_str());
511 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
512 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
513 DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
519 int UtcDaliTextEditorMarkupNestedUnderlineTags(void)
521 ToolkitTestApplication application;
522 tet_infoline(" UtcDaliTextEditorMarkupNestedUnderlineTags ");
524 TextEditor textEditor = TextEditor::New();
526 application.GetScene().Add(textEditor);
528 std::string testText = "start<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>end";
530 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
531 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
533 application.SendNotification();
534 application.Render();
536 const uint32_t expectedNumberOfUnderlineRuns = 2u;
538 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
539 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
541 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
543 Vector<UnderlinedGlyphRun> underlineRuns;
544 underlineRuns.Resize(numberOfUnderlineRuns);
545 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
550 GlyphIndex glyphIndex;
551 Length numberOfGlyphs;
552 UnderlineStyleProperties properties;
557 {"<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>",
561 Text::Underline::SOLID,
574 {"<u color='blue' >XYZ</u>",
578 Text::Underline::SOLID,
592 for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
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);
603 int UtcDaliTextEditorMarkupStrikethroughAttributes(void)
605 ToolkitTestApplication application;
606 tet_infoline(" UtcDaliTextEditorMarkupStrikethroughAttributes ");
608 TextEditor textEditor = TextEditor::New();
610 application.GetScene().Add(textEditor);
612 std::string testText =
613 "start<s>ABC1</s>then"
614 "<s color='green'>ABC2</s>then"
615 "<s height='5.0f'>ABC3</s>then"
616 "<s color='blue' height='4.0f' >ABC4</s>end";
618 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
619 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
621 application.SendNotification();
622 application.Render();
624 const uint32_t expectedNumberOfStrikethroughRuns = 4u;
626 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
627 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
629 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
631 Vector<StrikethroughGlyphRun> strikethroughRuns;
632 strikethroughRuns.Resize(numberOfStrikethroughRuns);
633 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
638 GlyphIndex glyphIndex;
639 Length numberOfGlyphs;
640 StrikethroughStyleProperties properties;
653 {"<s color='green'>ABC2</s>",
661 {"<s height='5.0f'>ABC3</s>",
669 {"<s color='blue' height='4.0f' >ABC4</s>",
679 for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
681 tet_infoline(data[i].title.c_str());
682 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
683 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
684 DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
690 int UtcDaliTextEditorMarkupSpanStrikethrough(void)
692 ToolkitTestApplication application;
693 tet_infoline(" UtcDaliTextEditorMarkupSpanStrikethrough ");
695 TextEditor textEditor = TextEditor::New();
697 application.GetScene().Add(textEditor);
699 std::string testText =
700 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
701 "<span s-color='blue'>ABC2</span>then"
702 "<span s-height='2.0f'>ABC3</span>then"
703 "<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";
705 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
706 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
708 application.SendNotification();
709 application.Render();
711 const uint32_t expectedNumberOfStrikethroughRuns = 3u;
713 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
714 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
716 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
718 Vector<StrikethroughGlyphRun> strikethroughRuns;
719 strikethroughRuns.Resize(numberOfStrikethroughRuns);
720 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
725 GlyphIndex glyphIndex;
726 Length numberOfGlyphs;
727 StrikethroughStyleProperties properties;
732 {"<span s-color='blue'>ABC2</span>then",
740 {"<span s-height='2.0f'>ABC3</span>then",
748 {"<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>",
758 for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
760 tet_infoline(data[i].title.c_str());
761 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
762 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
763 DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
769 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
771 ToolkitTestApplication application;
772 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
774 // Create a text editor
775 TextEditor textEditor = TextEditor::New();
776 //Set size to avoid automatic eliding
777 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
778 //Set very large font-size using point-size
779 textEditor.SetProperty(TextEditor::Property::POINT_SIZE, 1000);
780 //Specify font-family
781 textEditor.SetProperty(TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
782 //Set text to check if appear or not
783 textEditor.SetProperty(TextEditor::Property::TEXT, "A");
785 application.GetScene().Add(textEditor);
787 application.SendNotification();
788 application.Render();
790 //Check if Glyph is added to AtlasGlyphManger or not
791 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
792 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
797 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
799 ToolkitTestApplication application;
800 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
802 //Set Map of placeholder: text, font-family and point-size
803 Property::Map placeholderMapSet;
804 placeholderMapSet["text"] = "A";
805 placeholderMapSet["fontFamily"] = "DejaVu Sans";
806 placeholderMapSet["pixelSize"] = 1000.0f;
808 // Create a text editor
809 TextEditor textEditor = TextEditor::New();
810 //Set size to avoid automatic eliding
811 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
813 textEditor.SetProperty(TextEditor::Property::PLACEHOLDER, placeholderMapSet);
815 application.GetScene().Add(textEditor);
817 application.SendNotification();
818 application.Render();
820 //Check if Glyph is added to AtlasGlyphManger or not
821 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
822 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
827 int UtcDaliTextEditorBackgroundTag(void)
829 ToolkitTestApplication application;
830 tet_infoline("UtcDaliTextEditorBackgroundTag\n");
832 TextEditor editor = TextEditor::New();
833 DALI_TEST_CHECK(editor);
835 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
836 editor.SetProperty(TextEditor::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
837 application.GetScene().Add(editor);
838 application.SendNotification();
839 application.Render();
841 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
842 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
844 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
847 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
850 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
853 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
858 int UtcDaliTextEditorSpanBackgroundTag(void)
860 ToolkitTestApplication application;
861 tet_infoline("UtcDaliTextEditorSpanBackgroundTag\n");
863 TextEditor editor = TextEditor::New();
864 DALI_TEST_CHECK(editor);
866 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
867 editor.SetProperty(TextEditor::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
868 application.GetScene().Add(editor);
869 application.SendNotification();
870 application.Render();
872 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
873 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
875 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
878 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
881 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
884 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
889 int UtcDaliTextEditorTextWithSpan(void)
891 ToolkitTestApplication application;
892 tet_infoline("UtcDaliTextEditorTextWithSpan\n");
894 TextEditor editor = TextEditor::New();
895 DALI_TEST_CHECK(editor);
897 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
898 editor.SetProperty(TextEditor::Property::TEXT, "Hello Span");
899 application.GetScene().Add(editor);
901 application.SendNotification();
902 application.Render();
904 Vector3 originalSize = editor.GetNaturalSize();
905 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");
907 application.SendNotification();
908 application.Render();
910 Vector3 spanSize = editor.GetNaturalSize();
912 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
914 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
915 const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
917 DALI_TEST_CHECK(colorIndicesBuffer1);
920 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
923 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
926 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
928 editor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
930 application.SendNotification();
931 application.Render();
933 const ColorIndex* const colorIndicesBuffer2 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
935 DALI_TEST_CHECK(colorIndicesBuffer2);
938 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
941 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
944 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
947 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
952 int UtcDaliTextEditorControlBackgroundColor(void)
954 ToolkitTestApplication application;
955 tet_infoline(" UtcDaliTextEditorControlBackgroundColor\n");
957 TextEditor editor = TextEditor::New();
958 DALI_TEST_CHECK(editor);
960 Vector4 backgroundColor;
962 editor.SetProperty(TextEditor::Property::TEXT, "Background Color");
963 application.GetScene().Add(editor);
964 application.SendNotification();
965 application.Render();
967 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
968 ControllerPtr controller = editorImpl.GetTextController();
969 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
971 // Default color is transparent
972 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
973 DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
975 // Set background color to red
976 editor.SetBackgroundColor(Color::RED);
977 application.SendNotification();
978 application.Render();
981 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
982 DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
987 int UtcDaliTextEditorTextPositionWithMinLineAndBigFont(void)
989 ToolkitTestApplication application;
990 tet_infoline(" UtcDaliTextEditorTextPositionWithMinLine ");
992 TextEditor textEditor = TextEditor::New();
994 textEditor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>\ni");
995 textEditor.SetProperty(DevelTextEditor::Property::MIN_LINE_SIZE, 50);
996 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
998 application.GetScene().Add(textEditor);
1000 application.SendNotification();
1001 application.Render();
1003 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
1004 Text::ViewInterface& view = textEditorImpl.GetTextController()->GetView();
1006 Length numberOfGlyphs = view.GetNumberOfGlyphs();
1008 DALI_TEST_EQUALS(numberOfGlyphs, 3u, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1010 Vector<GlyphInfo> glyphs;
1011 glyphs.Resize(numberOfGlyphs);
1013 Vector<Vector2> positions;
1014 positions.Resize(numberOfGlyphs);
1016 float alignmentOffset = 0u;
1017 numberOfGlyphs = view.GetGlyphs(glyphs.Begin(),
1023 DALI_TEST_EQUALS(positions[2].y, 165.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1028 int UtcDaliTextEditorMarkupStrikethrough(void)
1030 ToolkitTestApplication application;
1031 tet_infoline(" UtcDaliTextEditorMarkupStrikethrough ");
1033 TextEditor textEditor = TextEditor::New();
1035 application.GetScene().Add(textEditor);
1037 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC</s>EF<s color='red'>GH</s>");
1038 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1040 application.SendNotification();
1041 application.Render();
1043 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
1045 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
1046 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1048 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
1050 Vector<StrikethroughGlyphRun> strikethroughRuns;
1051 strikethroughRuns.Resize(numberOfStrikethroughRuns);
1052 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
1054 //ABC have strikethrough
1055 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
1056 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
1057 DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
1059 //GH have strikethrough
1060 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
1061 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
1062 DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
1067 int UtcDaliTextEditorMarkupStrikethroughNoEndTag(void)
1069 ToolkitTestApplication application;
1070 tet_infoline(" UtcDaliTextEditorMarkupStrikethroughNoEndTag ");
1072 TextEditor textEditor = TextEditor::New();
1074 application.GetScene().Add(textEditor);
1076 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC");
1077 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1079 application.SendNotification();
1080 application.Render();
1082 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
1084 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
1085 Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1087 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
1092 int UtcDaliTextEditorMarkupParagraphTag(void)
1095 ToolkitTestApplication application;
1096 tet_infoline(" UtcDaliTextEditorMarkupParagraphTag ");
1098 TextEditor textEditor = TextEditor::New();
1099 application.GetScene().Add(textEditor);
1101 textEditor.SetProperty(TextEditor::Property::TEXT, "text one <p>Paragraph two</p> text three <p>Paragraph four</p> text five");
1102 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1104 application.SendNotification();
1105 application.Render();
1107 uint32_t expectedNumberOfBoundedParagraphRuns = 2u;
1109 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
1110 const Text::Length numberOfBoundedParagraphRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
1111 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
1113 const Vector<BoundedParagraphRun>& boundedParagraphRuns = textEditorImpl.GetTextController()->GetTextModel()->GetBoundedParagraphRuns();
1115 //<p>Paragraph two</p>
1116 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.characterIndex, 10u, TEST_LOCATION);
1117 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.numberOfCharacters, 14u, TEST_LOCATION);
1119 //<p>Paragraph four</p>
1120 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.characterIndex, 37u, TEST_LOCATION);
1121 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.numberOfCharacters, 15u, TEST_LOCATION);
1126 int UtcDaliTextEditorMarkupParagraphTagAlignAttribute(void)
1128 ToolkitTestApplication application;
1129 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute ");
1131 // Apply alignment for each type on property level on three paragraphs and in-between text.
1132 // Apply align in markup on the three paragraphs (each one a type).
1133 // Using the same text to gain similar results from both the property level and the markup.
1134 // Compare line alignment between the property level and the markup.
1136 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>";
1137 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>";
1139 //Set size to avoid automatic eliding
1140 Vector2 controllerSize = Vector2(1025, 1025);
1142 TextEditor textEditorBeginAlign = TextEditor::New();
1143 TextEditor textEditorCenterAlign = TextEditor::New();
1144 TextEditor textEditorEndAlign = TextEditor::New();
1145 TextEditor textEditorMultiAlign = TextEditor::New();
1147 application.GetScene().Add(textEditorBeginAlign);
1148 application.GetScene().Add(textEditorCenterAlign);
1149 application.GetScene().Add(textEditorEndAlign);
1150 application.GetScene().Add(textEditorMultiAlign);
1152 textEditorBeginAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1153 textEditorBeginAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1154 textEditorBeginAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1155 textEditorBeginAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::BEGIN);
1156 textEditorBeginAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1158 textEditorCenterAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1159 textEditorCenterAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1160 textEditorCenterAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1161 textEditorCenterAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
1162 textEditorCenterAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1164 textEditorEndAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1165 textEditorEndAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1166 textEditorEndAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1167 textEditorEndAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::END);
1168 textEditorEndAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1170 textEditorMultiAlign.SetProperty(TextEditor::Property::TEXT, textAlignInMarkup);
1171 textEditorMultiAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1172 textEditorMultiAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1173 textEditorMultiAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
1174 textEditorMultiAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1176 application.SendNotification();
1177 application.Render();
1179 uint32_t expectedNumberOfBoundedParagraphRuns = 4u;
1180 uint32_t expectedNumberOfLines = 7u;
1182 Toolkit::Internal::TextEditor& textEditorMultiAlignImpl = GetImpl(textEditorMultiAlign);
1183 Toolkit::Internal::TextEditor& textEditorBeginAlignImpl = GetImpl(textEditorBeginAlign);
1184 Toolkit::Internal::TextEditor& textEditorCenterAlignImpl = GetImpl(textEditorCenterAlign);
1185 Toolkit::Internal::TextEditor& textEditorEndAlignImpl = GetImpl(textEditorEndAlign);
1187 const Text::Length numberOfBoundedParagraphRuns = textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
1188 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
1190 DALI_TEST_EQUALS(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1191 DALI_TEST_CHECK(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines());
1193 DALI_TEST_EQUALS(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1194 DALI_TEST_CHECK(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetLines());
1196 DALI_TEST_EQUALS(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1197 DALI_TEST_CHECK(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines());
1199 DALI_TEST_EQUALS(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1200 DALI_TEST_CHECK(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetLines());
1202 const uint32_t LINE_INDEX_ALIGN_END = 1u;
1203 const uint32_t LINE_INDEX_ALIGN_CENTER = 3u;
1204 const uint32_t LINE_INDEX_ALIGN_BEGIN = 5u;
1205 const uint32_t LINE_INDEX_OUTSIDE_1 = 0u;
1206 const uint32_t LINE_INDEX_OUTSIDE_2 = 2u;
1207 const uint32_t LINE_INDEX_OUTSIDE_3 = 4u;
1208 const uint32_t LINE_INDEX_PARAGRAPH = 6u;
1210 //<p align='end'>Paragraph end</p>
1211 const LineRun& lineEndFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
1212 const LineRun& lineEndFromEndAlign = *(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
1213 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='end'>Paragraph end</p>");
1214 DALI_TEST_EQUALS(lineEndFromMultiAlign.alignmentOffset, lineEndFromEndAlign.alignmentOffset, TEST_LOCATION);
1215 DALI_TEST_EQUALS(lineEndFromMultiAlign.width, lineEndFromEndAlign.width, TEST_LOCATION);
1217 //<p align='center'>Paragraph center</p>
1218 const LineRun& lineCenterFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
1219 const LineRun& lineEndFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
1220 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='center'>Paragraph center</p>");
1221 DALI_TEST_EQUALS(lineCenterFromMultiAlign.alignmentOffset, lineEndFromCenterAlign.alignmentOffset, TEST_LOCATION);
1222 DALI_TEST_EQUALS(lineCenterFromMultiAlign.width, lineEndFromCenterAlign.width, TEST_LOCATION);
1224 //<p align='begin' >Paragraph begin</p>
1225 const LineRun& lineBeginFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
1226 const LineRun& lineEndFromBeginAlign = *(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
1227 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='begin' >Paragraph begin</p>");
1228 DALI_TEST_EQUALS(lineBeginFromMultiAlign.alignmentOffset, lineEndFromBeginAlign.alignmentOffset, TEST_LOCATION);
1229 DALI_TEST_EQUALS(lineBeginFromMultiAlign.width, lineEndFromBeginAlign.width, TEST_LOCATION);
1232 const LineRun& lineOutsideOneFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
1233 const LineRun& lineOutsideOneFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
1234 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside one");
1235 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.alignmentOffset, lineOutsideOneFromCenterAlign.alignmentOffset, TEST_LOCATION);
1236 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.width, lineOutsideOneFromCenterAlign.width, TEST_LOCATION);
1238 const LineRun& lineOutsideTwoFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
1239 const LineRun& lineOutsideTwoFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
1240 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside two");
1241 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.alignmentOffset, lineOutsideTwoFromCenterAlign.alignmentOffset, TEST_LOCATION);
1242 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.width, lineOutsideTwoFromCenterAlign.width, TEST_LOCATION);
1244 const LineRun& lineOutsideThreeFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
1245 const LineRun& lineOutsideThreeFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
1246 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside three");
1247 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.alignmentOffset, lineOutsideThreeFromCenterAlign.alignmentOffset, TEST_LOCATION);
1248 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.width, lineOutsideThreeFromCenterAlign.width, TEST_LOCATION);
1250 const LineRun& lineParagraphFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
1251 const LineRun& lineParagraphFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
1252 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p>Paragraph property alignment</p>");
1253 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.alignmentOffset, lineParagraphFromCenterAlign.alignmentOffset, TEST_LOCATION);
1254 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.width, lineParagraphFromCenterAlign.width, TEST_LOCATION);