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-editor-impl.h>
25 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
27 #include <dali-toolkit/internal/text/text-controller.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<UnderlinedGlyphRun> underlineRuns;
98 underlineRuns.Resize(numberOfUnderlineRuns);
99 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
102 DALI_TEST_EQUALS(underlineRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
103 DALI_TEST_EQUALS(underlineRuns[1u].glyphRun.glyphIndex, 1u, TEST_LOCATION);
104 DALI_TEST_EQUALS(underlineRuns[2u].glyphRun.glyphIndex, 2u, TEST_LOCATION);
107 DALI_TEST_EQUALS(underlineRuns[3u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
108 DALI_TEST_EQUALS(underlineRuns[4u].glyphRun.glyphIndex, 6u, TEST_LOCATION);
113 int UtcDaliTextEditorMarkupUnderlineAttributes(void)
115 ToolkitTestApplication application;
116 tet_infoline(" UtcDaliTextEditorMarkupUnderlineAttributes ");
118 TextEditor textEditor = TextEditor::New();
120 application.GetScene().Add(textEditor);
122 std::string testText =
123 "start<u>ABC1</u>then"
124 "<u type='solid'>ABC2</u>then"
125 "<u type='dashed'>ABC3</u>then"
126 "<u type='double'>ABC4</u>then"
127 "<u color='green'>ABC5</u>then"
128 "<u height='5.0f'>ABC6</u>then"
129 "<u type='dashed' dash-gap='3.0f'>ABC7</u>then"
130 "<u type='dashed' dash-width='4.0f'>ABC8</u>then"
131 "<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>ABC9</u>end"
135 textEditor.SetProperty(TextEditor::Property::TEXT, testText);
136 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
138 application.SendNotification();
139 application.Render();
141 const uint32_t NUMBER_OF_CASES = 9u;
142 uint32_t expectedNumberOfUnderlinedGlyphs = 36u;
144 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
145 const Text::Length numberOfUnderlineRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfUnderlineRuns();
147 DALI_TEST_EQUALS(numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION);
149 Vector<UnderlinedGlyphRun> underlineRuns;
150 underlineRuns.Resize(numberOfUnderlineRuns);
151 textEditorImpl.GetTextController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
158 GlyphIndex startGlyphIndex;
159 GlyphIndex endGlyphIndex;
160 UnderlineStyleProperties properties;
171 Text::Underline::SOLID,
183 //<u type='solid'>ABC2</u>
184 {"<u type='solid'>ABC2</u>",
190 Text::Underline::SOLID,
202 //<u type='dashed'>ABC3</u>
203 {"<u type='dashed'>ABC3</u>",
209 Text::Underline::DASHED,
221 //<u type='double'>ABC4</u>
222 {"<u type='double'>ABC4</u>",
228 Text::Underline::DOUBLE,
240 //<u color='green'>ABC5</u>
241 {"<u color='green'>ABC5</u>",
247 Text::Underline::SOLID,
259 //<u height='5.0f'>ABC6</u>
260 {"<u height='5.0f'>ABC6</u>",
266 Text::Underline::SOLID,
278 //<u type='dashed' dash-gap='3.0f'>ABC7</u>
279 {"<u type='dashed' dash-gap='3.0f'>ABC7</u>",
285 Text::Underline::DASHED,
297 //<u type='dashed' dash-width='4.0f'>ABC8</u>
298 {"<u type='dashed' dash-width='4.0f'>ABC8</u>",
304 Text::Underline::DASHED,
316 //<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>
317 {"<u color='blue' type='dashed' height='4.0f' dash-gap='2.0f' dash-width='3.0f'>",
323 Text::Underline::DASHED,
337 for(uint32_t i = 0; i < NUMBER_OF_CASES; i++)
339 tet_infoline(data[i].title.c_str());
340 DALI_TEST_EQUALS(underlineRuns[data[i].startIndex].glyphRun.glyphIndex, data[i].startGlyphIndex, TEST_LOCATION);
341 DALI_TEST_EQUALS(underlineRuns[data[i].endIndex].glyphRun.glyphIndex, data[i].endGlyphIndex, TEST_LOCATION);
343 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].startIndex].properties);
344 DALI_TEST_CHECK(data[i].properties == underlineRuns[data[i].endIndex].properties);
350 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
352 ToolkitTestApplication application;
353 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
355 // Create a text editor
356 TextEditor textEditor = TextEditor::New();
357 //Set size to avoid automatic eliding
358 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
359 //Set very large font-size using point-size
360 textEditor.SetProperty(TextEditor::Property::POINT_SIZE, 1000);
361 //Specify font-family
362 textEditor.SetProperty(TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
363 //Set text to check if appear or not
364 textEditor.SetProperty(TextEditor::Property::TEXT, "A");
366 application.GetScene().Add(textEditor);
368 application.SendNotification();
369 application.Render();
371 //Check if Glyph is added to AtlasGlyphManger or not
372 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
373 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
378 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
380 ToolkitTestApplication application;
381 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
383 //Set Map of placeholder: text, font-family and point-size
384 Property::Map placeholderMapSet;
385 placeholderMapSet["text"] = "A";
386 placeholderMapSet["fontFamily"] = "DejaVu Sans";
387 placeholderMapSet["pixelSize"] = 1000.0f;
389 // Create a text editor
390 TextEditor textEditor = TextEditor::New();
391 //Set size to avoid automatic eliding
392 textEditor.SetProperty(Actor::Property::SIZE, Vector2(1025, 1025));
394 textEditor.SetProperty(TextEditor::Property::PLACEHOLDER, placeholderMapSet);
396 application.GetScene().Add(textEditor);
398 application.SendNotification();
399 application.Render();
401 //Check if Glyph is added to AtlasGlyphManger or not
402 int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
403 DALI_TEST_EQUALS(countAtlas, 1, TEST_LOCATION);
408 int UtcDaliTextEditorBackgroundTag(void)
410 ToolkitTestApplication application;
411 tet_infoline("UtcDaliTextEditorBackgroundTag\n");
413 TextEditor editor = TextEditor::New();
414 DALI_TEST_CHECK(editor);
416 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
417 editor.SetProperty(TextEditor::Property::TEXT, "H<background color='red'>e</background> Worl<background color='yellow'>d</background>");
418 application.GetScene().Add(editor);
419 application.SendNotification();
420 application.Render();
422 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
423 const ColorIndex* const backgroundColorIndicesBuffer = editorImpl.GetTextController()->GetTextModel()->GetBackgroundColorIndices();
425 DALI_TEST_CHECK(backgroundColorIndicesBuffer);
428 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[0], 0u, TEST_LOCATION);
431 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[1], 1u, TEST_LOCATION);
434 DALI_TEST_EQUALS(backgroundColorIndicesBuffer[7], 2u, TEST_LOCATION);
439 int UtcDaliTextEditorTextWithSpan(void)
441 ToolkitTestApplication application;
442 tet_infoline("UtcDaliTextEditorTextWithSpan\n");
444 TextEditor editor = TextEditor::New();
445 DALI_TEST_CHECK(editor);
447 editor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
448 editor.SetProperty(TextEditor::Property::TEXT, "Hello Span");
449 application.GetScene().Add(editor);
451 application.SendNotification();
452 application.Render();
454 Vector3 originalSize = editor.GetNaturalSize();
455 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");
457 application.SendNotification();
458 application.Render();
460 Vector3 spanSize = editor.GetNaturalSize();
462 DALI_TEST_GREATER(spanSize.width, originalSize.width, TEST_LOCATION);
464 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
465 const ColorIndex* const colorIndicesBuffer1 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
467 DALI_TEST_CHECK(colorIndicesBuffer1);
470 DALI_TEST_EQUALS(colorIndicesBuffer1[0], 0u, TEST_LOCATION);
473 DALI_TEST_EQUALS(colorIndicesBuffer1[1], 1u, TEST_LOCATION);
476 DALI_TEST_EQUALS(colorIndicesBuffer1[6], 0u, TEST_LOCATION);
478 editor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>ello <span text-color='red'>S</span>pan");
480 application.SendNotification();
481 application.Render();
483 const ColorIndex* const colorIndicesBuffer2 = editorImpl.GetTextController()->GetTextModel()->GetColorIndices();
485 DALI_TEST_CHECK(colorIndicesBuffer2);
488 DALI_TEST_EQUALS(colorIndicesBuffer2[0], 0u, TEST_LOCATION);
491 DALI_TEST_EQUALS(colorIndicesBuffer2[1], 0u, TEST_LOCATION);
494 DALI_TEST_EQUALS(colorIndicesBuffer2[6], 1u, TEST_LOCATION);
497 DALI_TEST_EQUALS(colorIndicesBuffer2[7], 0u, TEST_LOCATION);
502 int UtcDaliTextEditorControlBackgroundColor(void)
504 ToolkitTestApplication application;
505 tet_infoline(" UtcDaliTextEditorControlBackgroundColor\n");
507 TextEditor editor = TextEditor::New();
508 DALI_TEST_CHECK(editor);
510 Vector4 backgroundColor;
512 editor.SetProperty(TextEditor::Property::TEXT, "Background Color");
513 application.GetScene().Add(editor);
514 application.SendNotification();
515 application.Render();
517 Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
518 ControllerPtr controller = editorImpl.GetTextController();
519 Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
521 // Default color is transparent
522 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
523 DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
525 // Set background color to red
526 editor.SetBackgroundColor(Color::RED);
527 application.SendNotification();
528 application.Render();
531 controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
532 DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
537 int UtcDaliTextEditorTextPositionWithMinLineAndBigFont(void)
539 ToolkitTestApplication application;
540 tet_infoline(" UtcDaliTextEditorTextPositionWithMinLine ");
542 TextEditor textEditor = TextEditor::New();
544 textEditor.SetProperty(TextEditor::Property::TEXT, "<span font-size='45'>H</span>\ni");
545 textEditor.SetProperty(DevelTextEditor::Property::MIN_LINE_SIZE, 50);
546 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
548 application.GetScene().Add(textEditor);
550 application.SendNotification();
551 application.Render();
553 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
554 Text::ViewInterface& view = textEditorImpl.GetTextController()->GetView();
556 Length numberOfGlyphs = view.GetNumberOfGlyphs();
558 DALI_TEST_EQUALS(numberOfGlyphs, 3u, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
560 Vector<GlyphInfo> glyphs;
561 glyphs.Resize(numberOfGlyphs);
563 Vector<Vector2> positions;
564 positions.Resize(numberOfGlyphs);
566 float alignmentOffset = 0u;
567 numberOfGlyphs = view.GetGlyphs(glyphs.Begin(),
573 DALI_TEST_EQUALS(positions[2].y, 165.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
578 int UtcDaliTextEditorMarkupStrikethrough(void)
580 ToolkitTestApplication application;
581 tet_infoline(" UtcDaliTextEditorMarkupStrikethrough ");
583 TextEditor textEditor = TextEditor::New();
585 application.GetScene().Add(textEditor);
587 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC</s>EF<s color='red'>GH</s>");
588 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
590 application.SendNotification();
591 application.Render();
593 uint32_t expectedNumberOfStrikethroughGlyphs = 2u;
595 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
596 const Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
598 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);
600 Vector<StrikethroughGlyphRun> strikethroughRuns;
601 strikethroughRuns.Resize(numberOfStrikethroughRuns);
602 textEditorImpl.GetTextController()->GetTextModel()->GetStrikethroughRuns(strikethroughRuns.Begin(), 0u, numberOfStrikethroughRuns);
604 //ABC have strikethrough
605 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.glyphIndex, 0u, TEST_LOCATION);
606 DALI_TEST_EQUALS(strikethroughRuns[0u].glyphRun.numberOfGlyphs, 3u, TEST_LOCATION);
607 DALI_TEST_CHECK(!strikethroughRuns[0u].isColorSet);
609 //GH have strikethrough
610 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.glyphIndex, 5u, TEST_LOCATION);
611 DALI_TEST_EQUALS(strikethroughRuns[1u].glyphRun.numberOfGlyphs, 2u, TEST_LOCATION);
612 DALI_TEST_CHECK(strikethroughRuns[1u].isColorSet);
617 int UtcDaliTextEditorMarkupStrikethroughNoEndTag(void)
619 ToolkitTestApplication application;
620 tet_infoline(" UtcDaliTextEditorMarkupStrikethroughNoEndTag ");
622 TextEditor textEditor = TextEditor::New();
624 application.GetScene().Add(textEditor);
626 textEditor.SetProperty(TextEditor::Property::TEXT, "<s>ABC");
627 textEditor.SetProperty(TextEditor ::Property::ENABLE_MARKUP, true);
629 application.SendNotification();
630 application.Render();
632 uint32_t expectedNumberOfStrikethroughGlyphs = 0u;
634 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl(textEditor);
635 Text::Length numberOfStrikethroughRuns = textEditorImpl.GetTextController()->GetTextModel()->GetNumberOfStrikethroughRuns();
637 DALI_TEST_EQUALS(numberOfStrikethroughRuns, expectedNumberOfStrikethroughGlyphs, TEST_LOCATION);