1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <string>
17 #include <fstream>
18
19 #include "drawing_bitmap.h"
20 #include "drawing_brush.h"
21 #include "drawing_canvas.h"
22 #include "drawing_color.h"
23 #include "drawing_font.h"
24 #include "drawing_font_collection.h"
25 #include "drawing_point.h"
26 #include "drawing_rect.h"
27 #include "drawing_text_declaration.h"
28 #include "drawing_text_line.h"
29 #include "drawing_text_typography.h"
30
31 #include "gtest/gtest.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35
36 namespace OHOS {
37 namespace {
38 constexpr static float FLOAT_DATA_EPSILON = 1e-6f;
39 }
40
41 class NativeDrawingLineTest : public testing::Test {
42 public:
SetUp()43 void SetUp() override
44 {
45 typoStyle_ = nullptr;
46 txtStyle_ = nullptr;
47 fontCollection_ = nullptr;
48 handler_ = nullptr;
49 typography_ = nullptr;
50 cBitmap_ = nullptr;
51 canvas_ = nullptr;
52 }
53
TearDown()54 void TearDown() override
55 {
56 if (canvas_ != nullptr) {
57 OH_Drawing_CanvasDestroy(canvas_);
58 canvas_ = nullptr;
59 }
60 if (typography_ != nullptr) {
61 OH_Drawing_DestroyTypography(typography_);
62 typography_ = nullptr;
63 }
64 if (handler_ != nullptr) {
65 OH_Drawing_DestroyTypographyHandler(handler_);
66 handler_ = nullptr;
67 }
68 if (txtStyle_ != nullptr) {
69 OH_Drawing_DestroyTextStyle(txtStyle_);
70 txtStyle_ = nullptr;
71 }
72 if (typoStyle_ != nullptr) {
73 OH_Drawing_DestroyTypographyStyle(typoStyle_);
74 typoStyle_ = nullptr;
75 }
76 if (cBitmap_ != nullptr) {
77 OH_Drawing_BitmapDestroy(cBitmap_);
78 cBitmap_ = nullptr;
79 }
80 if (fontCollection_ != nullptr) {
81 OH_Drawing_DestroyFontCollection(fontCollection_);
82 fontCollection_ = nullptr;
83 }
84 }
85
86 void PrepareCreateTextLine(const std::string& text);
87
88 protected:
89 OH_Drawing_TypographyStyle* typoStyle_ = nullptr;
90 OH_Drawing_TextStyle* txtStyle_ = nullptr;
91 OH_Drawing_FontCollection* fontCollection_ = nullptr;
92 OH_Drawing_TypographyCreate* handler_ = nullptr;
93 OH_Drawing_Typography* typography_ = nullptr;
94 OH_Drawing_Bitmap* cBitmap_ = nullptr;
95 OH_Drawing_Canvas* canvas_ = nullptr;
96 };
97
PrepareCreateTextLine(const std::string & text)98 void NativeDrawingLineTest::PrepareCreateTextLine(const std::string& text)
99 {
100 double maxWidth = 500.0;
101 uint32_t height = 40;
102 typoStyle_ = OH_Drawing_CreateTypographyStyle();
103 EXPECT_TRUE(typoStyle_ != nullptr);
104 txtStyle_ = OH_Drawing_CreateTextStyle();
105 EXPECT_TRUE(txtStyle_ != nullptr);
106 fontCollection_ = OH_Drawing_CreateFontCollection();
107 EXPECT_TRUE(fontCollection_ != nullptr);
108 handler_ = OH_Drawing_CreateTypographyHandler(typoStyle_, fontCollection_);
109 EXPECT_TRUE(handler_ != nullptr);
110 OH_Drawing_SetTextStyleColor(txtStyle_, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
111 double fontSize = 30;
112 OH_Drawing_SetTextStyleFontSize(txtStyle_, fontSize);
113 OH_Drawing_SetTextStyleFontWeight(txtStyle_, FONT_WEIGHT_400);
114 bool halfLeading = true;
115 OH_Drawing_SetTextStyleHalfLeading(txtStyle_, halfLeading);
116 const char* fontFamilies[] = {"Roboto"};
117 OH_Drawing_SetTextStyleFontFamilies(txtStyle_, 1, fontFamilies);
118 OH_Drawing_TypographyHandlerPushTextStyle(handler_, txtStyle_);
119 OH_Drawing_TypographyHandlerAddText(handler_, text.c_str());
120 OH_Drawing_TypographyHandlerPopTextStyle(handler_);
121 typography_ = OH_Drawing_CreateTypography(handler_);
122 EXPECT_TRUE(typography_ != nullptr);
123 OH_Drawing_TypographyLayout(typography_, maxWidth);
124 double position[2] = {10.0, 15.0};
125 cBitmap_ = OH_Drawing_BitmapCreate();
126 EXPECT_TRUE(cBitmap_ != nullptr);
127 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
128 uint32_t width = 20;
129 OH_Drawing_BitmapBuild(cBitmap_, width, height, &cFormat);
130 canvas_ = OH_Drawing_CanvasCreate();
131 EXPECT_TRUE(canvas_ != nullptr);
132 OH_Drawing_CanvasBind(canvas_, cBitmap_);
133 OH_Drawing_CanvasClear(canvas_, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
134 OH_Drawing_TypographyPaint(typography_, canvas_, position[0], position[1]);
135 }
136
137 /*
138 * @tc.name: NativeDrawingLineTest001
139 * @tc.desc: test for the textLine GetTextLines.
140 * @tc.type: FUNC
141 */
142 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest001, TestSize.Level1)
143 {
144 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
145 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
146 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
147 EXPECT_EQ(size, 3);
148 OH_Drawing_DestroyTextLines(textLines);
149 }
150
151 /*
152 * @tc.name: NativeDrawingLineTest002
153 * @tc.desc: test for the textLine GetTextLines.
154 * @tc.type: FUNC
155 */
156 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest002, TestSize.Level1)
157 {
158 PrepareCreateTextLine(
159 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
160 "Drawing \n\n \u231A \u513B"
161 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
162 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
163 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
164 EXPECT_EQ(size, 7);
165 OH_Drawing_DestroyTextLines(textLines);
166 }
167
168 /*
169 * @tc.name: NativeDrawingLineTest003
170 * @tc.desc: test for the textLine GetTextLines.
171 * @tc.type: FUNC
172 */
173 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest003, TestSize.Level1)
174 {
175 PrepareCreateTextLine("");
176 OH_Drawing_Array* textLines = textLines = OH_Drawing_TypographyGetTextLines(typography_);
177 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
178 EXPECT_EQ(size, 0);
179 OH_Drawing_DestroyTextLines(textLines);
180 }
181
182 /*
183 * @tc.name: NativeDrawingLineTest004
184 * @tc.desc: test for the textLine GetTextLines.
185 * @tc.type: FUNC
186 */
187 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest004, TestSize.Level1)
188 {
189 PrepareCreateTextLine("\n");
190 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
191 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
192 EXPECT_EQ(size, 2);
193 OH_Drawing_DestroyTextLines(textLines);
194 }
195
196 /*
197 * @tc.name: NativeDrawingLineTest005
198 * @tc.desc: test for the textLine GetTextLines.
199 * @tc.type: FUNC
200 */
201 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest005, TestSize.Level1)
202 {
203 PrepareCreateTextLine("\n\n\n");
204 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(nullptr);
205 EXPECT_TRUE(textLines == nullptr);
206
207 textLines = OH_Drawing_TypographyGetTextLines(typography_);
208 EXPECT_TRUE(textLines != nullptr);
209 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
210 EXPECT_EQ(size, 4);
211
212 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, -1);
213 EXPECT_TRUE(textLine == nullptr);
214
215 textLine = OH_Drawing_GetTextLineByIndex(textLines, 10);
216 EXPECT_TRUE(textLine == nullptr);
217
218 textLine = OH_Drawing_GetTextLineByIndex(nullptr, 0);
219 EXPECT_TRUE(textLine == nullptr);
220
221 textLine = OH_Drawing_GetTextLineByIndex(nullptr, -10);
222 EXPECT_TRUE(textLine == nullptr);
223
224 OH_Drawing_DestroyTextLines(textLines);
225 }
226
227 /*
228 * @tc.name: NativeDrawingLineTest006
229 * @tc.desc: test for the textLine GetGlyphCount.
230 * @tc.type: FUNC
231 */
232 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest006, TestSize.Level1)
233 {
234 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
235 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
236 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
237 EXPECT_EQ(size, 3);
238 for (size_t index = 0; index < size; index++) {
239 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
240 EXPECT_TRUE(textLine != nullptr);
241
242 double count = OH_Drawing_TextLineGetGlyphCount(textLine);
243 EXPECT_GE(count, 10);
244 }
245 OH_Drawing_DestroyTextLines(textLines);
246 }
247
248 /*
249 * @tc.name: NativeDrawingLineTest007
250 * @tc.desc: test for the textLine GetGlyphCount.
251 * @tc.type: FUNC
252 */
253 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest007, TestSize.Level1)
254 {
255 PrepareCreateTextLine(
256 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
257 "Drawing \n\n \u231A \u513B"
258 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
259 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
260 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
261 EXPECT_EQ(size, 7);
262 for (size_t index = 0; index < size; index++) {
263 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
264 EXPECT_TRUE(textLine != nullptr);
265
266 double count = OH_Drawing_TextLineGetGlyphCount(textLine);
267 if (index == 3) {
268 EXPECT_EQ(count, 0);
269 } else if (index == 6) {
270 EXPECT_EQ(count, 3);
271 } else {
272 EXPECT_GE(count, 10);
273 }
274 }
275 OH_Drawing_DestroyTextLines(textLines);
276 }
277
278 /*
279 * @tc.name: NativeDrawingLineTest008
280 * @tc.desc: test for the textLine GetGlyphCount.
281 * @tc.type: FUNC
282 */
283 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest008, TestSize.Level1)
284 {
285 PrepareCreateTextLine("\n\n\n\n");
286 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
287 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
288 EXPECT_EQ(size, 5);
289 for (size_t index = 0; index < size; index++) {
290 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
291 EXPECT_TRUE(textLine != nullptr);
292
293 double count = OH_Drawing_TextLineGetGlyphCount(textLine);
294 EXPECT_EQ(count, 0);
295 }
296 OH_Drawing_DestroyTextLines(textLines);
297
298 double count = OH_Drawing_TextLineGetGlyphCount(nullptr);
299 EXPECT_EQ(count, 0);
300 }
301
302 /*
303 * @tc.name: NativeDrawingLineTest009
304 * @tc.desc: test for the textLine GetTextRange.
305 * @tc.type: FUNC
306 */
307 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest009, TestSize.Level1)
308 {
309 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
310 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
311 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
312 EXPECT_EQ(size, 3);
313 size_t start = 0;
314 size_t end = 0;
315 for (size_t index = 0; index < size; index++) {
316 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
317 EXPECT_TRUE(textLine != nullptr);
318
319 OH_Drawing_TextLineGetTextRange(textLine, &start, &end);
320 EXPECT_GE(start, 0);
321 EXPECT_GT(end, 0);
322 }
323 OH_Drawing_DestroyTextLines(textLines);
324 }
325
326 /*
327 * @tc.name: NativeDrawingLineTest010
328 * @tc.desc: test for the textLine GetTextRange.
329 * @tc.type: FUNC
330 */
331 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest010, TestSize.Level1)
332 {
333 PrepareCreateTextLine(
334 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
335 "Drawing \n\n \u231A \u513B"
336 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
337 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
338 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
339 EXPECT_EQ(size, 7);
340
341 size_t start = 0;
342 size_t end = 0;
343 for (size_t index = 0; index < size; index++) {
344 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
345 EXPECT_TRUE(textLine != nullptr);
346
347 OH_Drawing_TextLineGetTextRange(textLine, &start, &end);
348 EXPECT_GE(start, 0);
349 EXPECT_GT(end, 0);
350 }
351 OH_Drawing_DestroyTextLines(textLines);
352 }
353
354 /*
355 * @tc.name: NativeDrawingLineTest011
356 * @tc.desc: test for the textLine GetTextRange.
357 * @tc.type: FUNC
358 */
359 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest011, TestSize.Level1)
360 {
361 PrepareCreateTextLine("\n");
362 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
363 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
364 EXPECT_EQ(size, 2);
365
366 size_t start = 0;
367 size_t end = 0;
368 for (size_t index = 0; index < size; index++) {
369 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
370 EXPECT_TRUE(textLine != nullptr);
371
372 OH_Drawing_TextLineGetTextRange(textLine, &start, &end);
373 EXPECT_EQ(start, 0);
374 EXPECT_EQ(end, 1);
375 }
376 OH_Drawing_DestroyTextLines(textLines);
377 }
378
379 /*
380 * @tc.name: NativeDrawingLineTest012
381 * @tc.desc: test for the textLine GetTextRange.
382 * @tc.type: FUNC
383 */
384 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest012, TestSize.Level1)
385 {
386 PrepareCreateTextLine("\n\n\n");
387 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
388 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
389 EXPECT_EQ(size, 4);
390
391 OH_Drawing_TextLine* textLine = textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
392 EXPECT_TRUE(textLine != nullptr);
393
394 size_t start = 0;
395 OH_Drawing_TextLineGetTextRange(textLine, &start, nullptr);
396 EXPECT_EQ(start, 0);
397
398 size_t end = 0;
399 OH_Drawing_TextLineGetTextRange(textLine, nullptr, &end);
400 EXPECT_EQ(end, 0);
401
402 OH_Drawing_TextLineGetTextRange(textLine, nullptr, nullptr);
403 OH_Drawing_DestroyTextLines(textLines);
404 }
405
406 /*
407 * @tc.name: NativeDrawingLineTest013
408 * @tc.desc: test for the textLine GetTypographicBounds.
409 * @tc.type: FUNC
410 */
411 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest013, TestSize.Level1)
412 {
413 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
414 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
415 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
416 EXPECT_EQ(size, 3);
417 double ascent = 0.0;
418 double descent = 0.0;
419 double leading = 0.0;
420 std::vector<float> widthArr = {206.639786, 490.139404, 459.509460};
421 for (size_t index = 0; index < size; index++) {
422 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
423 EXPECT_TRUE(textLine != nullptr);
424
425 double width = OH_Drawing_TextLineGetTypographicBounds(textLine, &ascent, &descent, &leading);
426 EXPECT_NEAR(ascent, -27.84, FLOAT_DATA_EPSILON);
427 EXPECT_NEAR(descent, 7.32, FLOAT_DATA_EPSILON);
428 EXPECT_NEAR(leading, 0.0, FLOAT_DATA_EPSILON);
429 EXPECT_NEAR(width, widthArr[index], FLOAT_DATA_EPSILON);
430 }
431 OH_Drawing_DestroyTextLines(textLines);
432 }
433
434 /*
435 * @tc.name: NativeDrawingLineTest014
436 * @tc.desc: test for the textLine GetTypographicBounds.
437 * @tc.type: FUNC
438 */
439 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest014, TestSize.Level1)
440 {
441 PrepareCreateTextLine(
442 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
443 "Drawing \n\n \u231A \u513B"
444 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
445 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
446 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
447 EXPECT_EQ(size, 7);
448
449 double ascent = 0.0;
450 double descent = 0.0;
451 double leading = 0.0;
452 std::vector<float> widthArr = {290.939697, 498.239380, 458.309509, 0.0, 497.952301, 409.497314, 51.300049};
453 for (size_t index = 0; index < size; index++) {
454 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
455 EXPECT_TRUE(textLine != nullptr);
456
457 double width = OH_Drawing_TextLineGetTypographicBounds(textLine, &ascent, &descent, &leading);
458 EXPECT_EQ(leading, 0);
459 if (index == 4) {
460 EXPECT_NEAR(ascent, -27.84, FLOAT_DATA_EPSILON);
461 EXPECT_NEAR(descent, 7.431193, FLOAT_DATA_EPSILON);
462 } else if (index == 5) {
463 EXPECT_NEAR(ascent, -35.369999, FLOAT_DATA_EPSILON);
464 EXPECT_NEAR(descent, 9.690001, FLOAT_DATA_EPSILON);
465 } else {
466 EXPECT_NEAR(ascent, -27.84, FLOAT_DATA_EPSILON);
467 EXPECT_NEAR(descent, 7.32, FLOAT_DATA_EPSILON);
468 }
469 EXPECT_NEAR(width, widthArr[index], FLOAT_DATA_EPSILON);
470 }
471 OH_Drawing_DestroyTextLines(textLines);
472 }
473
474 /*
475 * @tc.name: NativeDrawingLineTest015
476 * @tc.desc: test for the textLine GetTypographicBounds.
477 * @tc.type: FUNC
478 */
479 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest015, TestSize.Level1)
480 {
481 PrepareCreateTextLine("\n\n\n\n");
482 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
483 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
484 EXPECT_EQ(size, 5);
485
486 double ascent = 0.0;
487 double descent = 0.0;
488 double leading = 0.0;
489 for (size_t index = 0; index < size; index++) {
490 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
491 EXPECT_TRUE(textLine != nullptr);
492
493 double width = OH_Drawing_TextLineGetTypographicBounds(textLine, &ascent, &descent, &leading);
494 EXPECT_NEAR(ascent, -27.84, FLOAT_DATA_EPSILON);
495 EXPECT_NEAR(descent, 7.32, FLOAT_DATA_EPSILON);
496 EXPECT_EQ(leading, 0);
497 EXPECT_EQ(width, 0);
498 }
499 OH_Drawing_DestroyTextLines(textLines);
500 }
501
502 /*
503 * @tc.name: NativeDrawingLineTest016
504 * @tc.desc: test for the textLine GetTypographicBounds.
505 * @tc.type: FUNC
506 */
507 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest016, TestSize.Level1)
508 {
509 PrepareCreateTextLine("\n\n");
510 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
511 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
512 EXPECT_EQ(size, 3);
513
514 OH_Drawing_TextLine* textLine = textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
515 EXPECT_TRUE(textLine != nullptr);
516
517 double ascent = 0.0;
518 double width = OH_Drawing_TextLineGetTypographicBounds(textLine, &ascent, nullptr, nullptr);
519 EXPECT_EQ(ascent, 0);
520 EXPECT_EQ(width, 0);
521
522 double descent = 0.0;
523 width = OH_Drawing_TextLineGetTypographicBounds(textLine, nullptr, &descent, nullptr);
524 EXPECT_EQ(descent, 0);
525 EXPECT_EQ(width, 0);
526
527 double leading = 0.0;
528 width = OH_Drawing_TextLineGetTypographicBounds(textLine, nullptr, nullptr, &leading);
529 EXPECT_EQ(leading, 0);
530 EXPECT_EQ(width, 0);
531
532 width = OH_Drawing_TextLineGetTypographicBounds(textLine, nullptr, nullptr, nullptr);
533 EXPECT_EQ(width, 0);
534
535 OH_Drawing_DestroyTextLines(textLines);
536 }
537
538 /*
539 * @tc.name: NativeDrawingLineTest017
540 * @tc.desc: test for the textLine GetImageBounds.
541 * @tc.type: FUNC
542 */
543 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest017, TestSize.Level1)
544 {
545 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
546 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
547 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
548 EXPECT_EQ(size, 3);
549
550 for (size_t index = 0; index < size; index++) {
551 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
552 EXPECT_TRUE(textLine != nullptr);
553
554 OH_Drawing_Rect *rect = OH_Drawing_TextLineGetImageBounds(textLine);
555 EXPECT_GT(OH_Drawing_RectGetRight(rect), OH_Drawing_RectGetLeft(rect));
556 EXPECT_GT(OH_Drawing_RectGetBottom(rect), OH_Drawing_RectGetTop(rect));
557 EXPECT_LT(OH_Drawing_RectGetWidth(rect), 500.0);
558 EXPECT_LE(OH_Drawing_RectGetHeight(rect), 40);
559 OH_Drawing_RectDestroy(rect);
560 }
561 OH_Drawing_DestroyTextLines(textLines);
562 }
563
564 /*
565 * @tc.name: NativeDrawingLineTest018
566 * @tc.desc: test for the textLine GetImageBounds.
567 * @tc.type: FUNC
568 */
569 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest018, TestSize.Level1)
570 {
571 PrepareCreateTextLine(
572 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
573 "Drawing \n\n \u231A \u513B"
574 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
575 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
576 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
577 EXPECT_EQ(size, 7);
578
579 for (size_t index = 0; index < size; index++) {
580 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
581 EXPECT_TRUE(textLine != nullptr);
582
583 OH_Drawing_Rect *rect = OH_Drawing_TextLineGetImageBounds(textLine);
584 if (index == 3) {
585 EXPECT_EQ(OH_Drawing_RectGetLeft(rect), 0);
586 EXPECT_EQ(OH_Drawing_RectGetRight(rect), 0);
587 EXPECT_EQ(OH_Drawing_RectGetBottom(rect), OH_Drawing_RectGetTop(rect));
588 } else {
589 EXPECT_GT(OH_Drawing_RectGetRight(rect), OH_Drawing_RectGetLeft(rect));
590 EXPECT_GT(OH_Drawing_RectGetBottom(rect), OH_Drawing_RectGetTop(rect));
591 }
592 EXPECT_LT(OH_Drawing_RectGetWidth(rect), 500.0);
593 EXPECT_LE(OH_Drawing_RectGetHeight(rect), 40);
594 OH_Drawing_RectDestroy(rect);
595 }
596 OH_Drawing_DestroyTextLines(textLines);
597 }
598
599 /*
600 * @tc.name: NativeDrawingLineTest019
601 * @tc.desc: test for the textLine GetImageBounds.
602 * @tc.type: FUNC
603 */
604 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest019, TestSize.Level1)
605 {
606 PrepareCreateTextLine("\n\n\n\n");
607 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
608 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
609 EXPECT_EQ(size, 5);
610
611 for (size_t index = 0; index < size; index++) {
612 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
613 EXPECT_TRUE(textLine != nullptr);
614
615 OH_Drawing_Rect *rect = OH_Drawing_TextLineGetImageBounds(textLine);
616 EXPECT_EQ(OH_Drawing_RectGetLeft(rect), 0);
617 EXPECT_EQ(OH_Drawing_RectGetRight(rect), 0);
618 EXPECT_EQ(OH_Drawing_RectGetTop(rect), 0);
619 EXPECT_EQ(OH_Drawing_RectGetBottom(rect), 0);
620 OH_Drawing_RectDestroy(rect);
621 }
622 OH_Drawing_DestroyTextLines(textLines);
623
624 OH_Drawing_Rect *rect = OH_Drawing_TextLineGetImageBounds(nullptr);
625 EXPECT_TRUE(rect == nullptr);
626 }
627
628 /*
629 * @tc.name: NativeDrawingLineTest020
630 * @tc.desc: test for the textLine GetTrailingSpaceWidth.
631 * @tc.type: FUNC
632 */
633 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest020, TestSize.Level1)
634 {
635 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
636 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
637 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
638 EXPECT_EQ(size, 3);
639
640 for (size_t index = 0; index < size; index++) {
641 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
642 EXPECT_TRUE(textLine != nullptr);
643
644 double width = OH_Drawing_TextLineGetTrailingSpaceWidth(textLine);
645 EXPECT_GT(width, 1);
646 }
647 OH_Drawing_DestroyTextLines(textLines);
648 }
649
650 /*
651 * @tc.name: NativeDrawingLineTest021
652 * @tc.desc: test for the textLine GetTrailingSpaceWidth.
653 * @tc.type: FUNC
654 */
655 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest021, TestSize.Level1)
656 {
657 PrepareCreateTextLine(
658 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
659 "Drawing \n\n \u231A \u513B"
660 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
661 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
662 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
663 EXPECT_EQ(size, 7);
664
665 for (size_t index = 0; index < size; index++) {
666 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
667 EXPECT_TRUE(textLine != nullptr);
668
669 double width = OH_Drawing_TextLineGetTrailingSpaceWidth(textLine);
670 if (index < 3) {
671 EXPECT_GT(width, 1.0);
672 } else {
673 EXPECT_EQ(width, 0.0);
674 }
675 }
676 OH_Drawing_DestroyTextLines(textLines);
677 }
678
679 /*
680 * @tc.name: NativeDrawingLineTest022
681 * @tc.desc: test for the textLine GetTrailingSpaceWidth.
682 * @tc.type: FUNC
683 */
684 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest022, TestSize.Level1)
685 {
686 PrepareCreateTextLine("\n\n\n\n");
687 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
688 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
689 EXPECT_EQ(size, 5);
690
691 for (size_t index = 0; index < size; index++) {
692 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
693 EXPECT_TRUE(textLine != nullptr);
694
695 double width = OH_Drawing_TextLineGetTrailingSpaceWidth(textLine);
696 EXPECT_EQ(width, 0.0);
697 }
698 OH_Drawing_DestroyTextLines(textLines);
699
700 double width = OH_Drawing_TextLineGetTrailingSpaceWidth(nullptr);
701 EXPECT_EQ(width, 0.0);
702 }
703
704 /*
705 * @tc.name: NativeDrawingLineTest023
706 * @tc.desc: test for the textLine GetStringIndexForPosition.
707 * @tc.type: FUNC
708 */
709 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest023, TestSize.Level1)
710 {
711 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
712 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
713 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
714 EXPECT_EQ(size, 3);
715
716 const int maxCharacterNum = 88;
717 for (size_t index = 0; index < size; index++) {
718 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
719 EXPECT_TRUE(textLine != nullptr);
720
721 OH_Drawing_Point *point = OH_Drawing_PointCreate(1.0, 2.0);
722 int32_t characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
723 if (index == 0) {
724 EXPECT_EQ(characterIndex, 0);
725 } else {
726 EXPECT_GT(characterIndex, 0);
727 }
728 EXPECT_LT(characterIndex, maxCharacterNum);
729 OH_Drawing_PointSet(point, 90.0, 4.0);
730 characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
731 EXPECT_GT(characterIndex, 1);
732 EXPECT_LT(characterIndex, maxCharacterNum);
733 OH_Drawing_PointDestroy(point);
734 }
735 OH_Drawing_DestroyTextLines(textLines);
736 }
737
738 /*
739 * @tc.name: NativeDrawingLineTest024
740 * @tc.desc: test for the textLine GetStringIndexForPosition.
741 * @tc.type: FUNC
742 */
743 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest024, TestSize.Level1)
744 {
745 PrepareCreateTextLine(
746 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
747 "Drawing \n\n \u231A \u513B"
748 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
749 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
750 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
751 EXPECT_EQ(size, 7);
752
753 const int maxCharacterNum = 223;
754 for (size_t index = 0; index < size; index++) {
755 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
756 EXPECT_TRUE(textLine != nullptr);
757
758 OH_Drawing_Point *point = OH_Drawing_PointCreate(1.0, 2.0);
759 int32_t characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
760 if (index == 0) {
761 EXPECT_EQ(characterIndex, 0);
762 } else {
763 EXPECT_GT(characterIndex, 0);
764 }
765 EXPECT_LT(characterIndex, maxCharacterNum);
766 OH_Drawing_PointSet(point, 400.0, 4.0);
767 characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
768 EXPECT_GT(characterIndex, 1);
769 EXPECT_LT(characterIndex, maxCharacterNum);
770 OH_Drawing_PointDestroy(point);
771 }
772 OH_Drawing_DestroyTextLines(textLines);
773 }
774
775 /*
776 * @tc.name: NativeDrawingLineTest025
777 * @tc.desc: test for the textLine GetStringIndexForPosition.
778 * @tc.type: FUNC
779 */
780 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest025, TestSize.Level1)
781 {
782 PrepareCreateTextLine("\n\n\n");
783 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
784 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
785 EXPECT_EQ(size, 4);
786
787 for (size_t index = 0; index < size - 1; index++) {
788 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
789 EXPECT_TRUE(textLine != nullptr);
790
791 OH_Drawing_Point *point = OH_Drawing_PointCreate(0.0, 2.0);
792 int32_t characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
793 EXPECT_EQ(characterIndex, index + 1);
794 OH_Drawing_PointSet(point, 400.0, 4.0);
795 characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, point);
796 EXPECT_EQ(characterIndex, index + 1);
797 OH_Drawing_PointDestroy(point);
798 }
799 OH_Drawing_DestroyTextLines(textLines);
800 }
801
802 /*
803 * @tc.name: NativeDrawingLineTest026
804 * @tc.desc: test for the textLine GetStringIndexForPosition.
805 * @tc.type: FUNC
806 */
807 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest026, TestSize.Level1)
808 {
809 PrepareCreateTextLine("\n\n");
810 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
811 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
812 EXPECT_EQ(size, 3);
813
814 OH_Drawing_TextLine* textLine = textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
815 EXPECT_TRUE(textLine != nullptr);
816
817 int32_t characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(textLine, nullptr);
818 EXPECT_EQ(characterIndex, 0);
819
820 OH_Drawing_Point *point = OH_Drawing_PointCreate(0.0, 2.0);
821 characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(nullptr, point);
822 EXPECT_EQ(characterIndex, 0);
823 OH_Drawing_PointDestroy(point);
824
825 characterIndex = OH_Drawing_TextLineGetStringIndexForPosition(nullptr, nullptr);
826 EXPECT_EQ(characterIndex, 0);
827
828 OH_Drawing_DestroyTextLines(textLines);
829 }
830
831 /*
832 * @tc.name: NativeDrawingLineTest027
833 * @tc.desc: test for the textLine GetOffsetForStringIndex.
834 * @tc.type: FUNC
835 */
836 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest027, TestSize.Level1)
837 {
838 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
839 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
840 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
841 EXPECT_EQ(size, 3);
842
843 const int maxCharacterNum = 88;
844 for (size_t index = 0; index < size; index++) {
845 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
846 EXPECT_TRUE(textLine != nullptr);
847
848 double offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 0);
849 EXPECT_EQ(offset, 0.0);
850 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 10);
851 if (index == 0) {
852 EXPECT_GT(offset, 1.0);
853 } else {
854 EXPECT_EQ(offset, 0.0);
855 }
856 EXPECT_LE(offset, 500.0);
857 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, maxCharacterNum);
858 EXPECT_GT(offset, 1.0);
859 EXPECT_LE(offset, 500.0);
860 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, -2);
861 EXPECT_EQ(offset, 0.0);
862 }
863 OH_Drawing_DestroyTextLines(textLines);
864 }
865
866 /*
867 * @tc.name: NativeDrawingLineTest028
868 * @tc.desc: test for the textLine GetOffsetForStringIndex.
869 * @tc.type: FUNC
870 */
871 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest028, TestSize.Level1)
872 {
873 PrepareCreateTextLine(
874 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
875 "Drawing \n\n \u231A \u513B"
876 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
877 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
878 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
879 EXPECT_EQ(size, 7);
880
881 const int maxCharacterNum = 88;
882 for (size_t index = 0; index < size; index++) {
883 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
884 EXPECT_TRUE(textLine != nullptr);
885
886 double offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 0);
887 EXPECT_EQ(offset, 0.0);
888 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 10);
889 if (index == 0) {
890 EXPECT_GT(offset, 1.0);
891 } else {
892 EXPECT_EQ(offset, 0.0);
893 }
894 EXPECT_LE(offset, 500.0);
895 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, maxCharacterNum);
896 if (index < 3) {
897 EXPECT_GT(offset, 1.0);
898 } else {
899 EXPECT_EQ(offset, 0.0);
900 }
901 EXPECT_LE(offset, 500.0);
902 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, -2);
903 EXPECT_EQ(offset, 0.0);
904 }
905 OH_Drawing_DestroyTextLines(textLines);
906 }
907
908 /*
909 * @tc.name: NativeDrawingLineTest029
910 * @tc.desc: test for the textLine GetOffsetForStringIndex.
911 * @tc.type: FUNC
912 */
913 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest029, TestSize.Level1)
914 {
915 PrepareCreateTextLine("\n\n");
916 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
917 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
918 EXPECT_EQ(size, 3);
919
920 for (size_t index = 0; index < size; index++) {
921 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
922 EXPECT_TRUE(textLine != nullptr);
923
924 double offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 0);
925 EXPECT_EQ(offset, 0.0);
926 offset = OH_Drawing_TextLineGetOffsetForStringIndex(textLine, 100);
927 EXPECT_EQ(offset, 0.0);
928 }
929 OH_Drawing_DestroyTextLines(textLines);
930
931 double offset = OH_Drawing_TextLineGetOffsetForStringIndex(nullptr, 0);
932 EXPECT_EQ(offset, 0.0);
933 }
934
935 /*
936 * @tc.name: NativeDrawingLineTest030
937 * @tc.desc: test for the textLine GetAlignmentOffset.
938 * @tc.type: FUNC
939 */
940 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest030, TestSize.Level1)
941 {
942 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
943 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
944 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
945 EXPECT_EQ(size, 3);
946
947 for (size_t index = 0; index < size; index++) {
948 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
949 EXPECT_TRUE(textLine != nullptr);
950
951 double offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.0, 600);
952 EXPECT_EQ(offset, 0.0);
953 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.5, 700);
954 EXPECT_GT(offset, 100.0);
955 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, -1.0, 700);
956 EXPECT_EQ(offset, 0.0);
957 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 2.0, 20);
958 EXPECT_EQ(offset, 0.0);
959 }
960 OH_Drawing_DestroyTextLines(textLines);
961 }
962
963 /*
964 * @tc.name: NativeDrawingLineTest031
965 * @tc.desc: test for the textLine GetAlignmentOffset.
966 * @tc.type: FUNC
967 */
968 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest031, TestSize.Level1)
969 {
970 PrepareCreateTextLine(
971 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
972 "Drawing \n\n \u231A \u513B"
973 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
974 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
975 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
976 EXPECT_EQ(size, 7);
977
978 for (size_t index = 0; index < size; index++) {
979 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
980 EXPECT_TRUE(textLine != nullptr);
981
982 double offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.0, 600);
983 EXPECT_EQ(offset, 0.0);
984 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.5, 700);
985 EXPECT_GT(offset, 100.0);
986 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, -1.0, 700);
987 EXPECT_EQ(offset, 0.0);
988 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 2.0, 20);
989 if (index == 3) {
990 EXPECT_EQ(offset, 20.0);
991 } else {
992 EXPECT_EQ(offset, 0.0);
993 }
994 }
995 OH_Drawing_DestroyTextLines(textLines);
996 }
997
998 /*
999 * @tc.name: NativeDrawingLineTest032
1000 * @tc.desc: test for the textLine GetAlignmentOffset.
1001 * @tc.type: FUNC
1002 */
1003 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest032, TestSize.Level1)
1004 {
1005 PrepareCreateTextLine("\n\n\n\n");
1006 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1007 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1008 EXPECT_EQ(size, 5);
1009
1010 for (size_t index = 0; index < size; index++) {
1011 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1012 EXPECT_TRUE(textLine != nullptr);
1013
1014 double offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.0, 600);
1015 EXPECT_EQ(offset, 0.0);
1016 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 0.5, 700);
1017 EXPECT_EQ(offset, 350.0);
1018 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, -1.0, -700);
1019 EXPECT_EQ(offset, 0.0);
1020 offset = OH_Drawing_TextLineGetAlignmentOffset(textLine, 2.0, 20);
1021 EXPECT_EQ(offset, 20.0);
1022 }
1023 OH_Drawing_DestroyTextLines(textLines);
1024
1025 double offset = OH_Drawing_TextLineGetAlignmentOffset(nullptr, 0.0, 0.0);
1026 EXPECT_EQ(offset, 0.0);
1027 }
1028
1029 /*
1030 * @tc.name: NativeDrawingLineTest033
1031 * @tc.desc: test for the textLine EnumerateCaretOffsets.
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest033, TestSize.Level1)
1035 {
1036 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
1037 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1038 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1039 EXPECT_EQ(size, 3);
1040
1041 for (size_t index = 0; index < size; index++) {
1042 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1043 EXPECT_TRUE(textLine != nullptr);
1044
__anon6c0965ba0202(double offset, int32_t index, bool leadingEdge) 1045 OH_Drawing_TextLineEnumerateCaretOffsets(textLine, [](double offset, int32_t index, bool leadingEdge) {
1046 static int offsetNum = 0;
1047 if (index == 0 && leadingEdge) {
1048 EXPECT_EQ(offset, 0.0);
1049 } else {
1050 EXPECT_LE(offset, 500.0);
1051 }
1052 if (offsetNum++ % 2 == 0) {
1053 EXPECT_TRUE(leadingEdge);
1054 } else {
1055 EXPECT_FALSE(leadingEdge);
1056 }
1057 EXPECT_LE(index, 51);
1058 return index > 50;
1059 });
1060 }
1061 OH_Drawing_DestroyTextLines(textLines);
1062 }
1063
1064 /*
1065 * @tc.name: NativeDrawingLineTest034
1066 * @tc.desc: test for the textLine EnumerateCaretOffsets.
1067 * @tc.type: FUNC
1068 */
1069 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest034, TestSize.Level1)
1070 {
1071 PrepareCreateTextLine(
1072 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
1073 "Drawing \n\n \u231A \u513B"
1074 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
1075 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1076 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1077 EXPECT_EQ(size, 7);
1078
1079 for (size_t index = 0; index < size; index++) {
1080 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1081 EXPECT_TRUE(textLine != nullptr);
1082
__anon6c0965ba0302(double offset, int32_t index, bool leadingEdge) 1083 OH_Drawing_TextLineEnumerateCaretOffsets(textLine, [](double offset, int32_t index, bool leadingEdge) {
1084 EXPECT_GE(index, 0);
1085 EXPECT_EQ(offset, 0.0);
1086 EXPECT_TRUE(leadingEdge);
1087 return true;
1088 });
1089 }
1090 OH_Drawing_DestroyTextLines(textLines);
1091 }
1092
1093 /*
1094 * @tc.name: NativeDrawingLineTest035
1095 * @tc.desc: test for the textLine EnumerateCaretOffsets.
1096 * @tc.type: FUNC
1097 */
1098 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest035, TestSize.Level1)
1099 {
1100 PrepareCreateTextLine("\n\n\n");
1101 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1102 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1103 EXPECT_EQ(size, 4);
1104
1105 for (size_t index = 0; index < size; index++) {
1106 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1107 EXPECT_TRUE(textLine != nullptr);
1108
__anon6c0965ba0402(double offset, int32_t index, bool leadingEdge) 1109 OH_Drawing_TextLineEnumerateCaretOffsets(textLine, [](double offset, int32_t index, bool leadingEdge) {
1110 EXPECT_GE(index, 0);
1111 EXPECT_EQ(offset, 0.0);
1112 EXPECT_TRUE(leadingEdge);
1113 return false;
1114 });
1115 }
1116 OH_Drawing_DestroyTextLines(textLines);
1117 }
1118
1119 /*
1120 * @tc.name: NativeDrawingLineTest036
1121 * @tc.desc: test for the textLine EnumerateCaretOffsets.
1122 * @tc.type: FUNC
1123 */
1124 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest036, TestSize.Level1)
1125 {
1126 PrepareCreateTextLine("\n\n");
1127 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1128 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1129 EXPECT_EQ(size, 3);
1130
1131 OH_Drawing_TextLine* textLine = textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
1132 EXPECT_TRUE(textLine != nullptr);
1133 OH_Drawing_TextLineEnumerateCaretOffsets(textLine, nullptr);
__anon6c0965ba0502(double offset, int32_t index, bool leadingEdge) 1134 OH_Drawing_TextLineEnumerateCaretOffsets(nullptr, [](double offset, int32_t index, bool leadingEdge) {
1135 return false;
1136 });
1137 OH_Drawing_TextLineEnumerateCaretOffsets(nullptr, nullptr);
1138 OH_Drawing_DestroyTextLines(textLines);
1139 }
1140
1141 /*
1142 * @tc.name: NativeDrawingLineTest037
1143 * @tc.desc: test for the textLine CreateTruncatedLine.
1144 * @tc.type: FUNC
1145 */
1146 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest037, TestSize.Level1)
1147 {
1148 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
1149 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1150 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1151 EXPECT_EQ(size, 3);
1152
1153 for (size_t index = 0; index < size; index++) {
1154 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1155 EXPECT_TRUE(textLine != nullptr);
1156
1157 OH_Drawing_TextLine *truncatedLine =
1158 OH_Drawing_TextLineCreateTruncatedLine(textLine, 100, ELLIPSIS_MODAL_HEAD, "...");
1159 EXPECT_TRUE(truncatedLine != nullptr);
1160 OH_Drawing_TextLinePaint(truncatedLine, canvas_, 30, 250);
1161 double count = OH_Drawing_TextLineGetGlyphCount(truncatedLine);
1162 EXPECT_GT(count, 0);
1163 OH_Drawing_DestroyTextLine(truncatedLine);
1164 truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(textLine, 80, ELLIPSIS_MODAL_MIDDLE, "...");
1165 EXPECT_TRUE(truncatedLine == nullptr);
1166 truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(textLine, 50, ELLIPSIS_MODAL_TAIL, "...");
1167 EXPECT_TRUE(truncatedLine != nullptr);
1168 OH_Drawing_TextLinePaint(truncatedLine, canvas_, 30, 550);
1169 count = OH_Drawing_TextLineGetGlyphCount(truncatedLine);
1170 EXPECT_GT(count, 0);
1171 OH_Drawing_DestroyTextLine(truncatedLine);
1172 }
1173 OH_Drawing_DestroyTextLines(textLines);
1174 }
1175 /*
1176 * @tc.name: NativeDrawingLineTest038
1177 * @tc.desc: test for the textLine CreateTruncatedLine.
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest038, TestSize.Level1)
1181 {
1182 PrepareCreateTextLine(
1183 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
1184 "Drawing \n\n \u231A \u513B"
1185 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
1186 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1187 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1188 EXPECT_EQ(size, 7);
1189
1190 for (size_t index = 0; index < size; index++) {
1191 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1192 EXPECT_TRUE(textLine != nullptr);
1193
1194 OH_Drawing_TextLine *truncatedLine =
1195 OH_Drawing_TextLineCreateTruncatedLine(textLine, 30, ELLIPSIS_MODAL_TAIL, "123");
1196 EXPECT_TRUE(truncatedLine != nullptr);
1197 OH_Drawing_TextLinePaint(truncatedLine, canvas_, 30, 150);
1198 double count = OH_Drawing_TextLineGetGlyphCount(truncatedLine);
1199 if (index == 3) {
1200 EXPECT_EQ(count, 0);
1201 } else {
1202 EXPECT_GT(count, 0);
1203 }
1204 OH_Drawing_DestroyTextLine(truncatedLine);
1205 truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(textLine, 30, ELLIPSIS_MODAL_HEAD, "测试");
1206 EXPECT_TRUE(truncatedLine != nullptr);
1207 OH_Drawing_TextLinePaint(truncatedLine, canvas_, 30, 300);
1208 count = OH_Drawing_TextLineGetGlyphCount(truncatedLine);
1209 if (index == 3) {
1210 EXPECT_EQ(count, 0);
1211 } else {
1212 EXPECT_GT(count, 0);
1213 }
1214 OH_Drawing_DestroyTextLine(truncatedLine);
1215 }
1216 OH_Drawing_DestroyTextLines(textLines);
1217 }
1218
1219 /*
1220 * @tc.name: NativeDrawingLineTest039
1221 * @tc.desc: test for the textLine CreateTruncatedLine.
1222 * @tc.type: FUNC
1223 */
1224 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest039, TestSize.Level1)
1225 {
1226 PrepareCreateTextLine("\n\n");
1227 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1228 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1229 EXPECT_EQ(size, 3);
1230
1231 OH_Drawing_TextLine* textLine = textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
1232 EXPECT_TRUE(textLine != nullptr);
1233
1234 OH_Drawing_TextLine *truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(nullptr, 20, ELLIPSIS_MODAL_TAIL, "1");
1235 EXPECT_TRUE(truncatedLine == nullptr);
1236
1237 truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(textLine, 200, 5, "1");
1238 EXPECT_TRUE(truncatedLine == nullptr);
1239
1240 truncatedLine = OH_Drawing_TextLineCreateTruncatedLine(textLine, 100, ELLIPSIS_MODAL_TAIL, nullptr);
1241 EXPECT_TRUE(truncatedLine == nullptr);
1242
1243 OH_Drawing_DestroyTextLines(textLines);
1244 }
1245
1246 /*
1247 * @tc.name: NativeDrawingLineTest040
1248 * @tc.desc: test for the textLine GetGlyphRuns.
1249 * @tc.type: FUNC
1250 */
1251 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest040, TestSize.Level1)
1252 {
1253 PrepareCreateTextLine("Hello 测 World \n!@#$%^&*~(){}[] 123 4567890 - = ,. < >、/Drawing testlp 试 Drawing ");
1254 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1255 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1256 EXPECT_EQ(size, 3);
1257
1258 for (size_t index = 0; index < size; index++) {
1259 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1260 EXPECT_TRUE(textLine != nullptr);
1261
1262 OH_Drawing_Array *runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
1263 EXPECT_TRUE(runs != nullptr);
1264 size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
1265 if (index == 1) {
1266 EXPECT_EQ(runsSize, 1);
1267 } else {
1268 EXPECT_GT(runsSize, 1);
1269 }
1270 OH_Drawing_DestroyRuns(runs);
1271 }
1272 OH_Drawing_DestroyTextLines(textLines);
1273 }
1274 /*
1275 * @tc.name: NativeDrawingLineTest041
1276 * @tc.desc: test for the textLine GetGlyphRuns.
1277 * @tc.type: FUNC
1278 */
1279 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest041, TestSize.Level1)
1280 {
1281 PrepareCreateTextLine(
1282 "Hello \t 中国 测 World \n !@#$%^&*~(){}[] 123 4567890 - = ,. < >、/ Drawing testlp 试 "
1283 "Drawing \n\n \u231A \u513B"
1284 " \u00A9\uFE0F aaa clp11⌚مرحبا中国 测 World测试文本\n123");
1285 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1286 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1287 EXPECT_EQ(size, 7);
1288
1289 for (size_t index = 0; index < size; index++) {
1290 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1291 EXPECT_TRUE(textLine != nullptr);
1292
1293 OH_Drawing_Array *runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
1294 size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
1295 if (index == 3) {
1296 EXPECT_TRUE(runs == nullptr);
1297 EXPECT_EQ(runsSize, 0);
1298 } else if (index == 1 || index == 6) {
1299 EXPECT_TRUE(runs != nullptr);
1300 EXPECT_EQ(runsSize, 1);
1301 } else {
1302 EXPECT_TRUE(runs != nullptr);
1303 EXPECT_GE(runsSize, 6);
1304 }
1305 OH_Drawing_DestroyRuns(runs);
1306 }
1307 OH_Drawing_DestroyTextLines(textLines);
1308 }
1309 /*
1310 * @tc.name: NativeDrawingLineTest042
1311 * @tc.desc: test for the textLine GetGlyphRuns.
1312 * @tc.type: FUNC
1313 */
1314 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest042, TestSize.Level1)
1315 {
1316 PrepareCreateTextLine("\n\n\n");
1317 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1318 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1319 EXPECT_EQ(size, 4);
1320
1321 for (size_t index = 0; index < size - 1; index++) {
1322 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
1323 EXPECT_TRUE(textLine != nullptr);
1324
1325 OH_Drawing_Array *runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
1326 EXPECT_TRUE(runs == nullptr);
1327 size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
1328 EXPECT_EQ(runsSize, 0);
1329 OH_Drawing_DestroyRuns(runs);
1330 }
1331 OH_Drawing_DestroyTextLines(textLines);
1332 }
1333 /*
1334 * @tc.name: NativeDrawingLineTest043
1335 * @tc.desc: test for the textLine GetGlyphRuns.
1336 * @tc.type: FUNC
1337 */
1338 HWTEST_F(NativeDrawingLineTest, NativeDrawingLineTest043, TestSize.Level1)
1339 {
1340 PrepareCreateTextLine("\n\n");
1341 OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
1342 size_t size = OH_Drawing_GetDrawingArraySize(textLines);
1343 EXPECT_EQ(size, 3);
1344
1345 OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
1346 EXPECT_TRUE(textLine != nullptr);
1347
1348 OH_Drawing_Array *runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
1349 EXPECT_TRUE(runs == nullptr);
1350
1351 runs = OH_Drawing_TextLineGetGlyphRuns(nullptr);
1352 EXPECT_TRUE(runs == nullptr);
1353
1354 OH_Drawing_DestroyTextLines(textLines);
1355 }
1356 }