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>
31 #include <dali/devel-api/text-abstraction/bitmap-font.h>
32 #include <dali-toolkit/devel-api/text/bitmap-font.h>
35 using namespace Toolkit;
40 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
41 const PointSize26Dot6 EMOJI_FONT_SIZE = 3840u; // 60 * 64
44 int UtcDaliTextTypesetter(void)
46 tet_infoline(" UtcDaliTextTypesetter");
47 ToolkitTestApplication application;
49 // Creates a text controller.
50 ControllerPtr controller = Controller::New();
52 // Tests the rendering controller has been created.
53 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
54 DALI_TEST_CHECK( typesetter );
60 int UtcDaliTextTypesetterGetViewModel(void)
62 tet_infoline(" UtcDaliTextTypesetter");
63 ToolkitTestApplication application;
65 // Creates a text controller.
66 ControllerPtr controller = Controller::New();
68 // Tests the rendering controller has been created.
69 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
70 DALI_TEST_CHECK( typesetter );
72 // Tests the view model has been created.
73 ViewModel* model = typesetter->GetViewModel();
74 DALI_TEST_CHECK( NULL != model );
80 int UtcDaliTextRenderingControllerRender(void)
82 tet_infoline(" UtcDaliTextRenderingControllerRender");
83 ToolkitTestApplication application;
86 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
88 char* pathNamePtr = get_current_dir_name();
89 const std::string pathName( pathNamePtr );
92 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE );
93 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
95 // Creates a text controller.
96 ControllerPtr controller = Controller::New();
98 // Configures the text controller similarly to the text-label.
99 ConfigureTextLabel( controller );
102 controller->SetMarkupProcessorEnabled( true );
103 controller->SetText( "<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>" );
105 // Creates the text's model and relais-out the text.
106 const Size relayoutSize( 120.f, 60.f );
107 controller->Relayout( relayoutSize );
109 // Tests the rendering controller has been created.
110 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
111 DALI_TEST_CHECK( renderingController );
113 // Renders the text and creates the final bitmap.
114 PixelData bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
115 DALI_TEST_CHECK( bitmap );
117 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
118 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
119 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
121 // Changes vertical alignment.
122 controller->SetVerticalAlignment( Text::VerticalAlignment::CENTER );
123 controller->Relayout( relayoutSize );
125 // Renders the text and creates the final bitmap.
126 bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
127 DALI_TEST_CHECK( bitmap );
129 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
130 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
131 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
133 controller->SetVerticalAlignment( Text::VerticalAlignment::BOTTOM );
134 controller->Relayout( relayoutSize );
136 // Renders the text and creates the final bitmap.
137 bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
138 DALI_TEST_CHECK( bitmap );
140 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
141 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
142 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
144 tet_result(TET_PASS);
148 int UtcDaliTextTypesetterVerticalLineAlignment(void)
150 tet_infoline(" UtcDaliTextTypesetter");
151 ToolkitTestApplication application;
153 // Creates a text controller.
154 ControllerPtr controller = Controller::New();
156 // Configures the text controller similarly to the text-label.
157 ConfigureTextLabel( controller );
160 controller->SetMarkupProcessorEnabled( true );
161 controller->SetText( "<font family='TizenSansRegular'>Hello world</font>" );
163 // Creates the text's model and relais-out the text.
164 const Size relayoutSize( 120.f, 60.f );
165 controller->Relayout( relayoutSize );
167 // Tests the rendering controller has been created.
168 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
169 DALI_TEST_CHECK( renderingController );
172 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::TOP );
173 controller->Relayout( relayoutSize );
175 // Renders the text and creates the final bitmap.
176 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
177 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
181 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE );
182 controller->Relayout( relayoutSize );
184 // Renders the text and creates the final bitmap.
185 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
186 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
190 controller->SetVerticalLineAlignment( Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM );
191 controller->Relayout( relayoutSize );
193 // Renders the text and creates the final bitmap.
194 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
195 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
198 tet_result(TET_PASS);
202 int UtcDaliTextTypesetterBitmapFont(void)
204 tet_infoline("UtcDaliTextTypesetterBitmapFont ");
205 ToolkitTestApplication application;
207 DevelText::BitmapFontDescription fontDescription;
208 fontDescription.name = "Digits";
209 fontDescription.underlinePosition = 0.f;
210 fontDescription.underlineThickness = 0.f;
211 fontDescription.isColorFont = true;
213 fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0031.png", "0", 34.f, 0.f } );
214 fontDescription.glyphs.push_back( { TEST_RESOURCE_DIR "/fonts/bitmap/u0032.png", "1", 34.f, 0.f } );
216 TextAbstraction::BitmapFont bitmapFont;
217 DevelText::CreateBitmapFont( fontDescription, bitmapFont );
219 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
220 fontClient.GetFontId( bitmapFont );
222 // Creates a text controller.
223 ControllerPtr controller = Controller::New();
225 // Configures the text controller similarly to the text-label.
226 ConfigureTextLabel( controller );
229 controller->SetMarkupProcessorEnabled( true );
230 controller->SetText( "<font family='Digits'><color 'value'='red'>0</color></font>" );
232 // Creates the text's model and relais-out the text.
233 const Size relayoutSize( 31.f, 34.f );
234 controller->Relayout( relayoutSize );
236 // Tests the rendering controller has been created.
237 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
238 DALI_TEST_CHECK( renderingController );
240 controller->Relayout( relayoutSize );
242 // Renders the text and creates the final bitmap.
243 auto bitmap = renderingController->Render( relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT );
245 DALI_TEST_EQUALS( 31u, bitmap.GetWidth(), TEST_LOCATION );
246 DALI_TEST_EQUALS( 34u, bitmap.GetHeight(), TEST_LOCATION );
248 tet_result(TET_PASS);