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.
18 #include <bits/stdint-uintn.h>
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
26 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
27 #include <dali-toolkit/internal/text/rendering/view-model.h>
28 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 #include <dali-toolkit/internal/text/text-controller.h>
32 using namespace Toolkit;
35 int UtcDaliTextLabelMarkupUnderline(void)
37 ToolkitTestApplication application;
38 tet_infoline(" UtcDaliTextLabelMarkupUnderline ");
40 TextLabel textLabel = TextLabel::New();
42 application.GetScene().Add(textLabel);
44 textLabel.SetProperty(TextLabel::Property::TEXT, "<u>ABC</u>EF<u>GH</u>");
45 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
47 application.SendNotification();
50 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
52 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
53 const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
55 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
57 Vector<UnderlinedGlyphRun> underlineRuns;
58 underlineRuns.Resize(numberOfUnderlineRuns);
59 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
62 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
63 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 1u, TEST_LOCATION);
64 DALI_TEST_EQUALS(underlineRuns[2u].glyphRun.glyphIndex, 2u, TEST_LOCATION);
67 DALI_TEST_EQUALS(underlineRuns[3u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
68 DALI_TEST_EQUALS(underlineRuns[4u].glyphRun.glyphIndex, 6u, TEST_LOCATION);
73 int UtcDaliTextLabelMarkupUnderlineAttributes(void)
75 ToolkitTestApplication application;
76 tet_infoline(" UtcDaliTextLabelMarkupUnderlineAttributes ");
78 TextLabel textLabel = TextLabel::New();
80 application.GetScene().Add(textLabel);
82 std::string testText =
83 "start<u>ABC1</u>then"
84 "<u type='solid'>ABC2</u>then"
85 "<u type='dashed'>ABC3</u>then"
86 "<u type='double'>ABC4</u>then"
87 "<u color='green'>ABC5</u>then"
88 "<u height='5.0f'>ABC6</u>then"
89 "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
90 "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
91 "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
95 textLabel.SetProperty(TextLabel::Property::TEXT, testText);
96 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
98 application.SendNotification();
101 const uint32_t NUMBER_OF_CASES = 9u;
102 uint32_t expectedNumberOfUnderlinedGlyphs = 36u;
104 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
105 const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
107 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
109 Vector<UnderlinedGlyphRun> underlineRuns;
110 underlineRuns.Resize(numberOfUnderlineRuns);
111 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
118 GlyphIndex startGlyphIndex;
119 GlyphIndex endGlyphIndex;
120 UnderlineStyleProperties properties;
131 Text::Underline::SOLID,
143 //<u type='solid'>ABC2</u>
144 {"<u type='solid'>ABC2</u>",
150 Text::Underline::SOLID,
162 //<u type='dashed'>ABC3</u>
163 {"<u type='dashed'>ABC3</u>",
169 Text::Underline::DASHED,
181 //<u type='double'>ABC4</u>
182 {"<u type='double'>ABC4</u>",
188 Text::Underline::DOUBLE,
200 //<u color='green'>ABC5</u>
201 {"<u color='green'>ABC5</u>",
207 Text::Underline::SOLID,
219 //<u height='5.0f'>ABC6</u>
220 {"<u height='5.0f'>ABC6</u>",
226 Text::Underline::SOLID,
238 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
239 {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
245 Text::Underline::DASHED,
257 //<u type='dashed' dash-width='4.0f'>ABC8</u>
258 {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
264 Text::Underline::DASHED,
276 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
277 {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
283 Text::Underline::DASHED,
297 for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
299 tet_infoline(data[i].title.c_str());
300 DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
301 DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
303 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
304 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
310 int UtcDaliTextLabelBackgroundTag(void)
312 ToolkitTestApplication application;
313 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
315 TextLabel label = TextLabel::New();
316 DALI_TEST_CHECK(label);
318 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
319 label.SetProperty(TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
320 application.GetScene().Add(label);
321 application.SendNotification();
322 application.Render();
324 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
325 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
327 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
330 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
333 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
336 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
341 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
343 ToolkitTestApplication application;
344 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
345 TextLabel textLabel = TextLabel::New();
347 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
348 const ModelInterface* const textModel = textLabelImpl.GetTextController()->GetTextModel();
350 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
351 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
352 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), false, TEST_LOCATION);
353 DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
355 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
356 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
357 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), true, TEST_LOCATION);
358 DALI_TEST_CHECK(textModel->IsTextElideEnabled());
360 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
361 DALI_TEST_EQUALS(textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
363 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
364 DALI_TEST_EQUALS(textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
366 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
367 DALI_TEST_EQUALS(textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
369 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
370 DALI_TEST_EQUALS(textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
372 // Tests the rendering controller has been created.
373 TypesetterPtr typesetter = Typesetter::New(textModel);
374 DALI_TEST_CHECK(typesetter);
376 // Tests the view model has been created.
377 ViewModel* model = typesetter->GetViewModel();
379 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
380 DALI_TEST_CHECK(model->IsTextElideEnabled());
382 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
383 DALI_TEST_EQUALS(model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
385 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
386 DALI_TEST_EQUALS(model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
388 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
389 DALI_TEST_EQUALS(model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
391 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
392 DALI_TEST_EQUALS(model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
396 int UtcDaliTextLabelTextWithSpan(void)
398 ToolkitTestApplication application;
399 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
401 TextLabel label = TextLabel::New();
402 DALI_TEST_CHECK(label);
404 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
405 label.SetProperty(TextLabel::Property::TEXT, "Hello Span");
406 application.GetScene().Add(label);
408 application.SendNotification();
409 application.Render();
411 Vector3 originalSize = label.GetNaturalSize();
412 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");
414 application.SendNotification();
415 application.Render();
417 Vector3 spanSize = label.GetNaturalSize();
419 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
421 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
422 const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
424 DALI_TEST_CHECK(colorIndicesBuffer1);
427 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
430 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
433 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
435 label.SetProperty(TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
437 application.SendNotification();
438 application.Render();
440 const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
442 DALI_TEST_CHECK(colorIndicesBuffer2);
445 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
448 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
451 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
454 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
459 int UtcDaliTextLabelMarkupStrikethrough(void)
461 ToolkitTestApplication application;
462 tet_infoline(" UtcDaliTextLabelMarkupStrikethrough ");
464 TextLabel textLabel = TextLabel::New();
466 application.GetScene().Add(textLabel);
468 textLabel.SetProperty(TextLabel::Property::TEXT, "<s color='red'>ABC</s>EF<s color='green'>GH</s>");
469 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
471 application.SendNotification();
472 application.Render();
474 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
476 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
477 const Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
479 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
481 Vector<StrikethroughGlyphRun> strikethroughRuns;
482 strikethroughRuns.Resize(numberOfStrikethroughRuns);
483 textLabelImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
485 //ABC have strikethrough
486 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
487 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
488 DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
489 DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
490 DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
491 DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
493 //GH have strikethrough
494 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
495 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
496 DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
497 DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
498 DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
499 DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);
504 int UtcDaliTextLabelMarkupStrikethroughNoEndTag(void)
506 ToolkitTestApplication application;
507 tet_infoline(" UtcDaliTextLabelMarkupStrikethroughNoEndTag ");
509 TextLabel textLabel = TextLabel::New();
511 application.GetScene().Add(textLabel);
513 textLabel.SetProperty(TextLabel::Property::TEXT, "<s>ABC");
514 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
516 application.SendNotification();
517 application.Render();
519 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
521 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
522 Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
524 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);