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-editor-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 UtcDaliTextEditorSelectText(void)
35 ToolkitTestApplication application;
36 tet_infoline( "UtcDaliTextEditorSelectText" );
38 // Create a text editor
39 TextEditor textEditor = TextEditor::New();
40 textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
41 textEditor.SetProperty( TextEditor::Property::TEXT, "Hello World" );
43 // Add the text editor to the stage
44 application.GetScene().Add( textEditor );
46 application.SendNotification();
49 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
51 application.SendNotification();
54 // Highlight the whole text
55 textEditorImpl.SelectWholeText();
57 application.SendNotification();
60 std::string selectedText = textEditorImpl.GetSelectedText();
61 DALI_TEST_CHECK( selectedText == "Hello World" );
64 textEditorImpl.SelectNone();
66 application.SendNotification();
69 selectedText = textEditorImpl.GetSelectedText();
70 DALI_TEST_CHECK( selectedText == "" );
75 int UtcDaliTextEditorMarkupUnderline(void)
77 ToolkitTestApplication application;
78 tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
80 TextEditor textEditor = TextEditor::New();
82 application.GetScene().Add( textEditor );
84 textEditor.SetProperty( TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
85 textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true );
87 application.SendNotification();
90 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
92 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
93 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
95 DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
97 Vector<GlyphRun> underlineRuns;
98 underlineRuns.Resize(numberOfUnderlineRuns);
99 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
102 DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
103 DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
104 DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
107 DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
108 DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
113 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
115 ToolkitTestApplication application;
116 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
118 // Create a text editor
119 TextEditor textEditor = TextEditor::New();
120 //Set size to avoid automatic eliding
121 textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
122 //Set very large font-size using point-size
123 textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 1000);
124 //Specify font-family
125 textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
126 //Set text to check if appear or not
127 textEditor.SetProperty(TextEditor::Property::TEXT, "A");
129 application.GetScene().Add( textEditor );
131 application.SendNotification();
132 application.Render();
134 //Check if Glyph is added to AtlasGlyphManger or not
135 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
136 DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
142 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
144 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
147 //Set Map of placeholder: text, font-family and point-size
148 Property::Map placeholderMapSet;
149 placeholderMapSet["text"] = "A";
150 placeholderMapSet["fontFamily"] = "DejaVu Sans";
151 placeholderMapSet["pixelSize"] = 1000.0f;
153 // Create a text editor
154 TextEditor textEditor = TextEditor::New();
155 //Set size to avoid automatic eliding
156 textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
158 textEditor.SetProperty( TextEditor::Property::PLACEHOLDER, placeholderMapSet) ;
160 application.GetScene().Add( textEditor );
162 application.SendNotification();
163 application.Render();
165 //Check if Glyph is added to AtlasGlyphManger or not
166 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
167 DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
172 int UtcDaliTextEditorBackgroundTag(void)
174 ToolkitTestApplication application;
175 tet_infoline("UtcDaliTextEditorBackgroundTag\n");
177 TextEditor editor = TextEditor::New();
178 DALI_TEST_CHECK( editor );
180 editor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true );
181 editor.SetProperty( TextEditor::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>" );
182 application.GetScene().Add( editor );
183 application.SendNotification();
184 application.Render();
186 Toolkit::Internal::TextEditor& editorImpl = GetImpl( editor );
187 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
189 DALI_TEST_CHECK( backgroundColorIndicesBuffer );
192 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
195 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
198 DALI_TEST_EQUALS( backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
203 int UtcDaliTextEditorTextWithSpan(void)
205 ToolkitTestApplication application;
206 tet_infoline("UtcDaliTextEditorTextWithSpan\n");
208 TextEditor editor = TextEditor::New();
209 DALI_TEST_CHECK( editor );
211 editor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true );
212 editor.SetProperty( TextEditor::Property::TEXT, "Hello Span" );
213 application.GetScene().Add( editor );
215 application.SendNotification();
216 application.Render();
218 Vector3 originalSize = editor.GetNaturalSize();
219 editor.SetProperty( TextEditor::Property::TEXT, "H<span font-size='45' font-family='DejaVu Sans' font-width='condensed' font-slant='italic' text-color='red'>ello</span> Span" );
221 application.SendNotification();
222 application.Render();
224 Vector3 spanSize = editor.GetNaturalSize();
226 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
228 Toolkit::Internal::TextEditor& editorImpl = GetImpl( editor );
229 const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
231 DALI_TEST_CHECK( colorIndicesBuffer1 );
234 DALI_TEST_EQUALS( colorIndicesBuffer1[0], 0u, TEST_LOCATION);
237 DALI_TEST_EQUALS( colorIndicesBuffer1[1], 1u, TEST_LOCATION);
240 DALI_TEST_EQUALS( colorIndicesBuffer1[6], 0u, TEST_LOCATION);
243 editor.SetProperty( TextEditor::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan" );
245 application.SendNotification();
246 application.Render();
248 const ColorIndex* const colorIndicesBuffer2 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
250 DALI_TEST_CHECK( colorIndicesBuffer2 );
253 DALI_TEST_EQUALS( colorIndicesBuffer2[0], 0u, TEST_LOCATION);
256 DALI_TEST_EQUALS( colorIndicesBuffer2[1], 0u, TEST_LOCATION);
259 DALI_TEST_EQUALS( colorIndicesBuffer2[6], 1u, TEST_LOCATION);
262 DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);
267 int UtcDaliTextEditorControlBackgroundColor(void)
269 ToolkitTestApplication application;
270 tet_infoline(" UtcDaliTextEditorControlBackgroundColor\n");
272 TextEditor editor = TextEditor::New();
273 DALI_TEST_CHECK(editor);
275 Vector4 backgroundColor;
277 editor.SetProperty(TextEditor::Property::TEXT, "Background Color");
278 application.GetScene().Add(editor);
279 application.SendNotification();
280 application.Render();
282 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
283 ControllerPtr controller = editorImpl.GetTextController();
284 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
286 // Default color is transparent
287 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
288 DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
290 // Set background color to red
291 editor.SetBackgroundColor(Color::RED);
292 application.SendNotification();
293 application.Render();
296 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
297 DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);