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-field-impl.h>
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
30 using namespace Toolkit;
33 int UtcDaliTextFieldMultipleBackgroundText(void)
35 ToolkitTestApplication application;
36 tet_infoline("UtcDaliTextFieldMultipleBackgroundText");
38 // Create a text field
39 TextField textField = TextField::New();
40 textField.SetProperty(Actor::Property::SIZE, Vector2(400.f, 60.f));
41 textField.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
42 textField.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
44 // Add the text field to the stage
45 application.GetScene().Add(textField);
47 application.SendNotification();
50 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
51 ControllerPtr controller = textFieldImpl.GetTextController();
52 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
54 // Add multiple background colors for the text.
55 ColorRun backgroundColorRun1;
56 backgroundColorRun1.characterRun.characterIndex = 0u;
57 backgroundColorRun1.characterRun.numberOfCharacters = 1u;
58 backgroundColorRun1.color = Color::RED;
59 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun1);
61 ColorRun backgroundColorRun2;
62 backgroundColorRun2.characterRun.characterIndex = 5u;
63 backgroundColorRun2.characterRun.numberOfCharacters = 8u;
64 backgroundColorRun2.color = Color::CYAN;
65 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun2);
67 ColorRun backgroundColorRun3;
68 backgroundColorRun3.characterRun.characterIndex = 23u;
69 backgroundColorRun3.characterRun.numberOfCharacters = 6u;
70 backgroundColorRun3.color = Color::GREEN;
71 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun3);
73 // Check the case where there is only one character in the text
74 controller->SetText("S");
76 application.SendNotification();
79 // The offscreen root actor should have one child: the renderable.
80 Actor stencil = textField.GetChildAt(0u);
81 DALI_TEST_CHECK(stencil.GetChildCount() == 1u);
83 // The renderable actor should have two children: the text and the background.
84 Actor renderableActor = stencil.GetChildAt(0u);
85 DALI_TEST_CHECK(renderableActor.GetChildCount() == 2u);
87 // Check that the background is created
88 Actor backgroundActor = renderableActor.GetChildAt(0u);
89 DALI_TEST_CHECK(backgroundActor);
90 DALI_TEST_CHECK(backgroundActor.GetProperty<std::string>(Dali::Actor::Property::NAME) == "TextBackgroundColorActor");
92 // Change the text to contain more characters
93 controller->SetText("Text Multiple Background Test");
95 application.SendNotification();
98 // Highlight the whole text
99 textFieldImpl.SelectWholeText();
101 application.SendNotification();
102 application.Render();
104 // Now the offscreen root actor should have four children: the renderable, the clipped cursor, the highlight, and the background.
105 DALI_TEST_CHECK(stencil.GetChildCount() == 4u);
106 // The renderable actor should have one child only: the text
107 DALI_TEST_CHECK(renderableActor.GetChildCount() == 1u);
109 // The background should now be lowered below the highlight
110 backgroundActor = stencil.GetChildAt(0u);
111 DALI_TEST_CHECK(backgroundActor);
112 DALI_TEST_CHECK(backgroundActor.GetProperty<std::string>(Dali::Actor::Property::NAME) == "TextBackgroundColorActor");
117 int UtcDaliTextFieldSelectText(void)
119 ToolkitTestApplication application;
120 tet_infoline("UtcDaliTextFieldSelectText");
122 // Create a text field
123 TextField textField = TextField::New();
124 textField.SetProperty(Actor::Property::SIZE, Vector2(400.f, 60.f));
125 textField.SetProperty(TextField::Property::TEXT, "Hello World");
127 // Add the text field to the stage
128 application.GetScene().Add(textField);
130 application.SendNotification();
131 application.Render();
133 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
135 application.SendNotification();
136 application.Render();
138 // Highlight the whole text
139 textFieldImpl.SelectWholeText();
141 application.SendNotification();
142 application.Render();
144 DALI_TEST_CHECK(textFieldImpl.GetSelectedText() == "Hello World");
147 textFieldImpl.SelectNone();
149 application.SendNotification();
150 application.Render();
152 DALI_TEST_CHECK(textFieldImpl.GetSelectedText() == "");
157 int UtcDaliTextFieldMarkupUnderline(void)
159 ToolkitTestApplication application;
160 tet_infoline(" UtcDaliTextFieldMarkupUnderline ");
162 TextField textField = TextField::New();
164 application.GetScene().Add(textField);
166 textField.SetProperty(TextField::Property::TEXT, "<u>ABC</u>EF<u>GH</u>");
167 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
169 application.SendNotification();
170 application.Render();
172 uint32_t expectedNumberOfUnderlineRuns = 2u;
174 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
175 const Text::Length numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
177 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
179 Vector<UnderlinedGlyphRun> underlineRuns;
180 underlineRuns.Resize(numberOfUnderlineRuns);
181 textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
184 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
185 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
188 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
189 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
194 int UtcDaliTextFieldMarkupUnderlineAttributes(void)
196 ToolkitTestApplication application;
197 tet_infoline(" UtcDaliTextFieldMarkupUnderlineAttributes ");
199 TextField textField = TextField::New();
201 application.GetScene().Add(textField);
203 std::string testText =
204 "start<u>ABC1</u>then"
205 "<u type='solid'>ABC2</u>then"
206 "<u type='dashed'>ABC3</u>then"
207 "<u type='double'>ABC4</u>then"
208 "<u color='green'>ABC5</u>then"
209 "<u height='5.0f'>ABC6</u>then"
210 "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
211 "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
212 "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
216 textField.SetProperty(TextField::Property::TEXT, testText);
217 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
219 application.SendNotification();
220 application.Render();
222 const uint32_t expectedNumberOfUnderlineRuns = 9u;
224 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
225 const Text::Length numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
227 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
229 Vector<UnderlinedGlyphRun> underlineRuns;
230 underlineRuns.Resize(numberOfUnderlineRuns);
231 textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
236 GlyphIndex glyphIndex;
237 Length numberOfGlyphs;
238 UnderlineStyleProperties properties;
247 Text::Underline::SOLID,
259 //<u type='solid'>ABC2</u>
260 {"<u type='solid'>ABC2</u>",
264 Text::Underline::SOLID,
276 //<u type='dashed'>ABC3</u>
277 {"<u type='dashed'>ABC3</u>",
281 Text::Underline::DASHED,
293 //<u type='double'>ABC4</u>
294 {"<u type='double'>ABC4</u>",
298 Text::Underline::DOUBLE,
310 //<u color='green'>ABC5</u>
311 {"<u color='green'>ABC5</u>",
315 Text::Underline::SOLID,
327 //<u height='5.0f'>ABC6</u>
328 {"<u height='5.0f'>ABC6</u>",
332 Text::Underline::SOLID,
344 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
345 {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
349 Text::Underline::DASHED,
361 //<u type='dashed' dash-width='4.0f'>ABC8</u>
362 {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
366 Text::Underline::DASHED,
378 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
379 {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
383 Text::Underline::DASHED,
397 for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
399 tet_infoline(data[i].title.c_str());
400 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
401 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
402 DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
408 int UtcDaliTextFieldMarkupSpanUnderline(void)
410 ToolkitTestApplication application;
411 tet_infoline(" UtcDaliTextFieldMarkupSpanUnderline ");
413 TextField textField = TextField::New();
415 application.GetScene().Add(textField);
417 std::string testText =
418 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
419 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>then"
420 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>then"
421 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>then"
422 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>then"
423 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
424 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>then"
425 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>then"
426 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>end";
428 textField.SetProperty(TextField::Property::TEXT, testText);
429 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
431 application.SendNotification();
432 application.Render();
434 const uint32_t expectedNumberOfUnderlineRuns = 8u;
436 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
437 const Text::Length numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
439 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
441 Vector<UnderlinedGlyphRun> underlineRuns;
442 underlineRuns.Resize(numberOfUnderlineRuns);
443 textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
448 GlyphIndex glyphIndex;
449 Length numberOfGlyphs;
450 UnderlineStyleProperties properties;
454 //<u type='solid'>ABC2</u>
455 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
459 Text::Underline::SOLID,
471 //<u type='dashed'>ABC3</u>
472 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
476 Text::Underline::DASHED,
488 //<u type='double'>ABC4</u>
489 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
493 Text::Underline::DOUBLE,
505 //<u color='green'>ABC5</u>
506 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
510 Text::Underline::SOLID,
522 //<u height='5.0f'>ABC6</u>
523 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
527 Text::Underline::SOLID,
539 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
540 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-gap='3.0f'>ABC7</span>",
544 Text::Underline::DASHED,
556 //<u type='dashed' dash-width='4.0f'>ABC8</u>
557 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed' u-dash-width='4.0f'>ABC8</span>",
561 Text::Underline::DASHED,
573 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
574 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='blue' u-type='dashed' u-height='4.0f' u-dash-gap='2.0f' u-dash-width='3.0f'>ABC9</span>",
578 Text::Underline::DASHED,
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 UtcDaliTextFieldMarkupNestedUnderlineTags(void)
605 ToolkitTestApplication application;
606 tet_infoline(" UtcDaliTextFieldMarkupNestedUnderlineTags ");
608 TextField textField = TextField::New();
610 application.GetScene().Add(textField);
612 std::string testText = "start<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>end";
614 textField.SetProperty(TextField::Property::TEXT, testText);
615 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
617 application.SendNotification();
618 application.Render();
620 const uint32_t expectedNumberOfUnderlineRuns = 2u;
622 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
623 const Text::Length numberOfUnderlineRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
625 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlineRuns, TEST_LOCATION);
627 Vector<UnderlinedGlyphRun> underlineRuns;
628 underlineRuns.Resize(numberOfUnderlineRuns);
629 textFieldImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
634 GlyphIndex glyphIndex;
635 Length numberOfGlyphs;
636 UnderlineStyleProperties properties;
641 {"<u height='5.0f' color='green' >AB<u color='blue' >XYZ</u>CDE</u>",
645 Text::Underline::SOLID,
658 {"<u color='blue' >XYZ</u>",
662 Text::Underline::SOLID,
676 for(uint32_t i = 0; i < expectedNumberOfUnderlineRuns; i++)
678 tet_infoline(data[i].title.c_str());
679 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
680 DALI_TEST_EQUALS(underlineRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
681 DALI_TEST_CHECK(data[i].properties == underlineRuns[i].properties);
687 int UtcDaliTextFieldMarkupStrikethroughAttributes(void)
689 ToolkitTestApplication application;
690 tet_infoline(" UtcDaliTextFieldMarkupStrikethroughAttributes ");
692 TextField textField = TextField::New();
694 application.GetScene().Add(textField);
696 std::string testText =
697 "start<s>ABC1</s>then"
698 "<s color='green'>ABC2</s>then"
699 "<s height='5.0f'>ABC3</s>then"
700 "<s color='blue' height='4.0f' >ABC4</s>end";
702 textField.SetProperty(TextField::Property::TEXT, testText);
703 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
705 application.SendNotification();
706 application.Render();
708 const uint32_t expectedNumberOfStrikethroughRuns = 4u;
710 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
711 const Text::Length numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
713 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
715 Vector<StrikethroughGlyphRun> strikethroughRuns;
716 strikethroughRuns.Resize(numberOfStrikethroughRuns);
717 textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
722 GlyphIndex glyphIndex;
723 Length numberOfGlyphs;
724 StrikethroughStyleProperties properties;
737 {"<s color='green'>ABC2</s>",
745 {"<s height='5.0f'>ABC3</s>",
753 {"<s color='blue' height='4.0f' >ABC4</s>",
763 for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
765 tet_infoline(data[i].title.c_str());
766 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
767 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
768 DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
774 int UtcDaliTextFieldMarkupSpanStrikethrough(void)
776 ToolkitTestApplication application;
777 tet_infoline(" UtcDaliTextFieldMarkupSpanStrikethrough ");
779 TextField textField = TextField::New();
781 application.GetScene().Add(textField);
783 std::string testText =
784 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
785 "<span s-color='blue'>ABC2</span>then"
786 "<span s-height='2.0f'>ABC3</span>then"
787 "<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";
789 textField.SetProperty(TextField::Property::TEXT, testText);
790 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
792 application.SendNotification();
793 application.Render();
795 const uint32_t expectedNumberOfStrikethroughRuns = 3u;
797 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
798 const Text::Length numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
800 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughRuns, TEST_LOCATION);
802 Vector<StrikethroughGlyphRun> strikethroughRuns;
803 strikethroughRuns.Resize(numberOfStrikethroughRuns);
804 textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
809 GlyphIndex glyphIndex;
810 Length numberOfGlyphs;
811 StrikethroughStyleProperties properties;
816 {"<span s-color='blue'>ABC2</span>then",
824 {"<span s-height='2.0f'>ABC3</span>then",
832 {"<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>",
842 for(uint32_t i = 0; i < expectedNumberOfStrikethroughRuns; i++)
844 tet_infoline(data[i].title.c_str());
845 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.glyphIndex, data[i].glyphIndex, TEST_LOCATION);
846 DALI_TEST_EQUALS(strikethroughRuns[i].glyphRun.numberOfGlyphs, data[i].numberOfGlyphs, TEST_LOCATION);
847 DALI_TEST_CHECK(data[i].properties == strikethroughRuns[i].properties);
853 int UtcDaliTextFieldFontPointSizeLargerThanAtlas(void)
855 ToolkitTestApplication application;
856 tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlas ");
858 // Create a Text field
859 TextField textField = TextField::New();
860 //Set size to avoid automatic eliding
861 textField.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
862 //Set very large font-size using point-size
863 textField.SetProperty(TextField::Property::POINT_SIZE, 1000);
864 //Specify font-family
865 textField.SetProperty(TextField::Property::FONT_FAMILY, "DejaVu Sans");
866 //Set text to check if appear or not
867 textField.SetProperty(TextField::Property::TEXT, "A");
869 application.GetScene().Add(textField);
871 application.SendNotification();
872 application.Render();
874 //Check if Glyph is added to AtlasGlyphManger or not
875 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
876 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
881 int UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase(void)
883 ToolkitTestApplication application;
884 tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase ");
886 //Set Map of placeholder: text, font-family and point-size
887 Property::Map placeholderMapSet;
888 placeholderMapSet["text"] = "A";
889 placeholderMapSet["fontFamily"] = "DejaVu Sans";
890 placeholderMapSet["pixelSize"] = 1000.0f;
892 // Create a text editor
893 TextField textField = TextField::New();
894 //Set size to avoid automatic eliding
895 textField.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
897 textField.SetProperty(TextField::Property::PLACEHOLDER, placeholderMapSet);
899 application.GetScene().Add(textField);
901 application.SendNotification();
902 application.Render();
904 //Check if Glyph is added to AtlasGlyphManger or not
905 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
906 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
911 int UtcDaliTextFieldBackgroundTag(void)
913 ToolkitTestApplication application;
914 tet_infoline("UtcDaliTextFieldBackgroundTag\n");
916 TextField field = TextField::New();
917 DALI_TEST_CHECK(field);
919 field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
920 field.SetProperty(TextField::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
921 application.GetScene().Add(field);
922 application.SendNotification();
923 application.Render();
925 Toolkit::Internal::TextField& fieldImpl = GetImpl(field);
926 const ColorIndex* const backgroundColorIndicesBuffer = fieldImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
928 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
931 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
934 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
937 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
942 int UtcDaliTextFieldSpanBackgroundTag(void)
944 ToolkitTestApplication application;
945 tet_infoline("UtcDaliTextFieldSpanBackgroundTag\n");
947 TextField field = TextField::New();
948 DALI_TEST_CHECK(field);
950 field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
951 field.SetProperty(TextField::Property::TEXT, "H<span background-color='red'>e</span> Worl<span background-color='yellow'>d</span>");
952 application.GetScene().Add(field);
953 application.SendNotification();
954 application.Render();
956 Toolkit::Internal::TextField& fieldImpl = GetImpl(field);
957 const ColorIndex* const backgroundColorIndicesBuffer = fieldImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
959 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
962 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
965 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
968 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
973 int UtcDaliToolkitTextFieldEllipsisInternalAPIs(void)
975 ToolkitTestApplication application;
976 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs ");
977 TextField textField = TextField::New();
979 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
980 Text::ViewInterface& view = textFieldImpl.GetTextController()->GetView();
982 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - ELLIPSIS Disabled");
983 textField.SetProperty(DevelTextField::Property::ELLIPSIS, false);
984 DALI_TEST_EQUALS(textField.GetProperty<bool>(DevelTextField::Property::ELLIPSIS), false, TEST_LOCATION);
985 DALI_TEST_CHECK(!(view.IsTextElideEnabled()));
987 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - ELLIPSIS Enabled");
988 textField.SetProperty(DevelTextField::Property::ELLIPSIS, true);
989 DALI_TEST_EQUALS(textField.GetProperty<bool>(DevelTextField::Property::ELLIPSIS), true, TEST_LOCATION);
990 DALI_TEST_CHECK(view.IsTextElideEnabled());
992 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
993 DALI_TEST_EQUALS(view.GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
995 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
996 DALI_TEST_EQUALS(view.GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
998 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
999 DALI_TEST_EQUALS(view.GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1001 tet_infoline(" UtcDaliToolkitTextFieldEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
1002 DALI_TEST_EQUALS(view.GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
1006 int UtcDaliTextFieldTextWithSpan(void)
1008 ToolkitTestApplication application;
1009 tet_infoline("UtcDaliTextFieldTextWithSpan\n");
1011 TextField field = TextField::New();
1012 DALI_TEST_CHECK(field);
1014 field.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1015 field.SetProperty(TextField::Property::TEXT, "Hello Span");
1016 application.GetScene().Add(field);
1018 application.SendNotification();
1019 application.Render();
1021 Vector3 originalSize = field.GetNaturalSize();
1022 field.SetProperty(TextField::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span");
1024 application.SendNotification();
1025 application.Render();
1027 Vector3 spanSize = field.GetNaturalSize();
1029 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
1031 Toolkit::Internal::TextField& fieldImpl = GetImpl(field);
1032 const ColorIndex* const colorIndicesBuffer1 = fieldImpl.GetTextController()->GetTextModel()->GetColorIndices();
1034 DALI_TEST_CHECK(colorIndicesBuffer1);
1037 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
1040 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
1043 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
1045 field.SetProperty(TextField::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
1047 application.SendNotification();
1048 application.Render();
1050 const ColorIndex* const colorIndicesBuffer2 = fieldImpl.GetTextController()->GetTextModel()->GetColorIndices();
1052 DALI_TEST_CHECK(colorIndicesBuffer2);
1055 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
1058 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
1061 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
1064 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
1069 int UtcDaliTextFieldControlBackgroundColor(void)
1071 ToolkitTestApplication application;
1072 tet_infoline(" UtcDaliTextFieldControlBackgroundColor\n");
1074 TextField field = TextField::New();
1075 DALI_TEST_CHECK(field);
1077 Vector4 backgroundColor;
1079 field.SetProperty(TextField::Property::TEXT, "Background Color");
1080 application.GetScene().Add(field);
1081 application.SendNotification();
1082 application.Render();
1084 Toolkit::Internal::TextField& fieldImpl = GetImpl(field);
1085 ControllerPtr controller = fieldImpl.GetTextController();
1086 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
1088 // Default color is transparent
1089 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
1090 DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
1092 // Set background color to red
1093 field.SetBackgroundColor(Color::RED);
1094 application.SendNotification();
1095 application.Render();
1098 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
1099 DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
1104 int UtcDaliTextFieldMarkupStrikethrough(void)
1106 ToolkitTestApplication application;
1107 tet_infoline(" UtcDaliTextFieldMarkupStrikethrough ");
1109 TextField textField = TextField::New();
1111 application.GetScene().Add(textField);
1113 textField.SetProperty(TextField::Property::TEXT, "<s>ABC</s>EF<s color='red'>GH</s>");
1114 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1116 application.SendNotification();
1117 application.Render();
1119 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
1121 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
1122 const Text::Length numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1124 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
1126 Vector<StrikethroughGlyphRun> strikethroughRuns;
1127 strikethroughRuns.Resize(numberOfStrikethroughRuns);
1128 textFieldImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
1130 //ABC have strikethrough
1131 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
1132 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
1133 DALI_TEST_CHECK(!strikethroughRuns[0u].properties.colorDefined);
1135 //GH have strikethrough
1136 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
1137 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
1138 DALI_TEST_CHECK(strikethroughRuns[1u].properties.colorDefined);
1143 int UtcDaliTextFieldMarkupStrikethroughNoEndTag(void)
1145 ToolkitTestApplication application;
1146 tet_infoline(" UtcDaliTextFieldMarkupStrikethroughNoEndTag ");
1148 TextField textField = TextField::New();
1150 application.GetScene().Add(textField);
1152 textField.SetProperty(TextField::Property::TEXT, "<s>ABC");
1153 textField.SetProperty(TextField ::Property::ENABLE_MARKUP, true);
1155 application.SendNotification();
1156 application.Render();
1158 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
1160 Toolkit::Internal::TextField& textFieldImpl = GetImpl(textField);
1161 Text::Length numberOfStrikethroughRuns = textFieldImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
1163 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);