[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextGeometry.cpp
1
2
3 /*
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <iostream>
23
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
27 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
29 #include <dali-toolkit/devel-api/text/bitmap-font.h>
30 #include <dali-toolkit/devel-api/text/rendering-backend.h>
31 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
32 #include <dali-toolkit/devel-api/text/text-utils-devel.h>
33 #include <dali-toolkit/devel-api/text/text-geometry-devel.h>
34 #include "test-text-geometry-utils.h"
35
36 using namespace Dali;
37 using namespace Toolkit;
38 using namespace Text;
39
40 void dali_textgeometry_startup(void)
41 {
42   test_return_value = TET_UNDEF;
43 }
44
45 void dali_textgeometry_cleanup(void)
46 {
47   test_return_value = TET_PASS;
48 }
49
50 int UtcDaliTextGeometryGetLineBoundingRectangleLabel(void)
51 {
52   ToolkitTestApplication application;
53   tet_infoline("UtcDaliTextGeometryGetLineBoundingRectangleLabel");
54
55   TextLabel label = TextLabel::New();
56   DALI_TEST_CHECK(label);
57
58   application.GetScene().Add(label);
59
60   float lineSpacing = -20.f;
61
62   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
63   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
64   label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
65   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
66   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
67
68   application.SendNotification();
69   application.Render();
70
71   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
72
73   Rect<> expectedLineGeometry = {0, 16, 420, 16};
74
75   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
76
77   END_TEST;
78 }
79
80 int UtcDaliTextGeometryGetLineBoundingRectangleEditor(void)
81 {
82   ToolkitTestApplication application;
83   tet_infoline("UtcDaliTextGeometryGetLineBoundingRectangleEditor");
84
85   TextEditor editor = TextEditor::New();
86   DALI_TEST_CHECK(editor);
87
88   application.GetScene().Add(editor);
89
90   editor.SetProperty(Actor::Property::SIZE, Vector2(160.0f, 250.f));
91   editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f);
92   editor.SetProperty(TextEditor::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
93
94   application.SendNotification();
95   application.Render();
96
97   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(editor, 0);
98
99   Rect<> expectedLineGeometry = {0, 0, 91, 36};
100
101   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
102
103   END_TEST;
104 }
105
106 int UtcDaliTextGeometryGetLineBoundingRectangleField(void)
107 {
108   ToolkitTestApplication application;
109   tet_infoline("UtcDaliTextGeometryGetLineBoundingRectangleField");
110
111   TextField field = TextField::New();
112   DALI_TEST_CHECK(field);
113
114   application.GetScene().Add(field);
115
116   field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
117   field.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 350.f));
118   field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
119   field.SetProperty(TextField::Property::TEXT, "مرحبا بالعالم");
120
121   application.SendNotification();
122   application.Render();
123
124   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(field, 0);
125
126   Rect<> expectedLineGeometry = {0, 0, 163, 36};
127
128   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
129
130   END_TEST;
131 }
132
133 int UtcDaliTextGeometryEmptyTextGetLineBoundingRectangleLabel(void)
134 {
135   ToolkitTestApplication application;
136   tet_infoline("UtcDaliTextGeometryEmptyTextGetLineBoundingRectangleLabel");
137
138   TextLabel label = TextLabel::New();
139   DALI_TEST_CHECK(label);
140
141   application.GetScene().Add(label);
142
143   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
144   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
145   label.SetProperty(TextLabel::Property::TEXT, "");
146
147   application.SendNotification();
148   application.Render();
149
150   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 0);
151
152   Rect<> expectedLineGeometry = {0, 0, 0, 0};
153
154   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
155
156   END_TEST;
157 }
158
159 int UtcDaliTextGeometryLineSpacingPositiveGetLineBoundingRectangleLabel(void)
160 {
161   ToolkitTestApplication application;
162   tet_infoline("UtcDaliTextGeometryLineSpacingPositiveGetLineBoundingRectangleLabel");
163
164   TextLabel label = TextLabel::New();
165   DALI_TEST_CHECK(label);
166
167   application.GetScene().Add(label);
168
169   float lineSpacing = 20.f;
170
171   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
172   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
173   label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
174   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
175   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
176
177   application.SendNotification();
178   application.Render();
179
180   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
181
182   Rect<> expectedLineGeometry = {0, 56, 420, 56};
183
184   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
185
186   END_TEST;
187 }
188
189 int UtcDaliTextGeometryWithVerticalLineAlignmentTopGetLineBoundingRectangleLabel(void)
190 {
191   ToolkitTestApplication application;
192   tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentTopGetLineBoundingRectangleLabel");
193
194   TextLabel label = TextLabel::New();
195   DALI_TEST_CHECK(label);
196
197   application.GetScene().Add(label);
198
199   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
200   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
201   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
202   label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP");
203   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
204
205   application.SendNotification();
206   application.Render();
207
208   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
209
210   Rect<> expectedLineGeometry = {0, 36, 420, 36};
211
212   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
213
214   END_TEST;
215 }
216
217 int UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetLineBoundingRectangleLabel(void)
218 {
219   ToolkitTestApplication application;
220   tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetLineBoundingRectangleLabel");
221
222   TextLabel label = TextLabel::New();
223   DALI_TEST_CHECK(label);
224
225   application.GetScene().Add(label);
226
227   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
228   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
229   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
230   label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM");
231   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
232
233   application.SendNotification();
234   application.Render();
235
236   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
237
238   Rect<> expectedLineGeometry = {0, 36, 420, 36};
239
240   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
241
242   END_TEST;
243 }
244 int UtcDaliTextGeometryWithEllipsisMiddleGetLineBoundingRectangleLabel(void)
245 {
246   ToolkitTestApplication application;
247   tet_infoline("UtcDaliTextGeometryWithEllipsisMiddleGetLineBoundingRectangleLabel");
248
249   TextLabel label = TextLabel::New();
250   DALI_TEST_CHECK(label);
251
252   application.GetScene().Add(label);
253
254   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
255   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
256   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
257   label.SetProperty(TextLabel::Property::ELLIPSIS, true);
258   label.SetProperty(DevelTextLabel::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::MIDDLE);
259   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
260
261   application.SendNotification();
262   application.Render();
263
264   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
265
266   Rect<> expectedLineGeometry = {0, 36, 420, 36};
267
268   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
269
270   END_TEST;
271 }
272
273 int UtcDaliTextGeometryWithEllipsisStartGetLineBoundingRectangleLabel(void)
274 {
275   ToolkitTestApplication application;
276   tet_infoline("UtcDaliTextGeometryWithEllipsisStartGetLineBoundingRectangleLabel");
277
278   TextLabel label = TextLabel::New();
279   DALI_TEST_CHECK(label);
280
281   application.GetScene().Add(label);
282
283   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
284   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
285   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
286   label.SetProperty(TextLabel::Property::ELLIPSIS, true);
287   label.SetProperty(DevelTextLabel::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::START);
288   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
289
290   application.SendNotification();
291   application.Render();
292
293   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
294
295   Rect<> expectedLineGeometry = {0, 36, 420, 36};
296
297   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
298
299   END_TEST;
300 }
301
302 int UtcDaliTextGeometryWithEllipsisEndGetLineBoundingRectangleLabel(void)
303 {
304   ToolkitTestApplication application;
305   tet_infoline("UtcDaliTextGeometryWithEllipsisEndGetLineBoundingRectangleLabel");
306
307   TextLabel label = TextLabel::New();
308   DALI_TEST_CHECK(label);
309
310   application.GetScene().Add(label);
311
312   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
313   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
314   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
315   label.SetProperty(TextLabel::Property::ELLIPSIS, true);
316   label.SetProperty(DevelTextLabel::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::END);
317   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
318
319   application.SendNotification();
320   application.Render();
321
322   Rect<> lineGeometry = TextGeometry::GetLineBoundingRectangle(label, 1);
323
324   Rect<> expectedLineGeometry = {0, 36, 420, 36};
325
326   TestTextGeometryUtils::CheckRectGeometryResult(lineGeometry, expectedLineGeometry);
327
328   END_TEST;
329 }
330
331 int UtcDaliTextGeometryGetCharacterBoundingRectangleLabel(void)
332 {
333   ToolkitTestApplication application;
334   tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleLabel");
335
336   TextLabel label = TextLabel::New();
337   DALI_TEST_CHECK(label);
338
339   application.GetScene().Add(label);
340
341   float lineSpacing = -20.f;
342
343   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
344   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
345   label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
346   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
347   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
348
349   application.SendNotification();
350   application.Render();
351
352   Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
353
354   std::cout << " characterGeometry "<< characterGeometry <<std::endl;
355
356   Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
357   std::cout<< " expectedCharacterGeometry " << characterGeometry <<std::endl;
358
359   std:: cout << "if" << (characterGeometry == expectedCharacterGeometry) <<std::endl;
360   TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
361
362   END_TEST;
363 }
364
365 int UtcDaliTextGeometryGetCharacterBoundingRectangleEditor(void)
366 {
367   ToolkitTestApplication application;
368   tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleEditor");
369
370   TextEditor editor = TextEditor::New();
371   DALI_TEST_CHECK(editor);
372
373   application.GetScene().Add(editor);
374
375   editor.SetProperty(Actor::Property::SIZE, Vector2(160.0f, 250.f));
376   editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f);
377   editor.SetProperty(TextEditor::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
378
379   application.SendNotification();
380   application.Render();
381
382   Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(editor, 1);
383
384   Rect<> expectedCharacterGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
385
386   TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
387
388   END_TEST;
389 }
390
391 int UtcDaliTextGeometryGetCharacterBoundingRectangleField(void)
392 {
393   ToolkitTestApplication application;
394   tet_infoline("UtcDaliTextGeometryGetCharacterBoundingRectangleField");
395
396   TextField field = TextField::New();
397   DALI_TEST_CHECK(field);
398
399   application.GetScene().Add(field);
400
401   field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
402   field.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 350.f));
403   field.SetProperty(TextField::Property::POINT_SIZE, 10.f);
404   field.SetProperty(TextField::Property::TEXT, "مرحبا بالعالم");
405
406   application.SendNotification();
407   application.Render();
408
409   Rect<> characterGeometry = TextGeometry::GetCharacterBoundingRectangle(field, 0);
410
411   Rect<> expectedCharacterGeometry = {142.844f, 10.0f, 16.375f, 11.0f};
412
413   TestTextGeometryUtils::CheckRectGeometryResult(characterGeometry, expectedCharacterGeometry);
414
415   END_TEST;
416 }
417 // char tc
418
419 int UtcDaliTextGeometryEmptyTextGetCharacterBoundingRectangleLabel(void)
420 {
421   ToolkitTestApplication application;
422   tet_infoline("UtcDaliTextGeometryEmptyTextGetCharacterBoundingRectangleLabel");
423
424   TextLabel label = TextLabel::New();
425   DALI_TEST_CHECK(label);
426
427   application.GetScene().Add(label);
428
429   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
430   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
431   label.SetProperty(TextLabel::Property::TEXT, "");
432
433   application.SendNotification();
434   application.Render();
435
436   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 0);
437
438   Rect<> expectedCharGeometry = {0.0f, 0.0f, 0.0f, 0.0f};
439
440   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
441
442   END_TEST;
443 }
444
445 int UtcDaliTextGeometryLineSpacingPositiveGetCharacterBoundingRectangleLabel(void)
446 {
447   ToolkitTestApplication application;
448   tet_infoline("UtcDaliTextGeometryLineSpacingPositiveGetCharacterBoundingRectangleLabel");
449
450   TextLabel label = TextLabel::New();
451   DALI_TEST_CHECK(label);
452
453   application.GetScene().Add(label);
454
455   float lineSpacing = 20.f;
456
457   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
458   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
459   label.SetProperty(DevelTextLabel::Property::LINE_SPACING, lineSpacing);
460   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
461   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
462
463   application.SendNotification();
464   application.Render();
465
466   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
467
468   Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
469
470   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
471
472   END_TEST;
473 }
474
475 int UtcDaliTextGeometryWithVerticalLineAlignmentTopGetCharacterBoundingRectangleLabel(void)
476 {
477   ToolkitTestApplication application;
478   tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentTopGetCharacterBoundingRectangleLabel");
479
480   TextLabel label = TextLabel::New();
481   DALI_TEST_CHECK(label);
482
483   application.GetScene().Add(label);
484
485   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
486   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
487   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
488   label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "TOP");
489   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
490
491   application.SendNotification();
492   application.Render();
493
494   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
495
496   Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
497
498   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
499
500   END_TEST;
501 }
502
503 int UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetCharacterBoundingRectangleLabel(void)
504 {
505   ToolkitTestApplication application;
506   tet_infoline("UtcDaliTextGeometryWithVerticalLineAlignmentBottomGetCharacterBoundingRectangleLabel");
507
508   TextLabel label = TextLabel::New();
509   DALI_TEST_CHECK(label);
510
511   application.GetScene().Add(label);
512
513   label.SetProperty(Actor::Property::SIZE, Vector2(450.0f, 300.f));
514   label.SetProperty(TextLabel::Property::POINT_SIZE, 10.f);
515   label.SetProperty(TextLabel::Property::MULTI_LINE, true);
516   label.SetProperty(Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "BOTTOM");
517   label.SetProperty(TextLabel::Property::TEXT, "Lorem ipsum dolor sit amet, \n consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
518
519   application.SendNotification();
520   application.Render();
521
522   Rect<> charGeometry = TextGeometry::GetCharacterBoundingRectangle(label, 1);
523
524   Rect<> expectedCharGeometry = {13.4844f, 16.0f, 18.7031f, 16.0f};
525
526   TestTextGeometryUtils::CheckRectGeometryResult(charGeometry, expectedCharGeometry);
527
528   END_TEST;
529 }