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>
32 using namespace Toolkit;
37 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
38 const PointSize26Dot6 EMOJI_FONT_SIZE = 3840u; // 60 * 64
41 int UtcDaliTextTypesetter(void)
43 tet_infoline(" UtcDaliTextTypesetter");
44 ToolkitTestApplication application;
46 // Creates a text controller.
47 ControllerPtr controller = Controller::New();
49 // Tests the rendering controller has been created.
50 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
51 DALI_TEST_CHECK( typesetter );
57 int UtcDaliTextTypesetterGetViewModel(void)
59 tet_infoline(" UtcDaliTextTypesetter");
60 ToolkitTestApplication application;
62 // Creates a text controller.
63 ControllerPtr controller = Controller::New();
65 // Tests the rendering controller has been created.
66 TypesetterPtr typesetter = Typesetter::New( controller->GetTextModel() );
67 DALI_TEST_CHECK( typesetter );
69 // Tests the view model has been created.
70 ViewModel* model = typesetter->GetViewModel();
71 DALI_TEST_CHECK( NULL != model );
77 int UtcDaliTextRenderingControllerRender(void)
79 tet_infoline(" UtcDaliTextRenderingControllerRender");
80 ToolkitTestApplication application;
83 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
85 char* pathNamePtr = get_current_dir_name();
86 const std::string pathName( pathNamePtr );
89 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/BreezeColorEmoji.ttf", EMOJI_FONT_SIZE );
90 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
92 // Creates a text controller.
93 ControllerPtr controller = Controller::New();
95 // Configures the text controller similarly to the text-label.
96 ConfigureTextLabel( controller );
99 controller->SetMarkupProcessorEnabled( true );
100 controller->SetText( "<font family='TizenSansRegular'>Hello world </font><font family='BreezeColorEmoji'>\xF0\x9F\x98\x81</font>" );
102 // Creates the text's model and relais-out the text.
103 const Size relayoutSize( 120.f, 60.f );
104 controller->Relayout( relayoutSize );
106 // Tests the rendering controller has been created.
107 TypesetterPtr renderingController = Typesetter::New( controller->GetTextModel() );
108 DALI_TEST_CHECK( renderingController );
110 // Renders the text and creates the final bitmap.
111 PixelData bitmap = renderingController->Render( relayoutSize );
112 DALI_TEST_CHECK( bitmap );
114 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
115 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
116 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
118 // Changes vertical alignment.
119 controller->SetVerticalAlignment( Text::VerticalAlignment::CENTER );
120 controller->Relayout( relayoutSize );
122 // Renders the text and creates the final bitmap.
123 bitmap = renderingController->Render( relayoutSize );
124 DALI_TEST_CHECK( bitmap );
126 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
127 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
128 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
130 controller->SetVerticalAlignment( Text::VerticalAlignment::BOTTOM );
131 controller->Relayout( relayoutSize );
133 // Renders the text and creates the final bitmap.
134 bitmap = renderingController->Render( relayoutSize );
135 DALI_TEST_CHECK( bitmap );
137 DALI_TEST_EQUALS( 120u, bitmap.GetWidth(), TEST_LOCATION );
138 DALI_TEST_EQUALS( 60u, bitmap.GetHeight(), TEST_LOCATION );
139 DALI_TEST_EQUALS( Pixel::RGBA8888, bitmap.GetPixelFormat(), TEST_LOCATION );
141 tet_result(TET_PASS);