2 * Copyright (c) 2022 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.
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/internal/text/line-helper-functions.h>
25 #include <dali-toolkit/internal/text/controller/text-controller.h>
26 #include <dali-toolkit/internal/text/rendering/text-typesetter.h>
27 #include <dali-toolkit/internal/text/rendering/view-model.h>
28 #include <toolkit-text-utils.h>
31 using namespace Toolkit;
34 int UtcDaliGetPreOffsetVerticalLineAlignmentWithNegativeLineSpacing(void)
36 tet_infoline(" UtcDaliGetPreOffsetVerticalLineAlignmentWithNegativeLineSpacing ");
37 ToolkitTestApplication application;
39 uint32_t expectedNumberOfLines = 2u;
41 // Creates a text controller.
42 ControllerPtr controller = Controller::New();
44 // Configures the text controller similarly to the text-label.
45 ConfigureTextLabel(controller);
48 controller->SetMarkupProcessorEnabled(true);
49 controller->SetTextElideEnabled(false);
50 controller->SetText("<p rel-line-height=0.5>Line one Line two</p>");
52 // Creates the text's model and relais-out the text.
53 const Size relayoutSize(120.f, 100.f);
54 controller->Relayout(relayoutSize);
56 // Tests the rendering controller has been created.
57 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
58 DALI_TEST_CHECK(typesetter);
60 // Tests the view model has been created.
61 ViewModel* model = typesetter->GetViewModel();
62 DALI_TEST_CHECK(model);
64 application.SendNotification();
67 DALI_TEST_EQUALS(model->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
68 DALI_TEST_CHECK(model->GetLines());
70 const LineRun& lineOne = *(model->GetLines() + 0u);
71 const LineRun& lineTwo = *(model->GetLines() + 1u);
73 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
74 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 0.0f, TEST_LOCATION);
75 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);
77 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
78 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 0.0f, TEST_LOCATION);
79 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);
83 int UtcDaliGetPreOffsetVerticalLineAlignmentWithPositiveLineSpacing(void)
85 tet_infoline(" UtcDaliGetPreOffsetVerticalLineAlignmentWithPositiveLineSpacing ");
86 ToolkitTestApplication application;
88 uint32_t expectedNumberOfLines = 2u;
90 // Creates a text controller.
91 ControllerPtr controller = Controller::New();
93 // Configures the text controller similarly to the text-label.
94 ConfigureTextLabel(controller);
97 controller->SetMarkupProcessorEnabled(true);
98 controller->SetTextElideEnabled(false);
99 controller->SetText("<p rel-line-height=2.0>Line one Line two</p>");
101 // Creates the text's model and relais-out the text.
102 const Size relayoutSize(120.f, 100.f);
103 controller->Relayout(relayoutSize);
105 // Tests the rendering controller has been created.
106 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
107 DALI_TEST_CHECK(typesetter);
109 // Tests the view model has been created.
110 ViewModel* model = typesetter->GetViewModel();
111 DALI_TEST_CHECK(model);
113 application.SendNotification();
114 application.Render();
116 DALI_TEST_EQUALS(model->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
117 DALI_TEST_CHECK(model->GetLines());
119 const LineRun& lineOne = *(model->GetLines() + 0u);
120 const LineRun& lineTwo = *(model->GetLines() + 1u);
122 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
123 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 9.5f, TEST_LOCATION);
124 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 19.0f, TEST_LOCATION);
126 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
127 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 0.0f, TEST_LOCATION);
128 DALI_TEST_EQUALS(GetPreOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);
132 int UtcDaliGetPostOffsetVerticalLineAlignmentWithNegativeLineSpacing(void)
134 tet_infoline(" UtcDaliGetPostOffsetVerticalLineAlignmentWithNegativeLineSpacing ");
135 ToolkitTestApplication application;
137 uint32_t expectedNumberOfLines = 2u;
139 // Creates a text controller.
140 ControllerPtr controller = Controller::New();
142 // Configures the text controller similarly to the text-label.
143 ConfigureTextLabel(controller);
146 controller->SetMarkupProcessorEnabled(true);
147 controller->SetTextElideEnabled(false);
148 controller->SetText("<p rel-line-height=0.5>Line one Line two</p>");
150 // Creates the text's model and relais-out the text.
151 const Size relayoutSize(120.f, 100.f);
152 controller->Relayout(relayoutSize);
154 // Tests the rendering controller has been created.
155 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
156 DALI_TEST_CHECK(typesetter);
158 // Tests the view model has been created.
159 ViewModel* model = typesetter->GetViewModel();
160 DALI_TEST_CHECK(model);
162 application.SendNotification();
163 application.Render();
165 DALI_TEST_EQUALS(model->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
166 DALI_TEST_CHECK(model->GetLines());
168 const LineRun& lineOne = *(model->GetLines() + 0u);
169 const LineRun& lineTwo = *(model->GetLines() + 1u);
171 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), -9.5f, TEST_LOCATION);
172 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), -9.5f, TEST_LOCATION);
173 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), -9.5f, TEST_LOCATION);
175 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
176 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 0.0f, TEST_LOCATION);
177 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);
181 int UtcDaliGetPostOffsetVerticalLineAlignmentWithPositiveLineSpacing(void)
183 tet_infoline(" UtcDaliGetPostOffsetVerticalLineAlignmentWithPositiveLineSpacing ");
184 ToolkitTestApplication application;
186 uint32_t expectedNumberOfLines = 2u;
188 // Creates a text controller.
189 ControllerPtr controller = Controller::New();
191 // Configures the text controller similarly to the text-label.
192 ConfigureTextLabel(controller);
195 controller->SetMarkupProcessorEnabled(true);
196 controller->SetTextElideEnabled(false);
197 controller->SetText("<p rel-line-height=2.0>Line one Line two</p>");
199 // Creates the text's model and relais-out the text.
200 const Size relayoutSize(120.f, 100.f);
201 controller->Relayout(relayoutSize);
203 // Tests the rendering controller has been created.
204 TypesetterPtr typesetter = Typesetter::New(controller->GetTextModel());
205 DALI_TEST_CHECK(typesetter);
207 // Tests the view model has been created.
208 ViewModel* model = typesetter->GetViewModel();
209 DALI_TEST_CHECK(model);
211 application.SendNotification();
212 application.Render();
214 DALI_TEST_EQUALS(model->GetNumberOfLines(), expectedNumberOfLines, TEST_LOCATION);
215 DALI_TEST_CHECK(model->GetLines());
217 const LineRun& lineOne = *(model->GetLines() + 0u);
218 const LineRun& lineTwo = *(model->GetLines() + 1u);
220 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 19.0f, TEST_LOCATION);
221 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 9.5f, TEST_LOCATION);
222 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineOne, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);
224 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::TOP), 0.0f, TEST_LOCATION);
225 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::MIDDLE), 0.0f, TEST_LOCATION);
226 DALI_TEST_EQUALS(GetPostOffsetVerticalLineAlignment(lineTwo, Dali::Toolkit::DevelText::VerticalLineAlignment::BOTTOM), 0.0f, TEST_LOCATION);