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-label-impl.h>
25 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
26 #include <dali-toolkit/internal/text/rendering/view-model.h>
27 #include <dali-toolkit/internal/text/text-controller-impl.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
31 using namespace Toolkit;
34 int UtcDaliTextLabelMarkupUnderline(void)
36 ToolkitTestApplication application;
37 tet_infoline(" UtcDaliTextLabelMarkupUnderline ");
39 TextLabel textLabel = TextLabel::New();
41 application.GetScene().Add(textLabel);
43 textLabel.SetProperty(TextLabel::Property::TEXT, "<u>ABC</u>EF<u>GH</u>");
44 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
46 application.SendNotification();
49 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
51 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
52 const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
54 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
56 Vector<GlyphRun> underlineRuns;
57 underlineRuns.Resize(numberOfUnderlineRuns);
58 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
61 DALI_TEST_EQUALS(underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
62 DALI_TEST_EQUALS(underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
63 DALI_TEST_EQUALS(underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
66 DALI_TEST_EQUALS(underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
67 DALI_TEST_EQUALS(underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
72 int UtcDaliTextLabelBackgroundTag(void)
74 ToolkitTestApplication application;
75 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
77 TextLabel label = TextLabel::New();
78 DALI_TEST_CHECK(label);
80 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
81 label.SetProperty(TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
82 application.GetScene().Add(label);
83 application.SendNotification();
86 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
87 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
89 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
92 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
95 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
98 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
103 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
105 ToolkitTestApplication application;
106 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
107 TextLabel textLabel = TextLabel::New();
109 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
110 const ModelInterface* const textModel = textLabelImpl.GetTextController()->GetTextModel();
112 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
113 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
114 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), false, TEST_LOCATION);
115 DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
117 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
118 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
119 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), true, TEST_LOCATION);
120 DALI_TEST_CHECK(textModel->IsTextElideEnabled());
122 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
123 DALI_TEST_EQUALS(textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
125 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
126 DALI_TEST_EQUALS(textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
128 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
129 DALI_TEST_EQUALS(textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
131 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
132 DALI_TEST_EQUALS(textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
134 // Tests the rendering controller has been created.
135 TypesetterPtr typesetter = Typesetter::New(textModel);
136 DALI_TEST_CHECK(typesetter);
138 // Tests the view model has been created.
139 ViewModel* model = typesetter->GetViewModel();
141 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
142 DALI_TEST_CHECK(model->IsTextElideEnabled());
144 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
145 DALI_TEST_EQUALS(model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
147 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
148 DALI_TEST_EQUALS(model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
150 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
151 DALI_TEST_EQUALS(model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
153 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
154 DALI_TEST_EQUALS(model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
158 int UtcDaliTextLabelTextWithSpan(void)
160 ToolkitTestApplication application;
161 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
163 TextLabel label = TextLabel::New();
164 DALI_TEST_CHECK(label);
166 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
167 label.SetProperty(TextLabel::Property::TEXT, "Hello Span");
168 application.GetScene().Add(label);
170 application.SendNotification();
171 application.Render();
173 Vector3 originalSize = label.GetNaturalSize();
174 label.SetProperty(TextLabel::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span");
176 application.SendNotification();
177 application.Render();
179 Vector3 spanSize = label.GetNaturalSize();
181 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
183 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
184 const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
186 DALI_TEST_CHECK(colorIndicesBuffer1);
189 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
192 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
195 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
197 label.SetProperty(TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
199 application.SendNotification();
200 application.Render();
202 const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
204 DALI_TEST_CHECK(colorIndicesBuffer2);
207 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
210 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
213 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
216 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
221 int UtcDaliTextLabelMarkupStrikethrough(void)
223 ToolkitTestApplication application;
224 tet_infoline(" UtcDaliTextLabelMarkupStrikethrough ");
226 TextLabel textLabel = TextLabel::New();
228 application.GetScene().Add(textLabel);
230 textLabel.SetProperty(TextLabel::Property::TEXT, "<s color='red'>ABC</s>EF<s color='green'>GH</s>");
231 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
233 application.SendNotification();
234 application.Render();
236 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
238 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
239 const Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
241 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
243 Vector<StrikethroughGlyphRun> strikethroughRuns;
244 strikethroughRuns.Resize(numberOfStrikethroughRuns);
245 textLabelImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
247 //ABC have strikethrough
248 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
249 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
250 DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
251 DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
252 DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
253 DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
255 //GH have strikethrough
256 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
257 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
258 DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
259 DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
260 DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
261 DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);