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