2 * Copyright (c) 2023 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.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/text/spannable-string.h>
25 #include <dali-toolkit/internal/text/controller/text-controller.h>
26 #include <dali-toolkit/internal/text/font-description-run.h>
27 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
28 #include <dali-toolkit/internal/text/rendering/view-model.h>
29 #include <toolkit-text-utils.h>
32 using namespace Toolkit;
37 const std::string DEFAULT_FONT_DIR("/resources/fonts");
39 const Size CONTROL_SIZE(200.f, 400.f);
40 const Size CONTROL_SMALL_SIZE(50.f, 100.f);
41 const char* LOREM_IPSUM =
42 "Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.\n"
43 "Usu ne nisl maiorum iudicabit, veniam epicurei oporteat eos an.\n"
44 "Ne nec nulla regione albucius, mea doctus delenit ad!\n"
45 "Et everti blandit adversarium mei, eam porro neglegentur suscipiantur an.\n"
46 "Quidam corpora at duo. An eos possim scripserit?\n\n"
47 "Aťqui dicant sěnťenťíae aň vel!\n"
48 "Vis viris médiocrem elaboraret ét, verear civibus moderatius ex duo!\n"
49 "Án veri laborě iňtěgré quó, mei aď poššit lobortis, mei prompťa čonsťitůťó eů.\n"
50 "Aliquip sanctůs delicáta quí ěá, et natum aliquam est?\n"
51 "Asšúm sapěret usu ůť.\n"
52 "Síť ut apeirián laboramúš percipitur, sůas hařum ín éos?\n";
53 const Vector2 LOREM_SCROLL_POSITION(0.f, -265.f);
54 const Length LOREM_NUMBER_OF_LINES = 35u;
55 const Length LOREM_NUMBER_OF_LINES_ELIDED = 21u;
56 const Length LOREM_NUMBER_OF_GLYPHS = 632u;
57 const Length LOREM_NUMBER_OF_GLYPHS_ELIDED = 393u;
58 const Length LOREM_NUMBER_OF_CHARACTERS = 633u;
59 const Length LOREM_NUMBER_OF_CHARACTERS_ELIDED = 633u;
61 // The expected layout size for UtcDaliTextViewModelGetLayoutSize
62 const Size LAYOUT_SIZE(182.f, 48.f);
64 // The expected color indices for UtcDaliTextViewModelGetColors
65 const ColorIndex COLOR_INDICES[] = {0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 2u, 2u, 2u, 2u, 2u, 1u, 1u, 1u, 1u, 1u, 3u, 1u, 1u, 1u, 0u, 0u, 0u, 0u};
66 const Length NUMBER_OF_COLORS = 3u;
67 const Vector4 COLORS[] = {Color::RED, Color::BLUE, Color::GREEN};
71 std::string description;
74 unsigned int numberOfLines;
75 unsigned int numberOfGlyphs;
79 bool ElideTest(const ElideData& data)
81 std::cout << " testing : " << data.description << std::endl;
84 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
85 fontClient.SetDpi(93u, 93u);
87 char* pathNamePtr = get_current_dir_name();
88 const std::string pathName(pathNamePtr);
91 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
92 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf");
93 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf");
95 // Creates a text controller.
96 ControllerPtr controller = Controller::New();
98 // Tests the rendering controller has been created.
99 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
100 DALI_TEST_CHECK(typesetter);
102 // Tests the view model has been created.
103 ViewModel* model = typesetter->GetViewModel();
104 DALI_TEST_CHECK(NULL != model);
106 // Configures the text controller similarly to the text-label.
107 ConfigureTextLabel(controller);
109 // Sets a text and relais-out.
110 controller->SetMarkupProcessorEnabled(true);
112 controller->SetText(data.text);
113 controller->Relayout(data.size);
116 model->ElideGlyphs();
118 if(data.numberOfLines != model->GetNumberOfLines())
120 std::cout << " different number of lines : " << model->GetNumberOfLines() << ", expected : " << data.numberOfLines << std::endl;
124 if(data.numberOfGlyphs != model->GetNumberOfGlyphs())
126 std::cout << " different number of glyphs : " << model->GetNumberOfGlyphs() << ", expected : " << data.numberOfGlyphs << std::endl;
130 const Vector2* const layoutBuffer = model->GetLayout();
131 const Length numberOfLines = model->GetNumberOfLines();
133 if(numberOfLines != 0u)
135 const LineRun& lastLine = *(model->GetLines() + numberOfLines - 1u);
136 const Length numberOfLastLineGlyphs = data.numberOfGlyphs - lastLine.glyphRun.glyphIndex;
138 std::cout << " last line alignment offset : " << floor(lastLine.alignmentOffset) << std::endl;
140 for(unsigned int index = 0u; index < numberOfLastLineGlyphs; ++index)
142 if(*(data.positions + index) != floor(lastLine.alignmentOffset + (*(layoutBuffer + lastLine.glyphRun.glyphIndex + index)).x))
144 std::cout << " different layout :";
145 for(unsigned int i = 0; i < numberOfLastLineGlyphs; ++i)
147 std::cout << " " << floor(lastLine.alignmentOffset + (*(layoutBuffer + lastLine.glyphRun.glyphIndex + i)).x);
149 std::cout << std::endl;
150 std::cout << " expected :";
151 for(unsigned int i = 0; i < numberOfLastLineGlyphs; ++i)
153 std::cout << " " << *(data.positions + i);
155 std::cout << std::endl;
166 int UtcDaliTextViewModel(void)
168 tet_infoline(" UtcDaliTextViewModel");
169 ToolkitTestApplication application;
171 // Creates a text controller.
172 ControllerPtr controller = Controller::New();
174 // Tests the rendering controller has been created.
175 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
176 DALI_TEST_CHECK(typesetter);
178 // Tests the view model has been created.
179 ViewModel* model = typesetter->GetViewModel();
180 DALI_TEST_CHECK(NULL != model);
182 tet_result(TET_PASS);
186 int UtcDaliTextViewModelGetControlSize(void)
188 tet_infoline(" UtcDaliTextViewModelGetControlSize");
189 ToolkitTestApplication application;
191 // Creates a text controller.
192 ControllerPtr controller = Controller::New();
194 // Tests the rendering controller has been created.
195 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
196 DALI_TEST_CHECK(typesetter);
198 // Tests the view model has been created.
199 ViewModel* model = typesetter->GetViewModel();
200 DALI_TEST_CHECK(NULL != model);
202 // Configures the text controller similarly to the text-editor.
203 ConfigureTextEditor(controller);
205 // The text has not been laid-out. The stored control's size should be zero.
206 DALI_TEST_EQUALS(Size::ZERO, model->GetControlSize(), TEST_LOCATION);
208 // Sets a text and relais-out.
209 controller->SetText("Hello world");
210 controller->Relayout(CONTROL_SIZE);
212 // The control's size should be stored now.
213 DALI_TEST_EQUALS(CONTROL_SIZE, model->GetControlSize(), TEST_LOCATION);
215 tet_result(TET_PASS);
219 int UtcDaliTextViewModelGetLayoutSize(void)
221 tet_infoline(" UtcDaliTextViewModelGetLayoutSize");
222 ToolkitTestApplication application;
225 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
226 fontClient.SetDpi(93u, 93u);
228 char* pathNamePtr = get_current_dir_name();
229 const std::string pathName(pathNamePtr);
232 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
234 // Creates a text controller.
235 ControllerPtr controller = Controller::New();
237 // Tests the rendering controller has been created.
238 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
239 DALI_TEST_CHECK(typesetter);
241 // Tests the view model has been created.
242 ViewModel* model = typesetter->GetViewModel();
243 DALI_TEST_CHECK(NULL != model);
245 // Configures the text controller similarly to the text-editor.
246 ConfigureTextEditor(controller);
248 // The text has not been laid-out. The stored control's size should be zero.
249 DALI_TEST_EQUALS(Size::ZERO, model->GetLayoutSize(), TEST_LOCATION);
251 // Sets a text and relais-out.
252 controller->SetMarkupProcessorEnabled(true);
253 controller->SetText("<font family='TizenSansRegular' size='10'>Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.</font>");
254 controller->Relayout(CONTROL_SIZE);
256 // The control's size should be stored now.
257 DALI_TEST_EQUALS(LAYOUT_SIZE, model->GetLayoutSize(), TEST_LOCATION);
259 tet_result(TET_PASS);
263 int UtcDaliTextViewModelGetScrollPosition(void)
265 tet_infoline(" UtcDaliTextViewModelGetScrollPosition");
266 ToolkitTestApplication application;
268 // Creates a text controller.
269 ControllerPtr controller = Controller::New();
271 // Tests the rendering controller has been created.
272 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
273 DALI_TEST_CHECK(typesetter);
275 // Tests the view model has been created.
276 ViewModel* model = typesetter->GetViewModel();
277 DALI_TEST_CHECK(NULL != model);
279 // Configures the text controller similarly to the text-editor.
280 ConfigureTextEditor(controller);
282 // No text has been set. The scroll position should be zero.
283 DALI_TEST_EQUALS(Vector2::ZERO, model->GetScrollPosition(), TEST_LOCATION);
285 // Gains the keyboard focus, sets a big text and relais-out.
286 controller->KeyboardFocusGainEvent();
287 controller->SetText(LOREM_IPSUM);
288 controller->Relayout(CONTROL_SIZE);
290 // The text should be scrolled to the end.
291 DALI_TEST_EQUALS(LOREM_SCROLL_POSITION, model->GetScrollPosition(), TEST_LOCATION);
293 tet_result(TET_PASS);
297 int UtcDaliTextViewModelGetAlignment(void)
299 tet_infoline(" UtcDaliTextViewModelGetAlignment");
300 ToolkitTestApplication application;
302 // Creates a text controller.
303 ControllerPtr controller = Controller::New();
305 // Tests the rendering controller has been created.
306 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
307 DALI_TEST_CHECK(typesetter);
309 // Tests the view model has been created.
310 ViewModel* model = typesetter->GetViewModel();
311 DALI_TEST_CHECK(NULL != model);
313 DALI_TEST_EQUALS(Text::HorizontalAlignment::BEGIN, model->GetHorizontalAlignment(), TEST_LOCATION);
314 DALI_TEST_EQUALS(Text::VerticalAlignment::TOP, model->GetVerticalAlignment(), TEST_LOCATION);
316 controller->SetHorizontalAlignment(Text::HorizontalAlignment::CENTER);
317 controller->SetVerticalAlignment(Text::VerticalAlignment::CENTER);
319 DALI_TEST_EQUALS(Text::HorizontalAlignment::CENTER, model->GetHorizontalAlignment(), TEST_LOCATION);
320 DALI_TEST_EQUALS(Text::VerticalAlignment::CENTER, model->GetVerticalAlignment(), TEST_LOCATION);
322 tet_result(TET_PASS);
326 int UtcDaliTextViewModelIsTextElideEnabled(void)
328 tet_infoline(" UtcDaliTextViewModelIsTextElideEnabled");
329 ToolkitTestApplication application;
331 // Creates a text controller.
332 ControllerPtr controller = Controller::New();
334 // Tests the rendering controller has been created.
335 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
336 DALI_TEST_CHECK(typesetter);
338 // Tests the view model has been created.
339 ViewModel* model = typesetter->GetViewModel();
340 DALI_TEST_CHECK(NULL != model);
342 // Configures the text controller similarly to the text-editor.
343 ConfigureTextEditor(controller);
345 // Elide text should be disabled.
346 DALI_TEST_CHECK(!model->IsTextElideEnabled());
348 // Configures the text controller similarly to the text-label.
349 ConfigureTextLabel(controller);
351 // Elide text should be enabled.
352 DALI_TEST_CHECK(model->IsTextElideEnabled());
354 tet_result(TET_PASS);
358 int UtcDaliTextViewModelGetCharacters(void)
360 tet_infoline(" UtcDaliTextViewModelGetLines");
361 ToolkitTestApplication application;
363 // Creates a text controller.
364 ControllerPtr controller = Controller::New();
366 // Tests the rendering controller has been created.
367 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
368 DALI_TEST_CHECK(typesetter);
370 // Tests the view model has been created.
371 ViewModel* model = typesetter->GetViewModel();
372 DALI_TEST_CHECK(NULL != model);
374 // Configures the text controller similarly to the text-editor.
375 ConfigureTextEditor(controller);
377 // The number of characters should be zero.
378 DALI_TEST_EQUALS(0u, model->GetNumberOfCharacters(), TEST_LOCATION);
380 // Sets a text and relais-out.
381 controller->SetText(LOREM_IPSUM);
382 controller->Relayout(CONTROL_SIZE);
384 DALI_TEST_EQUALS(LOREM_NUMBER_OF_CHARACTERS, model->GetNumberOfCharacters(), TEST_LOCATION);
385 // Configures the text controller similarly to the text-label.
386 ConfigureTextLabel(controller);
388 // Relais-out for the text-label configuration.
389 controller->Relayout(Size(100.f, 100.f)); // Change the size to force a relayout.
390 controller->Relayout(CONTROL_SIZE);
392 DALI_TEST_EQUALS(LOREM_NUMBER_OF_CHARACTERS_ELIDED, model->GetNumberOfCharacters(), TEST_LOCATION);
394 tet_result(TET_PASS);
398 int UtcDaliTextViewModelGetLines(void)
400 tet_infoline(" UtcDaliTextViewModelGetLines");
401 ToolkitTestApplication application;
403 // Creates a text controller.
404 ControllerPtr controller = Controller::New();
406 // Tests the rendering controller has been created.
407 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
408 DALI_TEST_CHECK(typesetter);
410 // Tests the view model has been created.
411 ViewModel* model = typesetter->GetViewModel();
412 DALI_TEST_CHECK(NULL != model);
414 // Configures the text controller similarly to the text-editor.
415 ConfigureTextEditor(controller);
417 // The number of lines should be zero.
418 DALI_TEST_EQUALS(0u, model->GetNumberOfLines(), TEST_LOCATION);
419 DALI_TEST_CHECK(NULL == model->GetLines());
421 // Sets a text and relais-out.
422 controller->SetText(LOREM_IPSUM);
423 controller->Relayout(CONTROL_SIZE);
425 DALI_TEST_EQUALS(LOREM_NUMBER_OF_LINES, model->GetNumberOfLines(), TEST_LOCATION);
426 DALI_TEST_CHECK(NULL != model->GetLines());
428 // Configures the text controller similarly to the text-label.
429 ConfigureTextLabel(controller);
431 // Relais-out for the text-label configuration.
432 controller->Relayout(Size(100.f, 100.f)); // Change the size to force a relayout.
433 controller->Relayout(CONTROL_SIZE);
435 DALI_TEST_EQUALS(LOREM_NUMBER_OF_LINES_ELIDED, model->GetNumberOfLines(), TEST_LOCATION);
436 DALI_TEST_CHECK(NULL != model->GetLines());
438 tet_result(TET_PASS);
442 int UtcDaliTextViewModelGetGlyphsLayout(void)
444 tet_infoline(" UtcDaliTextViewModelGetGlyphsLayout");
445 ToolkitTestApplication application;
447 // Creates a text controller.
448 ControllerPtr controller = Controller::New();
450 // Tests the rendering controller has been created.
451 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
452 DALI_TEST_CHECK(typesetter);
454 // Tests the view model has been created.
455 ViewModel* model = typesetter->GetViewModel();
456 DALI_TEST_CHECK(NULL != model);
458 // Configures the text controller similarly to the text-editor.
459 ConfigureTextEditor(controller);
461 // The number of glyphs should be zero.
462 DALI_TEST_EQUALS(0u, model->GetNumberOfGlyphs(), TEST_LOCATION);
463 DALI_TEST_CHECK(NULL == model->GetGlyphs());
464 DALI_TEST_CHECK(NULL == model->GetLayout());
466 // Sets a text and relais-out.
467 controller->SetText(LOREM_IPSUM);
468 controller->Relayout(CONTROL_SIZE);
470 DALI_TEST_EQUALS(LOREM_NUMBER_OF_GLYPHS, model->GetNumberOfGlyphs(), TEST_LOCATION);
471 DALI_TEST_CHECK(NULL != model->GetGlyphs());
472 DALI_TEST_CHECK(NULL != model->GetLayout());
474 // Configures the text controller similarly to the text-label.
475 ConfigureTextLabel(controller);
477 // Relais-out for the text-label configuration.
478 controller->Relayout(Size(100.f, 100.f)); // Change the size to force a relayout.
479 controller->Relayout(CONTROL_SIZE);
482 model->ElideGlyphs();
484 DALI_TEST_EQUALS(LOREM_NUMBER_OF_GLYPHS_ELIDED, model->GetNumberOfGlyphs(), TEST_LOCATION);
485 DALI_TEST_CHECK(NULL != model->GetGlyphs());
486 DALI_TEST_CHECK(NULL != model->GetLayout());
488 tet_result(TET_PASS);
492 int UtcDaliTextViewModelGetColors(void)
494 tet_infoline(" UtcDaliTextViewModelGetColors");
495 ToolkitTestApplication application;
497 // Creates a text controller.
498 ControllerPtr controller = Controller::New();
500 // Tests the rendering controller has been created.
501 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
502 DALI_TEST_CHECK(typesetter);
504 // Tests the view model has been created.
505 ViewModel* model = typesetter->GetViewModel();
506 DALI_TEST_CHECK(NULL != model);
508 // Configures the text controller similarly to the text-label.
509 ConfigureTextLabel(controller);
511 // Sets a text and relais-out.
512 controller->SetMarkupProcessorEnabled(true);
513 controller->SetText("Lorem <color value='red'>ips<color value='blue'>um do</color>lor s<color value='green'>i</color>t a</color>met.");
514 controller->Relayout(CONTROL_SIZE);
516 DALI_TEST_EQUALS(Color::BLACK, model->GetDefaultColor(), TEST_LOCATION);
518 const ColorIndex* const colorIndicesBuffer = model->GetColorIndices();
520 const Length numberOfGlyphs = model->GetNumberOfGlyphs();
521 for(ColorIndex index = 0u; index < numberOfGlyphs; ++index)
523 DALI_TEST_EQUALS(COLOR_INDICES[index], *(colorIndicesBuffer + index), TEST_LOCATION);
526 const Vector4* const colors = model->GetColors();
527 for(unsigned int index = 0u; index < NUMBER_OF_COLORS; ++index)
529 DALI_TEST_EQUALS(COLORS[index], *(colors + index), TEST_LOCATION);
532 tet_result(TET_PASS);
536 int UtcDaliTextViewModelElideText01(void)
538 tet_infoline(" UtcDaliTextViewModelElideText01");
539 ToolkitTestApplication application;
541 // Creates a text controller.
542 ControllerPtr controller = Controller::New();
544 // Tests the rendering controller has been created.
545 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
546 DALI_TEST_CHECK(typesetter);
548 // Tests the view model has been created.
549 ViewModel* model = typesetter->GetViewModel();
550 DALI_TEST_CHECK(NULL != model);
552 // Configures the text controller similarly to the text-editor.
553 ConfigureTextEditor(controller);
555 // The number of glyphs should be zero.
556 DALI_TEST_EQUALS(0u, model->GetNumberOfGlyphs(), TEST_LOCATION);
557 DALI_TEST_EQUALS(0u, model->GetNumberOfLines(), TEST_LOCATION);
558 DALI_TEST_CHECK(NULL == model->GetGlyphs());
559 DALI_TEST_CHECK(NULL == model->GetLayout());
561 // Sets a text and relais-out.
562 controller->SetText(LOREM_IPSUM);
563 controller->Relayout(CONTROL_SIZE);
565 // Keep the pointers to the glyphs and layout.
566 // As the text is not elided with this configuration, the pointers shoud be the same after calling the ElideGlyphs() method.
567 const GlyphInfo* const glyphsModel = model->GetGlyphs();
568 const Vector2* layoutsModel = model->GetLayout();
570 // Elide the glyphs. Text shouldn't be elided with this configuration.
571 model->ElideGlyphs();
573 DALI_TEST_CHECK(glyphsModel == model->GetGlyphs());
574 DALI_TEST_CHECK(layoutsModel == model->GetLayout());
576 DALI_TEST_EQUALS(LOREM_NUMBER_OF_GLYPHS, model->GetNumberOfGlyphs(), TEST_LOCATION);
577 DALI_TEST_EQUALS(LOREM_NUMBER_OF_LINES, model->GetNumberOfLines(), TEST_LOCATION);
579 // Configures the text controller similarly to the text-label.
580 ConfigureTextLabel(controller);
582 // Clear the text and relais-out.
583 controller->SetText("");
584 controller->Relayout(CONTROL_SIZE);
586 DALI_TEST_EQUALS(0u, model->GetNumberOfGlyphs(), TEST_LOCATION);
587 DALI_TEST_EQUALS(0u, model->GetNumberOfLines(), TEST_LOCATION);
589 // Elide the glyphs. Should not add the ellipsis glyph.
590 model->ElideGlyphs();
592 DALI_TEST_EQUALS(0u, model->GetNumberOfGlyphs(), TEST_LOCATION);
594 // Sets a text that doesn't need to be elided.
595 controller->SetText("Hello\n");
596 controller->Relayout(CONTROL_SIZE);
599 model->ElideGlyphs();
601 DALI_TEST_EQUALS(6u, model->GetNumberOfGlyphs(), TEST_LOCATION);
602 DALI_TEST_EQUALS(2u, model->GetNumberOfLines(), TEST_LOCATION);
604 // Sets a text and relais-out.
605 controller->SetText(LOREM_IPSUM);
606 controller->Relayout(CONTROL_SIZE);
609 model->ElideGlyphs();
611 DALI_TEST_EQUALS(LOREM_NUMBER_OF_GLYPHS_ELIDED, model->GetNumberOfGlyphs(), TEST_LOCATION);
612 DALI_TEST_EQUALS(LOREM_NUMBER_OF_LINES_ELIDED, model->GetNumberOfLines(), TEST_LOCATION);
613 const GlyphInfo* const glyphs = model->GetGlyphs();
614 const Vector2* layouts = model->GetLayout();
615 DALI_TEST_CHECK(NULL != glyphs);
616 DALI_TEST_CHECK(NULL != layouts);
618 // When the ellipsis is enabled, at least a glyph has to be rendered.
619 // Even if the given width is too narrow for rendering an ellipsis glyph.
620 controller->SetText("…");
621 Vector3 sizeEllipsis = controller->GetNaturalSize();
622 controller->SetText("A");
623 Vector3 sizeA = controller->GetNaturalSize();
624 float testWidth = sizeA.width < sizeEllipsis.width ? sizeA.width : sizeEllipsis.width - 1.0;
626 controller->SetText("AB");
627 Vector3 sizeAB = controller->GetNaturalSize();
629 controller->Relayout(Size(testWidth, sizeAB.height));
632 model->ElideGlyphs();
633 DALI_TEST_EQUALS(1u, model->GetNumberOfGlyphs(), TEST_LOCATION);
634 DALI_TEST_EQUALS(1u, model->GetNumberOfLines(), TEST_LOCATION);
636 tet_result(TET_PASS);
640 int UtcDaliTextViewModelElideText02(void)
642 tet_infoline(" UtcDaliTextViewModelElideText02");
644 Size textSize00(100.f, 100.f);
646 Size textSize01(80.f, 100.f);
647 float positions01[] = {0.0f, 8.0f, 16.0f, 26.0f, 34.0f, 42.0f, 46.0f, 56.0f, 64.0f};
649 Size textSize02(80.f, 100.f);
650 float positions02[] = {69.0f, 63.0f, 59.0f, 51.0f, 47.0f, 43.0f, 34.0f, 26.0f, 7.0f};
652 Size textSize03(80.f, 100.f);
653 float positions03[] = {78.0f, 72.0f, 66.0f, 62.0f, 57.0f, 50.0f, 45.0f, 41.0f, 39.0f, 33.0f, 29.0f, 23.0f, 3.0f};
655 Size textSize04(80.f, 10.f);
656 float positions04[] = {1.f};
658 struct ElideData data[] =
667 "<font family='TizenSans'>Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.</font>",
673 "<font family='TizenSansHebrew'>צעד על לשון המלצת לאחרונה, אם לכאן שנורו סרבול מדע, קרן דת שפות להפוך.</font>",
679 "<font family='TizenSansArabic'>عل النفط ديسمبر الإمداد بال, بين وترك شعار هو. لمّ من المبرمة النفط بالسيطرة, أم يتم تحرّك وبغطاء, عدم في لإعادة وإقامة رجوعهم.</font>",
684 {"Small control size, no line fits.",
685 "<font family='TizenSans'>Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.</font>",
690 const unsigned int numberOfTests = 5u;
692 for(unsigned int index = 0u; index < numberOfTests; ++index)
694 ToolkitTestApplication application;
695 if(!ElideTest(data[index]))
697 tet_result(TET_FAIL);
701 tet_result(TET_PASS);
705 int UtcDaliTextViewModelGetFontRuns(void)
707 tet_infoline(" UtcDaliTextViewModelGetFontRuns");
708 ToolkitTestApplication application;
711 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
712 fontClient.SetDpi(93u, 93u);
714 char* pathNamePtr = get_current_dir_name();
715 const std::string pathName(pathNamePtr);
718 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
720 // Creates a text controller.
721 ControllerPtr controller = Controller::New();
723 // Tests the rendering controller has been created.
724 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
725 DALI_TEST_CHECK(typesetter);
727 // Tests the view model has been created.
728 ViewModel* model = typesetter->GetViewModel();
729 DALI_TEST_CHECK(NULL != model);
731 // Configures the text controller similarly to the text-editor.
732 ConfigureTextEditor(controller);
734 // Sets a text and relais-out.
735 controller->SetMarkupProcessorEnabled(true);
736 controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
737 controller->Relayout(CONTROL_SIZE);
739 const Vector<FontRun>& validFonts = model->GetFontRuns();
741 // The font-runs should be equal to number of segments have different fonts.
742 DALI_TEST_EQUALS(validFonts.Count(), 3u, TEST_LOCATION);
744 tet_result(TET_PASS);
748 int UtcDaliTextViewModelGetFontDescriptionRuns(void)
750 tet_infoline(" UtcDaliTextViewModelGetFontDescriptionRuns");
751 ToolkitTestApplication application;
754 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
755 fontClient.SetDpi(93u, 93u);
757 char* pathNamePtr = get_current_dir_name();
758 const std::string pathName(pathNamePtr);
761 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
763 // Creates a text controller.
764 ControllerPtr controller = Controller::New();
766 // Tests the rendering controller has been created.
767 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
768 DALI_TEST_CHECK(typesetter);
770 // Tests the view model has been created.
771 ViewModel* model = typesetter->GetViewModel();
772 DALI_TEST_CHECK(NULL != model);
774 // Configures the text controller similarly to the text-editor.
775 ConfigureTextEditor(controller);
777 // Sets a text and relais-out.
778 controller->SetMarkupProcessorEnabled(true);
779 controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
780 controller->Relayout(CONTROL_SIZE);
782 const Vector<FontDescriptionRun>& validFonts = model->GetFontDescriptionRuns();
784 // The font-description-runs should be equal number of the used fonts.
785 DALI_TEST_EQUALS(validFonts.Count(), 2u, TEST_LOCATION);
787 tet_result(TET_PASS);