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 UtcDaliTextLabelMarkupSpanUnderline(void)
311 ToolkitTestApplication application;
312 tet_infoline(" UtcDaliTextLabelMarkupSpanUnderline ");
314 TextLabel textLabel = TextLabel::New();
316 application.GetScene().Add(textLabel);
318 std::string testText =
319 "start<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ABC1</span>then"
320 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>then"
321 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>then"
322 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>then"
323 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>then"
324 "<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>then"
325 "<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"
326 "<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"
327 "<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"
331 textLabel.SetProperty(TextLabel::Property::TEXT, testText);
332 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
334 application.SendNotification();
335 application.Render();
337 const uint32_t NUMBER_OF_CASES = 8u;
338 uint32_t expectedNumberOfUnderlinedGlyphs = 32u;
340 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
341 const Text::Length numberOfUnderlineRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
343 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
345 Vector<UnderlinedGlyphRun> underlineRuns;
346 underlineRuns.Resize(numberOfUnderlineRuns);
347 textLabelImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
354 GlyphIndex startGlyphIndex;
355 GlyphIndex endGlyphIndex;
356 UnderlineStyleProperties properties;
361 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='solid'>ABC2</span>",
367 Text::Underline::SOLID,
379 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='dashed'>ABC3</span>",
385 Text::Underline::DASHED,
397 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-type='double'>ABC4</span>",
403 Text::Underline::DOUBLE,
415 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-color='green'>ABC5</span>",
421 Text::Underline::SOLID,
433 {"<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red' u-height='5.0f'>ABC6</span>",
439 Text::Underline::SOLID,
451 {"<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>",
457 Text::Underline::DASHED,
469 {"<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>",
475 Text::Underline::DASHED,
487 {"<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>",
493 Text::Underline::DASHED,
507 for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
509 tet_infoline(data[i].title.c_str());
510 DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
511 DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
513 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
514 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
520 int UtcDaliTextLabelBackgroundTag(void)
522 ToolkitTestApplication application;
523 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
525 TextLabel label = TextLabel::New();
526 DALI_TEST_CHECK(label);
528 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
529 label.SetProperty(TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
530 application.GetScene().Add(label);
531 application.SendNotification();
532 application.Render();
534 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
535 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
537 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
540 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
543 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
546 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
551 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
553 ToolkitTestApplication application;
554 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
555 TextLabel textLabel = TextLabel::New();
557 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
558 const ModelInterface* const textModel = textLabelImpl.GetTextController()->GetTextModel();
560 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
561 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
562 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), false, TEST_LOCATION);
563 DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
565 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
566 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
567 DALI_TEST_EQUALS(textLabel.GetProperty<bool>(DevelTextLabel::Property::ELLIPSIS), true, TEST_LOCATION);
568 DALI_TEST_CHECK(textModel->IsTextElideEnabled());
570 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
571 DALI_TEST_EQUALS(textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
573 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
574 DALI_TEST_EQUALS(textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
576 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
577 DALI_TEST_EQUALS(textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
579 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
580 DALI_TEST_EQUALS(textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
582 // Tests the rendering controller has been created.
583 TypesetterPtr typesetter = Typesetter::New(textModel);
584 DALI_TEST_CHECK(typesetter);
586 // Tests the view model has been created.
587 ViewModel* model = typesetter->GetViewModel();
589 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
590 DALI_TEST_CHECK(model->IsTextElideEnabled());
592 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
593 DALI_TEST_EQUALS(model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
595 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
596 DALI_TEST_EQUALS(model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
598 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
599 DALI_TEST_EQUALS(model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
601 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
602 DALI_TEST_EQUALS(model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION);
606 int UtcDaliTextLabelTextWithSpan(void)
608 ToolkitTestApplication application;
609 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
611 TextLabel label = TextLabel::New();
612 DALI_TEST_CHECK(label);
614 label.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
615 label.SetProperty(TextLabel::Property::TEXT, "Hello Span");
616 application.GetScene().Add(label);
618 application.SendNotification();
619 application.Render();
621 Vector3 originalSize = label.GetNaturalSize();
622 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");
624 application.SendNotification();
625 application.Render();
627 Vector3 spanSize = label.GetNaturalSize();
629 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
631 Toolkit::Internal::TextLabel& labelImpl = GetImpl(label);
632 const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
634 DALI_TEST_CHECK(colorIndicesBuffer1);
637 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
640 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
643 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
645 label.SetProperty(TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
647 application.SendNotification();
648 application.Render();
650 const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
652 DALI_TEST_CHECK(colorIndicesBuffer2);
655 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
658 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
661 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
664 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
669 int UtcDaliTextLabelMarkupStrikethrough(void)
671 ToolkitTestApplication application;
672 tet_infoline(" UtcDaliTextLabelMarkupStrikethrough ");
674 TextLabel textLabel = TextLabel::New();
676 application.GetScene().Add(textLabel);
678 textLabel.SetProperty(TextLabel::Property::TEXT, "<s color='red'>ABC</s>EF<s color='green'>GH</s>");
679 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
681 application.SendNotification();
682 application.Render();
684 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
686 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
687 const Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
689 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
691 Vector<StrikethroughGlyphRun> strikethroughRuns;
692 strikethroughRuns.Resize(numberOfStrikethroughRuns);
693 textLabelImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
695 //ABC have strikethrough
696 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
697 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
698 DALI_TEST_CHECK(strikethroughRuns[0u].isColorSet);
699 DALI_TEST_EQUALS(strikethroughRuns[0u].color.r, 1u, TEST_LOCATION);
700 DALI_TEST_EQUALS(strikethroughRuns[0u].color.g, 0u, TEST_LOCATION);
701 DALI_TEST_EQUALS(strikethroughRuns[0u].color.b, 0u, TEST_LOCATION);
703 //GH have strikethrough
704 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
705 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
706 DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
707 DALI_TEST_EQUALS(strikethroughRuns[1u].color.r, 0u, TEST_LOCATION);
708 DALI_TEST_EQUALS(strikethroughRuns[1u].color.g, 1u, TEST_LOCATION);
709 DALI_TEST_EQUALS(strikethroughRuns[1u].color.b, 0u, TEST_LOCATION);
714 int UtcDaliTextLabelMarkupStrikethroughNoEndTag(void)
716 ToolkitTestApplication application;
717 tet_infoline(" UtcDaliTextLabelMarkupStrikethroughNoEndTag ");
719 TextLabel textLabel = TextLabel::New();
721 application.GetScene().Add(textLabel);
723 textLabel.SetProperty(TextLabel::Property::TEXT, "<s>ABC");
724 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
726 application.SendNotification();
727 application.Render();
729 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
731 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
732 Text::Length numberOfStrikethroughRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
734 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
739 int UtcDaliTextLabelMarkupParagraphTag(void)
742 ToolkitTestApplication application;
744 tet_infoline(" UtcDaliTextLabelMarkupParagraphTag ");
745 TextLabel textLabel = TextLabel::New();
747 application.GetScene().Add(textLabel);
749 textLabel.SetProperty(TextLabel::Property::TEXT, "text one <p>Paragraph two</p> text three <p>Paragraph four</p> text five");
750 textLabel.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
751 textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true);
753 application.SendNotification();
754 application.Render();
756 uint32_t expectedNumberOfBoundedParagraphRuns = 2u;
758 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl(textLabel);
759 const Text::Length numberOfBoundedParagraphRuns = textLabelImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
760 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
762 const Vector<BoundedParagraphRun>& boundedParagraphRuns = textLabelImpl.GetTextController()->GetTextModel()->GetBoundedParagraphRuns();
764 //<p>Paragraph two</p>
765 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.characterIndex, 10u, TEST_LOCATION);
766 DALI_TEST_EQUALS(boundedParagraphRuns[0u].characterRun.numberOfCharacters, 14u, TEST_LOCATION);
768 //<p>Paragraph four</p>
769 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.characterIndex, 37u, TEST_LOCATION);
770 DALI_TEST_EQUALS(boundedParagraphRuns[1u].characterRun.numberOfCharacters, 15u, TEST_LOCATION);
775 int UtcDaliTextLabelMarkupParagraphTagAlignAttribute(void)
777 ToolkitTestApplication application;
778 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute ");
780 // Apply alignment for each type on property level on three paragraphs and in-between text.
781 // Apply align in markup on the three paragraphs (each one a type).
782 // Using the same text to gain similar results from both the property level and the markup.
783 // Compare line alignment between the property level and the markup.
785 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>";
786 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>";
788 //Set size to avoid automatic eliding
789 Vector2 controllerSize = Vector2(1025, 1025);
791 TextLabel textLabelBeginAlign = TextLabel::New();
792 TextLabel textLabelCenterAlign = TextLabel::New();
793 TextLabel textLabelEndAlign = TextLabel::New();
794 TextLabel textLabelMultiAlign = TextLabel::New();
796 application.GetScene().Add(textLabelBeginAlign);
797 application.GetScene().Add(textLabelCenterAlign);
798 application.GetScene().Add(textLabelEndAlign);
799 application.GetScene().Add(textLabelMultiAlign);
801 textLabelBeginAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
802 textLabelBeginAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
803 textLabelBeginAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
804 textLabelBeginAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
805 textLabelBeginAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::BEGIN);
806 textLabelBeginAlign.SetProperty(Actor::Property::SIZE, controllerSize);
808 textLabelCenterAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
809 textLabelCenterAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
810 textLabelCenterAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
811 textLabelCenterAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
812 textLabelCenterAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
813 textLabelCenterAlign.SetProperty(Actor::Property::SIZE, controllerSize);
815 textLabelEndAlign.SetProperty(TextLabel::Property::TEXT, textAlignOnPropertyLevel);
816 textLabelEndAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
817 textLabelEndAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
818 textLabelEndAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
819 textLabelEndAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::END);
820 textLabelEndAlign.SetProperty(Actor::Property::SIZE, controllerSize);
822 textLabelMultiAlign.SetProperty(TextLabel::Property::TEXT, textAlignInMarkup);
823 textLabelMultiAlign.SetProperty(TextLabel ::Property::ENABLE_MARKUP, true);
824 textLabelMultiAlign.SetProperty(TextLabel::Property::MULTI_LINE, true);
825 textLabelMultiAlign.SetProperty(TextLabel::Property::ELLIPSIS, false);
826 textLabelMultiAlign.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, Dali::Toolkit::Text::HorizontalAlignment::CENTER);
827 textLabelMultiAlign.SetProperty(Actor::Property::SIZE, controllerSize);
829 application.SendNotification();
830 application.Render();
832 uint32_t expectedNumberOfBoundedParagraphRuns = 4u;
833 uint32_t expectedNumberOfLines = 7u;
835 Toolkit::Internal::TextLabel& textLabelMultiAlignImpl = GetImpl(textLabelMultiAlign);
836 Toolkit::Internal::TextLabel& textLabelBeginAlignImpl = GetImpl(textLabelBeginAlign);
837 Toolkit::Internal::TextLabel& textLabelCenterAlignImpl = GetImpl(textLabelCenterAlign);
838 Toolkit::Internal::TextLabel& textLabelEndAlignImpl = GetImpl(textLabelEndAlign);
840 const Text::Length numberOfBoundedParagraphRuns = textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfBoundedParagraphRuns();
841 DALI_TEST_EQUALS(numberOfBoundedParagraphRuns, expectedNumberOfBoundedParagraphRuns, TEST_LOCATION);
843 DALI_TEST_EQUALS(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
844 DALI_TEST_CHECK(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines());
846 DALI_TEST_EQUALS(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
847 DALI_TEST_CHECK(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetLines());
849 DALI_TEST_EQUALS(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
850 DALI_TEST_CHECK(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines());
852 DALI_TEST_EQUALS(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
853 DALI_TEST_CHECK(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetLines());
855 const uint32_t LINE_INDEX_ALIGN_END = 1u;
856 const uint32_t LINE_INDEX_ALIGN_CENTER = 3u;
857 const uint32_t LINE_INDEX_ALIGN_BEGIN = 5u;
858 const uint32_t LINE_INDEX_OUTSIDE_1 = 0u;
859 const uint32_t LINE_INDEX_OUTSIDE_2 = 2u;
860 const uint32_t LINE_INDEX_OUTSIDE_3 = 4u;
861 const uint32_t LINE_INDEX_PARAGRAPH = 6u;
863 //<p align='end'>Paragraph end</p>
864 const LineRun& lineEndFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
865 const LineRun& lineEndFromEndAlign = *(textLabelEndAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_END);
866 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='end'>Paragraph end</p>");
867 DALI_TEST_EQUALS(lineEndFromMultiAlign.alignmentOffset, lineEndFromEndAlign.alignmentOffset, TEST_LOCATION);
868 DALI_TEST_EQUALS(lineEndFromMultiAlign.width, lineEndFromEndAlign.width, TEST_LOCATION);
870 //<p align='center'>Paragraph center</p>
871 const LineRun& lineCenterFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
872 const LineRun& lineEndFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_CENTER);
873 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='center'>Paragraph center</p>");
874 DALI_TEST_EQUALS(lineCenterFromMultiAlign.alignmentOffset, lineEndFromCenterAlign.alignmentOffset, TEST_LOCATION);
875 DALI_TEST_EQUALS(lineCenterFromMultiAlign.width, lineEndFromCenterAlign.width, TEST_LOCATION);
877 //<p align='begin' >Paragraph begin</p>
878 const LineRun& lineBeginFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
879 const LineRun& lineEndFromBeginAlign = *(textLabelBeginAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_ALIGN_BEGIN);
880 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p align='begin' >Paragraph begin</p>");
881 DALI_TEST_EQUALS(lineBeginFromMultiAlign.alignmentOffset, lineEndFromBeginAlign.alignmentOffset, TEST_LOCATION);
882 DALI_TEST_EQUALS(lineBeginFromMultiAlign.width, lineEndFromBeginAlign.width, TEST_LOCATION);
885 const LineRun& lineOutsideOneFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
886 const LineRun& lineOutsideOneFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_1);
887 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside one");
888 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.alignmentOffset, lineOutsideOneFromCenterAlign.alignmentOffset, TEST_LOCATION);
889 DALI_TEST_EQUALS(lineOutsideOneFromMultiAlign.width, lineOutsideOneFromCenterAlign.width, TEST_LOCATION);
891 const LineRun& lineOutsideTwoFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
892 const LineRun& lineOutsideTwoFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_2);
893 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside two");
894 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.alignmentOffset, lineOutsideTwoFromCenterAlign.alignmentOffset, TEST_LOCATION);
895 DALI_TEST_EQUALS(lineOutsideTwoFromMultiAlign.width, lineOutsideTwoFromCenterAlign.width, TEST_LOCATION);
897 const LineRun& lineOutsideThreeFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
898 const LineRun& lineOutsideThreeFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_OUTSIDE_3);
899 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - text outside three");
900 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.alignmentOffset, lineOutsideThreeFromCenterAlign.alignmentOffset, TEST_LOCATION);
901 DALI_TEST_EQUALS(lineOutsideThreeFromMultiAlign.width, lineOutsideThreeFromCenterAlign.width, TEST_LOCATION);
903 const LineRun& lineParagraphFromMultiAlign = *(textLabelMultiAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
904 const LineRun& lineParagraphFromCenterAlign = *(textLabelCenterAlignImpl.GetTextController()->GetTextModel()->GetLines() + LINE_INDEX_PARAGRAPH);
905 tet_infoline(" UtcDaliTextLabelMarkupParagraphTagAlignAttribute - <p>Paragraph property alignment</p>");
906 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.alignmentOffset, lineParagraphFromCenterAlign.alignmentOffset, TEST_LOCATION);
907 DALI_TEST_EQUALS(lineParagraphFromMultiAlign.width, lineParagraphFromCenterAlign.width, TEST_LOCATION);