2 * Copyright (c) 2021 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/text-controller.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 using namespace Toolkit;
32 int UtcDaliTextLabelMarkupUnderline(void)
34 ToolkitTestApplication application;
35 tet_infoline(" UtcDaliTextLabelMarkupUnderline ");
37 TextLabel textLabel = TextLabel::New();
39 application.GetScene().Add( textLabel );
41 textLabel.SetProperty( TextLabel::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
42 textLabel.SetProperty( TextLabel ::Property::ENABLE_MARKUP, true );
44 application.SendNotification();
47 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
49 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl( textLabel );
50 const Text::Length numberOfUnderlineRuns = textLabelImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
52 DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
54 Vector<GlyphRun> underlineRuns;
55 underlineRuns.Resize(numberOfUnderlineRuns);
56 textLabelImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
59 DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
60 DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
61 DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
64 DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
65 DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
71 int UtcDaliTextLabelBackgroundTag(void)
73 ToolkitTestApplication application;
74 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
76 TextLabel label = TextLabel::New();
77 DALI_TEST_CHECK( label );
79 label.SetProperty( TextLabel ::Property::ENABLE_MARKUP, true );
80 label.SetProperty( TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>" );
81 application.GetScene().Add( label );
82 application.SendNotification();
85 Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
86 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.getController()->GetTextModel()->GetBackgroundColorIndices();
88 DALI_TEST_CHECK( backgroundColorIndicesBuffer );
91 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
94 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
97 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
102 int UtcDaliTextLabelTextWithSpan(void)
104 ToolkitTestApplication application;
105 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
107 TextLabel label = TextLabel::New();
108 DALI_TEST_CHECK( label );
110 label.SetProperty( TextLabel ::Property::ENABLE_MARKUP, true );
111 label.SetProperty( TextLabel::Property::TEXT, "Hello Span" );
112 application.GetScene().Add( label );
114 application.SendNotification();
115 application.Render();
117 Vector3 originalSize = label.GetNaturalSize();
118 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" );
120 application.SendNotification();
121 application.Render();
123 Vector3 spanSize = label.GetNaturalSize();
125 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
127 Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
128 const ColorIndex* const colorIndicesBuffer1 = labelImpl.getController()->GetTextModel()->GetColorIndices();
130 DALI_TEST_CHECK( colorIndicesBuffer1 );
133 DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION);
136 DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION);
139 DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION);
142 label.SetProperty( TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan" );
144 application.SendNotification();
145 application.Render();
147 const ColorIndex* const colorIndicesBuffer2 = labelImpl.getController()->GetTextModel()->GetColorIndices();
149 DALI_TEST_CHECK( colorIndicesBuffer2 );
152 DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION);
155 DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION);
158 DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION);
161 DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);