2 * Copyright (c) 2016 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.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <toolkit-text-utils.h>
27 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
28 #include <dali-toolkit/internal/text/rendering/view-model.h>
29 #include <dali-toolkit/internal/text/text-controller.h>
30 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
33 using namespace Toolkit;
38 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
39 const PointSize26Dot6 EMOJI_FONT_SIZE = 3840u; // 60 * 64
42 int UtcDaliTextTypesetter(void)
44 tet_infoline(" UtcDaliTextTypesetter");
45 ToolkitTestApplication application;
47 // Creates a text controller.
48 ControllerPtr controller = Controller::New();
50 // Tests the rendering controller has been created.
51 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
52 DALI_TEST_CHECK( typesetter );
58 int UtcDaliTextTypesetterGetViewModel(void)
60 tet_infoline(" UtcDaliTextTypesetter");
61 ToolkitTestApplication application;
63 // Creates a text controller.
64 ControllerPtr controller = Controller::New();
66 // Tests the rendering controller has been created.
67 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
68 DALI_TEST_CHECK( typesetter );
70 // Tests the view model has been created.
71 ViewModel* model = typesetter->GetViewModel();
72 DALI_TEST_CHECK( NULL != model );
78 int UtcDaliTextRenderingControllerRender(void)
80 tet_infoline(" UtcDaliTextRenderingControllerRender");
81 ToolkitTestApplication application;
84 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
86 char* pathNamePtr = get_current_dir_name();
87 const std::string pathName( pathNamePtr );
90 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE );
91 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
93 // Creates a text controller.
94 ControllerPtr controller = Controller::New();
96 // Configures the text controller similarly to the text-label.
97 ConfigureTextLabel( controller );
100 controller->SetMarkupProcessorEnabled( true );
101 controller->SetText( "<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>" );
103 // Creates the text's model and relais-out the text.
104 const Size relayoutSize( 120.f, 60.f );
105 controller->Relayout( relayoutSize );
107 // Tests the rendering controller has been created.
108 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
109 DALI_TEST_CHECK( renderingController );
111 // Renders the text and creates the final bitmap.
112 PixelData bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
113 DALI_TEST_CHECK( bitmap );
115 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
116 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
117 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
119 // Changes vertical alignment.
120 controller->SetVerticalAlignment( Text::VerticalAlignment::CENTER );
121 controller->Relayout( relayoutSize );
123 // Renders the text and creates the final bitmap.
124 bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
125 DALI_TEST_CHECK( bitmap );
127 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
128 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
129 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
131 controller->SetVerticalAlignment( Text::VerticalAlignment::BOTTOM );
132 controller->Relayout( relayoutSize );
134 // Renders the text and creates the final bitmap.
135 bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
136 DALI_TEST_CHECK( bitmap );
138 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
139 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
140 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
142 tet_result(TET_PASS);
146 int UtcDaliTextTypesetterVerticalLineAlignment(void)
148 tet_infoline(" UtcDaliTextTypesetter");
149 ToolkitTestApplication application;
151 // Creates a text controller.
152 ControllerPtr controller = Controller::New();
154 // Configures the text controller similarly to the text-label.
155 ConfigureTextLabel( controller );
158 controller->SetMarkupProcessorEnabled( true );
159 controller->SetText( "<font family='TizenSansRegular'>Hello world</font>" );
161 // Creates the text's model and relais-out the text.
162 const Size relayoutSize( 120.f, 60.f );
163 controller->Relayout( relayoutSize );
165 // Tests the rendering controller has been created.
166 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
167 DALI_TEST_CHECK( renderingController );
170 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::TOP );
171 controller->Relayout( relayoutSize );
173 // Renders the text and creates the final bitmap.
174 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
175 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
179 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE );
180 controller->Relayout( relayoutSize );
182 // Renders the text and creates the final bitmap.
183 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
184 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
188 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM );
189 controller->Relayout( relayoutSize );
191 // Renders the text and creates the final bitmap.
192 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
193 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
196 tet_result(TET_PASS);