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/text/rendering/atlas/atlas-glyph-manager.h>
25 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
26 #include <dali-toolkit/internal/text/text-controller.h>
27 #include <dali-toolkit/internal/text/text-controller-impl.h>
30 using namespace Toolkit;
33 int UtcDaliTextFieldMultipleBackgroundText(void)
35 ToolkitTestApplication application;
36 tet_infoline( "UtcDaliTextFieldMultipleBackgroundText" );
38 // Create a text field
39 TextField textField = TextField::New();
40 textField.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
41 textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
42 textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
44 // Add the text field to the stage
45 application.GetScene().Add( textField );
47 application.SendNotification();
50 Toolkit::Internal::TextField& textFieldImpl = GetImpl( textField );
51 ControllerPtr controller = textFieldImpl.GetTextController();
52 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation( *controller.Get() );
54 // Add multiple background colors for the text.
55 ColorRun backgroundColorRun1;
56 backgroundColorRun1.characterRun.characterIndex = 0u;
57 backgroundColorRun1.characterRun.numberOfCharacters = 1u;
58 backgroundColorRun1.color = Color::RED;
59 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun1 );
61 ColorRun backgroundColorRun2;
62 backgroundColorRun2.characterRun.characterIndex = 5u;
63 backgroundColorRun2.characterRun.numberOfCharacters = 8u;
64 backgroundColorRun2.color = Color::CYAN;
65 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun2 );
67 ColorRun backgroundColorRun3;
68 backgroundColorRun3.characterRun.characterIndex = 23u;
69 backgroundColorRun3.characterRun.numberOfCharacters = 6u;
70 backgroundColorRun3.color = Color::GREEN;
71 controllerImpl.mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun3 );
73 // Check the case where there is only one character in the text
74 controller->SetText( "S" );
76 application.SendNotification();
79 // The offscreen root actor should have one child: the renderable.
80 Actor stencil = textField.GetChildAt( 0u );
81 DALI_TEST_CHECK( stencil.GetChildCount() == 1u );
83 // The renderable actor should have two children: the text and the background.
84 Actor renderableActor = stencil.GetChildAt( 0u );
85 DALI_TEST_CHECK( renderableActor.GetChildCount() == 2u );
87 // Check that the background is created
88 Actor backgroundActor = renderableActor.GetChildAt( 0u );
89 DALI_TEST_CHECK( backgroundActor );
90 DALI_TEST_CHECK( backgroundActor.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "TextBackgroundColorActor" );
92 // Change the text to contain more characters
93 controller->SetText( "Text Multiple Background Test" );
95 application.SendNotification();
98 // Highlight the whole text
99 textFieldImpl.SelectWholeText();
101 application.SendNotification();
102 application.Render();
104 // Now the offscreen root actor should have three children: the renderable, the highlight, and the background.
105 DALI_TEST_CHECK( stencil.GetChildCount() == 3u );
106 // The renderable actor should have one child only: the text
107 DALI_TEST_CHECK( renderableActor.GetChildCount() == 1u );
109 // The background should now be lowered below the highlight
110 backgroundActor = stencil.GetChildAt( 0u );
111 DALI_TEST_CHECK( backgroundActor );
112 DALI_TEST_CHECK( backgroundActor.GetProperty< std::string >( Dali::Actor::Property::NAME ) == "TextBackgroundColorActor" );
117 int UtcDaliTextFieldSelectText(void)
119 ToolkitTestApplication application;
120 tet_infoline( "UtcDaliTextFieldSelectText" );
122 // Create a text field
123 TextField textField = TextField::New();
124 textField.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
125 textField.SetProperty( TextField::Property::TEXT, "Hello World" );
127 // Add the text field to the stage
128 application.GetScene().Add( textField );
130 application.SendNotification();
131 application.Render();
133 Toolkit::Internal::TextField& textFieldImpl = GetImpl( textField );
135 application.SendNotification();
136 application.Render();
138 // Highlight the whole text
139 textFieldImpl.SelectWholeText();
141 application.SendNotification();
142 application.Render();
144 DALI_TEST_CHECK( textFieldImpl.GetSelectedText() == "Hello World" );
147 textFieldImpl.SelectNone();
149 application.SendNotification();
150 application.Render();
152 DALI_TEST_CHECK( textFieldImpl.GetSelectedText() == "" );
157 int UtcDaliTextFieldMarkupUnderline(void)
159 ToolkitTestApplication application;
160 tet_infoline(" UtcDaliTextFieldMarkupUnderline ");
162 TextField textField = TextField::New();
164 application.GetScene().Add( textField );
166 textField.SetProperty( TextField::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
167 textField.SetProperty( TextField ::Property::ENABLE_MARKUP, true );
169 application.SendNotification();
170 application.Render();
172 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
174 Toolkit::Internal::TextField& textFieldImpl = GetImpl( textField );
175 const Text::Length numberOfUnderlineRuns = textFieldImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
177 DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
179 Vector<GlyphRun> underlineRuns;
180 underlineRuns.Resize(numberOfUnderlineRuns);
181 textFieldImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
184 DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
185 DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
186 DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
189 DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
190 DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
196 int UtcDaliTextFieldFontPointSizeLargerThanAtlas(void)
198 ToolkitTestApplication application;
199 tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlas ");
201 // Create a Text field
202 TextField textField = TextField::New();
203 //Set size to avoid automatic eliding
204 textField.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
205 //Set very large font-size using point-size
206 textField.SetProperty( TextField::Property::POINT_SIZE, 1000) ;
207 //Specify font-family
208 textField.SetProperty( TextField::Property::FONT_FAMILY, "DejaVu Sans");
209 //Set text to check if appear or not
210 textField.SetProperty( TextField::Property::TEXT, "A");
212 application.GetScene().Add( textField );
214 application.SendNotification();
215 application.Render();
217 //Check if Glyph is added to AtlasGlyphManger or not
218 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
219 DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
225 int UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase(void)
227 ToolkitTestApplication application;
228 tet_infoline(" UtcDaliTextFieldFontPointSizeLargerThanAtlasPlaceholderCase ");
230 //Set Map of placeholder: text, font-family and point-size
231 Property::Map placeholderMapSet;
232 placeholderMapSet["text"] = "A";
233 placeholderMapSet["fontFamily"] = "DejaVu Sans";
234 placeholderMapSet["pixelSize"] = 1000.0f;
236 // Create a text editor
237 TextField textField = TextField::New();
238 //Set size to avoid automatic eliding
239 textField.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
241 textField.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet) ;
243 application.GetScene().Add( textField );
245 application.SendNotification();
246 application.Render();
248 //Check if Glyph is added to AtlasGlyphManger or not
249 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
250 DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
256 int UtcDaliTextFieldBackgroundTag(void)
258 ToolkitTestApplication application;
259 tet_infoline("UtcDaliTextFieldBackgroundTag\n");
261 TextField field = TextField::New();
262 DALI_TEST_CHECK( field );
264 field.SetProperty( TextField ::Property::ENABLE_MARKUP, true );
265 field.SetProperty( TextField::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>" );
266 application.GetScene().Add( field );
267 application.SendNotification();
268 application.Render();
270 Toolkit::Internal::TextField& fieldImpl = GetImpl( field );
271 const ColorIndex* const backgroundColorIndicesBuffer = fieldImpl.getController()->GetTextModel()->GetBackgroundColorIndices();
273 DALI_TEST_CHECK( backgroundColorIndicesBuffer );
276 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
279 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
282 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
287 int UtcDaliTextFieldTextWithSpan(void)
289 ToolkitTestApplication application;
290 tet_infoline("UtcDaliTextFieldTextWithSpan\n");
292 TextField field = TextField::New();
293 DALI_TEST_CHECK( field );
295 field.SetProperty( TextField ::Property::ENABLE_MARKUP, true );
296 field.SetProperty( TextField::Property::TEXT, "Hello Span" );
297 application.GetScene().Add( field );
299 application.SendNotification();
300 application.Render();
302 Vector3 originalSize = field.GetNaturalSize();
303 field.SetProperty( TextField::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span" );
305 application.SendNotification();
306 application.Render();
308 Vector3 spanSize = field.GetNaturalSize();
310 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
312 Toolkit::Internal::TextField& fieldImpl = GetImpl( field );
313 const ColorIndex* const colorIndicesBuffer1 = fieldImpl.getController()->GetTextModel()->GetColorIndices();
315 DALI_TEST_CHECK( colorIndicesBuffer1 );
318 DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION);
321 DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION);
324 DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION);
327 field.SetProperty( TextField::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan" );
329 application.SendNotification();
330 application.Render();
332 const ColorIndex* const colorIndicesBuffer2 = fieldImpl.getController()->GetTextModel()->GetColorIndices();
334 DALI_TEST_CHECK( colorIndicesBuffer2 );
337 DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION);
340 DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION);
343 DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION);
346 DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);