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 <dali-toolkit/devel-api/text/bitmap-font.h>
27 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
28 #include <dali-toolkit/internal/text/controller/text-controller.h>
29 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
30 #include <dali-toolkit/internal/text/rendering/view-model.h>
31 #include <dali/devel-api/text-abstraction/bitmap-font.h>
32 #include <toolkit-environment-variable.h>
33 #include <toolkit-text-utils.h>
36 using namespace Toolkit;
41 const std::string DEFAULT_FONT_DIR("/resources/fonts");
42 const PointSize26Dot6 EMOJI_FONT_SIZE = 3840u; // 60 * 64
44 constexpr auto DALI_RENDERED_GLYPH_COMPRESS_POLICY = "DALI_RENDERED_GLYPH_COMPRESS_POLICY";
47 int UtcDaliTextTypesetter(void)
49 tet_infoline(" UtcDaliTextTypesetter");
50 ToolkitTestApplication application;
52 // Creates a text controller.
53 ControllerPtr controller = Controller::New();
55 // Tests the rendering controller has been created.
56 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
57 DALI_TEST_CHECK(typesetter);
63 int UtcDaliTextTypesetterGetViewModel(void)
65 tet_infoline(" UtcDaliTextTypesetter");
66 ToolkitTestApplication application;
68 // Creates a text controller.
69 ControllerPtr controller = Controller::New();
71 // Tests the rendering controller has been created.
72 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
73 DALI_TEST_CHECK(typesetter);
75 // Tests the view model has been created.
76 ViewModel* model = typesetter->GetViewModel();
77 DALI_TEST_CHECK(NULL != model);
83 int UtcDaliTextRenderingControllerRenderRGBA(void)
85 tet_infoline(" UtcDaliTextRenderingControllerRenderRGBA");
86 ToolkitTestApplication application;
89 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
91 char* pathNamePtr = get_current_dir_name();
92 const std::string pathName(pathNamePtr);
95 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE);
96 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
98 // Creates a text controller.
99 ControllerPtr controller = Controller::New();
101 // Configures the text controller similarly to the text-label.
102 ConfigureTextLabel(controller);
105 controller->SetMarkupProcessorEnabled(true);
106 controller->SetText("<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>");
108 // Creates the text's model and relais-out the text.
109 const Size relayoutSize(120.f, 60.f);
110 controller->Relayout(relayoutSize);
112 // Tests the rendering controller has been created.
113 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
114 DALI_TEST_CHECK(renderingController);
116 // Renders the text and creates the final bitmap.
117 PixelData bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
118 DALI_TEST_CHECK(bitmap);
120 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
121 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
122 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
124 // Changes vertical alignment.
125 controller->SetVerticalAlignment(Text::VerticalAlignment::CENTER);
126 controller->Relayout(relayoutSize);
128 // Renders the text and creates the final bitmap.
129 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
130 DALI_TEST_CHECK(bitmap);
132 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
133 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
134 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
136 controller->SetVerticalAlignment(Text::VerticalAlignment::BOTTOM);
137 controller->Relayout(relayoutSize);
139 // Renders the text and creates the final bitmap.
140 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
141 DALI_TEST_CHECK(bitmap);
143 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
144 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
145 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
147 tet_result(TET_PASS);
151 int UtcDaliTextRenderingControllerRenderLuminance(void)
153 tet_infoline(" UtcDaliTextRenderingControllerRenderLuminance");
154 ToolkitTestApplication application;
157 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
159 char* pathNamePtr = get_current_dir_name();
160 const std::string pathName(pathNamePtr);
163 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE);
164 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
166 // Creates a text controller.
167 ControllerPtr controller = Controller::New();
169 // Configures the text controller similarly to the text-label.
170 ConfigureTextLabel(controller);
173 controller->SetMarkupProcessorEnabled(true);
174 controller->SetText("<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>");
176 // Creates the text's model and relais-out the text.
177 const Size relayoutSize(120.f, 60.f);
178 controller->Relayout(relayoutSize);
180 // Tests the rendering controller has been created.
181 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
182 DALI_TEST_CHECK(renderingController);
184 // Renders the text and creates the final bitmap.
185 PixelData bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
186 DALI_TEST_CHECK(bitmap);
188 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
189 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
190 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
192 // Changes vertical alignment.
193 controller->SetVerticalAlignment(Text::VerticalAlignment::CENTER);
194 controller->Relayout(relayoutSize);
196 // Renders the text and creates the final bitmap.
197 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
198 DALI_TEST_CHECK(bitmap);
200 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
201 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
202 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
204 controller->SetVerticalAlignment(Text::VerticalAlignment::BOTTOM);
205 controller->Relayout(relayoutSize);
207 // Renders the text and creates the final bitmap.
208 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
209 DALI_TEST_CHECK(bitmap);
211 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
212 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
213 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
215 tet_result(TET_PASS);
220 int UtcDaliTextRenderingControllerRenderWithCompressRGBA(void)
222 EnvironmentVariable::SetTestEnvironmentVariable(DALI_RENDERED_GLYPH_COMPRESS_POLICY, "m");
224 tet_infoline(" UtcDaliTextRenderingControllerRenderWithCompressRGBA");
225 ToolkitTestApplication application;
228 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
230 char* pathNamePtr = get_current_dir_name();
231 const std::string pathName(pathNamePtr);
234 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE);
235 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
237 // Creates a text controller.
238 ControllerPtr controller = Controller::New();
240 // Configures the text controller similarly to the text-label.
241 ConfigureTextLabel(controller);
244 controller->SetMarkupProcessorEnabled(true);
245 controller->SetText("<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>");
247 // Creates the text's model and relais-out the text.
248 const Size relayoutSize(120.f, 60.f);
249 controller->Relayout(relayoutSize);
251 // Tests the rendering controller has been created.
252 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
253 DALI_TEST_CHECK(renderingController);
255 // Renders the text and creates the final bitmap.
256 PixelData bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
257 DALI_TEST_CHECK(bitmap);
259 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
260 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
261 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
263 // Changes vertical alignment.
264 controller->SetVerticalAlignment(Text::VerticalAlignment::CENTER);
265 controller->Relayout(relayoutSize);
267 // Renders the text and creates the final bitmap.
268 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
269 DALI_TEST_CHECK(bitmap);
271 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
272 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
273 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
275 controller->SetVerticalAlignment(Text::VerticalAlignment::BOTTOM);
276 controller->Relayout(relayoutSize);
278 // Renders the text and creates the final bitmap.
279 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
280 DALI_TEST_CHECK(bitmap);
282 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
283 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
284 DALI_TEST_EQUALS(Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION);
286 tet_result(TET_PASS);
291 int UtcDaliTextRenderingControllerRenderWithCompressLuminance(void)
293 EnvironmentVariable::SetTestEnvironmentVariable(DALI_RENDERED_GLYPH_COMPRESS_POLICY, "m");
295 tet_infoline(" UtcDaliTextRenderingControllerRenderWithCompressLuminance");
296 ToolkitTestApplication application;
299 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
301 char* pathNamePtr = get_current_dir_name();
302 const std::string pathName(pathNamePtr);
305 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE);
306 fontClient.GetFontId(pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf");
308 // Creates a text controller.
309 ControllerPtr controller = Controller::New();
311 // Configures the text controller similarly to the text-label.
312 ConfigureTextLabel(controller);
315 controller->SetMarkupProcessorEnabled(true);
316 controller->SetText("<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>");
318 // Creates the text's model and relais-out the text.
319 const Size relayoutSize(120.f, 60.f);
320 controller->Relayout(relayoutSize);
322 // Tests the rendering controller has been created.
323 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
324 DALI_TEST_CHECK(renderingController);
326 // Renders the text and creates the final bitmap.
327 PixelData bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
328 DALI_TEST_CHECK(bitmap);
330 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
331 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
332 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
334 // Changes vertical alignment.
335 controller->SetVerticalAlignment(Text::VerticalAlignment::CENTER);
336 controller->Relayout(relayoutSize);
338 // Renders the text and creates the final bitmap.
339 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
340 DALI_TEST_CHECK(bitmap);
342 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
343 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
344 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
346 controller->SetVerticalAlignment(Text::VerticalAlignment::BOTTOM);
347 controller->Relayout(relayoutSize);
349 // Renders the text and creates the final bitmap.
350 bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT, Typesetter::RENDER_TEXT_AND_STYLES, false, Pixel::L8);
351 DALI_TEST_CHECK(bitmap);
353 DALI_TEST_EQUALS(120u, bitmap.GetWidth(), TEST_LOCATION);
354 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
355 DALI_TEST_EQUALS(Pixel::L8, bitmap.GetPixelFormat(), TEST_LOCATION);
357 tet_result(TET_PASS);
362 int UtcDaliTextTypesetterVerticalLineAlignment(void)
364 tet_infoline(" UtcDaliTextTypesetter");
365 ToolkitTestApplication application;
367 // Creates a text controller.
368 ControllerPtr controller = Controller::New();
370 // Configures the text controller similarly to the text-label.
371 ConfigureTextLabel(controller);
374 controller->SetMarkupProcessorEnabled(true);
375 controller->SetText("<font family='TizenSansRegular'>Hello world</font>");
377 // Creates the text's model and relais-out the text.
378 const Size relayoutSize(120.f, 60.f);
379 controller->Relayout(relayoutSize);
381 // Tests the rendering controller has been created.
382 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
383 DALI_TEST_CHECK(renderingController);
386 controller->SetVerticalLineAlignment(Dali::Toolkit::DevelText::VerticalLineAlignment::TOP);
387 controller->Relayout(relayoutSize);
389 // Renders the text and creates the final bitmap.
390 auto bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
391 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
395 controller->SetVerticalLineAlignment(Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE);
396 controller->Relayout(relayoutSize);
398 // Renders the text and creates the final bitmap.
399 auto bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
400 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
404 controller->SetVerticalLineAlignment(Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM);
405 controller->Relayout(relayoutSize);
407 // Renders the text and creates the final bitmap.
408 auto bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
409 DALI_TEST_EQUALS(60u, bitmap.GetHeight(), TEST_LOCATION);
412 tet_result(TET_PASS);
416 int UtcDaliTextTypesetterBitmapFont(void)
418 tet_infoline("UtcDaliTextTypesetterBitmapFont ");
419 ToolkitTestApplication application;
421 DevelText::BitmapFontDescription fontDescription;
422 fontDescription.name = "Digits";
423 fontDescription.underlinePosition = 0.f;
424 fontDescription.underlineThickness = 0.f;
425 fontDescription.isColorFont = true;
427 fontDescription.glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0031.png", "0", 34.f, 0.f});
428 fontDescription.glyphs.push_back({TEST_RESOURCE_DIR "/fonts/bitmap/u0032.png", "1", 34.f, 0.f});
430 TextAbstraction::BitmapFont bitmapFont;
431 DevelText::CreateBitmapFont(fontDescription, bitmapFont);
433 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
434 fontClient.GetFontId(bitmapFont);
436 // Creates a text controller.
437 ControllerPtr controller = Controller::New();
439 // Configures the text controller similarly to the text-label.
440 ConfigureTextLabel(controller);
443 controller->SetMarkupProcessorEnabled(true);
444 controller->SetText("<font family='Digits'><color 'value'='red'>0</color></font>");
446 // Creates the text's model and relais-out the text.
447 const Size relayoutSize(31.f, 34.f);
448 controller->Relayout(relayoutSize);
450 // Tests the rendering controller has been created.
451 TypesetterPtr renderingController = Typesetter::New(controller->GetTextModel());
452 DALI_TEST_CHECK(renderingController);
454 controller->Relayout(relayoutSize);
456 // Renders the text and creates the final bitmap.
457 auto bitmap = renderingController->Render(relayoutSize, Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT);
459 DALI_TEST_EQUALS(31u, bitmap.GetWidth(), TEST_LOCATION);
460 DALI_TEST_EQUALS(34u, bitmap.GetHeight(), TEST_LOCATION);
462 tet_result(TET_PASS);