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>
27 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
28 #include <dali-toolkit/internal/text/rendering/view-model.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);
73 int UtcDaliTextLabelBackgroundTag(void)
75 ToolkitTestApplication application;
76 tet_infoline("UtcDaliTextLabelBackgroundTag\n");
78 TextLabel label = TextLabel::New();
79 DALI_TEST_CHECK( label );
81 label.SetProperty( TextLabel ::Property::ENABLE_MARKUP, true );
82 label.SetProperty( TextLabel::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>" );
83 application.GetScene().Add( label );
84 application.SendNotification();
87 Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
88 const ColorIndex* const backgroundColorIndicesBuffer = labelImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
90 DALI_TEST_CHECK( backgroundColorIndicesBuffer );
93 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
96 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
99 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
104 int UtcDaliToolkitTextlabelEllipsisInternalAPIs(void)
106 ToolkitTestApplication application;
107 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs ");
108 TextLabel textLabel = TextLabel::New();
110 Toolkit::Internal::TextLabel& textLabelImpl = GetImpl( textLabel );
111 const ModelInterface* const textModel = textLabelImpl.GetTextController()->GetTextModel();
114 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Disabled");
115 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, false);
116 DALI_TEST_EQUALS( textLabel.GetProperty< bool >( DevelTextLabel::Property::ELLIPSIS ), false, TEST_LOCATION );
117 DALI_TEST_CHECK(!(textModel->IsTextElideEnabled()));
119 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - ELLIPSIS Enabled");
120 textLabel.SetProperty(DevelTextLabel::Property::ELLIPSIS, true);
121 DALI_TEST_EQUALS( textLabel.GetProperty< bool >( DevelTextLabel::Property::ELLIPSIS ), true, TEST_LOCATION );
122 DALI_TEST_CHECK(textModel->IsTextElideEnabled());
124 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs Default");
125 DALI_TEST_EQUALS( textModel->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
127 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs Default");
128 DALI_TEST_EQUALS( textModel->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
130 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs Default");
131 DALI_TEST_EQUALS( textModel->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
133 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs Default");
134 DALI_TEST_EQUALS( textModel->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
136 // Tests the rendering controller has been created.
137 TypesetterPtr typesetter = Typesetter::New( textModel );
138 DALI_TEST_CHECK(typesetter);
140 // Tests the view model has been created.
141 ViewModel* model = typesetter->GetViewModel();
143 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - IsTextElideEnabled ViewModel");
144 DALI_TEST_CHECK(model->IsTextElideEnabled());
146 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetStartIndexOfElidedGlyphs ViewModel");
147 DALI_TEST_EQUALS( model->GetStartIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
149 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetEndIndexOfElidedGlyphs ViewModel");
150 DALI_TEST_EQUALS( model->GetEndIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
152 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetFirstMiddleIndexOfElidedGlyphs ViewModel");
153 DALI_TEST_EQUALS( model->GetFirstMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
155 tet_infoline(" UtcDaliToolkitTextlabelEllipsisInternalAPIs - GetSecondMiddleIndexOfElidedGlyphs ViewModel");
156 DALI_TEST_EQUALS( model->GetSecondMiddleIndexOfElidedGlyphs(), 0u, TEST_LOCATION );
160 int UtcDaliTextLabelTextWithSpan(void)
162 ToolkitTestApplication application;
163 tet_infoline("UtcDaliTextLabelTextWithSpan\n");
165 TextLabel label = TextLabel::New();
166 DALI_TEST_CHECK( label );
168 label.SetProperty( TextLabel ::Property::ENABLE_MARKUP, true );
169 label.SetProperty( TextLabel::Property::TEXT, "Hello Span" );
170 application.GetScene().Add( label );
172 application.SendNotification();
173 application.Render();
175 Vector3 originalSize = label.GetNaturalSize();
176 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" );
178 application.SendNotification();
179 application.Render();
181 Vector3 spanSize = label.GetNaturalSize();
183 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
185 Toolkit::Internal::TextLabel& labelImpl = GetImpl( label );
186 const ColorIndex* const colorIndicesBuffer1 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
188 DALI_TEST_CHECK( colorIndicesBuffer1 );
191 DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION);
194 DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION);
197 DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION);
200 label.SetProperty( TextLabel::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan" );
202 application.SendNotification();
203 application.Render();
205 const ColorIndex* const colorIndicesBuffer2 = labelImpl.GetTextController()->GetTextModel()->GetColorIndices();
207 DALI_TEST_CHECK( colorIndicesBuffer2 );
210 DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION);
213 DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION);
216 DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION);
219 DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);