/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>
-#include <toolkit-text-utils.h>
+#include <dali-toolkit/devel-api/text/spannable-string.h>
+#include <dali-toolkit/internal/text/controller/text-controller.h>
#include <dali-toolkit/internal/text/font-description-run.h>
#include <dali-toolkit/internal/text/rendering/text-typesetter.h>
#include <dali-toolkit/internal/text/rendering/view-model.h>
-#include <dali-toolkit/internal/text/text-controller.h>
+#include <toolkit-text-utils.h>
using namespace Dali;
using namespace Toolkit;
"Aliquip sanctůs delicáta quí ěá, et natum aliquam est?\n"
"Asšúm sapěret usu ůť.\n"
"Síť ut apeirián laboramúš percipitur, sůas hařum ín éos?\n";
-const Vector2 LOREM_SCROLL_POSITION( 0.f, -208.f );
-const Length LOREM_NUMBER_OF_LINES = 32u;
+const Vector2 LOREM_SCROLL_POSITION( 0.f, -265.f );
+const Length LOREM_NUMBER_OF_LINES = 35u;
const Length LOREM_NUMBER_OF_LINES_ELIDED = 21u;
const Length LOREM_NUMBER_OF_GLYPHS = 632;
-const Length LOREM_NUMBER_OF_GLYPHS_ELIDED = 397u;
+const Length LOREM_NUMBER_OF_GLYPHS_ELIDED = 393u;
// The expected layout size for UtcDaliTextViewModelGetLayoutSize
-const Size LAYOUT_SIZE( 190.f, 48.f );
+const Size LAYOUT_SIZE( 181.f, 48.f );
// The expected color indices for UtcDaliTextViewModelGetColors
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 };
const LineRun& lastLine = *( model->GetLines() + numberOfLines - 1u );
const Length numberOfLastLineGlyphs = data.numberOfGlyphs - lastLine.glyphRun.glyphIndex;
- std::cout << " last line alignment offset : " << lastLine.alignmentOffset << std::endl;
+ std::cout << " last line alignment offset : " << floor(lastLine.alignmentOffset) << std::endl;
for( unsigned int index = 0u; index < numberOfLastLineGlyphs; ++index )
{
- if( *( data.positions + index ) != ( lastLine.alignmentOffset + ( *( layoutBuffer + lastLine.glyphRun.glyphIndex + index ) ).x ) )
+ if( *( data.positions + index ) != floor(lastLine.alignmentOffset + ( *( layoutBuffer + lastLine.glyphRun.glyphIndex + index ) ).x ) )
{
std::cout << " different layout :";
for( unsigned int i = 0; i < numberOfLastLineGlyphs; ++i )
{
- std::cout << " " << ( lastLine.alignmentOffset + ( *( layoutBuffer + lastLine.glyphRun.glyphIndex + i ) ).x );
+ std::cout << " " << floor( lastLine.alignmentOffset + ( *( layoutBuffer + lastLine.glyphRun.glyphIndex + i ) ).x );
}
std::cout << std::endl;
std::cout << " expected :";
ViewModel* model = typesetter->GetViewModel();
DALI_TEST_CHECK( NULL != model );
- DALI_TEST_EQUALS( Layout::HORIZONTAL_ALIGN_BEGIN, model->GetHorizontalAlignment(), TEST_LOCATION );
- DALI_TEST_EQUALS( Layout::VERTICAL_ALIGN_TOP, model->GetVerticalAlignment(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Text::HorizontalAlignment::BEGIN, model->GetHorizontalAlignment(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Text::VerticalAlignment::TOP, model->GetVerticalAlignment(), TEST_LOCATION );
- controller->SetHorizontalAlignment( Layout::HORIZONTAL_ALIGN_CENTER );
- controller->SetVerticalAlignment( Layout::VERTICAL_ALIGN_CENTER );
+ controller->SetHorizontalAlignment( Text::HorizontalAlignment::CENTER );
+ controller->SetVerticalAlignment( Text::VerticalAlignment::CENTER );
- DALI_TEST_EQUALS( Layout::HORIZONTAL_ALIGN_CENTER, model->GetHorizontalAlignment(), TEST_LOCATION );
- DALI_TEST_EQUALS( Layout::VERTICAL_ALIGN_CENTER, model->GetVerticalAlignment(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Text::HorizontalAlignment::CENTER, model->GetHorizontalAlignment(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Text::VerticalAlignment::CENTER, model->GetVerticalAlignment(), TEST_LOCATION );
tet_result(TET_PASS);
END_TEST;
DALI_TEST_CHECK( NULL != glyphs );
DALI_TEST_CHECK( NULL != layouts );
+ // When the ellipsis is enabled, at least a glyph has to be rendered.
+ // Even if the given width is too narrow for rendering an ellipsis glyph.
+ controller->SetText( "…" );
+ Vector3 sizeEllipsis = controller->GetNaturalSize();
+ controller->SetText( "A" );
+ Vector3 sizeA = controller->GetNaturalSize();
+ float testWidth = sizeA.width < sizeEllipsis.width ? sizeA.width : sizeEllipsis.width - 1.0;
+
+ controller->SetText( "AB" );
+ Vector3 sizeAB = controller->GetNaturalSize();
+
+ controller->Relayout( Size(testWidth, sizeAB.height) );
+
+ // Elide the glyphs.
+ model->ElideGlyphs();
+ DALI_TEST_EQUALS( 1u, model->GetNumberOfGlyphs(), TEST_LOCATION );
+ DALI_TEST_EQUALS( 1u, model->GetNumberOfLines(), TEST_LOCATION );
+
tet_result(TET_PASS);
END_TEST;
}
Size textSize00( 100.f, 100.f );
Size textSize01( 80.f, 100.f );
- float positions01[] = { 0.f, 10.f, 16.f, 26.f, 35.f, 38.f, 46.f, 56.f };
+ float positions01[] = { 0.f, 7.f, 16.f, 26.f, 33.f, 41.f, 45.f, 55.f, 64.0f };
Size textSize02( 80.f, 100.f );
- float positions02[] = { 72.f, 63.f, 54.f, 50.f, 43.f, 38.f, 30.f, 11.f };
+ float positions02[] = { 68.f, 62.f, 58.f, 50.f, 46.f, 42.f, 32.f, 24.f, 5.f };
Size textSize03( 80.f, 100.f );
- float positions03[] = { 77.f, 76.f, 71.f, 62.f, 60.f, 52.f, 47.f, 42.f, 39.f, 35.f, 32.f, 13.f };
+ float positions03[] = { 78.f, 72.f, 66.f, 62.f, 57.f, 50.f, 45.f, 41.f, 39.f, 33.f, 30.f, 24.f, 5.0f };
Size textSize04( 80.f, 10.f );
- float positions04[] = { 2.f };
+ float positions04[] = { 1.f };
struct ElideData data[] =
{
"<font family='TizenSans'>Lorem ipsum dolor sit amet, aeque definiebas ea mei, posse iracundia ne cum.</font>",
textSize01,
5u,
- 42u,
+ 36u,
positions01
},
{
"<font family='TizenSansHebrew'>צעד על לשון המלצת לאחרונה, אם לכאן שנורו סרבול מדע, קרן דת שפות להפוך.</font>",
textSize02,
5u,
- 49u,
+ 44u,
positions02
},
{
"<font family='TizenSansArabic'>عل النفط ديسمبر الإمداد بال, بين وترك شعار هو. لمّ من المبرمة النفط بالسيطرة, أم يتم تحرّك وبغطاء, عدم في لإعادة وإقامة رجوعهم.</font>",
textSize03,
5u,
- 79u,
+ 66u,
positions03
},
{
tet_result(TET_PASS);
END_TEST;
}
+
+int UtcDaliTextViewModelGetFontRuns(void)
+{
+ tet_infoline(" UtcDaliTextViewModelGetFontRuns");
+ ToolkitTestApplication application;
+
+ // Load some fonts.
+ TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+ fontClient.SetDpi(93u, 93u);
+
+ char* pathNamePtr = get_current_dir_name();
+ const std::string pathName(pathNamePtr);
+ free(pathNamePtr);
+
+ fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
+
+ // Creates a text controller.
+ ControllerPtr controller = Controller::New();
+
+ // Tests the rendering controller has been created.
+ TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
+ DALI_TEST_CHECK(typesetter);
+
+ // Tests the view model has been created.
+ ViewModel* model = typesetter->GetViewModel();
+ DALI_TEST_CHECK(NULL != model);
+
+ // Configures the text controller similarly to the text-editor.
+ ConfigureTextEditor(controller);
+
+ // Sets a text and relais-out.
+ controller->SetMarkupProcessorEnabled(true);
+ controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+ controller->Relayout(CONTROL_SIZE);
+
+ const Vector<FontRun>& validFonts = model->GetFontRuns();
+
+ // The font-runs should be equal to number of segments have different fonts.
+ DALI_TEST_EQUALS(validFonts.Count(), 3u, TEST_LOCATION);
+
+ tet_result(TET_PASS);
+ END_TEST;
+}
+
+int UtcDaliTextViewModelGetFontDescriptionRuns(void)
+{
+ tet_infoline(" UtcDaliTextViewModelGetFontDescriptionRuns");
+ ToolkitTestApplication application;
+
+ // Load some fonts.
+ TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
+ fontClient.SetDpi(93u, 93u);
+
+ char* pathNamePtr = get_current_dir_name();
+ const std::string pathName(pathNamePtr);
+ free(pathNamePtr);
+
+ fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
+
+ // Creates a text controller.
+ ControllerPtr controller = Controller::New();
+
+ // Tests the rendering controller has been created.
+ TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
+ DALI_TEST_CHECK(typesetter);
+
+ // Tests the view model has been created.
+ ViewModel* model = typesetter->GetViewModel();
+ DALI_TEST_CHECK(NULL != model);
+
+ // Configures the text controller similarly to the text-editor.
+ ConfigureTextEditor(controller);
+
+ // Sets a text and relais-out.
+ controller->SetMarkupProcessorEnabled(true);
+ controller->SetText("<font family='TizenSansRegular' size='10'>Hello </font>Hello<font family='TizenSansRegular' size='15'>Hello</font>");
+ controller->Relayout(CONTROL_SIZE);
+
+ const Vector<FontDescriptionRun>& validFonts = model->GetFontDescriptionRuns();
+
+ // The font-description-runs should be equal number of the used fonts.
+ DALI_TEST_EQUALS(validFonts.Count(), 2u, TEST_LOCATION);
+
+ tet_result(TET_PASS);
+ END_TEST;
+}
\ No newline at end of file