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 UtcDaliTextEditorMarkupSpanStrikethrough(void)
605 ToolkitTestApplication application;
606 tet_infoline(" UtcDaliTextEditorMarkupSpanStrikethrough ");
608 TextEditor textEditor = TextEditor::New();
610 application.GetScene().Add(textEditor);
612 std::string testText =
613 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
614 "<span s-color='blue'>ABC2</span>then"
615 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' s-color='green'>ABC3</span>end";
617 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
618 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
620 application.SendNotification();
621 application.Render();
623 const uint32_t expectedNumberOfStrikethroughRuns = 2u;
625 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
626 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
628 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
630 Vector<StrikethroughGlyphRun> strikethroughRuns;
631 strikethroughRuns.Resize(numberOfStrikethroughRuns);
632 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
637 GlyphIndex glyphIndex;
638 Length numberOfGlyphs;
639 StrikethroughStyleProperties properties;
644 {"<span s-color='blue'>ABC2</span>then",
652 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' s-color='green'>ABC3</span>",
662 for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
664 tet_infoline(data[i].title.c_str());
665 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
666 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
667 DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
673 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
675 ToolkitTestApplication application;
676 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
678 // Create a text editor
679 TextEditor textEditor = TextEditor::New();
680 //Set size to avoid automatic eliding
681 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
682 //Set very large font-size using point-size
683 textEditor.SetProperty(TextEditor::Property::POINT_SIZE, 1000);
684 //Specify font-family
685 textEditor.SetProperty(TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
686 //Set text to check if appear or not
687 textEditor.SetProperty(TextEditor::Property::TEXT, "A");
689 application.GetScene().Add(textEditor);
691 application.SendNotification();
692 application.Render();
694 //Check if Glyph is added to AtlasGlyphManger or not
695 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
696 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
701 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
703 ToolkitTestApplication application;
704 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
706 //Set Map of placeholder: text, font-family and point-size
707 Property::Map placeholderMapSet;
708 placeholderMapSet["text"] = "A";
709 placeholderMapSet["fontFamily"] = "DejaVu Sans";
710 placeholderMapSet["pixelSize"] = 1000.0f;
712 // Create a text editor
713 TextEditor textEditor = TextEditor::New();
714 //Set size to avoid automatic eliding
715 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
717 textEditor.SetProperty(TextEditor::Property::PLACEHOLDER, placeholderMapSet);
719 application.GetScene().Add(textEditor);
721 application.SendNotification();
722 application.Render();
724 //Check if Glyph is added to AtlasGlyphManger or not
725 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
726 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
731 int UtcDaliTextEditorBackgroundTag(void)
733 ToolkitTestApplication application;
734 tet_infoline("UtcDaliTextEditorBackgroundTag\n");
736 TextEditor editor = TextEditor::New();
737 DALI_TEST_CHECK(editor);
739 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
740 editor.SetProperty(TextEditor::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
741 application.GetScene().Add(editor);
742 application.SendNotification();
743 application.Render();
745 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
746 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
748 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
751 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
754 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
757 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
762 int UtcDaliTextEditorSpanBackgroundTag(void)
764 ToolkitTestApplication application;
765 tet_infoline("UtcDaliTextEditorSpanBackgroundTag\n");
767 TextEditor editor = TextEditor::New();
768 DALI_TEST_CHECK(editor);
770 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
771 editor.SetProperty(TextEditor::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
772 application.GetScene().Add(editor);
773 application.SendNotification();
774 application.Render();
776 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
777 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
779 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
782 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
785 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
788 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
793 int UtcDaliTextEditorTextWithSpan(void)
795 ToolkitTestApplication application;
796 tet_infoline("UtcDaliTextEditorTextWithSpan\n");
798 TextEditor editor = TextEditor::New();
799 DALI_TEST_CHECK(editor);
801 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
802 editor.SetProperty(TextEditor::Property::TEXT, "Hello Span");
803 application.GetScene().Add(editor);
805 application.SendNotification();
806 application.Render();
808 Vector3 originalSize = editor.GetNaturalSize();
809 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");
811 application.SendNotification();
812 application.Render();
814 Vector3 spanSize = editor.GetNaturalSize();
816 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
818 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
819 const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
821 DALI_TEST_CHECK(colorIndicesBuffer1);
824 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
827 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
830 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
832 editor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
834 application.SendNotification();
835 application.Render();
837 const ColorIndex* const colorIndicesBuffer2 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
839 DALI_TEST_CHECK(colorIndicesBuffer2);
842 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
845 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
848 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
851 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
856 int UtcDaliTextEditorControlBackgroundColor(void)
858 ToolkitTestApplication application;
859 tet_infoline(" UtcDaliTextEditorControlBackgroundColor\n");
861 TextEditor editor = TextEditor::New();
862 DALI_TEST_CHECK(editor);
864 Vector4 backgroundColor;
866 editor.SetProperty(TextEditor::Property::TEXT, "Background Color");
867 application.GetScene().Add(editor);
868 application.SendNotification();
869 application.Render();
871 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
872 ControllerPtr controller = editorImpl.GetTextController();
873 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
875 // Default color is transparent
876 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
877 DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
879 // Set background color to red
880 editor.SetBackgroundColor(Color::RED);
881 application.SendNotification();
882 application.Render();
885 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
886 DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
891 int UtcDaliTextEditorTextPositionWithMinLineAndBigFont(void)
893 ToolkitTestApplication application;
894 tet_infoline(" UtcDaliTextEditorTextPositionWithMinLine ");
896 TextEditor textEditor = TextEditor::New();
898 textEditor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>\ni");
899 textEditor.SetProperty(DevelTextEditor::Property::MIN_LINE_SIZE, 50);
900 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
902 application.GetScene().Add(textEditor);
904 application.SendNotification();
905 application.Render();
907 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
908 Text::ViewInterface& view = textEditorImpl.GetTextController()->GetView();
910 Length numberOfGlyphs = view.GetNumberOfGlyphs();
912 DALI_TEST_EQUALS(numberOfGlyphs, 3u, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
914 Vector<GlyphInfo> glyphs;
915 glyphs.Resize(numberOfGlyphs);
917 Vector<Vector2> positions;
918 positions.Resize(numberOfGlyphs);
920 float alignmentOffset = 0u;
921 numberOfGlyphs = view.GetGlyphs(glyphs.Begin(),
927 DALI_TEST_EQUALS(positions[2].y, 165.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
932 int UtcDaliTextEditorMarkupStrikethrough(void)
934 ToolkitTestApplication application;
935 tet_infoline(" UtcDaliTextEditorMarkupStrikethrough ");
937 TextEditor textEditor = TextEditor::New();
939 application.GetScene().Add(textEditor);
941 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC</s>EF<s color='red'>GH</s>");
942 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
944 application.SendNotification();
945 application.Render();
947 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
949 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
950 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
952 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
954 Vector<StrikethroughGlyphRun> strikethroughRuns;
955 strikethroughRuns.Resize(numberOfStrikethroughRuns);
956 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
958 //ABC have strikethrough
959 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
960 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
961 DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
963 //GH have strikethrough
964 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
965 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
966 DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
971 int UtcDaliTextEditorMarkupStrikethroughNoEndTag(void)
973 ToolkitTestApplication application;
974 tet_infoline(" UtcDaliTextEditorMarkupStrikethroughNoEndTag ");
976 TextEditor textEditor = TextEditor::New();
978 application.GetScene().Add(textEditor);
980 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC");
981 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
983 application.SendNotification();
984 application.Render();
986 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
988 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
989 Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
991 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
996 int UtcDaliTextEditorMarkupParagraphTag(void)
999 ToolkitTestApplication application;
1000 tet_infoline(" UtcDaliTextEditorMarkupParagraphTag ");
1002 TextEditor textEditor = TextEditor::New();
1003 application.GetScene().Add(textEditor);
1005 textEditor.SetProperty(TextEditor::Property::TEXT, "text one <p>Paragraph two</p> text three <p>Paragraph four</p> text five");
1006 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1008 application.SendNotification();
1009 application.Render();
1011 uint32_t expectedNumberOfBoundedParagraphRuns = 2u;
1013 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
1014 const Text::Length numberOfBoundedParagraphRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
1015 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
1017 const Vector<BoundedParagraphRun>& boundedParagraphRuns = textEditorImpl.GetTextController()->GetTextModel()->GetBoundedParagraphRuns();
1019 //<p>Paragraph two</p>
1020 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.characterIndex, 10u, TEST_LOCATION);
1021 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.numberOfCharacters, 14u, TEST_LOCATION);
1023 //<p>Paragraph four</p>
1024 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.characterIndex, 37u, TEST_LOCATION);
1025 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.numberOfCharacters, 15u, TEST_LOCATION);
1030 int UtcDaliTextEditorMarkupParagraphTagAlignAttribute(void)
1032 ToolkitTestApplication application;
1033 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute ");
1035 // Apply alignment for each type on property level on three paragraphs and in-between text.
1036 // Apply align in markup on the three paragraphs (each one a type).
1037 // Using the same text to gain similar results from both the property level and the markup.
1038 // Compare line alignment between the property level and the markup.
1040 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>";
1041 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>";
1043 //Set size to avoid automatic eliding
1044 Vector2 controllerSize = Vector2(1025, 1025);
1046 TextEditor textEditorBeginAlign = TextEditor::New();
1047 TextEditor textEditorCenterAlign = TextEditor::New();
1048 TextEditor textEditorEndAlign = TextEditor::New();
1049 TextEditor textEditorMultiAlign = TextEditor::New();
1051 application.GetScene().Add(textEditorBeginAlign);
1052 application.GetScene().Add(textEditorCenterAlign);
1053 application.GetScene().Add(textEditorEndAlign);
1054 application.GetScene().Add(textEditorMultiAlign);
1056 textEditorBeginAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1057 textEditorBeginAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1058 textEditorBeginAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1059 textEditorBeginAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::BEGIN);
1060 textEditorBeginAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1062 textEditorCenterAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1063 textEditorCenterAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1064 textEditorCenterAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1065 textEditorCenterAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
1066 textEditorCenterAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1068 textEditorEndAlign.SetProperty(TextEditor::Property::TEXT, textAlignOnPropertyLevel);
1069 textEditorEndAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1070 textEditorEndAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1071 textEditorEndAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::END);
1072 textEditorEndAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1074 textEditorMultiAlign.SetProperty(TextEditor::Property::TEXT, textAlignInMarkup);
1075 textEditorMultiAlign.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
1076 textEditorMultiAlign.SetProperty(DevelTextEditor::Property::ELLIPSIS, false);
1077 textEditorMultiAlign.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
1078 textEditorMultiAlign.SetProperty(Actor::Property::SIZE, controllerSize);
1080 application.SendNotification();
1081 application.Render();
1083 uint32_t expectedNumberOfBoundedParagraphRuns = 4u;
1084 uint32_t expectedNumberOfLines = 7u;
1086 Toolkit::Internal::TextEditor& textEditorMultiAlignImpl = GetImpl(textEditorMultiAlign);
1087 Toolkit::Internal::TextEditor& textEditorBeginAlignImpl = GetImpl(textEditorBeginAlign);
1088 Toolkit::Internal::TextEditor& textEditorCenterAlignImpl = GetImpl(textEditorCenterAlign);
1089 Toolkit::Internal::TextEditor& textEditorEndAlignImpl = GetImpl(textEditorEndAlign);
1091 const Text::Length numberOfBoundedParagraphRuns = textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
1092 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
1094 DALI_TEST_EQUALS(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1095 DALI_TEST_CHECK(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines());
1097 DALI_TEST_EQUALS(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1098 DALI_TEST_CHECK(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetLines());
1100 DALI_TEST_EQUALS(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1101 DALI_TEST_CHECK(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines());
1103 DALI_TEST_EQUALS(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
1104 DALI_TEST_CHECK(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetLines());
1106 const uint32_t LINE_INDEX_ALIGN_END = 1u;
1107 const uint32_t LINE_INDEX_ALIGN_CENTER = 3u;
1108 const uint32_t LINE_INDEX_ALIGN_BEGIN = 5u;
1109 const uint32_t LINE_INDEX_OUTSIDE_1 = 0u;
1110 const uint32_t LINE_INDEX_OUTSIDE_2 = 2u;
1111 const uint32_t LINE_INDEX_OUTSIDE_3 = 4u;
1112 const uint32_t LINE_INDEX_PARAGRAPH = 6u;
1114 //<p align='end'>Paragraph end</p>
1115 const LineRun& lineEndFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
1116 const LineRun& lineEndFromEndAlign = *(textEditorEndAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
1117 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='end'>Paragraph end</p>");
1118 DALI_TEST_EQUALS(lineEndFromMultiAlign.alignmentOffset, lineEndFromEndAlign.alignmentOffset, TEST_LOCATION);
1119 DALI_TEST_EQUALS(lineEndFromMultiAlign.width, lineEndFromEndAlign.width, TEST_LOCATION);
1121 //<p align='center'>Paragraph center</p>
1122 const LineRun& lineCenterFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
1123 const LineRun& lineEndFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
1124 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='center'>Paragraph center</p>");
1125 DALI_TEST_EQUALS(lineCenterFromMultiAlign.alignmentOffset, lineEndFromCenterAlign.alignmentOffset, TEST_LOCATION);
1126 DALI_TEST_EQUALS(lineCenterFromMultiAlign.width, lineEndFromCenterAlign.width, TEST_LOCATION);
1128 //<p align='begin' >Paragraph begin</p>
1129 const LineRun& lineBeginFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
1130 const LineRun& lineEndFromBeginAlign = *(textEditorBeginAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
1131 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p align='begin' >Paragraph begin</p>");
1132 DALI_TEST_EQUALS(lineBeginFromMultiAlign.alignmentOffset, lineEndFromBeginAlign.alignmentOffset, TEST_LOCATION);
1133 DALI_TEST_EQUALS(lineBeginFromMultiAlign.width, lineEndFromBeginAlign.width, TEST_LOCATION);
1136 const LineRun& lineOutsideOneFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
1137 const LineRun& lineOutsideOneFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
1138 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside one");
1139 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.alignmentOffset, lineOutsideOneFromCenterAlign.alignmentOffset, TEST_LOCATION);
1140 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.width, lineOutsideOneFromCenterAlign.width, TEST_LOCATION);
1142 const LineRun& lineOutsideTwoFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
1143 const LineRun& lineOutsideTwoFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
1144 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside two");
1145 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.alignmentOffset, lineOutsideTwoFromCenterAlign.alignmentOffset, TEST_LOCATION);
1146 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.width, lineOutsideTwoFromCenterAlign.width, TEST_LOCATION);
1148 const LineRun& lineOutsideThreeFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
1149 const LineRun& lineOutsideThreeFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
1150 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - text outside three");
1151 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.alignmentOffset, lineOutsideThreeFromCenterAlign.alignmentOffset, TEST_LOCATION);
1152 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.width, lineOutsideThreeFromCenterAlign.width, TEST_LOCATION);
1154 const LineRun& lineParagraphFromMultiAlign = *(textEditorMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
1155 const LineRun& lineParagraphFromCenterAlign = *(textEditorCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
1156 tet_infoline(" UtcDaliTextEditorMarkupParagraphTagAlignAttribute - <p>Paragraph property alignment</p>");
1157 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.alignmentOffset, lineParagraphFromCenterAlign.alignmentOffset, TEST_LOCATION);
1158 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.width, lineParagraphFromCenterAlign.width, TEST_LOCATION);