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<UnderlinedGlyphRun> underlineRuns;
57 underlineRuns.Resize(numberOfUnderlineRuns);
58 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
61 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
62 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 1u, TEST_LOCATION);
63 DALI_TEST_EQUALS(underlineRuns[2u].glyphRun.glyphIndex, 2u, TEST_LOCATION);
66 DALI_TEST_EQUALS(underlineRuns[3u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
67 DALI_TEST_EQUALS(underlineRuns[4u].glyphRun.glyphIndex, 6u, TEST_LOCATION);
72 int UtcDaliTextLabelMarkupUnderlineAttributes(void)
74 ToolkitTestApplication application;
75 tet_infoline(" UtcDaliTextLabelMarkupUnderlineAttributes ");
77 TextLabel textLabel = TextLabel::New();
79 application.GetScene().Add(textLabel);
81 std::string testText =
82 "start<u>ABC1</u>then"
83 "<u type='solid'>ABC2</u>then"
84 "<u type='dashed'>ABC3</u>then"
85 "<u type='double'>ABC4</u>then"
86 "<u color='green'>ABC5</u>then"
87 "<u height='5.0f'>ABC6</u>then"
88 "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
89 "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
90 "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
94 textLabel.SetProperty(TextLabel::Property::TEXT, testText);
95 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
97 application.SendNotification();
100 const uint32_t NUMBER_OF_CASES = 9u;
101 uint32_t expectedNumberOfUnderlinedGlyphs = 36u;
103 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
104 const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
106 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
108 Vector<UnderlinedGlyphRun> underlineRuns;
109 underlineRuns.Resize(numberOfUnderlineRuns);
110 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
117 GlyphIndex startGlyphIndex;
118 GlyphIndex endGlyphIndex;
119 UnderlineStyleProperties properties;
130 Text::Underline::SOLID,
142 //<u type='solid'>ABC2</u>
143 {"<u type='solid'>ABC2</u>",
149 Text::Underline::SOLID,
161 //<u type='dashed'>ABC3</u>
162 {"<u type='dashed'>ABC3</u>",
168 Text::Underline::DASHED,
180 //<u type='double'>ABC4</u>
181 {"<u type='double'>ABC4</u>",
187 Text::Underline::DOUBLE,
199 //<u color='green'>ABC5</u>
200 {"<u color='green'>ABC5</u>",
206 Text::Underline::SOLID,
218 //<u height='5.0f'>ABC6</u>
219 {"<u height='5.0f'>ABC6</u>",
225 Text::Underline::SOLID,
237 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
238 {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
244 Text::Underline::DASHED,
256 //<u type='dashed' dash-width='4.0f'>ABC8</u>
257 {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
263 Text::Underline::DASHED,
275 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
276 {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
282 Text::Underline::DASHED,
296 for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
298 tet_infoline(data[i].title.c_str());
299 DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
300 DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
302 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
303 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
309 int UtcDaliTextLabelBackgroundTag(void)
311 ToolkitTestApplication application;
312 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
314 TextLabel label = TextLabel::New();
315 DALI_TEST_CHECK(label);
317 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
318 label.SetProperty(TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
319 application.GetScene().Add(label);
320 application.SendNotification();
321 application.Render();
323 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
324 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
326 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
329 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
332 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
335 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
340 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
342 ToolkitTestApplication application;
343 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
344 TextLabel textLabel = TextLabel::New();
346 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
347 const ModelInterface* const textModel = textLabelImpl.GetTextController()->GetTextModel();
349 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
350 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
351 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), false, TEST_LOCATION);
352 DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
354 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
355 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
356 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), true, TEST_LOCATION);
357 DALI_TEST_CHECK(textModel->IsTextElideEnabled());
359 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
360 DALI_TEST_EQUALS(textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
362 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
363 DALI_TEST_EQUALS(textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
365 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
366 DALI_TEST_EQUALS(textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
368 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
369 DALI_TEST_EQUALS(textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
371 // Tests the rendering controller has been created.
372 TypesetterPtr typesetter = Typesetter::New(textModel);
373 DALI_TEST_CHECK(typesetter);
375 // Tests the view model has been created.
376 ViewModel* model = typesetter->GetViewModel();
378 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
379 DALI_TEST_CHECK(model->IsTextElideEnabled());
381 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
382 DALI_TEST_EQUALS(model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
384 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
385 DALI_TEST_EQUALS(model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
387 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
388 DALI_TEST_EQUALS(model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
390 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
391 DALI_TEST_EQUALS(model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
395 int UtcDaliTextLabelTextWithSpan(void)
397 ToolkitTestApplication application;
398 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
400 TextLabel label = TextLabel::New();
401 DALI_TEST_CHECK(label);
403 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
404 label.SetProperty(TextLabel::Property::TEXT, "Hello Span");
405 application.GetScene().Add(label);
407 application.SendNotification();
408 application.Render();
410 Vector3 originalSize = label.GetNaturalSize();
411 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");
413 application.SendNotification();
414 application.Render();
416 Vector3 spanSize = label.GetNaturalSize();
418 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
420 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
421 const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
423 DALI_TEST_CHECK(colorIndicesBuffer1);
426 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
429 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
432 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
434 label.SetProperty(TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
436 application.SendNotification();
437 application.Render();
439 const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
441 DALI_TEST_CHECK(colorIndicesBuffer2);
444 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
447 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
450 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
453 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
458 int UtcDaliTextLabelMarkupStrikethrough(void)
460 ToolkitTestApplication application;
461 tet_infoline(" UtcDaliTextLabelMarkupStrikethrough ");
463 TextLabel textLabel = TextLabel::New();
465 application.GetScene().Add(textLabel);
467 textLabel.SetProperty(TextLabel::Property::TEXT, "<s color='red'>ABC</s>EF<s color='green'>GH</s>");
468 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
470 application.SendNotification();
471 application.Render();
473 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
475 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
476 const Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
478 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
480 Vector<StrikethroughGlyphRun> strikethroughRuns;
481 strikethroughRuns.Resize(numberOfStrikethroughRuns);
482 textLabelImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
484 //ABC have strikethrough
485 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
486 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
487 DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
488 DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
489 DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
490 DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
492 //GH have strikethrough
493 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
494 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
495 DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
496 DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
497 DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
498 DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);
503 int UtcDaliTextLabelMarkupStrikethroughNoEndTag(void)
505 ToolkitTestApplication application;
506 tet_infoline(" UtcDaliTextLabelMarkupStrikethroughNoEndTag ");
508 TextLabel textLabel = TextLabel::New();
510 application.GetScene().Add(textLabel);
512 textLabel.SetProperty(TextLabel::Property::TEXT, "<s>ABC");
513 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
515 application.SendNotification();
516 application.Render();
518 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
520 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
521 Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
523 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);