• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 <fstream>
17 #include <string>
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_path.h"
26 #include "drawing_pen.h"
27 #include "drawing_rect.h"
28 #include "drawing_point.h"
29 #include "drawing_text_declaration.h"
30 #include "drawing_text_line.h"
31 #include "drawing_text_run.h"
32 #include "drawing_text_typography.h"
33 #include "gtest/gtest.h"
34 #include "rosen_text/typography.h"
35 #include "rosen_text/typography_create.h"
36 #include "text_style.h"
37 #include "txt/text_bundle_config_parser.h"
38 
39 using namespace OHOS::Rosen;
40 using namespace testing;
41 using namespace testing::ext;
42 
43 namespace OHOS {
44 namespace {
45 const double LEFT_POS = 50.0;
46 const double RIGHT_POS = 150.0;
47 const double ARC_FONT_SIZE = 30;
48 const double DEFAULT_FONT_SIZE = 50;
49 const char* DEFAULT_TEXT = "text";
50 const char* DEFAULT_LONG_TEXT =
51     "中文你好世界。 English Hello World.中文你好世界。 English Hello World.中文你好世界。 English Hello "
52     "World.中文你好世界。 English Hello World.";
53 const double MAX_WIDTH = 800.0;
54 const double SWEEP_DEGREE = 180.0;
55 constexpr static float FLOAT_DATA_EPSILON = 1e-6f;
56 const std::string VIS_LIST_FILE_NAME = "/system/fonts/visibility_list.json";
57 } // namespace
58 
59 class NdkTypographyTest : public testing::Test {
60 public:
61     void SetUp() override;
62     void TearDown() override;
63     void CreateTypographyHandler();
64     void CreateTypography();
65     void AddText();
66     void Layout();
67     void Paint();
68 
69 protected:
70     OH_Drawing_TypographyCreate* fHandler{nullptr};
71     OH_Drawing_Typography* fTypography{nullptr};
72     OH_Drawing_TypographyStyle* fTypoStyle{nullptr};
73     OH_Drawing_Canvas* fCanvas{nullptr};
74     OH_Drawing_Bitmap* fBitmap{nullptr};
75     int fLayoutWidth{50};
76 };
77 
SetUp()78 void NdkTypographyTest::SetUp()
79 {
80     fTypoStyle = OH_Drawing_CreateTypographyStyle();
81     ASSERT_NE(fTypoStyle, nullptr);
82     OH_Drawing_SetTypographyTextFontSize(fTypoStyle, DEFAULT_FONT_SIZE);
83 }
84 
TearDown()85 void NdkTypographyTest::TearDown()
86 {
87     if (fHandler != nullptr) {
88         OH_Drawing_DestroyTypographyHandler(fHandler);
89         fHandler = nullptr;
90     }
91     if (fTypography != nullptr) {
92         OH_Drawing_DestroyTypography(fTypography);
93         fTypography = nullptr;
94     }
95     if (fTypoStyle != nullptr) {
96         OH_Drawing_DestroyTypographyStyle(fTypoStyle);
97         fTypoStyle = nullptr;
98     }
99     if (fBitmap != nullptr) {
100         OH_Drawing_BitmapDestroy(fBitmap);
101         fBitmap = nullptr;
102     }
103     if (fCanvas != nullptr) {
104         OH_Drawing_CanvasDestroy(fCanvas);
105         fCanvas = nullptr;
106     }
107 }
108 
CreateTypographyHandler()109 void NdkTypographyTest::CreateTypographyHandler()
110 {
111     fHandler = OH_Drawing_CreateTypographyHandler(fTypoStyle, OH_Drawing_CreateFontCollection());
112     ASSERT_NE(fHandler, nullptr);
113 }
114 
CreateTypography()115 void NdkTypographyTest::CreateTypography()
116 {
117     fTypography = OH_Drawing_CreateTypography(fHandler);
118     ASSERT_NE(fTypography, nullptr);
119 }
120 
AddText()121 void NdkTypographyTest::AddText()
122 {
123     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
124     ASSERT_NE(txtStyle, nullptr);
125     OH_Drawing_SetTextStyleFontSize(txtStyle, DEFAULT_FONT_SIZE);
126     OH_Drawing_TypographyHandlerPushTextStyle(fHandler, txtStyle);
127     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
128 }
129 
130 
Layout()131 void NdkTypographyTest::Layout()
132 {
133     OH_Drawing_TypographyLayout(fTypography, fLayoutWidth);
134 }
135 
Paint()136 void NdkTypographyTest::Paint()
137 {
138     double position[2] = {10.0, 15.0};
139     fBitmap = OH_Drawing_BitmapCreate();
140     fCanvas = OH_Drawing_CanvasCreate();
141     ASSERT_NE(fTypography, nullptr);
142     OH_Drawing_CanvasBind(fCanvas, fBitmap);
143     OH_Drawing_CanvasClear(fCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
144     OH_Drawing_TypographyPaint(fTypography, fCanvas, position[0], position[1]);
145 }
146 
ConvertToOriginalText(OH_Drawing_TypographyStyle * style)147 static TypographyStyle* ConvertToOriginalText(OH_Drawing_TypographyStyle* style)
148 {
149     return reinterpret_cast<TypographyStyle*>(style);
150 }
151 
ConvertToOriginalText(OH_Drawing_TextStyle * style)152 static TextStyle* ConvertToOriginalText(OH_Drawing_TextStyle* style)
153 {
154     return reinterpret_cast<TextStyle*>(style);
155 }
156 
CheckTypographyRectsForRange(OH_Drawing_Typography * typography)157 static void CheckTypographyRectsForRange(OH_Drawing_Typography* typography)
158 {
159     struct TextBoxTestCase {
160         size_t start;
161         size_t end;
162         OH_Drawing_RectHeightStyle heightStyle;
163         OH_Drawing_RectWidthStyle widthStyle;
164         float expectedLeft;
165         float expectedTop;
166         float expectedRight;
167         float expectedBottom;
168     };
169     std::vector<TextBoxTestCase> RANGE_TEST_RESULT = {
170         { 0, 2, RECT_HEIGHT_STYLE_MAX, RECT_WIDTH_STYLE_TIGHT, 0.0f, 0.0f, 239.999786f, 360.000000f },
171         { 5, 7, RECT_HEIGHT_STYLE_STRUCT, RECT_WIDTH_STYLE_TIGHT, 599.999451f, 60.0f, 839.999207f, 300.0f },
172         { 34, 36, RECT_HEIGHT_STYLE_INCLUDELINESPACETOP, RECT_WIDTH_STYLE_TIGHT, 806.039307f, 720.000000f,
173             1046.039062f, 1080.000000f },
174         { 37, 39, RECT_HEIGHT_STYLE_INCLUDELINESPACEMIDDLE, RECT_WIDTH_STYLE_TIGHT, 0.000000f, 1149.337036f,
175             239.999817f, 1509.337036f },
176         { 41, 43, RECT_HEIGHT_STYLE_INCLUDELINESPACEBOTTOM, RECT_WIDTH_STYLE_TIGHT, 479.999573f, 1218.674072f,
177             719.999329f, 1578.674072f },
178         { 45, 47, RECT_HEIGHT_STYLE_TIGHT, RECT_WIDTH_STYLE_TIGHT,
179             959.999084f, 1218.674072f, 1199.998779f, 1359.314209f },
180         { 49, 51, RECT_HEIGHT_STYLE_TIGHT, RECT_WIDTH_STYLE_MAX, 240.000000f, 1578.674072f, 480.000000f, 1719.314209f }
181     };
182     for (size_t i = 0; i < RANGE_TEST_RESULT.size(); ++i) {
183         auto rect = OH_Drawing_TypographyGetRectsForRange(typography, RANGE_TEST_RESULT[i].start,
184             RANGE_TEST_RESULT[i].end, RANGE_TEST_RESULT[i].heightStyle, RANGE_TEST_RESULT[i].widthStyle);
185         const auto& testCase = RANGE_TEST_RESULT[i];
186         const float left = OH_Drawing_GetLeftFromTextBox(rect, 0);
187         const float right = OH_Drawing_GetRightFromTextBox(rect, 0);
188         const float top = OH_Drawing_GetTopFromTextBox(rect, 0);
189         const float bottom = OH_Drawing_GetBottomFromTextBox(rect, 0);
190         EXPECT_NEAR(left, testCase.expectedLeft, FLOAT_DATA_EPSILON);
191         EXPECT_NEAR(right, testCase.expectedRight, FLOAT_DATA_EPSILON);
192         EXPECT_NEAR(top, testCase.expectedTop, FLOAT_DATA_EPSILON);
193         EXPECT_NEAR(bottom, testCase.expectedBottom, FLOAT_DATA_EPSILON);
194         OH_Drawing_TypographyDestroyTextBox(rect);
195     }
196 }
197 /*
198  * @tc.name: TypographyTest001
199  * @tc.desc: test for creating TypographyStyle
200  * @tc.type: FUNC
201  */
202 HWTEST_F(NdkTypographyTest, TypographyTest001, TestSize.Level0)
203 {
204     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
205     EXPECT_NE(typoStyle, nullptr);
206     OH_Drawing_DestroyTypographyStyle(typoStyle);
207     OH_Drawing_DestroyTypographyStyle(nullptr);
208 }
209 
210 /*
211  * @tc.name: TypographyTest002
212  * @tc.desc: test for text direction
213  * @tc.type: FUNC
214  */
215 HWTEST_F(NdkTypographyTest, TypographyTest002, TestSize.Level0)
216 {
217     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
218     OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);
219     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::LTR);
220     OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_RTL);
221     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::RTL);
222     OH_Drawing_SetTypographyTextDirection(typoStyle, -1);
223     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::LTR);
224     OH_Drawing_SetTypographyTextDirection(nullptr, 0);
225     OH_Drawing_DestroyTypographyStyle(typoStyle);
226 }
227 
228 /*
229  * @tc.name: TypographyTest003
230  * @tc.desc: test for text alignment
231  * @tc.type: FUNC
232  */
233 HWTEST_F(NdkTypographyTest, TypographyTest003, TestSize.Level0)
234 {
235     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
236     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);
237     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::LEFT);
238     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_RIGHT);
239     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::RIGHT);
240     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_CENTER);
241     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::CENTER);
242     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_JUSTIFY);
243     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::JUSTIFY);
244     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_START);
245     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::START);
246     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_END);
247     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::END);
248     OH_Drawing_SetTypographyTextAlign(typoStyle, -1);
249     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::LEFT);
250     OH_Drawing_SetTypographyTextAlign(nullptr, 0);
251     OH_Drawing_DestroyTypographyStyle(typoStyle);
252 }
253 
254 /*
255  * @tc.name: TypographyTest004
256  * @tc.desc: test for max lines
257  * @tc.type: FUNC
258  */
259 HWTEST_F(NdkTypographyTest, TypographyTest004, TestSize.Level0)
260 {
261     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
262     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 100);
263     EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines, 100);
264     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 200);
265     EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines, 200);
266     OH_Drawing_SetTypographyTextMaxLines(typoStyle, -100);
267     EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines, 0);
268     OH_Drawing_SetTypographyTextMaxLines(nullptr, 0);
269     OH_Drawing_DestroyTypographyStyle(typoStyle);
270 }
271 
272 /*
273  * @tc.name: TypographyTest005
274  * @tc.desc: test for creating text style
275  * @tc.type: FUNC
276  */
277 HWTEST_F(NdkTypographyTest, TypographyTest005, TestSize.Level0)
278 {
279     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
280     EXPECT_NE(txtStyle, nullptr);
281     OH_Drawing_DestroyTextStyle(txtStyle);
282     OH_Drawing_DestroyTextStyle(nullptr);
283 }
284 
285 /*
286  * @tc.name: TypographyTest006
287  * @tc.desc: test for text color
288  * @tc.type: FUNC
289  */
290 HWTEST_F(NdkTypographyTest, TypographyTest006, TestSize.Level0)
291 {
292     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
293     // black
294     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
295     EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFF000000);
296     // red
297     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
298     EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFFFF0000);
299     // blue
300     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF));
301     EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFF0000FF);
302     OH_Drawing_SetTextStyleColor(nullptr, 0);
303     OH_Drawing_DestroyTextStyle(txtStyle);
304 }
305 
306 /*
307  * @tc.name: TypographyTest007
308  * @tc.desc: test for font size
309  * @tc.type: FUNC
310  */
311 HWTEST_F(NdkTypographyTest, TypographyTest007, TestSize.Level0)
312 {
313     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
314     OH_Drawing_SetTextStyleFontSize(txtStyle, 80);
315     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize, 80);
316     OH_Drawing_SetTextStyleFontSize(txtStyle, 40);
317     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize, 40);
318     OH_Drawing_SetTextStyleFontSize(txtStyle, -40);
319     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize, -40);
320     OH_Drawing_SetTextStyleFontSize(nullptr, 0);
321     OH_Drawing_DestroyTextStyle(txtStyle);
322 }
323 
324 /*
325  * @tc.name: TypographyTest008
326  * @tc.desc: test for font weight
327  * @tc.type: FUNC
328  */
329 HWTEST_F(NdkTypographyTest, TypographyTest008, TestSize.Level0)
330 {
331     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
332     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_100);
333     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W100);
334     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200);
335     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W200);
336     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_300);
337     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W300);
338     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
339     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W400);
340     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_500);
341     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W500);
342     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_600);
343     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W600);
344     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_700);
345     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W700);
346     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_800);
347     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W800);
348     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_900);
349     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W900);
350     OH_Drawing_SetTextStyleFontWeight(txtStyle, -1);
351     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W400);
352     OH_Drawing_SetTextStyleFontWeight(nullptr, 0);
353     OH_Drawing_DestroyTextStyle(txtStyle);
354 }
355 
356 /*
357  * @tc.name: TypographyTest009
358  * @tc.desc: test for baseline location
359  * @tc.type: FUNC
360  */
361 HWTEST_F(NdkTypographyTest, TypographyTest009, TestSize.Level0)
362 {
363     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
364     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
365     EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::ALPHABETIC);
366     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC);
367     EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::IDEOGRAPHIC);
368     OH_Drawing_SetTextStyleBaseLine(txtStyle, -1);
369     EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::ALPHABETIC);
370     OH_Drawing_SetTextStyleBaseLine(nullptr, 0);
371     OH_Drawing_DestroyTextStyle(txtStyle);
372 }
373 
374 /*
375  * @tc.name: TypographyTest010
376  * @tc.desc: test for text decoration
377  * @tc.type: FUNC
378  */
379 HWTEST_F(NdkTypographyTest, TypographyTest010, TestSize.Level0)
380 {
381     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
382     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE);
383     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::NONE);
384     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE);
385     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE);
386     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_OVERLINE);
387     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
388     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_LINE_THROUGH);
389     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::LINE_THROUGH);
390     OH_Drawing_SetTextStyleDecoration(txtStyle, -1);
391     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::NONE);
392     OH_Drawing_SetTextStyleDecoration(nullptr, 0);
393     OH_Drawing_DestroyTextStyle(txtStyle);
394 }
395 
396 /*
397  * @tc.name: TypographyTest011
398  * @tc.desc: test for text decoration color
399  * @tc.type: FUNC
400  */
401 HWTEST_F(NdkTypographyTest, TypographyTest011, TestSize.Level0)
402 {
403     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
404     OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
405     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor, 0xFF000000);
406     OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
407     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor, 0xFFFF0000);
408     OH_Drawing_SetTextStyleDecorationColor(nullptr, 0);
409     OH_Drawing_DestroyTextStyle(txtStyle);
410 }
411 
412 /*
413  * @tc.name: TypographyTest012
414  * @tc.desc: test for font height
415  * @tc.type: FUNC
416  */
417 HWTEST_F(NdkTypographyTest, TypographyTest012, TestSize.Level0)
418 {
419     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
420     OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.0);
421     EXPECT_EQ(ConvertToOriginalText(txtStyle)->heightScale, 0.0);
422     OH_Drawing_SetTextStyleFontHeight(txtStyle, -1.0);
423     EXPECT_EQ(ConvertToOriginalText(txtStyle)->heightScale, -1.0);
424     OH_Drawing_SetTextStyleFontHeight(nullptr, 0);
425     OH_Drawing_DestroyTextStyle(txtStyle);
426 }
427 
428 /*
429  * @tc.name: TypographyTest013
430  * @tc.desc: test for font families
431  * @tc.type: FUNC
432  */
433 HWTEST_F(NdkTypographyTest, TypographyTest013, TestSize.Level0)
434 {
435     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
436     const char* fontFamilies[] = { "Roboto", "Arial" };
437     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 2, fontFamilies);
438     std::vector<std::string> fontFamiliesResult = { "Roboto", "Arial" };
439     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontFamilies, fontFamiliesResult);
440     OH_Drawing_SetTextStyleFontFamilies(nullptr, 0, nullptr);
441     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 0, nullptr);
442     OH_Drawing_DestroyTextStyle(txtStyle);
443 }
444 
445 /*
446  * @tc.name: TypographyTest014
447  * @tc.desc: test for font italic
448  * @tc.type: FUNC
449  */
450 HWTEST_F(NdkTypographyTest, TypographyTest014, TestSize.Level0)
451 {
452     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
453     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
454     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::NORMAL);
455     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_ITALIC);
456     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::ITALIC);
457     OH_Drawing_SetTextStyleFontStyle(txtStyle, -1);
458     EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::NORMAL);
459     OH_Drawing_SetTextStyleFontStyle(nullptr, 0);
460     OH_Drawing_DestroyTextStyle(txtStyle);
461 }
462 
463 /*
464  * @tc.name: TypographyTest015
465  * @tc.desc: test for font locale
466  * @tc.type: FUNC
467  */
468 HWTEST_F(NdkTypographyTest, TypographyTest015, TestSize.Level0)
469 {
470     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
471     OH_Drawing_SetTextStyleLocale(txtStyle, "en");
472     EXPECT_EQ(ConvertToOriginalText(txtStyle)->locale, "en");
473     OH_Drawing_SetTextStyleLocale(txtStyle, "zh");
474     EXPECT_EQ(ConvertToOriginalText(txtStyle)->locale, "zh");
475     OH_Drawing_SetTextStyleLocale(nullptr, "");
476     OH_Drawing_DestroyTextStyle(txtStyle);
477 }
478 
479 /*
480  * @tc.name: TypographyTest016
481  * @tc.desc: test for typography
482  * @tc.type: FUNC
483  */
484 HWTEST_F(NdkTypographyTest, TypographyTest016, TestSize.Level0)
485 {
486     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
487     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
488     OH_Drawing_TypographyCreate* handler =
489         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
490     EXPECT_NE(handler, nullptr);
491 
492     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
493     double fontSize = 30;
494     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
495     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
496     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
497     const char* fontFamilies[] = { "Roboto" };
498     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
499     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
500     const char* text = "OpenHarmony\n";
501     OH_Drawing_TypographyHandlerAddText(handler, text);
502     OH_Drawing_TypographyHandlerPopTextStyle(handler);
503     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
504     const float indents[] = { 1.2, 3.4 };
505     OH_Drawing_TypographySetIndents(typography, 2, indents);
506     EXPECT_EQ(indents[1], OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
507     EXPECT_EQ(indents[0], OH_Drawing_TypographyGetIndentsWithIndex(typography, 0));
508     double maxWidth = 800.0;
509     EXPECT_EQ(static_cast<int>(OH_Drawing_TypographyGetAlphabeticBaseline(typography)), 0);
510     EXPECT_EQ(static_cast<int>(OH_Drawing_TypographyGetIdeographicBaseline(typography)), 0);
511     OH_Drawing_TypographyLayout(typography, maxWidth);
512     EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
513     double position[2] = { 10.0, 15.0 };
514     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
515     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
516     uint32_t width = 20;
517     uint32_t height = 40;
518     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
519     EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap));
520     EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap));
521     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
522     OH_Drawing_CanvasBind(cCanvas, cBitmap);
523     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
524     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography), 70);
525     EXPECT_EQ(static_cast<int>(OH_Drawing_TypographyGetLongestLine(typography)), 200);
526     EXPECT_TRUE(OH_Drawing_TypographyGetLongestLine(typography) <= maxWidth);
527     EXPECT_EQ(
528         OH_Drawing_TypographyGetMinIntrinsicWidth(typography), OH_Drawing_TypographyGetMaxIntrinsicWidth(typography));
529     EXPECT_EQ(static_cast<int>(OH_Drawing_TypographyGetAlphabeticBaseline(typography)), 27);
530     EXPECT_EQ(static_cast<int>(OH_Drawing_TypographyGetIdeographicBaseline(typography)), 35);
531     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
532     OH_Drawing_DestroyTypography(typography);
533     OH_Drawing_DestroyTypographyHandler(handler);
534     OH_Drawing_DestroyTextStyle(txtStyle);
535 }
536 
537 /*
538  * @tc.name: TypographyBreakStrategyTest001
539  * @tc.desc: test for break strategy GREEDY
540  * @tc.type: FUNC
541  */
542 HWTEST_F(NdkTypographyTest, TypographyBreakStrategyTest001, TestSize.Level0)
543 {
544     OH_Drawing_SetTypographyTextBreakStrategy(nullptr, 0);
545     OH_Drawing_SetTypographyTextBreakStrategy(fTypoStyle, -1);
546     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->breakStrategy, BreakStrategy::GREEDY);
547 
548     OH_Drawing_SetTypographyTextBreakStrategy(fTypoStyle, BREAK_STRATEGY_GREEDY);
549     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->breakStrategy, BreakStrategy::GREEDY);
550     CreateTypographyHandler();
551     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
552     CreateTypography();
553     OH_Drawing_TypographyLayout(fTypography, 200);
554     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
555     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
556 }
557 
558 /*
559  * @tc.name: TypographyBreakStrategyTest002
560  * @tc.desc: test for break strategy HIGH_QUALITY
561  * @tc.type: FUNC
562  */
563 HWTEST_F(NdkTypographyTest, TypographyBreakStrategyTest002, TestSize.Level0)
564 {
565     OH_Drawing_SetTypographyTextBreakStrategy(fTypoStyle, BREAK_STRATEGY_HIGH_QUALITY);
566     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->breakStrategy, BreakStrategy::HIGH_QUALITY);
567     CreateTypographyHandler();
568     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
569     CreateTypography();
570     OH_Drawing_TypographyLayout(fTypography, 200);
571     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
572     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
573 }
574 
575 /*
576  * @tc.name: TypographyBreakStrategyTest003
577  * @tc.desc: test for break strategy BALANCED
578  * @tc.type: FUNC
579  */
580 HWTEST_F(NdkTypographyTest, TypographyBreakStrategyTest003, TestSize.Level0)
581 {
582     OH_Drawing_SetTypographyTextBreakStrategy(fTypoStyle, BREAK_STRATEGY_BALANCED);
583     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->breakStrategy, BreakStrategy::BALANCED);
584     CreateTypographyHandler();
585     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
586     CreateTypography();
587     OH_Drawing_TypographyLayout(fTypography, 200);
588     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
589     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
590 }
591 
592 /*
593  * @tc.name: TypographyWordBreakTest001
594  * @tc.desc: test for word break type
595  * @tc.type: FUNC
596  */
597 HWTEST_F(NdkTypographyTest, TypographyWordBreakTest001, TestSize.Level0)
598 {
599     OH_Drawing_SetTypographyTextWordBreakType(nullptr, 0);
600     OH_Drawing_SetTypographyTextWordBreakType(fTypoStyle, -1);
601     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->wordBreakType, WordBreakType::BREAK_WORD);
602 
603     OH_Drawing_SetTypographyTextWordBreakType(fTypoStyle, WORD_BREAK_TYPE_NORMAL);
604     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->wordBreakType, WordBreakType::NORMAL);
605     CreateTypographyHandler();
606     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
607     CreateTypography();
608     OH_Drawing_TypographyLayout(fTypography, 200);
609     EXPECT_EQ(OH_Drawing_TypographyGetLineCount(fTypography), 20);
610     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
611     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
612 }
613 
614 /*
615  * @tc.name: TypographyWordBreakTest002
616  * @tc.desc: test for word break type
617  * @tc.type: FUNC
618  */
619 HWTEST_F(NdkTypographyTest, TypographyWordBreakTest002, TestSize.Level0)
620 {
621     OH_Drawing_SetTypographyTextWordBreakType(fTypoStyle, WORD_BREAK_TYPE_BREAK_ALL);
622     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->wordBreakType, WordBreakType::BREAK_ALL);
623     CreateTypographyHandler();
624     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
625     CreateTypography();
626     OH_Drawing_TypographyLayout(fTypography, 200);
627     EXPECT_EQ(OH_Drawing_TypographyGetLineCount(fTypography), 18);
628     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1062);
629     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 213);
630 }
631 
632 /*
633  * @tc.name: TypographyWordBreakTest003
634  * @tc.desc: test for word break type
635  * @tc.type: FUNC
636  */
637 HWTEST_F(NdkTypographyTest, TypographyWordBreakTest003, TestSize.Level0)
638 {
639     OH_Drawing_SetTypographyTextWordBreakType(fTypoStyle, WORD_BREAK_TYPE_BREAK_WORD);
640     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->wordBreakType, WordBreakType::BREAK_WORD);
641     CreateTypographyHandler();
642     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
643     CreateTypography();
644     OH_Drawing_TypographyLayout(fTypography, 200);
645     EXPECT_EQ(OH_Drawing_TypographyGetLineCount(fTypography), 20);
646     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
647     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
648 }
649 
650 /*
651  * @tc.name: TypographyWordBreakTest004
652  * @tc.desc: test for word break type
653  * @tc.type: FUNC
654  */
655 HWTEST_F(NdkTypographyTest, TypographyWordBreakTest004, TestSize.Level0)
656 {
657     OH_Drawing_SetTypographyTextWordBreakType(fTypoStyle, WORD_BREAK_TYPE_BREAK_HYPHEN);
658     EXPECT_EQ(ConvertToOriginalText(fTypoStyle)->wordBreakType, WordBreakType::BREAK_HYPHEN);
659     CreateTypographyHandler();
660     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
661     CreateTypography();
662     OH_Drawing_TypographyLayout(fTypography, 200);
663     EXPECT_EQ(OH_Drawing_TypographyGetLineCount(fTypography), 20);
664     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 1180);
665     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 200);
666 }
667 
668 /*
669  * @tc.name: TypographyTest019
670  * @tc.desc: test for ellipsis modal
671  * @tc.type: FUNC
672  */
673 HWTEST_F(NdkTypographyTest, TypographyTest019, TestSize.Level0)
674 {
675     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
676     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_HEAD);
677     EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::HEAD);
678     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_MIDDLE);
679     EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::MIDDLE);
680     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_TAIL);
681     EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::TAIL);
682     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, -1);
683     EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::TAIL);
684     OH_Drawing_SetTypographyTextEllipsisModal(nullptr, 0);
685     OH_Drawing_DestroyTypographyStyle(typoStyle);
686 }
687 
688 /*
689  * @tc.name: TypographyTest020
690  * @tc.desc: test for decoration style
691  * @tc.type: FUNC
692  */
693 HWTEST_F(NdkTypographyTest, TypographyTest020, TestSize.Level0)
694 {
695     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
696     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_SOLID);
697     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::SOLID);
698     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DOUBLE);
699     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DOUBLE);
700     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DOTTED);
701     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DOTTED);
702     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DASHED);
703     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DASHED);
704     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_WAVY);
705     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::WAVY);
706     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, -1);
707     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::SOLID);
708     OH_Drawing_SetTextStyleDecorationStyle(nullptr, 0);
709     OH_Drawing_DestroyTextStyle(txtStyle);
710 }
711 
712 /*
713  * @tc.name: TypographyTest021
714  * @tc.desc: test for decoration thickness scale
715  * @tc.type: FUNC
716  */
717 HWTEST_F(NdkTypographyTest, TypographyTest021, TestSize.Level0)
718 {
719     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
720     OH_Drawing_SetTextStyleDecorationThicknessScale(txtStyle, 10);
721     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessScale, 10);
722     OH_Drawing_SetTextStyleDecorationThicknessScale(txtStyle, 20);
723     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessScale, 20);
724     OH_Drawing_SetTextStyleDecorationThicknessScale(txtStyle, -20);
725     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessScale, -20);
726     OH_Drawing_SetTextStyleDecorationThicknessScale(nullptr, 0);
727     OH_Drawing_DestroyTextStyle(txtStyle);
728 }
729 
730 /*
731  * @tc.name: TypographyTest022
732  * @tc.desc: test for letter spacing
733  * @tc.type: FUNC
734  */
735 HWTEST_F(NdkTypographyTest, TypographyTest022, TestSize.Level0)
736 {
737     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
738     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 10);
739     EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing, 10);
740     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 20);
741     EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing, 20);
742     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, -20);
743     EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing, -20);
744     OH_Drawing_SetTextStyleLetterSpacing(nullptr, 0);
745     OH_Drawing_DestroyTextStyle(txtStyle);
746 }
747 
748 /*
749  * @tc.name: TypographyTest023
750  * @tc.desc: test for word spacing
751  * @tc.type: FUNC
752  */
753 HWTEST_F(NdkTypographyTest, TypographyTest023, TestSize.Level0)
754 {
755     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
756     OH_Drawing_SetTextStyleWordSpacing(txtStyle, 10);
757     EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing, 10);
758     OH_Drawing_SetTextStyleWordSpacing(txtStyle, 20);
759     EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing, 20);
760     OH_Drawing_SetTextStyleWordSpacing(txtStyle, -20);
761     EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing, -20);
762     OH_Drawing_SetTextStyleWordSpacing(nullptr, 0);
763     OH_Drawing_DestroyTextStyle(txtStyle);
764 }
765 
766 /*
767  * @tc.name: TypographyTest024
768  * @tc.desc: test for ellipsis modal
769  * @tc.type: FUNC
770  */
771 HWTEST_F(NdkTypographyTest, TypographyTest024, TestSize.Level0)
772 {
773     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
774     OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_HEAD);
775     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::HEAD);
776     OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_MIDDLE);
777     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::MIDDLE);
778     OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_TAIL);
779     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::TAIL);
780     OH_Drawing_SetTextStyleEllipsisModal(txtStyle, -1);
781     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::TAIL);
782     OH_Drawing_SetTextStyleEllipsisModal(nullptr, 0);
783     OH_Drawing_DestroyTextStyle(txtStyle);
784 }
785 
786 /*
787  * @tc.name: TypographyTest025
788  * @tc.desc: test for set ellipsis
789  * @tc.type: FUNC
790  */
791 HWTEST_F(NdkTypographyTest, TypographyTest025, TestSize.Level0)
792 {
793     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
794     OH_Drawing_SetTextStyleEllipsis(txtStyle, "...");
795     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsis, u"...");
796     OH_Drawing_SetTextStyleEllipsis(txtStyle, "hello");
797     EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsis, u"hello");
798     OH_Drawing_SetTextStyleEllipsis(nullptr, nullptr);
799     OH_Drawing_SetTextStyleEllipsis(txtStyle, nullptr);
800     OH_Drawing_DestroyTextStyle(txtStyle);
801 }
802 
803 /*
804  * @tc.name: TypographyTest026
805  * @tc.desc: test for typography and txtStyle
806  * @tc.type: FUNC
807  */
808 HWTEST_F(NdkTypographyTest, TypographyTest026, TestSize.Level0)
809 {
810     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
811     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
812     OH_Drawing_TypographyCreate* handler =
813         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
814     EXPECT_NE(handler, nullptr);
815     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
816     double fontSize = 30;
817     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
818     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
819     bool halfLeading = true;
820     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
821     const char* fontFamilies[] = { "Roboto" };
822     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
823     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
824     const char* text = "OpenHarmony\n";
825     OH_Drawing_TypographyHandlerAddText(handler, text);
826     OH_Drawing_PlaceholderSpan placeholderSpan = { 20, 40, ALIGNMENT_OFFSET_AT_BASELINE, TEXT_BASELINE_ALPHABETIC, 10 };
827     OH_Drawing_TypographyHandlerAddPlaceholder(handler, &placeholderSpan);
828     OH_Drawing_TypographyHandlerPopTextStyle(handler);
829     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
830     double maxWidth = 800.0;
831     OH_Drawing_TypographyLayout(typography, maxWidth);
832     double position[2] = { 10.0, 15.0 };
833     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
834     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
835     uint32_t width = 20;
836     uint32_t height = 40;
837     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
838     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
839     OH_Drawing_CanvasBind(cCanvas, cBitmap);
840     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
841     EXPECT_NE(OH_Drawing_TypographyDidExceedMaxLines(typography), true);
842     OH_Drawing_RectHeightStyle heightStyle = RECT_HEIGHT_STYLE_TIGHT;
843     OH_Drawing_RectWidthStyle widthStyle = RECT_WIDTH_STYLE_TIGHT;
844     auto box = OH_Drawing_TypographyGetRectsForRange(typography, 1, 2, heightStyle, widthStyle);
845     EXPECT_NE(box, nullptr);
846     OH_Drawing_GetRightFromTextBox(box, 0);
847     EXPECT_NE(OH_Drawing_TypographyGetRectsForPlaceholders(typography), nullptr);
848     EXPECT_NE(OH_Drawing_TypographyGetGlyphPositionAtCoordinate(typography, 1, 0), nullptr);
849     EXPECT_NE(OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 1, 0), nullptr);
850     EXPECT_NE(OH_Drawing_TypographyGetWordBoundary(typography, 1), nullptr);
851     EXPECT_NE(OH_Drawing_TypographyGetLineTextRange(typography, 1, true), nullptr);
852     EXPECT_NE(OH_Drawing_TypographyGetLineCount(typography), 0);
853     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
854     OH_Drawing_DestroyTypography(typography);
855     OH_Drawing_DestroyTypographyHandler(handler);
856     OH_Drawing_DestroyTypographyStyle(typoStyle);
857 }
858 
859 /*
860  * @tc.name: TypographyTest027
861  * @tc.desc: test for getting line info for text typography
862  * @tc.type: FUNC
863  */
864 HWTEST_F(NdkTypographyTest, TypographyTest027, TestSize.Level0)
865 {
866     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
867     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
868     OH_Drawing_TypographyCreate* handler =
869         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
870     EXPECT_NE(handler, nullptr);
871     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
872     double fontSize = 30;
873     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
874     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
875     bool halfLeading = true;
876     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
877     const char* fontFamilies[] = { "Roboto" };
878     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
879     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
880     const char* text = "OpenHarmony\n";
881     OH_Drawing_TypographyHandlerAddText(handler, text);
882     OH_Drawing_TypographyHandlerPopTextStyle(handler);
883     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
884     double maxWidth = 800.0;
885     OH_Drawing_TypographyLayout(typography, maxWidth);
886     double position[2] = { 10.0, 15.0 };
887     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
888     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
889     uint32_t width = 20;
890     uint32_t height = 40;
891     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
892     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
893     OH_Drawing_CanvasBind(cCanvas, cBitmap);
894     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
895     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
896     int lineNum = 0;
897     bool oneLine = true;
898     bool includeWhitespace = true;
899     OH_Drawing_LineMetrics lineMetrics;
900     EXPECT_FALSE(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, nullptr));
901     EXPECT_FALSE(OH_Drawing_TypographyGetLineInfo(typography, -1, oneLine, includeWhitespace, &lineMetrics));
902     EXPECT_TRUE(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, &lineMetrics));
903     OH_Drawing_DestroyTypography(typography);
904     OH_Drawing_DestroyTypographyHandler(handler);
905     OH_Drawing_DestroyTypographyStyle(typoStyle);
906 }
907 
908 /*
909  * @tc.name: TypographyTest028
910  * @tc.desc: test for getting line info for text typography
911  * @tc.type: FUNC
912  */
913 HWTEST_F(NdkTypographyTest, TypographyTest028, TestSize.Level0)
914 {
915     OH_Drawing_TextShadow* textShadow = OH_Drawing_CreateTextShadow();
916     EXPECT_NE(textShadow, nullptr);
917     OH_Drawing_DestroyTextShadow(textShadow);
918     OH_Drawing_DestroyTextShadow(nullptr);
919 }
920 
921 /*
922  * @tc.name: TypographyTest029
923  * @tc.desc: test for font weight of text typography
924  * @tc.type: FUNC
925  */
926 HWTEST_F(NdkTypographyTest, TypographyTest029, TestSize.Level0)
927 {
928     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
929     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_100);
930     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W100);
931     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_200);
932     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W200);
933     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_300);
934     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W300);
935     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_400);
936     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W400);
937     OH_Drawing_SetTypographyTextFontWeight(nullptr, FONT_WEIGHT_100);
938     OH_Drawing_DestroyTypographyStyle(typoStyle);
939 }
940 
941 /*
942  * @tc.name: TypographyTest030
943  * @tc.desc: test for font style of text typography
944  * @tc.type: FUNC
945  */
946 HWTEST_F(NdkTypographyTest, TypographyTest030, TestSize.Level0)
947 {
948     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
949     OH_Drawing_SetTypographyTextFontStyle(typoStyle, FONT_STYLE_NORMAL);
950     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::NORMAL);
951     OH_Drawing_SetTypographyTextFontStyle(typoStyle, FONT_STYLE_ITALIC);
952     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::ITALIC);
953     OH_Drawing_SetTypographyTextFontStyle(typoStyle, -1);
954     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::NORMAL);
955     OH_Drawing_SetTypographyTextFontStyle(nullptr, 0);
956     OH_Drawing_DestroyTypographyStyle(typoStyle);
957 }
958 
959 /*
960  * @tc.name: TypographyTest031
961  * @tc.desc: test for font family of text typography
962  * @tc.type: FUNC
963  */
964 HWTEST_F(NdkTypographyTest, TypographyTest031, TestSize.Level0)
965 {
966     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
967     OH_Drawing_SetTypographyTextFontFamily(typoStyle, "monospace");
968     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontFamily, "monospace");
969     OH_Drawing_SetTypographyTextFontFamily(nullptr, nullptr);
970     OH_Drawing_DestroyTypographyStyle(typoStyle);
971     OH_Drawing_DestroyTypographyStyle(nullptr);
972 }
973 
974 /*
975  * @tc.name: TypographyTest032
976  * @tc.desc: test for font size of text typography
977  * @tc.type: FUNC
978  */
979 HWTEST_F(NdkTypographyTest, TypographyTest032, TestSize.Level0)
980 {
981     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
982     OH_Drawing_SetTypographyTextFontSize(typoStyle, 80);
983     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize, 80);
984     OH_Drawing_SetTypographyTextFontSize(typoStyle, 40);
985     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize, 40);
986     // -1 is invalid value
987     OH_Drawing_SetTypographyTextFontSize(typoStyle, -1);
988     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize, -1);
989     OH_Drawing_SetTypographyTextFontSize(nullptr, 0);
990     OH_Drawing_DestroyTypographyStyle(typoStyle);
991 }
992 
993 /*
994  * @tc.name: TypographyTest033
995  * @tc.desc: test for font height of text typography
996  * @tc.type: FUNC
997  */
998 HWTEST_F(NdkTypographyTest, TypographyTest033, TestSize.Level0)
999 {
1000     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1001     OH_Drawing_SetTypographyTextFontHeight(typoStyle, 0.0);
1002     EXPECT_EQ(ConvertToOriginalText(typoStyle)->heightScale, 0.0);
1003     // -1 is invalid value
1004     OH_Drawing_SetTypographyTextFontHeight(typoStyle, -1);
1005     EXPECT_EQ(ConvertToOriginalText(typoStyle)->heightScale, 0);
1006     OH_Drawing_SetTypographyTextFontHeight(nullptr, 0);
1007     OH_Drawing_DestroyTypographyStyle(typoStyle);
1008 }
1009 
1010 /*
1011  * @tc.name: TypographyTest034
1012  * @tc.desc: test for font style of line style for text typography
1013  * @tc.type: FUNC
1014  */
1015 HWTEST_F(NdkTypographyTest, TypographyTest034, TestSize.Level0)
1016 {
1017     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1018     OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, FONT_STYLE_NORMAL);
1019     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::NORMAL);
1020     OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, FONT_STYLE_ITALIC);
1021     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::ITALIC);
1022     OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, -1);
1023     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::NORMAL);
1024     OH_Drawing_SetTypographyTextLineStyleFontStyle(nullptr, 0);
1025     OH_Drawing_DestroyTypographyStyle(typoStyle);
1026 }
1027 
1028 /*
1029  * @tc.name: TypographyTest035
1030  * @tc.desc: test for font weight of line style for text typography
1031  * @tc.type: FUNC
1032  */
1033 HWTEST_F(NdkTypographyTest, TypographyTest035, TestSize.Level0)
1034 {
1035     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1036     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_100);
1037     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W100);
1038     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_200);
1039     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W200);
1040     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_300);
1041     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W300);
1042     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_400);
1043     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W400);
1044     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_500);
1045     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W500);
1046     OH_Drawing_SetTypographyTextLineStyleFontWeight(nullptr, 0);
1047     OH_Drawing_DestroyTypographyStyle(typoStyle);
1048 }
1049 
1050 /*
1051  * @tc.name: TypographyTest036
1052  * @tc.desc: test for font size of line style for text typography
1053  * @tc.type: FUNC
1054  */
1055 HWTEST_F(NdkTypographyTest, TypographyTest036, TestSize.Level0)
1056 {
1057     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1058 
1059     OH_Drawing_SetTypographyTextLineStyleFontSize(fTypoStyle, 80);
1060     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontSize(fTypoStyle), 80);
1061     OH_Drawing_SetTypographyTextLineStyleFontSize(fTypoStyle, 100);
1062     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontSize(fTypoStyle), 100);
1063     OH_Drawing_SetTypographyTextLineStyleFontSize(nullptr, 0);
1064 
1065     CreateTypographyHandler();
1066     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1067     CreateTypography();
1068     Layout();
1069     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 117);
1070 }
1071 
1072 /*
1073  * @tc.name: TypographyTest037
1074  * @tc.desc: test for font families of line style for text typography
1075  * @tc.type: FUNC
1076  */
1077 HWTEST_F(NdkTypographyTest, TypographyTest037, TestSize.Level0)
1078 {
1079     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1080     const char* fontFamilies[] = { "Roboto" };
1081     OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle, 1, fontFamilies);
1082     std::vector<std::string> fontFamiliesResult = { "Roboto" };
1083     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontFamilies, fontFamiliesResult);
1084     OH_Drawing_SetTypographyTextLineStyleFontFamilies(nullptr, 0, nullptr);
1085     OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle, 0, nullptr);
1086     OH_Drawing_DestroyTypographyStyle(typoStyle);
1087 }
1088 
1089 /*
1090  * @tc.name: TypographyTest038
1091  * @tc.desc: test for spacing scale of line style for text typography
1092  * @tc.type: FUNC
1093  */
1094 HWTEST_F(NdkTypographyTest, TypographyTest038, TestSize.Level0)
1095 {
1096     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1097 
1098     OH_Drawing_SetTypographyTextLineStyleSpacingScale(fTypoStyle, 1.0);
1099     EXPECT_EQ((ConvertToOriginalText(fTypoStyle)->lineStyleSpacingScale), 1.0);
1100     OH_Drawing_SetTypographyTextLineStyleSpacingScale(fTypoStyle, 30.0);
1101     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetSpacingScale(fTypoStyle), 30.0);
1102     OH_Drawing_SetTypographyTextLineStyleSpacingScale(nullptr, 0);
1103 
1104     CreateTypographyHandler();
1105     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1106     CreateTypography();
1107     Layout();
1108     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 436);
1109 }
1110 
1111 /*
1112  * @tc.name: TypographyTest039
1113  * @tc.desc: test for font height of line style for text typography
1114  * @tc.type: FUNC
1115  */
1116 HWTEST_F(NdkTypographyTest, TypographyTest039, TestSize.Level0)
1117 {
1118     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1119 
1120     OH_Drawing_SetTypographyTextLineStyleFontHeight(nullptr, 0);
1121     OH_Drawing_SetTypographyTextLineStyleFontHeight(fTypoStyle, 10.5);
1122     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetHeightScale(fTypoStyle), 10.5);
1123     EXPECT_TRUE(OH_Drawing_TypographyTextlineStyleGetHeightOnly(fTypoStyle));
1124 
1125     CreateTypographyHandler();
1126     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1127     CreateTypography();
1128     Layout();
1129     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 147);
1130 }
1131 
1132 /*
1133  * @tc.name: TypographyTest040
1134  * @tc.desc: test for line metrics for text typography
1135  * @tc.type: FUNC
1136  */
1137 HWTEST_F(NdkTypographyTest, TypographyTest040, TestSize.Level0)
1138 {
1139     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1140     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1141     OH_Drawing_TypographyCreate* handler =
1142         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1143     EXPECT_NE(handler, nullptr);
1144     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1145     double fontSize = 30;
1146     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1147     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1148     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
1149     const char* fontFamilies[] = { "Roboto" };
1150     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1151     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1152     OH_Drawing_TypographyHandlerAddText(handler, "OpenHarmony\n");
1153     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1154     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1155     double maxWidth = 800.0;
1156     OH_Drawing_TypographyLayout(typography, maxWidth);
1157     EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
1158     double position[2] = { 10.0, 15.0 };
1159     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1160     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1161     uint32_t width = 20;
1162     uint32_t height = 40;
1163     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1164     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1165     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1166     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1167     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1168     OH_Drawing_FontDescriptor* descriptor = OH_Drawing_CreateFontDescriptor();
1169     OH_Drawing_FontParser* parser = OH_Drawing_CreateFontParser();
1170 
1171     if (std::filesystem::exists(VIS_LIST_FILE_NAME)) {
1172         size_t fontNum;
1173         char** list = OH_Drawing_FontParserGetSystemFontList(parser, &fontNum);
1174         EXPECT_NE(list, nullptr);
1175         EXPECT_NE(OH_Drawing_FontParserGetFontByName(parser, list[0]), nullptr);
1176         OH_Drawing_DestroySystemFontList(list, fontNum);
1177     }
1178     OH_Drawing_DestroyFontParser(parser);
1179     OH_Drawing_DestroyFontDescriptor(descriptor);
1180     OH_Drawing_LineMetrics* vectorMetrics = OH_Drawing_TypographyGetLineMetrics(typography);
1181     EXPECT_NE(vectorMetrics, nullptr);
1182     EXPECT_NE(OH_Drawing_LineMetricsGetSize(vectorMetrics), 0);
1183     OH_Drawing_DestroyLineMetrics(vectorMetrics);
1184     OH_Drawing_LineMetrics* metrics = new OH_Drawing_LineMetrics();
1185     EXPECT_TRUE(OH_Drawing_TypographyGetLineMetricsAt(typography, 0, metrics));
1186     OH_Drawing_DestroyTypography(typography);
1187     OH_Drawing_DestroyTypographyHandler(handler);
1188 }
1189 
1190 /*
1191  * @tc.name: TypographyTest041
1192  * @tc.desc: test for font weight of line style for text typography
1193  * @tc.type: FUNC
1194  */
1195 HWTEST_F(NdkTypographyTest, TypographyTest041, TestSize.Level0)
1196 {
1197     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1198     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_600);
1199     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W600);
1200     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_700);
1201     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W700);
1202     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_800);
1203     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W800);
1204     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_900);
1205     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W900);
1206     OH_Drawing_SetTypographyTextLineStyleFontWeight(nullptr, 0);
1207     OH_Drawing_DestroyTypographyStyle(typoStyle);
1208 }
1209 
1210 /*
1211  * @tc.name: TypographyTest042
1212  * @tc.desc: test for text shadow for textstyle
1213  * @tc.type: FUNC
1214  */
1215 HWTEST_F(NdkTypographyTest, TypographyTest042, TestSize.Level0)
1216 {
1217     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1218     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1219     OH_Drawing_TypographyCreate* handler =
1220         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1221     EXPECT_NE(handler, nullptr);
1222     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1223     double fontSize = 30;
1224     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1225     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1226     bool halfLeading = true;
1227     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1228     const char* fontFamilies[] = { "Roboto" };
1229     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1230     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1231     const char* text = "OpenHarmony\n";
1232     OH_Drawing_TypographyHandlerAddText(handler, text);
1233     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1234     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1235     double maxWidth = 800.0;
1236     OH_Drawing_TypographyLayout(typography, maxWidth);
1237     double position[2] = { 10.0, 15.0 };
1238     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1239     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1240     uint32_t width = 20;
1241     uint32_t height = 40;
1242     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1243     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1244     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1245     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1246     EXPECT_NE(OH_Drawing_TextStyleGetShadows(txtStyle), nullptr);
1247     OH_Drawing_TextStyleClearShadows(txtStyle);
1248     OH_Drawing_TextShadow* textshadows = OH_Drawing_TextStyleGetShadows(txtStyle);
1249     OH_Drawing_DestroyTextShadows(textshadows);
1250     OH_Drawing_DestroyTextShadows(nullptr);
1251     OH_Drawing_TextStyleAddShadow(txtStyle, nullptr);
1252     OH_Drawing_TextStyleAddShadow(txtStyle, OH_Drawing_CreateTextShadow());
1253     EXPECT_NE(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 0), nullptr);
1254     EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 10000000), nullptr);
1255     EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(nullptr, 0), nullptr);
1256     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyle), 1);
1257     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(nullptr), 0);
1258     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1259     OH_Drawing_DestroyTypography(typography);
1260     OH_Drawing_DestroyTypographyHandler(handler);
1261 }
1262 
1263 /*
1264  * @tc.name: TypographyTest043
1265  * @tc.desc: test for foreground brush for textstyle
1266  * @tc.type: FUNC
1267  */
1268 HWTEST_F(NdkTypographyTest, TypographyTest043, TestSize.Level0)
1269 {
1270     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1271     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1272     OH_Drawing_TypographyCreate* handler =
1273         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1274     EXPECT_NE(handler, nullptr);
1275     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1276     double fontSize = 30;
1277     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1278     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1279     bool halfLeading = true;
1280     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1281     const char* fontFamilies[] = { "Roboto" };
1282     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1283     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1284     const char* text = "OpenHarmony\n";
1285     OH_Drawing_TypographyHandlerAddText(handler, text);
1286     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1287     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1288     double maxWidth = 800.0;
1289     OH_Drawing_TypographyLayout(typography, maxWidth);
1290     double position[2] = { 10.0, 15.0 };
1291     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1292     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1293     uint32_t width = 20;
1294     uint32_t height = 40;
1295     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1296     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1297     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1298     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1299     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1300     OH_Drawing_Brush* foregroundBrush = OH_Drawing_BrushCreate();
1301     uint8_t alpha = 128;
1302     OH_Drawing_BrushSetAlpha(foregroundBrush, alpha);
1303     OH_Drawing_SetTextStyleForegroundBrush(txtStyle, nullptr);
1304     OH_Drawing_SetTextStyleForegroundBrush(txtStyle, foregroundBrush);
1305     OH_Drawing_Brush* resForegroundBrush = OH_Drawing_BrushCreate();
1306     OH_Drawing_TextStyleGetForegroundBrush(txtStyle, nullptr);
1307     OH_Drawing_TextStyleGetForegroundBrush(txtStyle, resForegroundBrush);
1308     EXPECT_EQ(OH_Drawing_BrushGetAlpha(resForegroundBrush), alpha);
1309     OH_Drawing_BrushDestroy(resForegroundBrush);
1310     OH_Drawing_BrushDestroy(foregroundBrush);
1311     OH_Drawing_DestroyTypography(typography);
1312     OH_Drawing_DestroyTypographyHandler(handler);
1313 }
1314 
1315 /*
1316  * @tc.name: TypographyTest044
1317  * @tc.desc: test for effectiveAlignment, isLineUnlimited, isEllipsized for text typography
1318  * @tc.type: FUNC
1319  */
1320 HWTEST_F(NdkTypographyTest, TypographyTest044, TestSize.Level0)
1321 {
1322     CreateTypographyHandler();
1323     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1324     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1325     double fontSize = 30;
1326     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1327     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1328     bool halfLeading = true;
1329     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1330     const char* fontFamilies[] = {"Roboto"};
1331     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1332     OH_Drawing_TypographyHandlerPushTextStyle(fHandler, txtStyle);
1333     const char* text = "OpenHarmony\n";
1334     OH_Drawing_TypographyHandlerAddText(fHandler, text);
1335     OH_Drawing_TypographyHandlerPopTextStyle(fHandler);
1336     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(fHandler);
1337     double maxWidth = 800.0;
1338     OH_Drawing_TypographyLayout(typography, maxWidth);
1339     double position[2] = {10.0, 15.0};
1340     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1341     OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1342     uint32_t width = 20;
1343     uint32_t height = 40;
1344     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1345     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1346     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1347     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1348     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1349     OH_Drawing_Font_Metrics fontmetrics;
1350     EXPECT_TRUE(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics));
1351     EXPECT_FALSE(OH_Drawing_TextStyleGetFontMetrics(nullptr, txtStyle, &fontmetrics));
1352     OH_Drawing_DisableFontCollectionFallback(OH_Drawing_CreateFontCollection());
1353     OH_Drawing_DisableFontCollectionFallback(nullptr);
1354     OH_Drawing_DisableFontCollectionSystemFont(OH_Drawing_CreateFontCollection());
1355     OH_Drawing_SetTypographyTextEllipsis(fTypoStyle, text);
1356     OH_Drawing_SetTypographyTextLocale(fTypoStyle, text);
1357     OH_Drawing_SetTypographyTextSplitRatio(fTypoStyle, fontSize);
1358     OH_Drawing_TypographyGetTextStyle(fTypoStyle);
1359     EXPECT_EQ(OH_Drawing_TypographyGetEffectiveAlignment(fTypoStyle), 0);
1360     EXPECT_TRUE(OH_Drawing_TypographyIsLineUnlimited(fTypoStyle));
1361     EXPECT_TRUE(OH_Drawing_TypographyIsEllipsized(fTypoStyle));
1362     OH_Drawing_SetTypographyTextStyle(fTypoStyle, txtStyle);
1363     OH_Drawing_TypographyLayout(typography, fLayoutWidth);
1364     OH_Drawing_PositionAndAffinity* positionAndAffinity =
1365         OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 100, 10);
1366     EXPECT_EQ(OH_Drawing_GetPositionFromPositionAndAffinity(positionAndAffinity), 2);
1367     OH_Drawing_DestroyTypography(typography);
1368 }
1369 
1370 /*
1371  * @tc.name: TypographyTest045
1372  * @tc.desc: test for background brush for textstyle
1373  * @tc.type: FUNC
1374  */
1375 HWTEST_F(NdkTypographyTest, TypographyTest045, TestSize.Level0)
1376 {
1377     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1378     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1379     OH_Drawing_TypographyCreate* handler =
1380         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1381     EXPECT_NE(handler, nullptr);
1382 
1383     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1384     double fontSize = 30;
1385     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1386     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1387     bool halfLeading = true;
1388     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1389     const char* fontFamilies[] = { "Roboto" };
1390     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1391     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1392     const char* text = "OpenHarmony\n";
1393     OH_Drawing_TypographyHandlerAddText(handler, text);
1394     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1395     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1396     double maxWidth = 800.0;
1397     OH_Drawing_TypographyLayout(typography, maxWidth);
1398     double position[2] = { 10.0, 15.0 };
1399     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1400     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1401     uint32_t width = 20;
1402     uint32_t height = 40;
1403     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1404     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1405     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1406     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1407     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1408     OH_Drawing_Brush* backgroundBrush = OH_Drawing_BrushCreate();
1409     uint8_t backgroundAlpha = 64;
1410     OH_Drawing_BrushSetAlpha(backgroundBrush, backgroundAlpha);
1411     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, nullptr);
1412     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, backgroundBrush);
1413     OH_Drawing_Brush* resBackgroundBrush = OH_Drawing_BrushCreate();
1414     OH_Drawing_TextStyleGetBackgroundBrush(txtStyle, nullptr);
1415     OH_Drawing_TextStyleGetBackgroundBrush(txtStyle, resBackgroundBrush);
1416     EXPECT_EQ(OH_Drawing_BrushGetAlpha(resBackgroundBrush), backgroundAlpha);
1417     OH_Drawing_BrushDestroy(resBackgroundBrush);
1418     OH_Drawing_BrushDestroy(backgroundBrush);
1419     OH_Drawing_DestroyTypography(typography);
1420     OH_Drawing_DestroyTypographyHandler(handler);
1421 }
1422 
1423 /*
1424  * @tc.name: TypographyTest046
1425  * @tc.desc: test for background pen for textstyle
1426  * @tc.type: FUNC
1427  */
1428 HWTEST_F(NdkTypographyTest, TypographyTest046, TestSize.Level0)
1429 {
1430     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1431     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1432     OH_Drawing_TypographyCreate* handler =
1433         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1434     EXPECT_NE(handler, nullptr);
1435 
1436     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1437     double fontSize = 30;
1438     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1439     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1440     bool halfLeading = true;
1441     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1442     const char* fontFamilies[] = { "Roboto" };
1443     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1444     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1445     const char* text = "OpenHarmony\n";
1446     OH_Drawing_TypographyHandlerAddText(handler, text);
1447     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1448     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1449     double maxWidth = 800.0;
1450     OH_Drawing_TypographyLayout(typography, maxWidth);
1451     double position[2] = { 10.0, 15.0 };
1452     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1453     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1454     uint32_t width = 20;
1455     uint32_t height = 40;
1456     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1457     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1458     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1459     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1460     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1461     OH_Drawing_Pen* backgroundPen = OH_Drawing_PenCreate();
1462     float backgroundPenWidth = 10;
1463     OH_Drawing_PenSetWidth(backgroundPen, backgroundPenWidth);
1464     OH_Drawing_SetTextStyleBackgroundPen(txtStyle, nullptr);
1465     OH_Drawing_SetTextStyleBackgroundPen(txtStyle, backgroundPen);
1466     OH_Drawing_Pen* resBackgroundPen = OH_Drawing_PenCreate();
1467     OH_Drawing_TextStyleGetBackgroundPen(txtStyle, nullptr);
1468     OH_Drawing_TextStyleGetBackgroundPen(txtStyle, resBackgroundPen);
1469     EXPECT_EQ(OH_Drawing_PenGetWidth(resBackgroundPen), backgroundPenWidth);
1470     OH_Drawing_PenDestroy(resBackgroundPen);
1471     OH_Drawing_PenDestroy(backgroundPen);
1472     OH_Drawing_DestroyTypography(typography);
1473     OH_Drawing_DestroyTypographyHandler(handler);
1474 }
1475 
1476 /*
1477  * @tc.name: TypographyTest047
1478  * @tc.desc: test for foreground pen for textstyle
1479  * @tc.type: FUNC
1480  */
1481 HWTEST_F(NdkTypographyTest, TypographyTest047, TestSize.Level0)
1482 {
1483     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1484     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1485     OH_Drawing_TypographyCreate* handler =
1486         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1487     EXPECT_NE(handler, nullptr);
1488     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1489     double fontSize = 30;
1490     OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1491     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1492     bool halfLeading = true;
1493     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1494     const char* fontFamilies[] = { "Roboto" };
1495     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1496     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1497     const char* text = "OpenHarmony\n";
1498     OH_Drawing_TypographyHandlerAddText(handler, text);
1499     OH_Drawing_TypographyHandlerPopTextStyle(handler);
1500     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1501     double maxWidth = 800.0;    // 800.0 was used for testing
1502     OH_Drawing_TypographyLayout(typography, maxWidth);
1503     double position[2] = { 10.0, 15.0 };    // 10.0 and 15.0 were used for testing
1504     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1505     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
1506     uint32_t width = 20;    // 20 was used for testing
1507     uint32_t height = 40;   // 40 was used for testing
1508     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1509     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1510     OH_Drawing_CanvasBind(cCanvas, cBitmap);
1511     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1512     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1513     OH_Drawing_Pen* foregroundPen = OH_Drawing_PenCreate();
1514     float foregroundPenWidth = 20;  // 20 was used for testing
1515     OH_Drawing_PenSetWidth(foregroundPen, foregroundPenWidth);
1516     OH_Drawing_SetTextStyleForegroundPen(txtStyle, nullptr);
1517     OH_Drawing_SetTextStyleForegroundPen(txtStyle, foregroundPen);
1518     OH_Drawing_Pen* resForegroundPen = OH_Drawing_PenCreate();
1519     OH_Drawing_TextStyleGetForegroundPen(txtStyle, nullptr);
1520     OH_Drawing_TextStyleGetForegroundPen(txtStyle, resForegroundPen);
1521     EXPECT_EQ(OH_Drawing_PenGetWidth(resForegroundPen), foregroundPenWidth);
1522     OH_Drawing_PenDestroy(resForegroundPen);
1523     OH_Drawing_PenDestroy(foregroundPen);
1524     OH_Drawing_DestroyTypography(typography);
1525     OH_Drawing_DestroyTypographyHandler(handler);
1526 }
1527 
1528 /*
1529  * @tc.name: TypographyTest048
1530  * @tc.desc: test for font weight for text typography
1531  * @tc.type: FUNC
1532  */
1533 HWTEST_F(NdkTypographyTest, TypographyTest048, TestSize.Level0)
1534 {
1535     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1536     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_500);
1537     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W500);
1538     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_600);
1539     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W600);
1540     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_700);
1541     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W700);
1542     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_800);
1543     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W800);
1544     OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_900);
1545     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W900);
1546     OH_Drawing_SetTypographyTextFontWeight(nullptr, 0);
1547     OH_Drawing_DestroyTypographyStyle(typoStyle);
1548 }
1549 
1550 /*
1551  * @tc.name: TypographyTest049
1552  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1553  * @tc.type: FUNC
1554  */
1555 HWTEST_F(NdkTypographyTest, TypographyTest049, TestSize.Level0)
1556 {
1557     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 2);
1558     bool halfLeading = true;
1559     OH_Drawing_SetTypographyTextHalfLeading(fTypoStyle, halfLeading);
1560     EXPECT_TRUE(ConvertToOriginalText(fTypoStyle)->halfLeading);
1561 
1562     OH_Drawing_SetTypographyTextLineStyleHalfLeading(fTypoStyle, halfLeading);
1563     EXPECT_TRUE(ConvertToOriginalText(fTypoStyle)->lineStyleHalfLeading);
1564 
1565     OH_Drawing_SetTypographyTextLineStyleFontSize(fTypoStyle, 80);
1566     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontSize(fTypoStyle), 80);
1567 
1568     bool uselineStyle = true;
1569     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, uselineStyle);
1570     EXPECT_TRUE(ConvertToOriginalText(fTypoStyle)->useLineStyle);
1571 
1572     bool linestyleOnly = true;
1573     OH_Drawing_SetTypographyTextLineStyleOnly(fTypoStyle, linestyleOnly);
1574     EXPECT_TRUE(ConvertToOriginalText(fTypoStyle)->lineStyleOnly);
1575     OH_Drawing_SetTypographyTextLineStyleOnly(nullptr, 0);
1576 
1577     CreateTypographyHandler();
1578     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1579     CreateTypography();
1580     Layout();
1581 
1582     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 94);
1583 }
1584 
1585 /*
1586  * @tc.name: TypographyTest050
1587  * @tc.desc: test for getting numbers for textstyle
1588  * @tc.type: FUNC
1589  */
1590 HWTEST_F(NdkTypographyTest, TypographyTest050, TestSize.Level0)
1591 {
1592     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1593     OH_Drawing_SetTextStyleColor(txtStyle, 1);
1594     EXPECT_EQ(OH_Drawing_TextStyleGetColor(txtStyle), 1);
1595     EXPECT_EQ(OH_Drawing_TextStyleGetColor(nullptr), 0xFFFFFFFF);
1596     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_SOLID);
1597     EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(txtStyle), 0);
1598     EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(nullptr), TEXT_DECORATION_STYLE_SOLID);
1599     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_100);
1600     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 0);
1601     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(nullptr), FONT_WEIGHT_400);
1602     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
1603     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyle), 0);
1604     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(nullptr), FONT_STYLE_NORMAL);
1605     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
1606     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(txtStyle), 0);
1607     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(nullptr), TEXT_BASELINE_ALPHABETIC);
1608     const char* fontFamilies[] = { "Roboto" };
1609     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1610     size_t fontFamiliesNumber;
1611     char** fontFamiliesList = OH_Drawing_TextStyleGetFontFamilies(txtStyle, &fontFamiliesNumber);
1612     EXPECT_NE(fontFamiliesList, nullptr);
1613     EXPECT_EQ(OH_Drawing_TextStyleGetFontFamilies(nullptr, &fontFamiliesNumber), nullptr);
1614     OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, fontFamiliesNumber);
1615     OH_Drawing_SetTextStyleFontSize(txtStyle, 60); // 60 means font size for test
1616     EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(txtStyle), 60);
1617     EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(nullptr), 0.0);
1618     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 20); // 20 means letter spacing for test
1619     EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(txtStyle), 20);
1620     EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(nullptr), 0.0);
1621     OH_Drawing_SetTextStyleWordSpacing(txtStyle, 80); // 80 means word spacing for test
1622     EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(txtStyle), 80);
1623     EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(nullptr), 0.0);
1624     OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.0); // 0.0 means font height for test
1625     EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(txtStyle), 0.0);
1626     EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(nullptr), 0.0);
1627     bool halfLeading = true;
1628     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1629     EXPECT_TRUE(OH_Drawing_TextStyleGetHalfLeading(txtStyle));
1630     EXPECT_FALSE(OH_Drawing_TextStyleGetHalfLeading(nullptr));
1631     OH_Drawing_SetTextStyleLocale(txtStyle, "en");
1632     EXPECT_EQ(std::strcmp(OH_Drawing_TextStyleGetLocale(txtStyle), "en"), 0);
1633     EXPECT_EQ(OH_Drawing_TextStyleGetLocale(nullptr), nullptr);
1634 }
1635 
1636 /*
1637  * @tc.name: TypographyTest051
1638  * @tc.desc: test for getting line info for text typography
1639  * @tc.type: FUNC
1640  */
1641 HWTEST_F(NdkTypographyTest, TypographyTest051, TestSize.Level0)
1642 {
1643     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1644     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1645     OH_Drawing_TypographyCreate* handler =
1646         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
1647     OH_Drawing_RectStyle_Info rectStyleInfo = { 1, 1.5, 1.5, 1.5, 1.5 }; // 1.5 means corner radius for test
1648     int styleId = 1;                                                     // 1 means styleId for test
1649     OH_Drawing_TextStyleSetBackgroundRect(txtStyle, nullptr, styleId);
1650     OH_Drawing_TextStyleSetBackgroundRect(nullptr, &rectStyleInfo, styleId);
1651     OH_Drawing_TextStyleSetBackgroundRect(txtStyle, &rectStyleInfo, styleId);
1652     uint32_t symbol = 2; // 2 means symbol for test
1653     OH_Drawing_TypographyHandlerAddSymbol(handler, symbol);
1654     OH_Drawing_TypographyHandlerAddSymbol(nullptr, symbol);
1655     const char* key1 = "宋体";
1656     int value1 = 1; // 1 for test
1657     OH_Drawing_TextStyleAddFontFeature(nullptr, key1, value1);
1658     OH_Drawing_TextStyleAddFontFeature(txtStyle, nullptr, value1);
1659     OH_Drawing_TextStyleAddFontFeature(txtStyle, key1, value1);
1660     const char* key2 = "斜体";
1661     int value2 = 2; // 2 for test
1662     OH_Drawing_TextStyleAddFontFeature(txtStyle, key2, value2);
1663     const char* key3 = "方体";
1664     int value3 = 3; // 3 for test
1665     OH_Drawing_TextStyleAddFontFeature(txtStyle, key3, value3);
1666     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 3); // 3 means font feature size for test
1667     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(nullptr), 0);
1668     OH_Drawing_FontFeature* fontFeaturesArray = OH_Drawing_TextStyleGetFontFeatures(txtStyle);
1669     EXPECT_NE(fontFeaturesArray, nullptr);
1670     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatures(nullptr), nullptr);
1671     OH_Drawing_TextStyleDestroyFontFeatures(fontFeaturesArray, OH_Drawing_TextStyleGetFontFeatureSize(txtStyle));
1672     OH_Drawing_TextStyleDestroyFontFeatures(nullptr, OH_Drawing_TextStyleGetFontFeatureSize(txtStyle));
1673     OH_Drawing_TextStyleClearFontFeature(txtStyle);
1674     OH_Drawing_TextStyleClearFontFeature(nullptr);
1675     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 0);
1676     double lineShift = 1.5; // 1.5 means baseline shift for test
1677     OH_Drawing_TextStyleSetBaselineShift(nullptr, lineShift);
1678     EXPECT_EQ(OH_Drawing_TextStyleGetBaselineShift(nullptr), 0.0);
1679     OH_Drawing_TextStyleSetBaselineShift(txtStyle, lineShift);
1680     EXPECT_EQ(OH_Drawing_TextStyleGetBaselineShift(txtStyle), 1.5);
1681 }
1682 
1683 /*
1684  * @tc.name: TypographyTest052
1685  * @tc.desc: test for setting the mode of leading over and under text
1686  * @tc.type: FUNC
1687  */
1688 HWTEST_F(NdkTypographyTest, TypographyTest052, TestSize.Level0)
1689 {
1690     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1691     OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_ALL);
1692     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::ALL);
1693     OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_FIRST_ASCENT);
1694     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_FIRST_ASCENT);
1695     OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_LAST_ASCENT);
1696     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_LAST_ASCENT);
1697     OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_ALL);
1698     EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_ALL);
1699     OH_Drawing_TypographyTextSetHeightBehavior(nullptr, TEXT_HEIGHT_ALL);
1700     OH_Drawing_DestroyTypographyStyle(typoStyle);
1701 }
1702 
1703 /*
1704  * @tc.name: TypographyHeightBehaviorTest001
1705  * @tc.desc: test for getting the mode of leading over and under text
1706  * @tc.type: FUNC
1707  */
1708 HWTEST_F(NdkTypographyTest, TypographyHeightBehaviorTest001, TestSize.Level0)
1709 {
1710     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 10.01);
1711     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(nullptr), TEXT_HEIGHT_ALL);
1712 
1713     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 10);
1714     OH_Drawing_TypographyTextSetHeightBehavior(fTypoStyle, TEXT_HEIGHT_ALL);
1715     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(fTypoStyle), TEXT_HEIGHT_ALL);
1716     CreateTypographyHandler();
1717     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
1718     CreateTypography();
1719     Layout();
1720     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 38000);
1721 }
1722 
1723 /*
1724  * @tc.name: TypographyHeightBehaviorTest002
1725  * @tc.desc: test for getting the mode of leading over and under text
1726  * @tc.type: FUNC
1727  */
1728 HWTEST_F(NdkTypographyTest, TypographyHeightBehaviorTest002, TestSize.Level0)
1729 {
1730     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 10);
1731     OH_Drawing_TypographyTextSetHeightBehavior(fTypoStyle, TEXT_HEIGHT_DISABLE_FIRST_ASCENT);
1732     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(fTypoStyle), TEXT_HEIGHT_DISABLE_FIRST_ASCENT);
1733     CreateTypographyHandler();
1734     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
1735     CreateTypography();
1736     Layout();
1737     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 37650);
1738 }
1739 
1740 /*
1741  * @tc.name: TypographyHeightBehaviorTest003
1742  * @tc.desc: test for getting the mode of leading over and under text
1743  * @tc.type: FUNC
1744  */
1745 HWTEST_F(NdkTypographyTest, TypographyHeightBehaviorTest003, TestSize.Level0)
1746 {
1747     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 10);
1748     OH_Drawing_TypographyTextSetHeightBehavior(fTypoStyle, TEXT_HEIGHT_DISABLE_LAST_ASCENT);
1749     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(fTypoStyle), TEXT_HEIGHT_DISABLE_LAST_ASCENT);
1750     CreateTypographyHandler();
1751     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
1752     CreateTypography();
1753     Layout();
1754     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 37908);
1755 }
1756 
1757 /*
1758  * @tc.name: TypographyHeightBehaviorTest004
1759  * @tc.desc: test for getting the mode of leading over and under text
1760  * @tc.type: FUNC
1761  */
1762 HWTEST_F(NdkTypographyTest, TypographyHeightBehaviorTest004, TestSize.Level0)
1763 {
1764     OH_Drawing_SetTypographyTextFontHeight(fTypoStyle, 10);
1765     OH_Drawing_TypographyTextSetHeightBehavior(fTypoStyle, TEXT_HEIGHT_DISABLE_ALL);
1766     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(fTypoStyle), TEXT_HEIGHT_DISABLE_ALL);
1767     CreateTypographyHandler();
1768     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_LONG_TEXT);
1769     CreateTypography();
1770     Layout();
1771     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 37558);
1772 }
1773 
1774 /*
1775  * @tc.name: TypographyTest054
1776  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1777  * @tc.type: FUNC
1778  */
1779 HWTEST_F(NdkTypographyTest, TypographyTest054, TestSize.Level0)
1780 {
1781     CreateTypographyHandler();
1782     AddText();
1783     CreateTypography();
1784     Layout();
1785     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 118);
1786     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 45);
1787     OH_Drawing_TypographyMarkDirty(fTypography);
1788     OH_Drawing_TypographyMarkDirty(nullptr);
1789     Layout();
1790     EXPECT_EQ(OH_Drawing_TypographyGetHeight(fTypography), 118);
1791     EXPECT_EQ(::round(OH_Drawing_TypographyGetLongestLineWithIndent(fTypography)), 45);
1792     Paint();
1793 }
1794 
1795 /*
1796  * @tc.name: TypographyTest055
1797  * @tc.desc: test for unresolved glyphs count of text typography
1798  * @tc.type: FUNC
1799  */
1800 HWTEST_F(NdkTypographyTest, TypographyTest055, TestSize.Level0)
1801 {
1802     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1803     ASSERT_NE(typoStyle, nullptr);
1804     OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
1805     ASSERT_NE(fontCollection, nullptr);
1806     OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);
1807     ASSERT_NE(handler, nullptr);
1808     const char* text = "OpenHarmony";
1809     OH_Drawing_TypographyHandlerAddText(handler, text);
1810     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1811     ASSERT_NE(typography, nullptr);
1812     int32_t result = OH_Drawing_TypographyGetUnresolvedGlyphsCount(typography);
1813     EXPECT_NE(result, 0);
1814     const char* unresolvedGlyphText = "\uFFFF";
1815     OH_Drawing_TypographyHandlerAddText(handler, unresolvedGlyphText);
1816     typography = OH_Drawing_CreateTypography(handler);
1817     ASSERT_NE(typography, nullptr);
1818     result = OH_Drawing_TypographyGetUnresolvedGlyphsCount(typography);
1819     EXPECT_NE(result, 1);
1820     result = OH_Drawing_TypographyGetUnresolvedGlyphsCount(nullptr);
1821     EXPECT_EQ(result, 0);
1822     OH_Drawing_DestroyTypographyStyle(typoStyle);
1823     OH_Drawing_DestroyFontCollection(fontCollection);
1824     OH_Drawing_DestroyTypographyHandler(handler);
1825     OH_Drawing_DestroyTypography(typography);
1826 }
1827 
1828 /*
1829  * @tc.name: TypographyTest056
1830  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1831  * @tc.type: FUNC
1832  */
1833 HWTEST_F(NdkTypographyTest, TypographyTest056, TestSize.Level0)
1834 {
1835     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1836     ASSERT_NE(typoStyle, nullptr);
1837     OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
1838     ASSERT_NE(fontCollection, nullptr);
1839     OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);
1840     ASSERT_NE(handler, nullptr);
1841     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1842     ASSERT_NE(typography, nullptr);
1843     size_t from = 10;     // 10 means font size for test
1844     size_t to = 11;       // 11 means font size for test
1845     float fontSize = 1.0; // 1.0 means font size for test
1846     OH_Drawing_TypographyUpdateFontSize(typography, from, to, fontSize);
1847     OH_Drawing_TypographyUpdateFontSize(nullptr, from, to, fontSize);
1848     OH_Drawing_DestroyTypographyStyle(typoStyle);
1849     OH_Drawing_DestroyFontCollection(fontCollection);
1850     OH_Drawing_DestroyTypographyHandler(handler);
1851     OH_Drawing_DestroyTypography(typography);
1852 }
1853 
1854 /*
1855  * @tc.name: TypographyLineStyleTest001
1856  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1857  * @tc.type: FUNC
1858  */
1859 HWTEST_F(NdkTypographyTest, TypographyLineStyleTest001, TestSize.Level0)
1860 {
1861     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1862     EXPECT_TRUE(OH_Drawing_TypographyTextGetLineStyle(fTypoStyle));
1863     EXPECT_FALSE(OH_Drawing_TypographyTextGetLineStyle(nullptr));
1864 
1865     CreateTypographyHandler();
1866     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1867     CreateTypography();
1868     Layout();
1869     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 59);
1870 }
1871 
1872 /*
1873  * @tc.name: TypographyLineStyleTest002
1874  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1875  * @tc.type: FUNC
1876  */
1877 HWTEST_F(NdkTypographyTest, TypographyLineStyleTest002, TestSize.Level0)
1878 {
1879     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1880     EXPECT_TRUE(OH_Drawing_TypographyTextGetLineStyle(fTypoStyle));
1881     EXPECT_FALSE(OH_Drawing_TypographyTextGetLineStyle(nullptr));
1882     OH_Drawing_SetTypographyTextLineStyleFontSize(fTypoStyle, DEFAULT_FONT_SIZE + 1);
1883 
1884     CreateTypographyHandler();
1885     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1886     CreateTypography();
1887     Layout();
1888     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 60);
1889 }
1890 
1891 /*
1892  * @tc.name: TypographyLineStyleTest003
1893  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1894  * @tc.type: FUNC
1895  */
1896 HWTEST_F(NdkTypographyTest, TypographyLineStyleTest003, TestSize.Level0)
1897 {
1898     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1899     EXPECT_TRUE(OH_Drawing_TypographyTextGetLineStyle(fTypoStyle));
1900     EXPECT_FALSE(OH_Drawing_TypographyTextGetLineStyle(nullptr));
1901     OH_Drawing_SetTypographyTextLineStyleFontSize(fTypoStyle, DEFAULT_FONT_SIZE - 1);
1902     CreateTypographyHandler();
1903     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1904     CreateTypography();
1905     Layout();
1906     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 59);
1907 }
1908 
1909 /*
1910  * @tc.name: TypographyTest058
1911  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1912  * @tc.type: FUNC
1913  */
1914 HWTEST_F(NdkTypographyTest, TypographyTest058, TestSize.Level0)
1915 {
1916     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1917     ASSERT_NE(typoStyle, nullptr);
1918     int weight = FONT_WEIGHT_100;
1919     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, weight);
1920     OH_Drawing_FontWeight result = OH_Drawing_TypographyTextlineStyleGetFontWeight(typoStyle);
1921     EXPECT_EQ(result, FONT_WEIGHT_100);
1922     result = OH_Drawing_TypographyTextlineStyleGetFontWeight(nullptr);
1923     EXPECT_EQ(result, FONT_WEIGHT_400);
1924     OH_Drawing_DestroyTypographyStyle(typoStyle);
1925 }
1926 
1927 /*
1928  * @tc.name: TypographyTest059
1929  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1930  * @tc.type: FUNC
1931  */
1932 HWTEST_F(NdkTypographyTest, TypographyTest059, TestSize.Level0)
1933 {
1934     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1935     ASSERT_NE(typoStyle, nullptr);
1936     int fontStyle = FONT_STYLE_ITALIC;
1937     OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, fontStyle);
1938     OH_Drawing_FontStyle result = OH_Drawing_TypographyTextlineStyleGetFontStyle(typoStyle);
1939     EXPECT_EQ(result, FONT_STYLE_ITALIC);
1940     result = OH_Drawing_TypographyTextlineStyleGetFontStyle(nullptr);
1941     EXPECT_EQ(result, FONT_STYLE_NORMAL);
1942     OH_Drawing_DestroyTypographyStyle(typoStyle);
1943 }
1944 
1945 /*
1946  * @tc.name: TypographyTest060
1947  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1948  * @tc.type: FUNC
1949  */
1950 HWTEST_F(NdkTypographyTest, TypographyTest060, TestSize.Level0)
1951 {
1952     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
1953     size_t fontNum = 1; // 1 means font number for test
1954     const char* fontFamilies[] = { "Roboto" };
1955     int fontFamiliesNumber = 1; // 1 means font families number for test
1956     OH_Drawing_SetTypographyTextLineStyleFontFamilies(fTypoStyle, fontFamiliesNumber, fontFamilies);
1957     char** result = OH_Drawing_TypographyTextlineStyleGetFontFamilies(fTypoStyle, &fontNum);
1958     EXPECT_NE(result, nullptr);
1959     result = OH_Drawing_TypographyTextlineStyleGetFontFamilies(nullptr, &fontNum);
1960     EXPECT_EQ(result, nullptr);
1961     OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(result, fontNum);
1962 
1963     CreateTypographyHandler();
1964     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
1965     CreateTypography();
1966     Layout();
1967     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 59);
1968 }
1969 
1970 /*
1971  * @tc.name: TypographyTest061
1972  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1973  * @tc.type: FUNC
1974  */
1975 HWTEST_F(NdkTypographyTest, TypographyTest061, TestSize.Level0)
1976 {
1977     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1978     ASSERT_NE(typoStyle, nullptr);
1979     double result = OH_Drawing_TypographyTextlineStyleGetFontSize(typoStyle);
1980     // 14.0 Fontsize default value
1981     EXPECT_EQ(result, 14.0);
1982     result = OH_Drawing_TypographyTextlineStyleGetFontSize(nullptr);
1983     EXPECT_EQ(result, 0);
1984     OH_Drawing_DestroyTypographyStyle(typoStyle);
1985 }
1986 
1987 /*
1988  * @tc.name: TypographyTest062
1989  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1990  * @tc.type: FUNC
1991  */
1992 HWTEST_F(NdkTypographyTest, TypographyTest062, TestSize.Level0)
1993 {
1994     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1995     ASSERT_NE(typoStyle, nullptr);
1996     double result = OH_Drawing_TypographyTextlineStyleGetHeightScale(typoStyle);
1997     EXPECT_EQ(result, 1.0); // 1.0 means enable the font height for line styles in text layout only
1998     result = OH_Drawing_TypographyTextlineStyleGetHeightScale(nullptr);
1999     EXPECT_EQ(result, 0);
2000     OH_Drawing_DestroyTypographyStyle(typoStyle);
2001 }
2002 
2003 /*
2004  * @tc.name: TypographyTest063
2005  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2006  * @tc.type: FUNC
2007  */
2008 HWTEST_F(NdkTypographyTest, TypographyTest063, TestSize.Level0)
2009 {
2010     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2011     ASSERT_NE(typoStyle, nullptr);
2012     // 2.0 measn font height for test
2013     double lineStyleFontHeight = 2.0;
2014     OH_Drawing_SetTypographyTextLineStyleFontHeight(typoStyle, lineStyleFontHeight);
2015     bool result = OH_Drawing_TypographyTextlineStyleGetHeightOnly(typoStyle);
2016     EXPECT_TRUE(result);
2017     result = OH_Drawing_TypographyTextlineStyleGetHeightOnly(nullptr);
2018     EXPECT_FALSE(result);
2019     OH_Drawing_DestroyTypographyStyle(typoStyle);
2020 }
2021 
2022 /*
2023  * @tc.name: TypographyTest064
2024  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2025  * @tc.type: FUNC
2026  */
2027 HWTEST_F(NdkTypographyTest, TypographyTest064, TestSize.Level0)
2028 {
2029     OH_Drawing_SetTypographyTextUseLineStyle(fTypoStyle, true);
2030 
2031     OH_Drawing_SetTypographyTextLineStyleHalfLeading(fTypoStyle, true);
2032     EXPECT_TRUE(OH_Drawing_TypographyTextlineStyleGetHalfLeading(fTypoStyle));
2033     EXPECT_FALSE(OH_Drawing_TypographyTextlineStyleGetHalfLeading(nullptr));
2034 
2035     CreateTypographyHandler();
2036     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
2037     CreateTypography();
2038     Layout();
2039     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 0), 59);
2040 }
2041 
2042 /*
2043  * @tc.name: TypographyTest065
2044  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2045  * @tc.type: FUNC
2046  */
2047 HWTEST_F(NdkTypographyTest, TypographyTest065, TestSize.Level0)
2048 {
2049     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2050     ASSERT_NE(typoStyle, nullptr);
2051     double result = OH_Drawing_TypographyTextlineStyleGetSpacingScale(typoStyle);
2052     // -1.0 for test
2053     EXPECT_EQ(result, -1.0);
2054     result = OH_Drawing_TypographyTextlineStyleGetSpacingScale(nullptr);
2055     EXPECT_EQ(result, 0);
2056     OH_Drawing_DestroyTypographyStyle(typoStyle);
2057 }
2058 
2059 /*
2060  * @tc.name: TypographyTest066
2061  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2062  * @tc.type: FUNC
2063  */
2064 HWTEST_F(NdkTypographyTest, TypographyTest066, TestSize.Level0)
2065 {
2066     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2067     ASSERT_NE(typoStyle, nullptr);
2068     int direction = TEXT_DIRECTION_RTL;
2069     OH_Drawing_SetTypographyTextDirection(typoStyle, direction);
2070     OH_Drawing_TextDirection result = OH_Drawing_TypographyGetTextDirection(typoStyle);
2071     EXPECT_EQ(result, TEXT_DIRECTION_RTL);
2072     result = OH_Drawing_TypographyGetTextDirection(nullptr);
2073     EXPECT_EQ(result, TEXT_DIRECTION_LTR);
2074     OH_Drawing_DestroyTypographyStyle(typoStyle);
2075 }
2076 
2077 /*
2078  * @tc.name: TypographyTest067
2079  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2080  * @tc.type: FUNC
2081  */
2082 HWTEST_F(NdkTypographyTest, TypographyTest067, TestSize.Level0)
2083 {
2084     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2085     ASSERT_NE(typoStyle, nullptr);
2086     size_t result = OH_Drawing_TypographyGetTextMaxLines(typoStyle);
2087     EXPECT_NE(result, 0);
2088     result = OH_Drawing_TypographyGetTextMaxLines(nullptr);
2089     EXPECT_EQ(result, 0);
2090     OH_Drawing_DestroyTypographyStyle(typoStyle);
2091 }
2092 
2093 /*
2094  * @tc.name: TypographyTest068
2095  * @tc.desc: test typography ellipsis
2096  * @tc.type: FUNC
2097  */
2098 HWTEST_F(NdkTypographyTest, TypographyTest068, TestSize.Level0)
2099 {
2100     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2101     ASSERT_NE(typoStyle, nullptr);
2102     char* result = OH_Drawing_TypographyGetTextEllipsis(typoStyle);
2103     EXPECT_NE(result, nullptr);
2104     result = OH_Drawing_TypographyGetTextEllipsis(nullptr);
2105     EXPECT_EQ(result, nullptr);
2106     OH_Drawing_TypographyDestroyEllipsis(result);
2107     EXPECT_FALSE(OH_Drawing_TypographyIsEllipsized(typoStyle));
2108     OH_Drawing_SetTypographyTextEllipsis(typoStyle, "");
2109     EXPECT_FALSE(OH_Drawing_TypographyIsEllipsized(typoStyle));
2110     OH_Drawing_SetTypographyTextEllipsis(typoStyle, "...");
2111     EXPECT_TRUE(OH_Drawing_TypographyIsEllipsized(typoStyle));
2112     OH_Drawing_DestroyTypographyStyle(typoStyle);
2113 }
2114 
2115 /*
2116  * @tc.name: TypographyTest069
2117  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2118  * @tc.type: FUNC
2119  */
2120 HWTEST_F(NdkTypographyTest, TypographyTest069, TestSize.Level0)
2121 {
2122     OH_Drawing_TypographyStyle* from = OH_Drawing_CreateTypographyStyle();
2123     OH_Drawing_TypographyStyle* to = OH_Drawing_CreateTypographyStyle();
2124     bool result = OH_Drawing_TypographyStyleEquals(from, to);
2125     EXPECT_TRUE(result);
2126     result = OH_Drawing_TypographyStyleEquals(nullptr, to);
2127     EXPECT_FALSE(result);
2128     result = OH_Drawing_TypographyStyleEquals(from, nullptr);
2129     EXPECT_FALSE(result);
2130 
2131     OH_Drawing_SetTypographyTextFontWeight(from, FONT_WEIGHT_100);
2132     EXPECT_FALSE(OH_Drawing_TypographyStyleEquals(from, to));
2133 
2134     OH_Drawing_SetTypographyTextFontWeight(to, FONT_WEIGHT_100);
2135     EXPECT_TRUE(OH_Drawing_TypographyStyleEquals(from, to));
2136 
2137     OH_Drawing_TypographyStyleSetHintsEnabled(from, true);
2138     EXPECT_TRUE(OH_Drawing_TypographyStyleEquals(from, to));
2139 
2140     OH_Drawing_TextStyle* textStyle = OH_Drawing_CreateTextStyle();
2141     OH_Drawing_SetTextStyleFontSize(textStyle, DEFAULT_FONT_SIZE);
2142     OH_Drawing_SetTypographyTextStyle(from, textStyle);
2143     EXPECT_TRUE(OH_Drawing_TypographyStyleEquals(from, to));
2144 
2145     OH_Drawing_TypographyTextSetHeightBehavior(from, TEXT_HEIGHT_DISABLE_ALL);
2146     EXPECT_TRUE(OH_Drawing_TypographyStyleEquals(from, to));
2147 
2148     OH_Drawing_DestroyTypographyStyle(from);
2149     OH_Drawing_DestroyTypographyStyle(to);
2150 }
2151 
2152 /*
2153  * @tc.name: TypographyTest070
2154  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2155  * @tc.type: FUNC
2156  */
2157 HWTEST_F(NdkTypographyTest, TypographyTest070, TestSize.Level0)
2158 {
2159     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2160     ASSERT_NE(typoStyle, nullptr);
2161     OH_Drawing_SetTypographyTextLineStyleOnly(typoStyle, true);
2162     bool result = OH_Drawing_TypographyTextlineGetStyleOnly(typoStyle);
2163     EXPECT_TRUE(result);
2164     result = OH_Drawing_TypographyTextlineGetStyleOnly(nullptr);
2165     EXPECT_FALSE(result);
2166     OH_Drawing_DestroyTypographyStyle(typoStyle);
2167 }
2168 
2169 /*
2170  * @tc.name: TypographyTest071
2171  * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2172  * @tc.type: FUNC
2173  */
2174 HWTEST_F(NdkTypographyTest, TypographyTest071, TestSize.Level0)
2175 {
2176     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2177     ASSERT_NE(typoStyle, nullptr);
2178     int align = TEXT_ALIGN_RIGHT;
2179     OH_Drawing_SetTypographyTextAlign(typoStyle, align);
2180     OH_Drawing_TextAlign result = OH_Drawing_TypographyGetTextAlign(typoStyle);
2181     EXPECT_EQ(result, TEXT_ALIGN_RIGHT);
2182     result = OH_Drawing_TypographyGetTextAlign(nullptr);
2183     EXPECT_EQ(result, TEXT_ALIGN_LEFT);
2184     OH_Drawing_DestroyTypographyStyle(typoStyle);
2185 }
2186 
2187 /*
2188  * @tc.name: TypographyTest072
2189  * @tc.desc: test for create and releases the memory occupied by system font configuration information
2190  * @tc.type: FUNC
2191  */
2192 HWTEST_F(NdkTypographyTest, TypographyTest072, TestSize.Level0)
2193 {
2194     OH_Drawing_FontConfigInfoErrorCode code = ERROR_FONT_CONFIG_INFO_UNKNOWN;
2195     OH_Drawing_FontConfigInfo* configJsonInfo = OH_Drawing_GetSystemFontConfigInfo(&code);
2196     if (configJsonInfo != nullptr) {
2197         EXPECT_EQ(code, SUCCESS_FONT_CONFIG_INFO);
2198         uint32_t fontGenericInfoSize = configJsonInfo->fontGenericInfoSize;
2199         uint32_t fallbackInfoSize = configJsonInfo->fallbackGroupSet[0].fallbackInfoSize;
2200         EXPECT_EQ(fontGenericInfoSize, 6);
2201         EXPECT_EQ(fallbackInfoSize, 135);
2202     } else {
2203         EXPECT_NE(code, SUCCESS_FONT_CONFIG_INFO);
2204     }
2205     OH_Drawing_DestroySystemFontConfigInfo(configJsonInfo);
2206     OH_Drawing_DestroySystemFontConfigInfo(nullptr);
2207 }
2208 
2209 /*
2210  * @tc.name: TypographyTest073
2211  * @tc.desc: test for getting all font metrics array from current line
2212  * @tc.type: FUNC
2213  */
2214 HWTEST_F(NdkTypographyTest, TypographyTest073, TestSize.Level0)
2215 {
2216     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2217     EXPECT_NE(typoStyle, nullptr);
2218     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2219     EXPECT_NE(txtStyle, nullptr);
2220     OH_Drawing_TypographyCreate* handler =
2221         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2222     EXPECT_NE(handler, nullptr);
2223     size_t charNumber = 0;
2224     const char* text = "OpenHarmony\n";
2225     OH_Drawing_TypographyHandlerAddText(handler, text);
2226     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2227     EXPECT_NE(typography, nullptr);
2228     OH_Drawing_Font_Metrics* StartLineFont = OH_Drawing_TypographyGetLineFontMetrics(typography, 1, &charNumber);
2229     EXPECT_EQ(StartLineFont, nullptr);
2230     OH_Drawing_TypographyDestroyLineFontMetrics(StartLineFont);
2231     OH_Drawing_DestroyTypography(typography);
2232     OH_Drawing_DestroyTypographyHandler(handler);
2233     OH_Drawing_DestroyTypographyStyle(typoStyle);
2234     OH_Drawing_DestroyTextStyle(txtStyle);
2235 }
2236 
2237 /*
2238  * @tc.name: TypographyTest075
2239  * @tc.desc: test for sets and gets isPlaceholder for TextStyle objects
2240  * @tc.type: FUNC
2241  */
2242 HWTEST_F(NdkTypographyTest, TypographyTest075, TestSize.Level0)
2243 {
2244     EXPECT_FALSE(OH_Drawing_TextStyleIsPlaceholder(nullptr));
2245     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2246     EXPECT_FALSE(OH_Drawing_TextStyleIsPlaceholder(txtStyle));
2247     OH_Drawing_TextStyleSetPlaceholder(nullptr);
2248     OH_Drawing_TextStyleSetPlaceholder(txtStyle);
2249     EXPECT_TRUE(OH_Drawing_TextStyleIsPlaceholder(txtStyle));
2250     EXPECT_TRUE(ConvertToOriginalText(txtStyle)->isPlaceholder);
2251     OH_Drawing_DestroyTextStyle(txtStyle);
2252 }
2253 
2254 /*
2255  * @tc.name: TypographyTest076
2256  * @tc.desc: test for the two TextStyle objects have matching properties
2257  * @tc.type: FUNC
2258  */
2259 HWTEST_F(NdkTypographyTest, TypographyTest076, TestSize.Level0)
2260 {
2261     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2262     OH_Drawing_TextStyle* txtStyleCompare = OH_Drawing_CreateTextStyle();
2263     bool result = OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES);
2264     EXPECT_TRUE(result);
2265     OH_Drawing_SetTextStyleLocale(txtStyle, "en");
2266     result = OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES);
2267     EXPECT_FALSE(result);
2268     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(nullptr, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES));
2269     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, nullptr, TEXT_STYLE_ALL_ATTRIBUTES));
2270     OH_Drawing_DestroyTextStyle(txtStyle);
2271     OH_Drawing_DestroyTextStyle(txtStyleCompare);
2272 }
2273 
2274 /*
2275  * @tc.name: TypographyTest080
2276  * @tc.desc: test for whether two TextStyle objects are equal
2277  * @tc.type: FUNC
2278  */
2279 HWTEST_F(NdkTypographyTest, TypographyTest080, TestSize.Level0)
2280 {
2281     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2282     OH_Drawing_TextStyle* txtStyleCompare = OH_Drawing_CreateTextStyle();
2283     bool result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2284     EXPECT_TRUE(result);
2285 
2286     OH_Drawing_SetTextStyleColor(txtStyle, 1);
2287     result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2288     EXPECT_FALSE(result);
2289     OH_Drawing_SetTextStyleColor(txtStyleCompare, 1);
2290     result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2291     EXPECT_TRUE(result);
2292     EXPECT_FALSE(OH_Drawing_TextStyleIsEqual(nullptr, txtStyleCompare));
2293     EXPECT_FALSE(OH_Drawing_TextStyleIsEqual(txtStyle, nullptr));
2294     EXPECT_TRUE(OH_Drawing_TextStyleIsEqual(nullptr, nullptr));
2295     OH_Drawing_DestroyTextStyle(txtStyle);
2296     OH_Drawing_DestroyTextStyle(txtStyleCompare);
2297 }
2298 
2299 /*
2300  * @tc.name: TypographyTest081
2301  * @tc.desc: test for getting and setting text style
2302  * @tc.type: FUNC
2303  */
2304 HWTEST_F(NdkTypographyTest, TypographyTest081, TestSize.Level0)
2305 {
2306     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2307     EXPECT_NE(txtStyle, nullptr);
2308     OH_Drawing_FontStyleStruct normalStyle;
2309     normalStyle.weight = FONT_WEIGHT_400;
2310     normalStyle.width = FONT_WIDTH_NORMAL;
2311     normalStyle.slant = FONT_STYLE_NORMAL;
2312     OH_Drawing_SetTextStyleFontStyleStruct(txtStyle, normalStyle);
2313     OH_Drawing_SetTextStyleFontStyleStruct(nullptr, normalStyle);
2314 
2315     OH_Drawing_FontStyleStruct style = OH_Drawing_TextStyleGetFontStyleStruct(txtStyle);
2316     EXPECT_EQ(style.weight, normalStyle.weight);
2317     EXPECT_EQ(style.width, normalStyle.width);
2318     EXPECT_EQ(style.slant, normalStyle.slant);
2319     OH_Drawing_DestroyTextStyle(txtStyle);
2320 }
2321 
2322 /*
2323  * @tc.name: TypographyTest082
2324  * @tc.desc: test for getting and setting typography style
2325  * @tc.type: FUNC
2326  */
2327 HWTEST_F(NdkTypographyTest, TypographyTest082, TestSize.Level0)
2328 {
2329     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2330     EXPECT_NE(typoStyle, nullptr);
2331     OH_Drawing_FontStyleStruct normalStyle;
2332     normalStyle.weight = FONT_WEIGHT_400;
2333     normalStyle.width = FONT_WIDTH_NORMAL;
2334     normalStyle.slant = FONT_STYLE_NORMAL;
2335     OH_Drawing_SetTypographyStyleFontStyleStruct(typoStyle, normalStyle);
2336     OH_Drawing_SetTypographyStyleFontStyleStruct(nullptr, normalStyle);
2337 
2338     OH_Drawing_FontStyleStruct style = OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyle);
2339     EXPECT_EQ(style.weight, normalStyle.weight);
2340     EXPECT_EQ(style.width, normalStyle.width);
2341     EXPECT_EQ(style.slant, normalStyle.slant);
2342     OH_Drawing_DestroyTypographyStyle(typoStyle);
2343 }
2344 
2345 /*
2346  * @tc.name: TypographyTest083
2347  * @tc.desc: test for the font properties of two TextStyle objects are equal
2348  * @tc.type: FUNC
2349  */
2350 HWTEST_F(NdkTypographyTest, TypographyTest083, TestSize.Level0)
2351 {
2352     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2353     OH_Drawing_TextStyle* txtStyleCompare = OH_Drawing_CreateTextStyle();
2354     OH_Drawing_SetTextStyleLocale(txtStyle, "en");
2355     OH_Drawing_SetTextStyleLocale(txtStyleCompare, "en");
2356     bool result = OH_Drawing_TextStyleIsEqualByFont(txtStyle, txtStyleCompare);
2357     EXPECT_TRUE(result);
2358 
2359     OH_Drawing_SetTextStyleLocale(txtStyle, "ch");
2360     result = OH_Drawing_TextStyleIsEqualByFont(txtStyle, txtStyleCompare);
2361     EXPECT_FALSE(result);
2362     EXPECT_FALSE(OH_Drawing_TextStyleIsEqualByFont(nullptr, txtStyleCompare));
2363     EXPECT_FALSE(OH_Drawing_TextStyleIsEqualByFont(txtStyle, nullptr));
2364     OH_Drawing_DestroyTextStyle(txtStyle);
2365     OH_Drawing_DestroyTextStyle(txtStyleCompare);
2366 }
2367 
2368 /*
2369  * @tc.name: TypographyTest084
2370  * @tc.desc: test for BREAK_STRATEGY_GREEDY
2371  * @tc.type: FUNC
2372  */
2373 HWTEST_F(NdkTypographyTest, TypographyTest084, TestSize.Level0)
2374 {
2375     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2376     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2377     OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_GREEDY);
2378     OH_Drawing_TypographyCreate* handler =
2379         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2380     EXPECT_NE(handler, nullptr);
2381     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2382     const char* text = "breakStrategyTest breakStrategy breakStrategyGreedyTest";
2383     OH_Drawing_TypographyHandlerAddText(handler, text);
2384     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2385     // {1.2, 3.4} for unit test
2386     const float indents[] = { 1.2, 3.4 };
2387     OH_Drawing_TypographySetIndents(typography, 2, indents);
2388     // 300.0 for unit test
2389     double maxWidth = 300.0;
2390     OH_Drawing_TypographyLayout(typography, maxWidth);
2391     OH_Drawing_TypographyLayout(nullptr, maxWidth);
2392     EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2393 }
2394 
2395 /*
2396  * @tc.name: TypographyTest085
2397  * @tc.desc: test for BREAK_STRATEGY_BALANCED
2398  * @tc.type: FUNC
2399  */
2400 HWTEST_F(NdkTypographyTest, TypographyTest085, TestSize.Level0)
2401 {
2402     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2403     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2404     OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_BALANCED);
2405     OH_Drawing_TypographyCreate* handler =
2406         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2407     EXPECT_NE(handler, nullptr);
2408     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2409     const char* text = "breakStrategyTest breakStrategy breakStrategyBALANCEDTest";
2410     OH_Drawing_TypographyHandlerAddText(handler, text);
2411     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2412     // {1.2, 3.4} for unit test
2413     const float indents[] = { 1.2, 3.4 };
2414     OH_Drawing_TypographySetIndents(typography, 2, indents);
2415     // 300.0 for unit test
2416     double maxWidth = 300.0;
2417     OH_Drawing_TypographyLayout(typography, maxWidth);
2418     EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2419 }
2420 
2421 /*
2422  * @tc.name: TypographyTest086
2423  * @tc.desc: test for BREAK_STRATEGY_HIGH_QUALITY
2424  * @tc.type: FUNC
2425  */
2426 HWTEST_F(NdkTypographyTest, TypographyTest086, TestSize.Level0)
2427 {
2428     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2429     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2430     OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_HIGH_QUALITY);
2431     OH_Drawing_TypographyCreate* handler =
2432         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2433     EXPECT_NE(handler, nullptr);
2434     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2435     const char* text = "breakStrategyTest breakStrategy breakStrategyHighQualityTest";
2436     OH_Drawing_TypographyHandlerAddText(handler, text);
2437     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2438     // {1.2, 3.4} for unit test
2439     const float indents[] = { 1.2, 3.4 };
2440     OH_Drawing_TypographySetIndents(typography, 2, indents);
2441     OH_Drawing_TypographySetIndents(nullptr, 0, indents);
2442     // 300.0 for unit test
2443     double maxWidth = 300.0;
2444     OH_Drawing_TypographyLayout(typography, maxWidth);
2445     EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2446 }
2447 
2448 /*
2449  * @tc.name: TypographyTest089
2450  * @tc.desc: test for getting line  metrics for text typography
2451  * @tc.type: FUNC
2452  */
2453 HWTEST_F(NdkTypographyTest, TypographyTest089, TestSize.Level0)
2454 {
2455     OH_Drawing_Typography* typography = nullptr;
2456     OH_Drawing_LineMetrics* vectorMetrics = OH_Drawing_TypographyGetLineMetrics(typography);
2457     EXPECT_EQ(vectorMetrics, nullptr);
2458 }
2459 
2460 /*
2461  * @tc.name: TypographyTest090
2462  * @tc.desc: test for getting size of line metrics for text typography
2463  * @tc.type: FUNC
2464  */
2465 HWTEST_F(NdkTypographyTest, TypographyTest090, TestSize.Level0)
2466 {
2467     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2468     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2469     const char fontFamiliesTest[] = { 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79,
2470         0x4f, 0x53, 0x5f, 0x53, 0x61, 0x6e, 0x73 };
2471     const char *fontFamilies[] = {fontFamiliesTest};
2472     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2473     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
2474     OH_Drawing_TypographyCreate* handler =
2475         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2476     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2477     const char *text = "这是一个排版信息获取接口的测试文本";
2478     OH_Drawing_TypographyHandlerAddText(handler, text);
2479     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2480     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2481 
2482     OH_Drawing_LineMetrics* lineMetrics = OH_Drawing_TypographyGetLineMetrics(typography);
2483     EXPECT_NE(lineMetrics, nullptr);
2484     int lineMetricsSize = OH_Drawing_LineMetricsGetSize(lineMetrics);
2485     EXPECT_EQ(lineMetricsSize, 2);
2486     OH_Drawing_Font_Metrics metrics = lineMetrics[0].firstCharMetrics;
2487 
2488     OH_Drawing_LineMetrics lineMetric;
2489     OH_Drawing_TypographyGetLineMetricsAt(typography, 0, &lineMetric);
2490     OH_Drawing_Font_Metrics metric = lineMetric.firstCharMetrics;
2491 
2492     EXPECT_EQ(lineMetric.ascender, lineMetrics[0].ascender);
2493     EXPECT_EQ(lineMetric.descender, lineMetrics[0].descender);
2494     EXPECT_EQ(lineMetric.width, lineMetrics[0].width);
2495     EXPECT_EQ(lineMetric.height, lineMetrics[0].height);
2496     EXPECT_EQ(lineMetric.x, lineMetrics[0].x);
2497     EXPECT_EQ(lineMetric.y, lineMetrics[0].y);
2498     EXPECT_EQ(lineMetric.startIndex, lineMetrics[0].startIndex);
2499     EXPECT_EQ(lineMetric.endIndex, lineMetrics[0].endIndex);
2500 
2501     EXPECT_EQ(metric.flags, metrics.flags);
2502     EXPECT_EQ(metric.top, metrics.top);
2503     EXPECT_EQ(metric.ascent, metrics.ascent);
2504     EXPECT_EQ(metric.descent, metrics.descent);
2505     EXPECT_EQ(metric.avgCharWidth, metrics.avgCharWidth);
2506     EXPECT_EQ(metric.maxCharWidth, metrics.maxCharWidth);
2507     EXPECT_EQ(metric.xMin, metrics.xMin);
2508     EXPECT_EQ(metric.xMax, metrics.xMax);
2509     EXPECT_EQ(metric.xHeight, metrics.xHeight);
2510     EXPECT_EQ(metric.underlineThickness, metrics.underlineThickness);
2511     EXPECT_EQ(metric.underlinePosition, metrics.underlinePosition);
2512     EXPECT_EQ(metric.strikeoutThickness, metrics.strikeoutThickness);
2513     EXPECT_EQ(metric.strikeoutPosition, metrics.strikeoutPosition);
2514 
2515     OH_Drawing_DestroyLineMetrics(lineMetrics);
2516     OH_Drawing_DestroyTypography(typography);
2517     OH_Drawing_DestroyTextStyle(txtStyle);
2518     OH_Drawing_DestroyTypographyHandler(handler);
2519     OH_Drawing_DestroyTypographyStyle(typoStyle);
2520 }
2521 
2522 /*
2523  * @tc.name: TypographyTest091
2524  * @tc.desc: test returning line metrics info for the line text typography
2525  * @tc.type: FUNC
2526  */
2527 HWTEST_F(NdkTypographyTest, TypographyTest091, TestSize.Level0)
2528 {
2529     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2530     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2531     const char fontFamiliesTest[] = { 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79,
2532         0x4f, 0x53, 0x5f, 0x53, 0x61, 0x6e, 0x73 };
2533     const char *fontFamilies[] = {fontFamiliesTest};
2534     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2535     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
2536     OH_Drawing_TypographyCreate* handler =
2537         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2538     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2539     const char *text = "这是一个排版信息获取接口的测试文本";
2540     OH_Drawing_TypographyHandlerAddText(handler, text);
2541     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2542     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2543 
2544     OH_Drawing_LineMetrics lineMetric;
2545     OH_Drawing_TypographyGetLineMetricsAt(typography, 0, &lineMetric);
2546     EXPECT_NEAR(lineMetric.ascender, 46.399998, FLOAT_DATA_EPSILON);
2547     EXPECT_NEAR(lineMetric.descender, 12.200000, FLOAT_DATA_EPSILON);
2548     EXPECT_EQ(lineMetric.capHeight, 35.0);
2549     EXPECT_EQ(lineMetric.xHeight, 25.0);
2550     EXPECT_NEAR(lineMetric.width, 799.999146, FLOAT_DATA_EPSILON);
2551     EXPECT_EQ(lineMetric.height, 59.0);
2552     EXPECT_EQ(lineMetric.x, 0.0);
2553     EXPECT_EQ(lineMetric.y, 0.0);
2554     EXPECT_EQ(lineMetric.startIndex, 0);
2555     EXPECT_EQ(lineMetric.endIndex, 16);
2556 
2557     OH_Drawing_Font_Metrics metric = lineMetric.firstCharMetrics;
2558     EXPECT_NEAR(metric.top, -52.799999, FLOAT_DATA_EPSILON);
2559     EXPECT_NEAR(metric.underlineThickness, 2.500000, FLOAT_DATA_EPSILON);
2560     EXPECT_NEAR(metric.underlinePosition, 10.350000, FLOAT_DATA_EPSILON);
2561     EXPECT_NEAR(metric.strikeoutThickness, 2.500000, FLOAT_DATA_EPSILON);
2562     EXPECT_NEAR(metric.strikeoutPosition, -15.000001, FLOAT_DATA_EPSILON);
2563 
2564     OH_Drawing_DestroyTextStyle(txtStyle);
2565     OH_Drawing_DestroyTypography(typography);
2566     OH_Drawing_DestroyTypographyHandler(handler);
2567     OH_Drawing_DestroyTypographyStyle(typoStyle);
2568 }
2569 
2570 /*
2571  * @tc.name: TypographyTest092
2572  * @tc.desc: test for getting indets of index for text typography
2573  * @tc.type: FUNC
2574  */
2575 HWTEST_F(NdkTypographyTest, TypographyTest092, TestSize.Level0)
2576 {
2577     OH_Drawing_Typography* typography = nullptr;
2578     EXPECT_EQ(0.0, OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
2579     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2580     OH_Drawing_TypographyCreate* handler =
2581         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2582     typography = OH_Drawing_CreateTypography(handler);
2583     EXPECT_EQ(0.0, OH_Drawing_TypographyGetIndentsWithIndex(typography, -1));
2584     // {1.2, 3.4} for unit test
2585     const float indents[] = { 1.2, 3.4 };
2586     OH_Drawing_TypographySetIndents(typography, 2, indents);
2587     int indexOutOfBounds = 3;
2588     EXPECT_EQ(0, OH_Drawing_TypographyGetIndentsWithIndex(nullptr, 0));
2589     EXPECT_EQ(indents[1], OH_Drawing_TypographyGetIndentsWithIndex(typography, indexOutOfBounds));
2590     OH_Drawing_DestroyTypography(typography);
2591     OH_Drawing_DestroyTypographyHandler(handler);
2592     OH_Drawing_DestroyTypographyStyle(typoStyle);
2593 }
2594 
2595 /*
2596  * @tc.name: TypographyTest093
2597  * @tc.desc: test for getting line font metrics for text typography
2598  * @tc.type: FUNC
2599  */
2600 HWTEST_F(NdkTypographyTest, TypographyTest093, TestSize.Level0)
2601 {
2602     size_t charNumber = 0;
2603     EXPECT_EQ(OH_Drawing_TypographyGetLineFontMetrics(nullptr, 1, &charNumber), nullptr);
2604     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2605     OH_Drawing_TypographyCreate* handler =
2606         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2607     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2608     EXPECT_EQ(OH_Drawing_TypographyGetLineFontMetrics(typography, 1, nullptr), nullptr);
2609     EXPECT_EQ(OH_Drawing_TypographyGetLineFontMetrics(typography, 0, &charNumber), nullptr);
2610     EXPECT_EQ(OH_Drawing_TypographyGetLineFontMetrics(nullptr, 0, nullptr), nullptr);
2611     OH_Drawing_DestroyTypography(typography);
2612     OH_Drawing_DestroyTypographyHandler(handler);
2613     OH_Drawing_DestroyTypographyStyle(typoStyle);
2614 }
2615 
2616 /*
2617  * @tc.name: TypographyTest094
2618  * @tc.desc: test for setting font weight for text typography
2619  * @tc.type: FUNC
2620  */
2621 HWTEST_F(NdkTypographyTest, TypographyTest094, TestSize.Level0)
2622 {
2623     OH_Drawing_SetTypographyTextFontWeight(nullptr, FONT_WEIGHT_100);
2624     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2625     OH_Drawing_SetTypographyTextFontWeight(typoStyle, -1);
2626     EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W400);
2627     OH_Drawing_SetTypographyTextFontStyle(nullptr, FONT_STYLE_NORMAL);
2628     OH_Drawing_DestroyTypographyStyle(typoStyle);
2629 }
2630 
2631 /*
2632  * @tc.name: TypographyTest095
2633  * @tc.desc: test for setting font height for text typography
2634  * @tc.type: FUNC
2635  */
2636 HWTEST_F(NdkTypographyTest, TypographyTest095, TestSize.Level0)
2637 {
2638     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2639     // -1.2 for unit test
2640     OH_Drawing_SetTypographyTextFontHeight(typoStyle, -1.2);
2641     OH_Drawing_SetTypographyTextFontHeight(nullptr, 0);
2642     EXPECT_TRUE(ConvertToOriginalText(typoStyle)->heightOnly);
2643     EXPECT_EQ(ConvertToOriginalText(typoStyle)->heightScale, 0);
2644 }
2645 
2646 /*
2647  * @tc.name: TypographyTest096
2648  * @tc.desc: test for setting half leading for text typography
2649  * @tc.type: FUNC
2650  */
2651 HWTEST_F(NdkTypographyTest, TypographyTest096, TestSize.Level0)
2652 {
2653     bool halfLeading = false;
2654     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2655     OH_Drawing_SetTypographyTextHalfLeading(typoStyle, halfLeading);
2656     OH_Drawing_SetTypographyTextHalfLeading(nullptr, halfLeading);
2657     EXPECT_FALSE(ConvertToOriginalText(typoStyle)->halfLeading);
2658 }
2659 
2660 /*
2661  * @tc.name: TypographyTest097
2662  * @tc.desc: test for setting text line style font weight for text typography
2663  * @tc.type: FUNC
2664  */
2665 HWTEST_F(NdkTypographyTest, TypographyTest097, TestSize.Level0)
2666 {
2667     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2668     // -1 for unit test
2669     int weight = -1;
2670     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, weight);
2671     OH_Drawing_SetTypographyTextLineStyleFontWeight(nullptr, weight);
2672     EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W400);
2673 }
2674 
2675 /*
2676  * @tc.name: TypographyTest098
2677  * @tc.desc: test for text line style getting font families for text typography
2678  * @tc.type: FUNC
2679  */
2680 HWTEST_F(NdkTypographyTest, TypographyTest098, TestSize.Level0)
2681 {
2682     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2683     char** result = OH_Drawing_TypographyTextlineStyleGetFontFamilies(typoStyle, nullptr);
2684     EXPECT_EQ(result, nullptr);
2685 }
2686 
2687 /*
2688  * @tc.name: TypographyTest099
2689  * @tc.desc: test for text line style setting half leading for text typography
2690  * @tc.type: FUNC
2691  */
2692 HWTEST_F(NdkTypographyTest, TypographyTest099, TestSize.Level0)
2693 {
2694     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2695     bool lineStyleHalfLeading = false;
2696     OH_Drawing_SetTypographyTextLineStyleHalfLeading(typoStyle, lineStyleHalfLeading);
2697     OH_Drawing_SetTypographyTextLineStyleHalfLeading(nullptr, lineStyleHalfLeading);
2698     bool result = OH_Drawing_TypographyTextlineStyleGetHalfLeading(typoStyle);
2699     EXPECT_FALSE(result);
2700 }
2701 
2702 /*
2703  * @tc.name: TypographyTest100
2704  * @tc.desc: test for getting style struct for text typography
2705  * @tc.type: FUNC
2706  */
2707 HWTEST_F(NdkTypographyTest, TypographyTest100, TestSize.Level0)
2708 {
2709     // 0.0 for unit test
2710     double lineShift = 0.0;
2711     EXPECT_EQ(OH_Drawing_TypographyStyleGetStrutStyle(nullptr), nullptr);
2712     OH_Drawing_TextStyleSetBaselineShift(nullptr, lineShift);
2713     EXPECT_EQ(OH_Drawing_TextStyleGetBaselineShift(nullptr), 0.0);
2714     EXPECT_EQ(OH_Drawing_TypographyStyleGetEffectiveAlignment(nullptr), TEXT_ALIGN_START);
2715     EXPECT_FALSE(OH_Drawing_TypographyStyleIsHintEnabled(nullptr));
2716 }
2717 
2718 /*
2719  * @tc.name: TypographyTest101
2720  * @tc.desc: test for getting font style struct for text typography
2721  * @tc.type: FUNC
2722  */
2723 HWTEST_F(NdkTypographyTest, TypographyTest101, TestSize.Level0)
2724 {
2725     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2726     EXPECT_NE(typoStyle, nullptr);
2727     OH_Drawing_FontStyleStruct normalStyle;
2728     normalStyle.weight = FONT_WEIGHT_900;
2729     normalStyle.width = FONT_WIDTH_ULTRA_EXPANDED;
2730     normalStyle.slant = FONT_STYLE_ITALIC;
2731     OH_Drawing_SetTypographyStyleFontStyleStruct(typoStyle, normalStyle);
2732 
2733     OH_Drawing_FontStyleStruct style = OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyle);
2734     EXPECT_EQ(style.weight, FONT_WEIGHT_900);
2735     EXPECT_EQ(style.width, FONT_WIDTH_ULTRA_EXPANDED);
2736     EXPECT_EQ(style.slant, FONT_STYLE_ITALIC);
2737     OH_Drawing_DestroyTypographyStyle(typoStyle);
2738 }
2739 
2740 /*
2741  * @tc.name: TypographyTest102
2742  * @tc.desc: test for the font parser
2743  * @tc.type: FUNC
2744  */
2745 HWTEST_F(NdkTypographyTest, TypographyTest102, TestSize.Level0)
2746 {
2747     OH_Drawing_FontParser* parser = OH_Drawing_CreateFontParser();
2748     if (std::filesystem::exists(VIS_LIST_FILE_NAME)) {
2749         size_t fontNum;
2750         char** list = OH_Drawing_FontParserGetSystemFontList(parser, &fontNum);
2751         EXPECT_NE(list, nullptr);
2752         EXPECT_EQ(OH_Drawing_FontParserGetSystemFontList(nullptr, &fontNum), nullptr);
2753         const char* name = list[0];
2754         EXPECT_NE(OH_Drawing_FontParserGetFontByName(parser, name), nullptr);
2755         EXPECT_EQ(OH_Drawing_FontParserGetFontByName(nullptr, name), nullptr);
2756         OH_Drawing_DestroySystemFontList(list, fontNum);
2757         OH_Drawing_DestroySystemFontList(nullptr, fontNum);
2758     }
2759     char** listNull = OH_Drawing_FontParserGetSystemFontList(parser, nullptr);
2760     EXPECT_EQ(listNull, nullptr);
2761     OH_Drawing_DestroyFontParser(parser);
2762 }
2763 
2764 /*
2765  * @tc.name: TypographyTest103
2766  * @tc.desc: test arc text offset
2767  * @tc.type: FUNC
2768  */
2769 HWTEST_F(NdkTypographyTest, TypographyTest104, TestSize.Level0)
2770 {
2771     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2772     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2773     OH_Drawing_TypographyCreate* handler =
2774         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2775     EXPECT_NE(handler, nullptr);
2776     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
2777     OH_Drawing_SetTextStyleFontSize(txtStyle, ARC_FONT_SIZE);
2778     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
2779     bool halfLeading = true;
2780     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
2781     const char* fontFamilies[] = { "Roboto" };
2782     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2783     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2784     const char* text = "OpenHarmony\n";
2785     OH_Drawing_TypographyHandlerAddText(handler, text);
2786     OH_Drawing_TypographyHandlerPopTextStyle(handler);
2787     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2788     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2789     OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
2790     OH_Drawing_PathArcTo(cPath, LEFT_POS, LEFT_POS, RIGHT_POS, RIGHT_POS, 0, SWEEP_DEGREE);
2791 
2792     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
2793     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
2794     OH_Drawing_CanvasDrawPath(cCanvas, cPath);
2795     OH_Drawing_TypographyPaintOnPath(nullptr, nullptr, nullptr, -1, -2);
2796     OH_Drawing_TypographyPaintOnPath(typography, cCanvas, cPath, ARC_FONT_SIZE, ARC_FONT_SIZE);
2797     OH_Drawing_TypographyPaintOnPath(typography, cCanvas, cPath, 1.5, 100);
2798     OH_Drawing_Font_Metrics fontmetrics;
2799     EXPECT_TRUE(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics));
2800     OH_Drawing_SetTypographyTextStyle(typoStyle, txtStyle);
2801     OH_Drawing_DestroyTypography(typography);
2802     OH_Drawing_DestroyTypographyHandler(handler);
2803     OH_Drawing_DestroyTypographyStyle(typoStyle);
2804     OH_Drawing_DestroyTextStyle(txtStyle);
2805     OH_Drawing_PathDestroy(cPath);
2806     OH_Drawing_CanvasDestroy(cCanvas);
2807 }
2808 
2809 /*
2810  * @tc.name: TypographyTest104
2811  * @tc.desc: test arc text drawing
2812  * @tc.type: FUNC
2813  */
2814 HWTEST_F(NdkTypographyTest, TypographyTest103, TestSize.Level0)
2815 {
2816     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2817     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2818     OH_Drawing_TypographyCreate* handler =
2819         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2820     EXPECT_NE(handler, nullptr);
2821     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
2822     OH_Drawing_SetTextStyleFontSize(txtStyle, ARC_FONT_SIZE);
2823     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
2824     bool halfLeading = true;
2825     OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
2826     const char* fontFamilies[] = { "Roboto" };
2827     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2828     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2829     const char* text = "OpenHarmony\n";
2830     OH_Drawing_TypographyHandlerAddText(handler, text);
2831     OH_Drawing_TypographyHandlerPopTextStyle(handler);
2832     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2833     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2834     OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
2835     OH_Drawing_PathArcTo(cPath, LEFT_POS, LEFT_POS, RIGHT_POS, RIGHT_POS, 0, SWEEP_DEGREE);
2836 
2837     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
2838     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
2839     OH_Drawing_CanvasDrawPath(cCanvas, cPath);
2840     OH_Drawing_TypographyPaintOnPath(typography, cCanvas, cPath, ARC_FONT_SIZE, ARC_FONT_SIZE);
2841     OH_Drawing_Font_Metrics fontmetrics;
2842     EXPECT_TRUE(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics));
2843     OH_Drawing_SetTypographyTextStyle(typoStyle, txtStyle);
2844     OH_Drawing_DestroyTypography(typography);
2845     OH_Drawing_DestroyTypographyHandler(handler);
2846     OH_Drawing_DestroyTypographyStyle(typoStyle);
2847     OH_Drawing_DestroyTextStyle(txtStyle);
2848     OH_Drawing_PathDestroy(cPath);
2849     OH_Drawing_CanvasDestroy(cCanvas);
2850 }
2851 
2852 /*
2853  * @tc.name: TypographyTest105
2854  * @tc.desc: test for the text box
2855  * @tc.type: FUNC
2856  */
2857 HWTEST_F(NdkTypographyTest, TypographyTest105, TestSize.Level0)
2858 {
2859     CreateTypographyHandler();
2860 
2861     OH_Drawing_PlaceholderSpan placeholderSpan1 = {150, 150, ALIGNMENT_OFFSET_AT_BASELINE, TEXT_BASELINE_IDEOGRAPHIC,
2862         0};
2863     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan1);
2864 
2865     OH_Drawing_PlaceholderSpan placeholderSpan2 = {100, 100, ALIGNMENT_ABOVE_BASELINE, TEXT_BASELINE_ALPHABETIC, 0};
2866     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan2);
2867 
2868     OH_Drawing_PlaceholderSpan placeholderSpan3 = {150, 150, ALIGNMENT_BELOW_BASELINE, TEXT_BASELINE_IDEOGRAPHIC, 0};
2869     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan3);
2870 
2871     OH_Drawing_PlaceholderSpan placeholderSpan4 = {70.5, 70.5, ALIGNMENT_TOP_OF_ROW_BOX, TEXT_BASELINE_ALPHABETIC, 0};
2872     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan4);
2873 
2874     OH_Drawing_PlaceholderSpan placeholderSpan5 = {150, 150, ALIGNMENT_BOTTOM_OF_ROW_BOX, TEXT_BASELINE_IDEOGRAPHIC, 0};
2875     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan5);
2876 
2877     OH_Drawing_PlaceholderSpan placeholderSpan6 = {0, 0, ALIGNMENT_CENTER_OF_ROW_BOX, TEXT_BASELINE_ALPHABETIC, 0};
2878     OH_Drawing_TypographyHandlerAddPlaceholder(fHandler, &placeholderSpan6);
2879 
2880     OH_Drawing_TypographyHandlerAddText(fHandler, DEFAULT_TEXT);
2881     CreateTypography();
2882     Layout();
2883 
2884     OH_Drawing_TextBox* textBox = OH_Drawing_TypographyGetRectsForPlaceholders(fTypography);
2885     EXPECT_EQ(OH_Drawing_GetLeftFromTextBox(textBox, 0), 0);
2886     EXPECT_EQ(OH_Drawing_GetRightFromTextBox(textBox, 0), 150);
2887     EXPECT_EQ(::round(OH_Drawing_GetTopFromTextBox(textBox, 0)), 0);
2888     EXPECT_EQ(::round(OH_Drawing_GetBottomFromTextBox(textBox, 0)), 150);
2889     EXPECT_EQ(OH_Drawing_GetTextDirectionFromTextBox(textBox, 0), 1);
2890     EXPECT_EQ(OH_Drawing_GetSizeOfTextBox(textBox), 6);
2891 
2892     OH_Drawing_PositionAndAffinity* positionAndAffinity =
2893         OH_Drawing_TypographyGetGlyphPositionAtCoordinate(fTypography, 50.5, 10.5);
2894     EXPECT_EQ(OH_Drawing_GetPositionFromPositionAndAffinity(positionAndAffinity), 0);
2895     EXPECT_EQ(OH_Drawing_GetPositionFromPositionAndAffinity(nullptr), 0);
2896     EXPECT_EQ(OH_Drawing_GetAffinityFromPositionAndAffinity(positionAndAffinity), 0);
2897     EXPECT_EQ(OH_Drawing_GetAffinityFromPositionAndAffinity(nullptr), 0);
2898 
2899     OH_Drawing_Range* range = OH_Drawing_TypographyGetWordBoundary(fTypography, 1);
2900     EXPECT_EQ(OH_Drawing_GetStartFromRange(range), 1);
2901     EXPECT_EQ(OH_Drawing_GetStartFromRange(nullptr), 0);
2902     EXPECT_EQ(OH_Drawing_GetEndFromRange(range), 2);
2903     EXPECT_EQ(OH_Drawing_GetEndFromRange(nullptr), 0);
2904     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(fTypography, 1), 112);
2905     EXPECT_EQ(OH_Drawing_TypographyGetLineHeight(nullptr, 1), 0);
2906     EXPECT_EQ(OH_Drawing_TypographyGetLineWidth(fTypography, 1), 100);
2907     EXPECT_EQ(OH_Drawing_TypographyGetLineWidth(nullptr, 1), 0);
2908 }
2909 
2910 /*
2911  * @tc.name: TypographyTest106
2912  * @tc.desc: test for the textbox.
2913  * @tc.type: FUNC
2914  */
2915 HWTEST_F(NdkTypographyTest, TypographyTest106, TestSize.Level0)
2916 {
2917     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2918     OH_Drawing_TypographyCreate* handler =
2919         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2920 
2921     OH_Drawing_PlaceholderSpan *placeholderSpan = new OH_Drawing_PlaceholderSpan();
2922     placeholderSpan->width = 150.0;
2923     placeholderSpan->height = 160.0;
2924     OH_Drawing_TypographyHandlerAddPlaceholder(handler, placeholderSpan);
2925     OH_Drawing_TypographyHandlerAddPlaceholder(handler, placeholderSpan);
2926     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2927     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2928     OH_Drawing_TextBox* textBox = OH_Drawing_TypographyGetRectsForPlaceholders(typography);
2929     int size = OH_Drawing_GetSizeOfTextBox(textBox);
2930     EXPECT_EQ(size, 2);
2931     for (int i = 0; i < size; i++) {
2932         EXPECT_EQ(OH_Drawing_GetLeftFromTextBox(textBox, i), 0.000000 + i * 150.000000);
2933         EXPECT_EQ(OH_Drawing_GetRightFromTextBox(textBox, i), 150.000000 + i * 150.000000);
2934         EXPECT_EQ(static_cast<int>(OH_Drawing_GetTopFromTextBox(textBox, i)), 0);
2935         EXPECT_EQ(static_cast<int>(OH_Drawing_GetBottomFromTextBox(textBox, i)), 159);
2936     }
2937     OH_Drawing_TypographyGetRectsForPlaceholders(nullptr);
2938     EXPECT_NE(textBox, nullptr);
2939     OH_Drawing_DestroyTypographyStyle(typoStyle);
2940     OH_Drawing_DestroyTypographyHandler(handler);
2941     OH_Drawing_DestroyTypography(typography);
2942     OH_Drawing_TypographyDestroyTextBox(textBox);
2943 }
2944 
2945 /*
2946  * @tc.name: TypographyTest107
2947  * @tc.desc: test for default textshadow.
2948  * @tc.type: FUNC
2949  */
2950 HWTEST_F(NdkTypographyTest, TypographyTest107, TestSize.Level0)
2951 {
2952     // Test default scenario
2953     OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
2954     EXPECT_NE(shadow, nullptr);
2955     uint32_t color = 0;
2956     OH_Drawing_Point* offset = OH_Drawing_PointCreate(0, 0);
2957     double blurRadius = 0.0;
2958     OH_Drawing_SetTextShadow(shadow, color, offset, blurRadius);
2959     OH_Drawing_DestroyTextShadow(shadow);
2960     OH_Drawing_PointDestroy(offset);
2961     OH_Drawing_SetTextShadow(nullptr, color, nullptr, blurRadius);
2962     OH_Drawing_SetTextShadow(shadow, color, nullptr, blurRadius);
2963     OH_Drawing_DestroyTextShadow(nullptr);
2964     OH_Drawing_PointDestroy(nullptr);
2965     EXPECT_NE(shadow, nullptr);
2966 }
2967 
2968 /*
2969  * @tc.name: TextStyleAddShadowTest001
2970  * @tc.desc: test for multiple shadow parameters and abnormal shadow parameters.
2971  * @tc.type: FUNC
2972  */
2973 HWTEST_F(NdkTypographyTest, TextStyleAddShadowTest001, TestSize.Level0)
2974 {
2975     // Test the full shadow parameters of the scene
2976     OH_Drawing_TextShadow* shadow2 = OH_Drawing_CreateTextShadow();
2977     uint32_t color2 = OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00);
2978     OH_Drawing_Point* offset2 = OH_Drawing_PointCreate(10, 10);
2979     double blurRadius2 = 10.0;
2980     OH_Drawing_SetTextShadow(shadow2, color2, offset2, blurRadius2);
2981     OH_Drawing_TextStyle* textStyle = OH_Drawing_CreateTextStyle();
2982     OH_Drawing_TextStyleAddShadow(textStyle, shadow2);
2983     OH_Drawing_TextStyleAddShadow(textStyle, shadow2);
2984     int getCount2 = OH_Drawing_TextStyleGetShadowCount(textStyle);
2985     EXPECT_EQ(getCount2, 2);
2986     OH_Drawing_TextStyleClearShadows(textStyle);
2987     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(textStyle), 0);
2988     OH_Drawing_TextShadow* shadow21 = OH_Drawing_CreateTextShadow();
2989     uint32_t color21 = OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0x00);
2990     OH_Drawing_Point* offset21 = OH_Drawing_PointCreate(-10, -10);
2991     double blurRadius21 = 20.0;
2992     OH_Drawing_SetTextShadow(shadow21, color21, offset21, blurRadius21);
2993     OH_Drawing_TextStyleAddShadow(textStyle, shadow21);
2994     OH_Drawing_TextStyleAddShadow(textStyle, shadow2);
2995     OH_Drawing_TextShadow* getShadow2 = OH_Drawing_TextStyleGetShadowWithIndex(textStyle, getCount2 - 1);
2996     EXPECT_NE(getShadow2, nullptr);
2997     OH_Drawing_TextShadow* getShadow21 = OH_Drawing_TextStyleGetShadowWithIndex(textStyle, 0);
2998     EXPECT_NE(getShadow21, nullptr);
2999     EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(textStyle, -1), nullptr);
3000     EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(textStyle, getCount2), nullptr);
3001     OH_Drawing_PointDestroy(offset2);
3002     OH_Drawing_PointDestroy(offset21);
3003     OH_Drawing_DestroyTextShadow(shadow2);
3004     OH_Drawing_DestroyTextShadow(shadow21);
3005     EXPECT_NE(shadow2, nullptr);
3006     EXPECT_NE(shadow21, nullptr);
3007 
3008     // Test the scene for abnormal shadow parameters
3009     OH_Drawing_TextShadow* shadow3 = OH_Drawing_CreateTextShadow();
3010     uint32_t color3 = -1;
3011     OH_Drawing_Point* offset3 = OH_Drawing_PointCreate(10, 10);
3012     double blurRadius3 = -10.0;
3013     OH_Drawing_SetTextShadow(shadow3, color3, offset3, blurRadius3);
3014     EXPECT_NE(shadow3, nullptr);
3015     OH_Drawing_TextStyleAddShadow(textStyle, shadow3);
3016     OH_Drawing_TextStyleAddShadow(textStyle, shadow3);
3017     OH_Drawing_PointDestroy(offset3);
3018     OH_Drawing_DestroyTextShadow(shadow3);
3019     OH_Drawing_TextShadow* shadow3AllGet = OH_Drawing_TextStyleGetShadows(textStyle);
3020     EXPECT_NE(shadow3AllGet, nullptr);
3021     OH_Drawing_DestroyTextShadows(shadow3AllGet);
3022     EXPECT_NE(shadow3AllGet, nullptr);
3023 }
3024 
3025 /*
3026  * @tc.name: AddTextStyleDecorationTest001
3027  * @tc.desc: test for add multiple text decoration
3028  * @tc.type: FUNC
3029  */
3030 HWTEST_F(NdkTypographyTest, AddTextStyleDecorationTest001, TestSize.Level0)
3031 {
3032     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3033     EXPECT_NE(txtStyle, nullptr);
3034     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE);
3035 
3036     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE);
3037     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE);
3038 
3039     OH_Drawing_AddTextStyleDecoration(txtStyle, -1);
3040     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE);
3041 
3042     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_OVERLINE);
3043     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE | TextDecoration::OVERLINE);
3044 
3045     OH_Drawing_AddTextStyleDecoration(nullptr, TEXT_DECORATION_LINE_THROUGH);
3046     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE | TextDecoration::OVERLINE);
3047 
3048     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_LINE_THROUGH);
3049     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration,
3050         TextDecoration::UNDERLINE | TextDecoration::OVERLINE | TextDecoration::LINE_THROUGH);
3051 
3052     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE);
3053     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::NONE);
3054     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE | TEXT_DECORATION_LINE_THROUGH);
3055     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE | TextDecoration::LINE_THROUGH);
3056     OH_Drawing_AddTextStyleDecoration(nullptr, TEXT_DECORATION_UNDERLINE | TEXT_DECORATION_LINE_THROUGH);
3057 
3058     OH_Drawing_DestroyTextStyle(txtStyle);
3059 }
3060 
3061 /*
3062  * @tc.name: RemoveTextStyleDecorationTest001
3063  * @tc.desc: test for remove specific text decoration
3064  * @tc.type: FUNC
3065  */
3066 HWTEST_F(NdkTypographyTest, RemoveTextStyleDecorationTest001, TestSize.Level0)
3067 {
3068     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3069     EXPECT_NE(txtStyle, nullptr);
3070     OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE);
3071 
3072     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE);
3073     OH_Drawing_AddTextStyleDecoration(txtStyle, TEXT_DECORATION_OVERLINE);
3074     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE | TextDecoration::OVERLINE);
3075     OH_Drawing_RemoveTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE);
3076     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
3077 
3078     OH_Drawing_RemoveTextStyleDecoration(txtStyle, -1);
3079     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
3080 
3081     OH_Drawing_RemoveTextStyleDecoration(nullptr, TEXT_DECORATION_LINE_THROUGH);
3082     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
3083 
3084     OH_Drawing_AddTextStyleDecoration(txtStyle,
3085         TEXT_DECORATION_UNDERLINE | TEXT_DECORATION_OVERLINE | TEXT_DECORATION_LINE_THROUGH);
3086     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration,
3087         TextDecoration::UNDERLINE | TextDecoration::OVERLINE | TextDecoration::LINE_THROUGH);
3088     OH_Drawing_RemoveTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE | TEXT_DECORATION_LINE_THROUGH);
3089     EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
3090     OH_Drawing_RemoveTextStyleDecoration(nullptr, TEXT_DECORATION_UNDERLINE | TEXT_DECORATION_LINE_THROUGH);
3091 
3092     OH_Drawing_DestroyTextStyle(txtStyle);
3093 }
3094 
3095 /*
3096  * @tc.name: TypographyTest108
3097  * @tc.desc: test for the text tab create and destroy
3098  * @tc.type: FUNC
3099  */
3100 HWTEST_F(NdkTypographyTest, TypographyTest108, TestSize.Level0)
3101 {
3102     OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
3103     EXPECT_NE(textTab, nullptr);
3104     OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_END, -1.0);
3105     EXPECT_NE(textTab2, nullptr);
3106     OH_Drawing_DestroyTextTab(textTab);
3107     OH_Drawing_DestroyTextTab(textTab2);
3108 }
3109 
3110 /*
3111  * @tc.name: TypographyTest109
3112  * @tc.desc: test for get alignment of the text tab
3113  * @tc.type: FUNC
3114  */
3115 HWTEST_F(NdkTypographyTest, TypographyTest109, TestSize.Level0)
3116 {
3117     OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
3118     EXPECT_EQ(OH_Drawing_GetTextTabAlignment(textTab), TEXT_ALIGN_LEFT);
3119     OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_JUSTIFY, 0.0);
3120     EXPECT_EQ(OH_Drawing_GetTextTabAlignment(textTab), TEXT_ALIGN_LEFT);
3121     EXPECT_EQ(OH_Drawing_GetTextTabAlignment(nullptr), TEXT_ALIGN_LEFT);
3122     OH_Drawing_DestroyTextTab(textTab);
3123     OH_Drawing_DestroyTextTab(textTab2);
3124 }
3125 
3126 /*
3127  * @tc.name: TypographyTest110
3128  * @tc.desc: test for get location of the text tab
3129  * @tc.type: FUNC
3130  */
3131 HWTEST_F(NdkTypographyTest, TypographyTest110, TestSize.Level0)
3132 {
3133     OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
3134     EXPECT_EQ(OH_Drawing_GetTextTabLocation(textTab), 0.0);
3135     OH_Drawing_DestroyTextTab(textTab);
3136     OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, -100.0);
3137     EXPECT_EQ(OH_Drawing_GetTextTabLocation(textTab2), -100.0);
3138     EXPECT_EQ(OH_Drawing_GetTextTabLocation(nullptr), 0.0);
3139     OH_Drawing_DestroyTextTab(textTab2);
3140 }
3141 
3142 /*
3143  * @tc.name: TypographyTest111
3144  * @tc.desc: test for typography style set text tab
3145  * @tc.type: FUNC
3146  */
3147 HWTEST_F(NdkTypographyTest, TypographyTest111, TestSize.Level0)
3148 {
3149     OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, -1.0);
3150     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3151     OH_Drawing_SetTypographyTextTab(typoStyle, textTab);
3152     OH_Drawing_SetTypographyTextTab(nullptr, textTab);
3153     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3154     EXPECT_EQ(ConvertToOriginalText(typoStyle)->tab.alignment, TextAlign::LEFT);
3155     EXPECT_EQ(ConvertToOriginalText(typoStyle)->tab.location, -1.0);
3156     OH_Drawing_DestroyTextTab(textTab);
3157     OH_Drawing_DestroyTypographyStyle(typoStyle);
3158 }
3159 
3160 /*
3161  * @tc.name: TypographyTest112
3162  * @tc.desc: test for truncated emoji text drawing
3163  * @tc.type: FUNC
3164  */
3165 HWTEST_F(NdkTypographyTest, TypographyTest112, TestSize.Level0)
3166 {
3167     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3168     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3169     OH_Drawing_TypographyCreate* handler =
3170         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
3171     EXPECT_NE(handler, nullptr);
3172     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
3173     OH_Drawing_SetTextStyleFontSize(txtStyle, ARC_FONT_SIZE);
3174     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
3175     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
3176     const char* text = "\xF0\x9F\x98";
3177     OHOS::Rosen::SPText::TextBundleConfigParser::GetInstance().initStatus_ = true;
3178     OHOS::Rosen::SPText::TextBundleConfigParser::GetInstance().bundleApiVersion_ =
3179         OHOS::Rosen::SPText::SINCE_API18_VERSION;
3180     OH_Drawing_TypographyHandlerAddText(handler, text);
3181     OHOS::Rosen::SPText::TextBundleConfigParser::GetInstance().initStatus_ = false;
3182     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3183     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
3184     EXPECT_NE(typography, nullptr);
3185     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
3186 
3187     float longestLineWidth = OH_Drawing_TypographyGetLongestLine(typography);
3188     ASSERT_TRUE(skia::textlayout::nearlyEqual(longestLineWidth, ARC_FONT_SIZE));
3189 
3190     OH_Drawing_DestroyTypography(typography);
3191     OH_Drawing_DestroyTypographyHandler(handler);
3192     OH_Drawing_DestroyTypographyStyle(typoStyle);
3193     OH_Drawing_DestroyTextStyle(txtStyle);
3194 }
3195 
3196 /*
3197  * @tc.name: TextStyleGetTest001
3198  * @tc.desc: test for getting basic attributes from textstyle
3199  * @tc.type: FUNC
3200  */
3201 HWTEST_F(NdkTypographyTest, TextStyleGetTest001, TestSize.Level0)
3202 {
3203     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3204     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_WAVY);
3205     EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(txtStyle), 4);
3206     EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(nullptr), TEXT_DECORATION_STYLE_SOLID);
3207 
3208     OH_Drawing_SetTextStyleHalfLeading(txtStyle, false);
3209     EXPECT_FALSE(OH_Drawing_TextStyleGetHalfLeading(txtStyle));
3210     EXPECT_EQ(OH_Drawing_TextStyleGetHalfLeading(nullptr), TEXT_DECORATION_STYLE_SOLID);
3211     OH_Drawing_SetTextStyleHalfLeading(txtStyle, -2);
3212     EXPECT_TRUE(OH_Drawing_TextStyleGetHalfLeading(txtStyle));
3213     OH_Drawing_SetTextStyleHalfLeading(txtStyle, 20);
3214     EXPECT_TRUE(OH_Drawing_TextStyleGetHalfLeading(txtStyle));
3215 
3216     OH_Drawing_SetTextStyleFontSize(txtStyle, -20); // This value does not actually take effect.
3217     EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(txtStyle), -20);
3218     OH_Drawing_SetTextStyleFontSize(txtStyle, 10.5632);
3219     EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(txtStyle), 10.5632);
3220     EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(nullptr), 0.0);
3221 
3222     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200);
3223     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 1);
3224     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(nullptr), FONT_WEIGHT_400);
3225     OH_Drawing_SetTextStyleFontWeight(txtStyle, -100);
3226     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), FONT_WEIGHT_400);
3227 
3228     // The current value does not take effect and the returned enumeration value is 1
3229     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_OBLIQUE);
3230     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyle), 1);
3231     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_ITALIC);
3232     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyle), 1);
3233     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(nullptr), FONT_STYLE_NORMAL);
3234     OH_Drawing_SetTextStyleFontStyle(txtStyle, -1);
3235     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyle), FONT_STYLE_NORMAL);
3236 
3237     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC);
3238     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(txtStyle), 1);
3239     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(nullptr), TEXT_BASELINE_ALPHABETIC);
3240     OH_Drawing_SetTextStyleBaseLine(txtStyle, -5);
3241     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(txtStyle), TEXT_BASELINE_ALPHABETIC);
3242 
3243     const char* fontFamilies[] = { "Text", "Text2" };
3244     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 2, fontFamilies);
3245     size_t fontFamiliesNumber;
3246     char** fontFamiliesList = OH_Drawing_TextStyleGetFontFamilies(txtStyle, &fontFamiliesNumber);
3247     EXPECT_EQ(fontFamiliesNumber, 2);
3248     EXPECT_NE(fontFamiliesList, nullptr);
3249     EXPECT_EQ(OH_Drawing_TextStyleGetFontFamilies(nullptr, &fontFamiliesNumber), nullptr);
3250     OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, fontFamiliesNumber);
3251     OH_Drawing_DestroyTextStyle(txtStyle);
3252 }
3253 
3254 /*
3255  * @tc.name: TextStyleGetTest002
3256  * @tc.desc: test for getting other attributes value from textstyle
3257  * @tc.type: FUNC
3258  */
3259 HWTEST_F(NdkTypographyTest, TextStyleGetTest002, TestSize.Level0)
3260 {
3261     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3262     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, -20);
3263     EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(txtStyle), -20);
3264     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 0.56);
3265     EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(txtStyle), 0.56);
3266     EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(nullptr), 0.0);
3267 
3268     OH_Drawing_SetTextStyleFontHeight(txtStyle, -0.50);
3269     EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(txtStyle), -0.50);
3270     OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.5632);
3271     EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(txtStyle), 0.5632);
3272     EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(nullptr), 0.0);
3273 
3274     OH_Drawing_SetTextStyleWordSpacing(txtStyle, -30);
3275     EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(txtStyle), -30);
3276     OH_Drawing_SetTextStyleWordSpacing(txtStyle, -2.50);
3277     EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(txtStyle), -2.50);
3278     EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(nullptr), 0.0);
3279 
3280     OH_Drawing_SetTextStyleLocale(txtStyle, "zh-Hans");
3281     EXPECT_EQ(std::strcmp(OH_Drawing_TextStyleGetLocale(txtStyle), "zh-Hans"), 0);
3282     EXPECT_EQ(OH_Drawing_TextStyleGetLocale(nullptr), nullptr);
3283 
3284     OH_Drawing_Brush* brush = OH_Drawing_BrushCreate();
3285     OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(255, 50, 0, 255));
3286     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, brush);
3287     OH_Drawing_Brush* brush1 = OH_Drawing_BrushCreate();
3288     OH_Drawing_TextStyleGetBackgroundBrush(txtStyle, brush1);
3289     EXPECT_EQ(OH_Drawing_BrushGetAlpha(brush), OH_Drawing_BrushGetAlpha(brush1));
3290     EXPECT_NE(brush, brush1);
3291 
3292     EXPECT_FALSE(OH_Drawing_TextStyleIsPlaceholder(txtStyle));
3293     EXPECT_FALSE(OH_Drawing_TextStyleIsPlaceholder(nullptr));
3294     OH_Drawing_TextStyleSetPlaceholder(txtStyle);
3295     EXPECT_TRUE(OH_Drawing_TextStyleIsPlaceholder(txtStyle));
3296     OH_Drawing_TextStyleSetPlaceholder(txtStyle);
3297     EXPECT_TRUE(OH_Drawing_TextStyleIsPlaceholder(txtStyle));
3298 
3299     OH_Drawing_BrushDestroy(brush);
3300     OH_Drawing_BrushDestroy(brush1);
3301     OH_Drawing_DestroyTextStyle(txtStyle);
3302 }
3303 
3304 /*
3305  * @tc.name: TextStyleGetTest003
3306  * @tc.desc: test for OH_Drawing_SetTextStyleFontStyleStruct
3307  * @tc.type: FUNC
3308  */
3309 HWTEST_F(NdkTypographyTest, TextStyleGetTest003, TestSize.Level0)
3310 {
3311     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3312 
3313     // Test the default value.
3314     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 3);
3315     OH_Drawing_FontStyleStruct fontStyle;
3316     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 3);
3317     EXPECT_EQ(fontStyle.slant, 0);
3318     EXPECT_EQ(fontStyle.width, 0);
3319     OH_Drawing_SetTextStyleFontStyleStruct(txtStyle, fontStyle);
3320     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 0);
3321     EXPECT_EQ(fontStyle.slant, 0);
3322     EXPECT_EQ(fontStyle.width, 0);
3323     OH_Drawing_FontStyleStruct fontStyle1 = OH_Drawing_TextStyleGetFontStyleStruct(txtStyle);
3324     EXPECT_EQ(fontStyle1.slant, FONT_STYLE_NORMAL);
3325     EXPECT_EQ(fontStyle1.slant, 0);
3326     EXPECT_EQ(fontStyle1.width, FONT_WIDTH_NORMAL);
3327     EXPECT_EQ(fontStyle1.width, 5);
3328     EXPECT_EQ(fontStyle1.weight, FONT_WEIGHT_100);
3329 
3330     // Test normal assignment
3331     fontStyle.slant = FONT_STYLE_OBLIQUE;
3332     fontStyle.weight = FONT_WEIGHT_600;
3333     fontStyle.width = FONT_WIDTH_EXTRA_EXPANDED;
3334     OH_Drawing_SetTextStyleFontStyleStruct(txtStyle, fontStyle);
3335     fontStyle1 = OH_Drawing_TextStyleGetFontStyleStruct(txtStyle);
3336 
3337     // Specification: The enumerated value of FONT_STYLE_OBLIQUE passed out is uniformly 1.
3338     EXPECT_EQ(fontStyle1.slant, 1);
3339     EXPECT_NE(fontStyle1.slant, fontStyle.slant);
3340     EXPECT_EQ(fontStyle1.width, fontStyle.width);
3341     EXPECT_EQ(fontStyle1.width, FONT_WIDTH_EXTRA_EXPANDED);
3342     EXPECT_EQ(fontStyle1.weight, fontStyle.weight);
3343     EXPECT_EQ(fontStyle1.weight, FONT_WEIGHT_600);
3344 
3345     // Test the abnormal values.
3346     fontStyle.slant = static_cast<OH_Drawing_FontStyle>(-1);
3347     fontStyle.weight = static_cast<OH_Drawing_FontWeight>(-1);
3348     fontStyle.width = static_cast<OH_Drawing_FontWidth>(-1);
3349     OH_Drawing_SetTextStyleFontStyleStruct(txtStyle, fontStyle);
3350     fontStyle1 = OH_Drawing_TextStyleGetFontStyleStruct(txtStyle);
3351     EXPECT_EQ(fontStyle1.slant, FONT_STYLE_NORMAL);
3352     EXPECT_EQ(fontStyle1.width, FONT_WIDTH_NORMAL);
3353     EXPECT_EQ(fontStyle1.weight, FONT_WEIGHT_400);
3354     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(nullptr).slant, FONT_STYLE_NORMAL);
3355     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(nullptr).width, FONT_WIDTH_NORMAL);
3356     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(nullptr).weight, FONT_WEIGHT_400);
3357     OH_Drawing_DestroyTextStyle(txtStyle);
3358 }
3359 
3360 /*
3361  * @tc.name: TextStyleGetTest004
3362  * @tc.desc: test for TextStyle fontFeature
3363  * @tc.type: FUNC
3364  */
3365 HWTEST_F(NdkTypographyTest, TextStyleGetTest004, TestSize.Level0)
3366 {
3367     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3368     OH_Drawing_TextStyleAddFontFeature(txtStyle, "frac", 1);
3369     OH_Drawing_TextStyleAddFontFeature(txtStyle, "numr", 1);
3370     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 2);
3371     OH_Drawing_TextStyleClearFontFeature(txtStyle);
3372     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 0);
3373 
3374     OH_Drawing_TextStyleAddFontFeature(txtStyle, "frac", 1);
3375     OH_Drawing_TextStyleAddFontFeature(txtStyle, "frac", 0);
3376     OH_Drawing_TextStyleAddFontFeature(txtStyle, "numr", 1);
3377     OH_Drawing_TextStyleAddFontFeature(txtStyle, "liga", 1);
3378     OH_Drawing_TextStyleAddFontFeature(txtStyle, "liga", 1);
3379     OH_Drawing_TextStyleAddFontFeature(txtStyle, "", 1);
3380     OH_Drawing_TextStyleAddFontFeature(txtStyle, "testtesttesttesttest", 10);
3381     size_t mySize = OH_Drawing_TextStyleGetFontFeatureSize(txtStyle);
3382     EXPECT_EQ(mySize, 7);
3383 
3384     OH_Drawing_FontFeature* myFontFeatures = OH_Drawing_TextStyleGetFontFeatures(txtStyle);
3385     EXPECT_STREQ(myFontFeatures[0].tag, "frac");
3386     EXPECT_EQ(myFontFeatures[0].value, 1);
3387     EXPECT_STREQ(myFontFeatures[5].tag, "");
3388     EXPECT_EQ(myFontFeatures[5].value, 1);
3389     EXPECT_STREQ(myFontFeatures[3].tag, myFontFeatures[4].tag);
3390     EXPECT_EQ(myFontFeatures[3].value, myFontFeatures[4].value);
3391     EXPECT_STREQ(myFontFeatures[mySize - 1].tag, "testtesttesttesttest");
3392     EXPECT_EQ(myFontFeatures[mySize - 1].value, 10);
3393     OH_Drawing_TextStyleDestroyFontFeatures(myFontFeatures, mySize);
3394     OH_Drawing_DestroyTextStyle(txtStyle);
3395 }
3396 
3397 /*
3398  * @tc.name: TextStyleGetTest005
3399  * @tc.desc: test for OH_Drawing_TextStyleIsAttributeMatched false
3400  * @tc.type: FUNC
3401  */
3402 HWTEST_F(NdkTypographyTest, TextStyleGetTest005, TestSize.Level0)
3403 {
3404     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3405     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_WAVY);
3406     OH_Drawing_SetTextStyleHalfLeading(txtStyle, false);
3407     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200);
3408     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_OBLIQUE);
3409     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC);
3410     const char* fontFamilies[] = { "Text", "Text2" };
3411     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 2, fontFamilies);
3412     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, -20);
3413     OH_Drawing_SetTextStyleWordSpacing(txtStyle, -30);
3414     OH_Drawing_SetTextStyleLocale(txtStyle, "zh-Hans");
3415 
3416     OH_Drawing_Brush* brush = OH_Drawing_BrushCreate();
3417     OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(255, 50, 0, 255));
3418     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, brush);
3419 
3420     OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
3421     OH_Drawing_Point* point = OH_Drawing_PointCreate(10, -5);
3422     OH_Drawing_SetTextShadow(shadow, OH_Drawing_ColorSetArgb(255, 255, 0, 255), point, 10);
3423     OH_Drawing_TextStyleAddShadow(txtStyle, shadow);
3424 
3425     OH_Drawing_TextStyle* textStyleGet = OH_Drawing_CreateTextStyle();
3426     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_NONE));
3427     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_BACKGROUND));
3428     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_ALL_ATTRIBUTES));
3429     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_FONT));
3430     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_SHADOW));
3431     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_DECORATIONS));
3432     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_WORD_SPACING));
3433     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, textStyleGet, TEXT_STYLE_LETTER_SPACING));
3434 
3435     OH_Drawing_DestroyTextStyle(txtStyle);
3436     OH_Drawing_DestroyTextStyle(textStyleGet);
3437     OH_Drawing_PointDestroy(point);
3438     OH_Drawing_BrushDestroy(brush);
3439     OH_Drawing_DestroyTextShadow(shadow);
3440 }
3441 
3442 /*
3443  * @tc.name: TextStyleGetTest006
3444  * @tc.desc: test for OH_Drawing_TextStyleIsAttributeMatched true
3445  * @tc.type: FUNC
3446  */
3447 HWTEST_F(NdkTypographyTest, TextStyleGetTest006, TestSize.Level0)
3448 {
3449     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
3450     OH_Drawing_TextStyle* txtStyleCompare = OH_Drawing_CreateTextStyle();
3451     OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_WAVY);
3452     OH_Drawing_SetTextStyleDecorationStyle(txtStyleCompare, TEXT_DECORATION_STYLE_WAVY);
3453     OH_Drawing_SetTextStyleHalfLeading(txtStyle, false);
3454     OH_Drawing_SetTextStyleHalfLeading(txtStyleCompare, false);
3455     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200);
3456     OH_Drawing_SetTextStyleFontWeight(txtStyleCompare, FONT_WEIGHT_200);
3457     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_OBLIQUE);
3458     OH_Drawing_SetTextStyleFontStyle(txtStyleCompare, FONT_STYLE_OBLIQUE);
3459     OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC);
3460     OH_Drawing_SetTextStyleBaseLine(txtStyleCompare, TEXT_BASELINE_IDEOGRAPHIC);
3461     const char* fontFamilies[] = { "Text", "Text2" };
3462     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 2, fontFamilies);
3463     OH_Drawing_SetTextStyleFontFamilies(txtStyleCompare, 2, fontFamilies);
3464     OH_Drawing_SetTextStyleLetterSpacing(txtStyle, -20);
3465     OH_Drawing_SetTextStyleLetterSpacing(txtStyleCompare, -20);
3466     OH_Drawing_SetTextStyleWordSpacing(txtStyle, -30);
3467     OH_Drawing_SetTextStyleWordSpacing(txtStyleCompare, -30);
3468     OH_Drawing_SetTextStyleLocale(txtStyle, "zh-Hans");
3469     OH_Drawing_SetTextStyleLocale(txtStyleCompare, "zh-Hans");
3470 
3471     OH_Drawing_Brush* brush = OH_Drawing_BrushCreate();
3472     OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(255, 50, 0, 255));
3473     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, brush);
3474     OH_Drawing_SetTextStyleBackgroundBrush(txtStyleCompare, brush);
3475 
3476     OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
3477     OH_Drawing_Point* point = OH_Drawing_PointCreate(10, -5);
3478     OH_Drawing_SetTextShadow(shadow, OH_Drawing_ColorSetArgb(255, 255, 0, 255), point, 10);
3479     OH_Drawing_TextStyleAddShadow(txtStyle, shadow);
3480     OH_Drawing_TextStyleAddShadow(txtStyleCompare, shadow);
3481 
3482     EXPECT_FALSE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_NONE));
3483     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_BACKGROUND));
3484     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES));
3485     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_FONT));
3486     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_SHADOW));
3487     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_DECORATIONS));
3488     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_WORD_SPACING));
3489     EXPECT_TRUE(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_LETTER_SPACING));
3490 
3491     OH_Drawing_DestroyTextStyle(txtStyle);
3492     OH_Drawing_DestroyTextStyle(txtStyleCompare);
3493     OH_Drawing_PointDestroy(point);
3494     OH_Drawing_BrushDestroy(brush);
3495     OH_Drawing_DestroyTextShadow(shadow);
3496 }
3497 
3498 /*
3499  * @tc.name: TypographyTest113
3500  * @tc.desc: test for the input nullptr.
3501  * @tc.type: FUNC
3502  * @tc.require: IALK43
3503  */
3504 HWTEST_F(NdkTypographyTest, TypographyTest113, TestSize.Level0)
3505 {
3506     OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(nullptr, nullptr);
3507     EXPECT_EQ(handler, nullptr);
3508     OH_Drawing_DestroyTypographyHandler(handler);
3509     handler = OH_Drawing_CreateTypographyHandler(OH_Drawing_CreateTypographyStyle(), OH_Drawing_CreateFontCollection());
3510     OH_Drawing_TypographyHandlerPushTextStyle(handler, nullptr);
3511     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3512     OH_Drawing_TypographyHandlerAddText(handler, nullptr);
3513 }
3514 
3515 /*
3516  * @tc.name: TypographyTest117
3517  * @tc.desc: test for text tab with left alignment
3518  * @tc.type: FUNC
3519  */
3520 HWTEST_F(NdkTypographyTest, TypographyTest117, TestSize.Level0)
3521 {
3522     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3523     OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
3524     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 10);
3525 
3526     OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 100);
3527     OH_Drawing_SetTypographyTextTab(typoStyle, tab);
3528 
3529     OH_Drawing_TypographyCreate *handler =
3530         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3531     OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
3532     OH_Drawing_SetTextStyleFontSize(textStyle, 52);
3533     OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
3534 
3535     const char *text = "Hello\tWorld\tHello";
3536     OH_Drawing_TypographyHandlerAddText(handler, text);
3537     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3538 
3539     OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
3540     OH_Drawing_TypographyLayout(typography, 1200);
3541 
3542     double width = OH_Drawing_TypographyGetLongestLine(typography);
3543     EXPECT_NEAR(width, 522.772095, FLOAT_DATA_EPSILON);
3544 
3545     // branch coverage
3546     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3547 
3548     OH_Drawing_DestroyTypography(typography);
3549     OH_Drawing_DestroyTextStyle(textStyle);
3550     OH_Drawing_DestroyTypographyHandler(handler);
3551     OH_Drawing_DestroyTextTab(tab);
3552     OH_Drawing_DestroyTypographyStyle(typoStyle);
3553 }
3554 
3555 /*
3556  * @tc.name: TypographyTest118
3557  * @tc.desc: test for text tab with left alignment
3558  * @tc.type: FUNC
3559  */
3560 HWTEST_F(NdkTypographyTest, TypographyTest118, TestSize.Level0)
3561 {
3562     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3563     OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
3564     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 10);
3565 
3566     OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_RIGHT, 100);
3567     OH_Drawing_SetTypographyTextTab(typoStyle, tab);
3568 
3569     OH_Drawing_TypographyCreate *handler =
3570         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3571     OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
3572     OH_Drawing_SetTextStyleFontSize(textStyle, 52);
3573     OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
3574 
3575     const char *text = "Hello\tWorld\tHello";
3576     OH_Drawing_TypographyHandlerAddText(handler, text);
3577     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3578 
3579     OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
3580     OH_Drawing_TypographyLayout(typography, 1200);
3581 
3582     double width = OH_Drawing_TypographyGetLongestLine(typography);
3583     EXPECT_NEAR(width, 386.828308, FLOAT_DATA_EPSILON);
3584 
3585     // branch coverage
3586     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3587 
3588     OH_Drawing_DestroyTypography(typography);
3589     OH_Drawing_DestroyTextStyle(textStyle);
3590     OH_Drawing_DestroyTypographyHandler(handler);
3591     OH_Drawing_DestroyTextTab(tab);
3592     OH_Drawing_DestroyTypographyStyle(typoStyle);
3593 }
3594 
3595 /*
3596  * @tc.name: TypographyTest119
3597  * @tc.desc: test for text tab with center alignment
3598  * @tc.type: FUNC
3599  */
3600 HWTEST_F(NdkTypographyTest, TypographyTest119, TestSize.Level0)
3601 {
3602     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3603     OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
3604     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 10);
3605 
3606     OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, 100);
3607     OH_Drawing_SetTypographyTextTab(typoStyle, tab);
3608 
3609     OH_Drawing_TypographyCreate *handler =
3610         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3611     OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
3612     OH_Drawing_SetTextStyleFontSize(textStyle, 52);
3613     OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
3614 
3615     const char *text = "Hello\tWorld\tHello";
3616     OH_Drawing_TypographyHandlerAddText(handler, text);
3617     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3618 
3619     OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
3620     OH_Drawing_TypographyLayout(typography, 1200);
3621 
3622     double width = OH_Drawing_TypographyGetLongestLine(typography);
3623     EXPECT_NEAR(width, 393.414185, FLOAT_DATA_EPSILON);
3624 
3625     // branch coverage
3626     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3627 
3628     OH_Drawing_DestroyTypography(typography);
3629     OH_Drawing_DestroyTextStyle(textStyle);
3630     OH_Drawing_DestroyTypographyHandler(handler);
3631     OH_Drawing_DestroyTextTab(tab);
3632     OH_Drawing_DestroyTypographyStyle(typoStyle);
3633 }
3634 
3635 /*
3636  * @tc.name: TypographyTest120
3637  * @tc.desc: test for setting both the texttab and text layout direction
3638  * @tc.type: FUNC
3639  */
3640 HWTEST_F(NdkTypographyTest, TypographyTest120, TestSize.Level0)
3641 {
3642     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3643     OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
3644     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 10);
3645     OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_CENTER);
3646 
3647     OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, 100);
3648     OH_Drawing_SetTypographyTextTab(typoStyle, tab);
3649 
3650     OH_Drawing_TypographyCreate *handler =
3651         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3652     OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
3653     OH_Drawing_SetTextStyleFontSize(textStyle, 52);
3654     OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
3655 
3656     const char *text = "Hello\tWorld\tHello";
3657     OH_Drawing_TypographyHandlerAddText(handler, text);
3658     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3659 
3660     OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
3661     OH_Drawing_TypographyLayout(typography, 1200);
3662 
3663     double width = OH_Drawing_TypographyGetLongestLine(typography);
3664     EXPECT_NEAR(width, 414.388336, FLOAT_DATA_EPSILON);
3665 
3666     // branch coverage
3667     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3668 
3669     OH_Drawing_DestroyTypography(typography);
3670     OH_Drawing_DestroyTextStyle(textStyle);
3671     OH_Drawing_DestroyTypographyHandler(handler);
3672     OH_Drawing_DestroyTextTab(tab);
3673     OH_Drawing_DestroyTypographyStyle(typoStyle);
3674 }
3675 
3676 /*
3677  * @tc.name: TypographyTest121
3678  * @tc.desc: test for setting both the texttab and ellipsis
3679  * @tc.type: FUNC
3680  */
3681 HWTEST_F(NdkTypographyTest, TypographyTest121, TestSize.Level0)
3682 {
3683     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3684     OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
3685     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 10);
3686     OH_Drawing_SetTypographyTextEllipsis(typoStyle, "...");
3687     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_TAIL);
3688 
3689     OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, 100);
3690     OH_Drawing_SetTypographyTextTab(typoStyle, tab);
3691 
3692     OH_Drawing_TypographyCreate *handler =
3693         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3694     OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
3695     OH_Drawing_SetTextStyleFontSize(textStyle, 52);
3696     OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
3697 
3698     const char *text = "Hello\tWorld\tHello";
3699     OH_Drawing_TypographyHandlerAddText(handler, text);
3700     OH_Drawing_TypographyHandlerPopTextStyle(handler);
3701 
3702     OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
3703     OH_Drawing_TypographyLayout(typography, 1200);
3704 
3705     double width = OH_Drawing_TypographyGetLongestLine(typography);
3706     EXPECT_NEAR(width, 414.388336, FLOAT_DATA_EPSILON);
3707 
3708     // branch coverage
3709     OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
3710 
3711     OH_Drawing_DestroyTypography(typography);
3712     OH_Drawing_DestroyTextStyle(textStyle);
3713     OH_Drawing_DestroyTypographyHandler(handler);
3714     OH_Drawing_DestroyTextTab(tab);
3715     OH_Drawing_DestroyTypographyStyle(typoStyle);
3716 }
3717 
3718 /*
3719  * @tc.name: FontParserGetSystemFontListTest001
3720  * @tc.desc: test for the OH_Drawing_FontParserGetSystemFontList.
3721  * @tc.type: FUNC
3722  * @tc.require: IALK43
3723  */
3724 HWTEST_F(NdkTypographyTest, FontParserGetSystemFontListTest001, TestSize.Level0)
3725 {
3726     OH_Drawing_FontParser* fontParser = OH_Drawing_CreateFontParser();
3727     ASSERT_NE(fontParser, nullptr);
3728     size_t value = 100; // 100 for test
3729     size_t* num = &value;
3730     if (std::filesystem::exists(VIS_LIST_FILE_NAME)) {
3731         ASSERT_NE(OH_Drawing_FontParserGetSystemFontList(fontParser, num), nullptr);
3732         EXPECT_EQ(value, 1);
3733     } else {
3734         ASSERT_EQ(OH_Drawing_FontParserGetSystemFontList(fontParser, num), nullptr);
3735         EXPECT_EQ(value, 0);
3736     }
3737     num = nullptr;
3738     ASSERT_EQ(OH_Drawing_FontParserGetSystemFontList(fontParser, num), nullptr);
3739     fontParser = nullptr;
3740     ASSERT_EQ(OH_Drawing_FontParserGetSystemFontList(fontParser, num), nullptr);
3741 }
3742 
3743 /*
3744  * @tc.name: DestroySystemFontListTest001
3745  * @tc.desc: test for the OH_Drawing_DestroySystemFontList.
3746  * @tc.type: FUNC
3747  * @tc.require: IALK43
3748  */
3749 HWTEST_F(NdkTypographyTest, DestroySystemFontListTest001, TestSize.Level0)
3750 {
3751     char** fontList = new char*[3]; // 3 means the number of font
3752     std::string tempStr1 = "Test1";
3753     std::string tempStr3 = "Test3";
3754     fontList[0] = new char[tempStr1.size() + 1];
3755     std::copy(tempStr1.begin(), tempStr1.end(), fontList[0]);
3756     fontList[0][tempStr1.size()] = '\0';
3757     fontList[1] = nullptr;
3758     fontList[2] = new char[tempStr3.size() + 1]; // 2 means the index of font
3759     std::copy(tempStr3.begin(), tempStr3.end(), fontList[2]); // 2 means the index of font
3760     fontList[2][tempStr3.size()] = '\0'; // 2 means the index of font
3761     size_t num = 3; // 3 means the number of font
3762     ASSERT_NE(fontList, nullptr);
3763     OH_Drawing_DestroySystemFontList(fontList, num);
3764 
3765     fontList = nullptr;
3766     OH_Drawing_DestroySystemFontList(fontList, num);
3767 }
3768 
3769 /*
3770  * @tc.name: FontParserGetFontByNameTest001
3771  * @tc.desc: test for the OH_Drawing_FontParserGetFontByName.
3772  * @tc.type: FUNC
3773  * @tc.require: IALK43
3774  */
3775 HWTEST_F(NdkTypographyTest, FontParserGetFontByNameTest001, TestSize.Level0)
3776 {
3777     OH_Drawing_FontParser* fontParser = OH_Drawing_CreateFontParser();
3778     ASSERT_NE(fontParser, nullptr);
3779     const char* name = "test";
3780     OH_Drawing_FontDescriptor* fontDescriptor = OH_Drawing_FontParserGetFontByName(fontParser, name);
3781     ASSERT_EQ(fontDescriptor, nullptr);
3782 
3783     OH_Drawing_FontDescriptor* fontDescriptor1 = OH_Drawing_FontParserGetFontByName(fontParser, nullptr);
3784     ASSERT_EQ(fontDescriptor1, nullptr);
3785 
3786     OH_Drawing_FontDescriptor* fontDescriptor2 = OH_Drawing_FontParserGetFontByName(nullptr, name);
3787     ASSERT_EQ(fontDescriptor2, nullptr);
3788     OH_Drawing_DestroyFontParser(fontParser);
3789 }
3790 
3791 /*
3792  * @tc.name: TypographyGetLineMetricsTest001
3793  * @tc.desc: test for the OH_Drawing_TypographyGetLineMetrics.
3794  * @tc.type: FUNC
3795  * @tc.require: IALK43
3796  */
3797 HWTEST_F(NdkTypographyTest, TypographyGetLineMetricsTest001, TestSize.Level0)
3798 {
3799     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3800     OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
3801         OH_Drawing_CreateFontCollection());
3802     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
3803     ASSERT_NE(typography, nullptr);
3804     OH_Drawing_LineMetrics* lineMetrics = OH_Drawing_TypographyGetLineMetrics(typography);
3805     ASSERT_EQ(lineMetrics, nullptr);
3806     OH_Drawing_DestroyTypographyStyle(typoStyle);
3807     OH_Drawing_DestroyTypographyHandler(handler);
3808     OH_Drawing_DestroyTypography(typography);
3809 }
3810 
3811 /*
3812  * @tc.name: TextStyleGetShadowCountTest001
3813  * @tc.desc: test for the OH_Drawing_TextStyleGetShadowCount.
3814  * @tc.type: FUNC
3815  * @tc.require: IALK43
3816  */
3817 HWTEST_F(NdkTypographyTest, TextStyleGetShadowCountTest001, TestSize.Level0)
3818 {
3819     OH_Drawing_TextStyle* style = OH_Drawing_CreateTextStyle();
3820     ASSERT_NE(style, nullptr);
3821     ASSERT_EQ(OH_Drawing_TextStyleGetShadowCount(style), 0);
3822     OH_Drawing_TextShadow* textShadow = OH_Drawing_TextStyleGetShadows(style);
3823     ASSERT_NE(textShadow, nullptr);
3824 
3825     ASSERT_EQ(OH_Drawing_TextStyleGetShadowCount(nullptr), 0);
3826     OH_Drawing_TextShadow* textShadow1 = OH_Drawing_TextStyleGetShadows(nullptr);
3827     ASSERT_EQ(textShadow1, nullptr);
3828     OH_Drawing_DestroyTextStyle(style);
3829     OH_Drawing_DestroyTextShadows(textShadow);
3830 }
3831 
3832 /*
3833  * @tc.name: SetTextShadowTest001
3834  * @tc.desc: test for the OH_Drawing_SetTextShadow.
3835  * @tc.type: FUNC
3836  * @tc.require: IALK43
3837  */
3838 HWTEST_F(NdkTypographyTest, SetTextShadowTest001, TestSize.Level0)
3839 {
3840     OH_Drawing_TextStyle* style = OH_Drawing_CreateTextStyle();
3841     OH_Drawing_TextShadow* originShadow = OH_Drawing_CreateTextShadow();
3842     OH_Drawing_TextStyleAddShadow(style, originShadow);
3843     OH_Drawing_TextShadow* shadow = OH_Drawing_TextStyleGetShadowWithIndex(style, 0);
3844     ASSERT_NE(shadow, nullptr);
3845     uint32_t color = 0;
3846     OH_Drawing_Point* offset = OH_Drawing_PointCreate(0, 0);
3847     ASSERT_NE(offset, nullptr);
3848     double blurRadius = 0.0;
3849     OH_Drawing_SetTextShadow(shadow, color, offset, blurRadius);
3850     OH_Drawing_SetTextShadow(shadow, color, nullptr, blurRadius);
3851     OH_Drawing_SetTextShadow(nullptr, color, offset, blurRadius);
3852 
3853     OH_Drawing_DestroyTextStyle(style);
3854     OH_Drawing_PointDestroy(offset);
3855     OH_Drawing_DestroyTextShadow(originShadow);
3856 }
3857 
3858 /*
3859  * @tc.name: TextStyleAddShadowTest002
3860  * @tc.desc: test for the OH_Drawing_TextStyleAddShadow.
3861  * @tc.type: FUNC
3862  * @tc.require: IALK43
3863  */
3864 HWTEST_F(NdkTypographyTest, TextStyleAddShadowTest002, TestSize.Level0)
3865 {
3866     OH_Drawing_TextStyle* style = OH_Drawing_CreateTextStyle();
3867     OH_Drawing_TextShadow* shadow = OH_Drawing_TextStyleGetShadows(style);
3868     ASSERT_NE(shadow, nullptr);
3869     OH_Drawing_TextStyleAddShadow(style, shadow);
3870     EXPECT_NE(OH_Drawing_TextStyleGetShadows(style), nullptr);
3871     OH_Drawing_TextStyleClearShadows(style);
3872     OH_Drawing_TextStyleAddShadow(nullptr, shadow);
3873     OH_Drawing_TextStyleClearShadows(nullptr);
3874     OH_Drawing_TextStyleAddShadow(style, nullptr);
3875     OH_Drawing_DestroyTextStyle(style);
3876     OH_Drawing_DestroyTextShadows(shadow);
3877 }
3878 
3879 /*
3880  * @tc.name: TextStyleGetShadowWithIndexTest001
3881  * @tc.desc: test for the OH_Drawing_TextStyleGetShadowWithIndex.
3882  * @tc.type: FUNC
3883  * @tc.require: IALK43
3884  */
3885 HWTEST_F(NdkTypographyTest, TextStyleGetShadowWithIndexTest001, TestSize.Level0)
3886 {
3887     OH_Drawing_TextStyle* style = OH_Drawing_CreateTextStyle();
3888     ASSERT_NE(style, nullptr);
3889     OH_Drawing_TextShadow* textShadow = OH_Drawing_TextStyleGetShadowWithIndex(style, 0);
3890     ASSERT_EQ(textShadow, nullptr);
3891     // 2 for test
3892     OH_Drawing_TextShadow* textShadow1 = OH_Drawing_TextStyleGetShadowWithIndex(style, 2);
3893     ASSERT_EQ(textShadow1, nullptr);
3894     // -1 for test
3895     OH_Drawing_TextShadow* textShadow2 = OH_Drawing_TextStyleGetShadowWithIndex(style, -1);
3896     ASSERT_EQ(textShadow2, nullptr);
3897     // -1 for test
3898     OH_Drawing_TextShadow* textShadow3 = OH_Drawing_TextStyleGetShadowWithIndex(nullptr, -1);
3899     ASSERT_EQ(textShadow3, nullptr);
3900     OH_Drawing_DestroyTextStyle(style);
3901 }
3902 
3903 /*
3904  * @tc.name: TextStyleGetShadowsTest001
3905  * @tc.desc: test for the OH_Drawing_DestroyTextShadows.
3906  * @tc.type: FUNC
3907  * @tc.require: IALK43
3908  */
3909 HWTEST_F(NdkTypographyTest, TextStyleGetShadowsTest001, TestSize.Level0)
3910 {
3911     OH_Drawing_TextStyle* style = OH_Drawing_CreateTextStyle();
3912     OH_Drawing_TextShadow* shadow = OH_Drawing_TextStyleGetShadows(style);
3913     ASSERT_NE(shadow, nullptr);
3914     OH_Drawing_DestroyTextShadows(shadow);
3915     OH_Drawing_DestroyTextShadows(nullptr);
3916     OH_Drawing_DestroyTextStyle(style);
3917 }
3918 
3919 /*
3920  * @tc.name: SetTypographyTextEllipsisTest001
3921  * @tc.desc: test for the OH_Drawing_SetTypographyTextLocale.
3922  * @tc.type: FUNC
3923  * @tc.require: IALK43
3924  */
3925 HWTEST_F(NdkTypographyTest, SetTypographyTextEllipsisTest001, TestSize.Level0)
3926 {
3927     OH_Drawing_TypographyStyle* style = OH_Drawing_CreateTypographyStyle();
3928     ASSERT_NE(style, nullptr);
3929     const char* locale = "zh-cn";
3930     OH_Drawing_SetTypographyTextLocale(style, locale);
3931     OH_Drawing_SetTypographyTextSplitRatio(style, 0.f);
3932     OH_Drawing_TextStyle* textStyle = OH_Drawing_TypographyGetTextStyle(style);
3933     ASSERT_NE(textStyle, nullptr);
3934     ASSERT_EQ(OH_Drawing_TypographyGetEffectiveAlignment(style), 0);
3935     ASSERT_EQ(OH_Drawing_TypographyIsLineUnlimited(style), true);
3936     ASSERT_EQ(OH_Drawing_TypographyIsEllipsized(style), false);
3937     const char* ellipsis = "ellipsis";
3938     OH_Drawing_SetTypographyTextEllipsis(style, ellipsis);
3939 
3940     const char* ellipsisVal = nullptr;
3941     OH_Drawing_SetTypographyTextEllipsis(style, ellipsisVal);
3942 
3943     const char* locale2 = "en-gb";
3944     OH_Drawing_SetTypographyTextLocale(nullptr, locale2);
3945     OH_Drawing_SetTypographyTextSplitRatio(nullptr, 0.f);
3946     OH_Drawing_TextStyle* textStyle1 = OH_Drawing_TypographyGetTextStyle(nullptr);
3947     ASSERT_EQ(textStyle1, nullptr);
3948     ASSERT_EQ(OH_Drawing_TypographyGetEffectiveAlignment(nullptr), 0);
3949     ASSERT_EQ(OH_Drawing_TypographyIsLineUnlimited(nullptr), false);
3950     ASSERT_EQ(OH_Drawing_TypographyIsEllipsized(nullptr), false);
3951     OH_Drawing_SetTypographyTextEllipsis(nullptr, ellipsisVal);
3952     OH_Drawing_DestroyTypographyStyle(style);
3953 }
3954 
3955 /*
3956  * @tc.name: TypographyHandlerPushTextStyleTest001
3957  * @tc.desc: test for the actual effective value of textstyle in each of the three scenarios.
3958  * @tc.type: FUNC
3959  * @tc.require: IALK43
3960  */
3961 HWTEST_F(NdkTypographyTest, TypographyHandlerPushTextStyleTest001, TestSize.Level0)
3962 {
3963     // Use interfaces such as OH_Drawing_SetTypographyTextFontSize to test the fallback textstyle.
3964     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
3965     OH_Drawing_SetTypographyTextFontSize(typoStyle, 100);
3966     OH_Drawing_SetTypographyTextFontHeight(typoStyle, 1);
3967     OH_Drawing_TextStyle* textStyle = OH_Drawing_TypographyGetTextStyle(typoStyle);
3968     ASSERT_NE(textStyle, nullptr);
3969     OH_Drawing_TypographyCreate* handler =
3970         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
3971     ASSERT_NE(handler, nullptr);
3972     const char* text = "test OH_Drawing_SetTypographyTextLineStylexxx";
3973     OH_Drawing_TypographyHandlerAddText(handler, text);
3974     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
3975     double maxWidth = 10000.0;
3976     OH_Drawing_TypographyLayout(typography, maxWidth);
3977     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography), 100);
3978 
3979     // After setting the default text style in typographstyle, the fallback text style becomes ineffective.
3980     OH_Drawing_TypographyStyle* typoStyle2 = OH_Drawing_CreateTypographyStyle();
3981     OH_Drawing_SetTypographyTextFontSize(typoStyle2, 500);
3982     OH_Drawing_SetTypographyTextFontHeight(typoStyle2, 1);
3983     OH_Drawing_TextStyle* textStyle2 = OH_Drawing_CreateTextStyle();
3984     OH_Drawing_SetTextStyleFontSize(textStyle2, 30);
3985     OH_Drawing_SetTextStyleFontHeight(textStyle2, 2);
3986     OH_Drawing_SetTypographyTextStyle(typoStyle2, textStyle2);
3987     OH_Drawing_TypographyCreate* handler2 =
3988         OH_Drawing_CreateTypographyHandler(typoStyle2, OH_Drawing_CreateSharedFontCollection());
3989     ASSERT_NE(handler2, nullptr);
3990     const char* text2 = "test OH_Drawing_OH_Drawing_SetTypographyTextStyle, 该方法优先";
3991     OH_Drawing_TypographyHandlerAddText(handler2, text2);
3992     OH_Drawing_Typography* typography2 = OH_Drawing_CreateTypography(handler2);
3993     OH_Drawing_TypographyLayout(typography2, maxWidth);
3994     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography2), 60);
3995 
3996     // After pushing a new text style, the default text style becomes ineffective.
3997     OH_Drawing_TypographyStyle* typoStyle3 = OH_Drawing_CreateTypographyStyle();
3998     OH_Drawing_SetTypographyTextFontSize(typoStyle3, 500);
3999     OH_Drawing_SetTypographyTextFontHeight(typoStyle3, 1);
4000     OH_Drawing_TextStyle* textStyle3 = OH_Drawing_CreateTextStyle();
4001     OH_Drawing_SetTextStyleFontSize(textStyle3, 30);
4002     OH_Drawing_SetTextStyleFontHeight(textStyle3, 2);
4003     OH_Drawing_SetTypographyTextStyle(typoStyle3, textStyle3);
4004     OH_Drawing_SetTextStyleFontSize(textStyle3, 80);
4005     OH_Drawing_SetTextStyleFontHeight(textStyle3, 3);
4006     OH_Drawing_TypographyCreate* handler3 =
4007         OH_Drawing_CreateTypographyHandler(typoStyle3, OH_Drawing_CreateSharedFontCollection());
4008     ASSERT_NE(handler3, nullptr);
4009     OH_Drawing_TypographyHandlerPushTextStyle(handler3, textStyle3);
4010     const char* text3 = "test OH_Drawing_TypographyHandlerPushTextStyle, 该方法优先";
4011     OH_Drawing_TypographyHandlerAddText(handler3, text3);
4012     OH_Drawing_Typography* typography3 = OH_Drawing_CreateTypography(handler3);
4013     OH_Drawing_TypographyLayout(typography3, maxWidth);
4014     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography3), 240);
4015 }
4016 
4017 /*
4018  * @tc.name: TypographyHandlerPushTextStyleTest002
4019  * @tc.desc: test the height of Tibetan and Uighur in push textstyle scenarios.
4020  * @tc.type: FUNC
4021  * @tc.require: IALK43
4022  */
4023 HWTEST_F(NdkTypographyTest, TypographyHandlerPushTextStyleTest002, TestSize.Level0)
4024 {
4025     // After pushing a new text style, the default text style becomes ineffective.
4026     OH_Drawing_TypographyStyle* typoStyle3 = OH_Drawing_CreateTypographyStyle();
4027     OH_Drawing_SetTypographyTextFontSize(typoStyle3, 500);
4028     OH_Drawing_SetTypographyTextFontHeight(typoStyle3, 1);
4029     OH_Drawing_TextStyle* textStyle3 = OH_Drawing_CreateTextStyle();
4030     OH_Drawing_SetTextStyleFontSize(textStyle3, 30);
4031     OH_Drawing_SetTextStyleFontHeight(textStyle3, 2);
4032     OH_Drawing_SetTypographyTextStyle(typoStyle3, textStyle3);
4033     OH_Drawing_SetTextStyleFontSize(textStyle3, 80);
4034     OH_Drawing_SetTextStyleFontHeight(textStyle3, 3);
4035 
4036     // Testing the line height of Uyghur text in 'heightonly' mode
4037     const char* text4 = "بۇ ئۇسۇل ئالدىنقى ئورۇندا";
4038     OH_Drawing_TypographyCreate* handler4 =
4039         OH_Drawing_CreateTypographyHandler(typoStyle3, OH_Drawing_CreateSharedFontCollection());
4040     ASSERT_NE(handler4, nullptr);
4041     OH_Drawing_TypographyHandlerPushTextStyle(handler4, textStyle3);
4042     OH_Drawing_TypographyHandlerAddText(handler4, text4);
4043     OH_Drawing_Typography* typography4 = OH_Drawing_CreateTypography(handler4);
4044     double maxWidth = 10000.0;
4045     OH_Drawing_TypographyLayout(typography4, maxWidth);
4046     EXPECT_NE(OH_Drawing_TypographyGetHeight(typography4), 240);
4047     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography4), 242);
4048 
4049     // Testing the line height of Tibetan text in 'heightonly' mode.
4050     const char* text5 = "ཐབས་ལམ་འདི་ལྡནཐབས་ལམ་འདི་ལྡན";
4051     OH_Drawing_TypographyCreate* handler5 =
4052         OH_Drawing_CreateTypographyHandler(typoStyle3, OH_Drawing_CreateSharedFontCollection());
4053     ASSERT_NE(handler4, nullptr);
4054     OH_Drawing_TypographyHandlerPushTextStyle(handler5, textStyle3);
4055     OH_Drawing_TypographyHandlerAddText(handler5, text5);
4056     OH_Drawing_Typography* typography5 = OH_Drawing_CreateTypography(handler5);
4057     OH_Drawing_TypographyLayout(typography5, maxWidth);
4058     EXPECT_NE(OH_Drawing_TypographyGetHeight(typography5), 0);
4059     EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography5), 240);
4060 }
4061 
4062 /*
4063  * @tc.name: FontFamiliesTest001
4064  * @tc.desc: test for the OH_Drawing_TypographyTextlineStyleDestroyFontFamilies.
4065  * @tc.type: FUNC
4066  * @tc.require: IALK43
4067  */
4068 HWTEST_F(NdkTypographyTest, FontFamiliesTest001, TestSize.Level0)
4069 {
4070     char** fontFamilies = new char*[3]; // 3 means the number of font
4071     std::string tempStr1 = "Test1";
4072     std::string tempStr3 = "Test3";
4073     fontFamilies[0] = new char[tempStr1.size() + 1];
4074     std::copy(tempStr1.begin(), tempStr1.end(), fontFamilies[0]);
4075     fontFamilies[0][tempStr1.size()] = '\0';
4076     fontFamilies[1] = nullptr;
4077     fontFamilies[2] = new char[tempStr3.size() + 1]; // 2 means the index of font
4078     std::copy(tempStr3.begin(), tempStr3.end(), fontFamilies[2]); // 2 means the index of font
4079     fontFamilies[2][tempStr3.size()] = '\0'; // 2 means the index of font
4080     size_t num = 3; // 3 means the number of font
4081     ASSERT_NE(fontFamilies, nullptr);
4082     OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(fontFamilies, num);
4083 
4084     fontFamilies = nullptr;
4085     OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(fontFamilies, num);
4086 }
4087 
4088 /*
4089  * @tc.name: TypographyGetLineFontMetricsTest001
4090  * @tc.desc: test for the OH_Drawing_TypographyGetLineFontMetrics.
4091  * @tc.type: FUNC
4092  * @tc.require: IALK43
4093  */
4094 HWTEST_F(NdkTypographyTest, TypographyGetLineFontMetricsTest001, TestSize.Level0)
4095 {
4096     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4097     OH_Drawing_TypographyCreate* handler =
4098         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4099     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4100     ASSERT_NE(typography, nullptr);
4101     size_t lineNumber = 1;
4102     size_t fontMetrics = 1;
4103     size_t* fontMetricsSize = &fontMetrics;
4104     ASSERT_NE(fontMetricsSize, nullptr);
4105     OH_Drawing_Font_Metrics* metrics = OH_Drawing_TypographyGetLineFontMetrics(typography, lineNumber, fontMetricsSize);
4106     ASSERT_EQ(metrics, nullptr);
4107 
4108     OH_Drawing_Font_Metrics* metrics1 = OH_Drawing_TypographyGetLineFontMetrics(typography, 0, fontMetricsSize);
4109     ASSERT_EQ(metrics1, nullptr);
4110     OH_Drawing_Font_Metrics* metrics2 = OH_Drawing_TypographyGetLineFontMetrics(typography, lineNumber, nullptr);
4111     ASSERT_EQ(metrics2, nullptr);
4112     OH_Drawing_Font_Metrics* metrics3 = OH_Drawing_TypographyGetLineFontMetrics(nullptr, lineNumber, fontMetricsSize);
4113     ASSERT_EQ(metrics3, nullptr);
4114     OH_Drawing_TypographyDestroyLineFontMetrics(metrics);
4115     OH_Drawing_DestroyTypographyStyle(typoStyle);
4116     OH_Drawing_DestroyTypographyHandler(handler);
4117     OH_Drawing_DestroyTypography(typography);
4118 }
4119 
4120 /*
4121  * @tc.name: TextStyleAddFontVariationTest001
4122  * @tc.desc: test for the OH_Drawing_TextStyleAddFontVariation.
4123  * @tc.type: FUNC
4124  * @tc.require: IALK43
4125  */
4126 HWTEST_F(NdkTypographyTest, TextStyleAddFontVariationTest001, TestSize.Level0)
4127 {
4128     OH_Drawing_TypographyStyle* style = OH_Drawing_CreateTypographyStyle();
4129     ASSERT_NE(style, nullptr);
4130     OH_Drawing_TextStyle* textStyle = OH_Drawing_TypographyGetTextStyle(style);
4131     ASSERT_NE(textStyle, nullptr);
4132     const char* axis = "T";
4133     const float value = 1.f;
4134     OH_Drawing_TextStyleAddFontVariation(textStyle, axis, value);
4135     OH_Drawing_TextStyleAddFontVariation(textStyle, nullptr, value);
4136     OH_Drawing_TextStyleAddFontVariation(nullptr, axis, value);
4137     OH_Drawing_DestroyTypographyStyle(style);
4138 }
4139 
4140 /*
4141 * @tc.name: TypographyLineInfoTest001
4142 * @tc.desc: test for getting line info and line font metrics for one line with white space
4143 * @tc.type: FUNC
4144 */
4145 HWTEST_F(NdkTypographyTest, TypographyLineInfoTest001, TestSize.Level0)
4146 {
4147     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4148     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4149     const char fontFamiliesTest[] = { 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79,
4150         0x4f, 0x53, 0x5f, 0x53, 0x61, 0x6e, 0x73 };
4151     const char *fontFamilies[] = {fontFamiliesTest};
4152     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
4153     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4154     OH_Drawing_TypographyCreate* handler =
4155         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4156     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4157     const char *text = "这是一个 test123排版信息获取接口   ";
4158     OH_Drawing_TypographyHandlerAddText(handler, text);
4159     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4160     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4161 
4162     OH_Drawing_LineMetrics lineInfoNoSpace;
4163     OH_Drawing_TypographyGetLineInfo(typography, 0, true, false, &lineInfoNoSpace);
4164     OH_Drawing_LineMetrics lineInfoHasSpace;
4165     OH_Drawing_TypographyGetLineInfo(typography, 0, true, true, &lineInfoHasSpace);
4166 
4167     EXPECT_EQ(lineInfoNoSpace.startIndex, 0);
4168     EXPECT_EQ(lineInfoNoSpace.endIndex, 23);
4169     EXPECT_NEAR(lineInfoNoSpace.width, 786.149231, FLOAT_DATA_EPSILON);
4170     EXPECT_EQ(lineInfoHasSpace.startIndex, 0);
4171     EXPECT_EQ(lineInfoHasSpace.endIndex, 23);
4172     EXPECT_NEAR(lineInfoHasSpace.width, 826.649230, FLOAT_DATA_EPSILON);
4173 
4174     OH_Drawing_Font_Metrics textStyleMetrics;
4175     OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &textStyleMetrics);
4176     EXPECT_NEAR(textStyleMetrics.top, -52.799999, FLOAT_DATA_EPSILON);
4177     EXPECT_NEAR(textStyleMetrics.avgCharWidth, 25.000000, FLOAT_DATA_EPSILON);
4178     EXPECT_NEAR(textStyleMetrics.maxCharWidth, 124.300003, FLOAT_DATA_EPSILON);
4179     EXPECT_NEAR(textStyleMetrics.xHeight, 25.000000, FLOAT_DATA_EPSILON);
4180     EXPECT_NEAR(textStyleMetrics.capHeight, 35.000000, FLOAT_DATA_EPSILON);
4181     EXPECT_NEAR(textStyleMetrics.underlineThickness, 2.500000, FLOAT_DATA_EPSILON);
4182     EXPECT_NEAR(textStyleMetrics.underlinePosition, 10.350000, FLOAT_DATA_EPSILON);
4183     EXPECT_NEAR(textStyleMetrics.strikeoutThickness, 2.500000, FLOAT_DATA_EPSILON);
4184     EXPECT_NEAR(textStyleMetrics.strikeoutPosition, -15.000001, FLOAT_DATA_EPSILON);
4185     OH_Drawing_DestroyTypography(typography);
4186     OH_Drawing_DestroyTypographyStyle(typoStyle);
4187     OH_Drawing_DestroyTypographyHandler(handler);
4188     OH_Drawing_DestroyTextStyle(txtStyle);
4189 }
4190 
4191 /*
4192 * @tc.name: TypographyLineInfoTest002
4193 * @tc.desc: test for getting line info and line font metrics for one line with white space
4194 * @tc.type: FUNC
4195 */
4196 HWTEST_F(NdkTypographyTest, TypographyLineInfoTest002, TestSize.Level0)
4197 {
4198     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4199     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4200     const char fontFamiliesTest[] = { 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e, 0x79,
4201         0x4f, 0x53, 0x5f, 0x53, 0x61, 0x6e, 0x73 };
4202     const char *fontFamilies[] = {fontFamiliesTest};
4203     OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
4204     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4205     OH_Drawing_TypographyCreate* handler =
4206         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4207     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4208     const char *text = "这是一个 test123排版信息获取接口   123444  Test  ";
4209     OH_Drawing_TypographyHandlerAddText(handler, text);
4210     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4211     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4212 
4213     OH_Drawing_LineMetrics lineInfoNoSpace;
4214     OH_Drawing_TypographyGetLineInfo(typography, 1, false, false, &lineInfoNoSpace);
4215     OH_Drawing_LineMetrics lineInfoHasSpace;
4216     OH_Drawing_TypographyGetLineInfo(typography, 1, false, true, &lineInfoHasSpace);
4217 
4218     EXPECT_EQ(lineInfoNoSpace.startIndex, 23);
4219     EXPECT_EQ(lineInfoNoSpace.endIndex, 37);
4220     EXPECT_NEAR(lineInfoNoSpace.width, 289.999756, FLOAT_DATA_EPSILON);
4221     EXPECT_EQ(lineInfoHasSpace.startIndex, 23);
4222     EXPECT_EQ(lineInfoHasSpace.endIndex, 37);
4223     EXPECT_NEAR(lineInfoHasSpace.width, 316.999756, FLOAT_DATA_EPSILON);
4224 
4225     size_t fontMetricsSize = 0;
4226     OH_Drawing_Font_Metrics* metrics = OH_Drawing_TypographyGetLineFontMetrics(typography, 2,
4227          &fontMetricsSize);
4228     EXPECT_NE(metrics, nullptr);
4229     EXPECT_EQ(fontMetricsSize, 12);
4230     EXPECT_NEAR(metrics[1].top, -52.799999, FLOAT_DATA_EPSILON);
4231     EXPECT_NEAR(metrics[1].avgCharWidth, 25.000000, FLOAT_DATA_EPSILON);
4232     EXPECT_NEAR(metrics[1].maxCharWidth, 124.300003, FLOAT_DATA_EPSILON);
4233     EXPECT_NEAR(metrics[1].xMin, -27.400000, FLOAT_DATA_EPSILON);
4234     EXPECT_NEAR(metrics[1].xMax, 96.900002, FLOAT_DATA_EPSILON);
4235     EXPECT_NEAR(metrics[1].xHeight, 25.000000, FLOAT_DATA_EPSILON);
4236     EXPECT_NEAR(metrics[1].capHeight, 35.000000, FLOAT_DATA_EPSILON);
4237     EXPECT_NEAR(metrics[1].underlineThickness, 2.500000, FLOAT_DATA_EPSILON);
4238     EXPECT_NEAR(metrics[1].underlinePosition, 10.350000, FLOAT_DATA_EPSILON);
4239     EXPECT_NEAR(metrics[1].strikeoutThickness, 2.500000, FLOAT_DATA_EPSILON);
4240     EXPECT_NEAR(metrics[1].strikeoutPosition, -15.000001, FLOAT_DATA_EPSILON);
4241     OH_Drawing_TypographyDestroyLineFontMetrics(metrics);
4242     OH_Drawing_DestroyTypography(typography);
4243     OH_Drawing_DestroyTypographyStyle(typoStyle);
4244     OH_Drawing_DestroyTypographyHandler(handler);
4245     OH_Drawing_DestroyTextStyle(txtStyle);
4246 }
4247 
4248 /*
4249  * @tc.name: TypographyRectsForRangeTest001
4250  * @tc.desc: test for typography rectsForRange
4251  * @tc.type: FUNC
4252  */
4253 HWTEST_F(NdkTypographyTest, TypographyRectsForRangeTest001, TestSize.Level0)
4254 {
4255     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4256     OH_Drawing_StrutStyle strutStyle = {
4257         .weight = FONT_WEIGHT_400, .style = FONT_STYLE_NORMAL, .size = 120.0,
4258         .heightScale = 2, .heightOverride = true, .halfLeading = true, .leading = 1.0
4259     };
4260     OH_Drawing_SetTypographyStyleTextStrutStyle(typoStyle, &strutStyle);
4261     OH_Drawing_SetTypographyTextUseLineStyle(typoStyle, true);
4262     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4263     OH_Drawing_SetTextStyleFontSize(txtStyle, 120);
4264     OH_Drawing_TypographyCreate *handler =
4265         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4266     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4267     const char *text = "这是一个排版信息获取接口的测试文本: Hello World";
4268     OH_Drawing_TypographyHandlerAddText(handler, text);
4269     text = "这是一个排版信息获取接口的排版信息排版信息排版信息排版信息.";
4270     OH_Drawing_TypographyHandlerAddText(handler, text);
4271     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4272     OH_Drawing_TypographyLayout(typography, 1200.0);
4273     CheckTypographyRectsForRange(typography);
4274     OH_Drawing_DestroyTypographyStyle(typoStyle);
4275     OH_Drawing_DestroyTypographyHandler(handler);
4276     OH_Drawing_DestroyTypography(typography);
4277 }
4278 
4279 /*
4280 * @tc.name: TypographyDidExceedMaxLinesTest001
4281 * @tc.desc: test for typography mutiple lines.
4282 * @tc.type: FUNC
4283 */
4284 HWTEST_F(NdkTypographyTest, TypographyDidExceedMaxLinesTest001, TestSize.Level0)
4285 {
4286     std::vector<pair<int, double>> lineResult = {
4287         {75, 796.899231}, {59, 780.399231}, {59, 750.999268},
4288         {59, 773.041809}, {59, 774.646362}, {68, 595.349548}, {59, 349.772766}};
4289     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4290     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4291     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4292     const char *fontFamilies[] = {"HMOS Color Emoji", "Roboto"};
4293     OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle, 2,  fontFamilies);
4294     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
4295     OH_Drawing_TypographyCreate* handler =
4296         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4297     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4298     const char *text = "这是一个排版信息دددھساسااساساس获取接口的测试文本:Hello World 这\n是版信息获取接测试文本Drawing.";
4299     OH_Drawing_TypographyHandlerAddText(handler, text);
4300     text = "这是一个排版信息བསདབད获取接口的སངབངསབ测试文lo World 这是一个 ..... \u1234排版信息的测试文སསསས本Drawing.དདདདདད.       ";
4301     OH_Drawing_TypographyHandlerAddText(handler, text);
4302     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4303     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4304     size_t fontFamilyCount = 0;
4305     char** fontFamiliesResult = OH_Drawing_TypographyTextlineStyleGetFontFamilies(typoStyle, &fontFamilyCount);
4306     EXPECT_EQ(fontFamilyCount, 2);
4307     for (size_t i = 0; i < fontFamilyCount; i++) {
4308         EXPECT_STREQ(fontFamilies[i], fontFamiliesResult[i]);
4309     }
4310     int lineCount = OH_Drawing_TypographyGetLineCount(typography);
4311     EXPECT_NEAR(OH_Drawing_TypographyGetLongestLine(typography), 796.899231, FLOAT_DATA_EPSILON);
4312     EXPECT_NEAR(OH_Drawing_TypographyGetHeight(typography), 438.000000, FLOAT_DATA_EPSILON);
4313     EXPECT_EQ(lineCount, 7);
4314     EXPECT_EQ(OH_Drawing_TypographyDidExceedMaxLines(typography), false);
4315     double maxLineWidth = 0.0, expectedLineHeight = 0.0;
4316     for (int i = 0; i < lineCount; i++) {
4317         double lineHeight = OH_Drawing_TypographyGetLineHeight(typography, i);
4318         double lineWidth = OH_Drawing_TypographyGetLineWidth(typography, i);
4319         EXPECT_NEAR(lineHeight, lineResult[i].first, FLOAT_DATA_EPSILON);
4320         EXPECT_NEAR(lineWidth, lineResult[i].second, FLOAT_DATA_EPSILON);
4321         maxLineWidth = std::max(maxLineWidth, lineWidth);
4322         expectedLineHeight += lineHeight;
4323     }
4324     EXPECT_EQ(OH_Drawing_TypographyDidExceedMaxLines(typography), false);
4325     EXPECT_NEAR(OH_Drawing_TypographyGetLongestLine(typography), maxLineWidth, FLOAT_DATA_EPSILON);
4326     EXPECT_NEAR(OH_Drawing_TypographyGetHeight(typography), expectedLineHeight, FLOAT_DATA_EPSILON);
4327     OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(fontFamiliesResult, fontFamilyCount);
4328     OH_Drawing_DestroyTypography(typography);
4329     OH_Drawing_DestroyTypographyHandler(handler);
4330     OH_Drawing_DestroyTypographyStyle(typoStyle);
4331     OH_Drawing_DestroyTextStyle(txtStyle);
4332 }
4333 
4334 /*
4335 * @tc.name: TypographyGetWordBoundaryTest001
4336 * @tc.desc: test for typography mutiple lines,but set the maximum number of lines
4337 * @tc.type: FUNC
4338 */
4339 HWTEST_F(NdkTypographyTest, TypographyGetWordBoundaryTest001, TestSize.Level0)
4340 {
4341     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4342     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4343     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x11, 0x11, 0xFF));
4344     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4345     OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
4346     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 2);
4347     OH_Drawing_TypographyCreate* handler =
4348         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4349     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4350     const char *text = "这是一个排版信息دددھساسااساساس获取接口的测试文本:Hello World 这\n是版信息获取接测试文本Drawing.";
4351     OH_Drawing_TypographyHandlerAddText(handler, text);
4352     text = "这是一个排版信息བསདབད获取接口的སངབངསབ测试文lo World 这是一个 ..... \u1234排版信息";
4353     OH_Drawing_TypographyHandlerAddText(handler, text);
4354     text = "的测试文སསསས本Drawing.དདདདདད.       ";
4355     OH_Drawing_TypographyHandlerAddText(handler, text);
4356     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4357     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4358     bool isExceedMaxLines = OH_Drawing_TypographyDidExceedMaxLines(typography);
4359     int currentLines = OH_Drawing_TypographyGetLineCount(typography);
4360     int maxLines = OH_Drawing_TypographyGetTextMaxLines(typoStyle);
4361     double longestLine = OH_Drawing_TypographyGetLongestLine(typography);
4362     double longestLineIndent = OH_Drawing_TypographyGetLongestLineWithIndent(typography);
4363 
4364     OH_Drawing_Range* rangeFirst = OH_Drawing_TypographyGetWordBoundary(typography, 0);
4365     int startFirst = OH_Drawing_GetStartFromRange(rangeFirst);
4366     int endFirst = OH_Drawing_GetEndFromRange(rangeFirst);
4367     EXPECT_EQ(startFirst, 0);
4368     EXPECT_EQ(endFirst, 1);
4369     OH_Drawing_Range* rangeLast = OH_Drawing_TypographyGetWordBoundary(typography, 10);
4370     int startLast = OH_Drawing_GetStartFromRange(rangeLast);
4371     int endLast = OH_Drawing_GetEndFromRange(rangeLast);
4372     EXPECT_EQ(startLast, 8);
4373     EXPECT_EQ(endLast, 22);
4374 
4375     OH_Drawing_Range* rangeWord = OH_Drawing_TypographyGetWordBoundary(typography, 34);
4376     int startWord = OH_Drawing_GetStartFromRange(rangeWord);
4377     int endWord = OH_Drawing_GetEndFromRange(rangeWord);
4378     EXPECT_EQ(startWord, 32);
4379     EXPECT_EQ(endWord, 37);
4380 
4381     EXPECT_EQ(currentLines, 2);
4382     EXPECT_EQ(maxLines, 2);
4383     EXPECT_EQ(isExceedMaxLines, true);
4384     EXPECT_EQ(longestLine, longestLineIndent);
4385     EXPECT_NEAR(longestLine, 796.899231, FLOAT_DATA_EPSILON);
4386 
4387     OH_Drawing_DestroyTypographyStyle(typoStyle);
4388     OH_Drawing_DestroyTypography(typography);
4389     OH_Drawing_DestroyTypographyHandler(handler);
4390     OH_Drawing_DestroyTextStyle(txtStyle);
4391 }
4392 
4393 /*
4394 * @tc.name: TypographyGetIndentsWithIndexTest001
4395 * @tc.desc: test for typography mutiple lines,but set mutiple indents
4396 * @tc.type: FUNC
4397 */
4398 HWTEST_F(NdkTypographyTest, TypographyGetIndentsWithIndexTest001, TestSize.Level0)
4399 {
4400     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4401     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4402     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x11, 0x11, 0xFF));
4403     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4404     OH_Drawing_TypographyCreate* handler =
4405         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4406     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4407     const char *text = "这是一个排版信息دددھساسااساساس获取接口的测试文本:Hello World 这\n是版信息获取接测试文本Drawing.";
4408     OH_Drawing_TypographyHandlerAddText(handler, text);
4409     text = "这是一个排版信息བསདབད获取接口的སངབངསབ测试文lo World这是一个 ..... \u1234排版信息的测试文སསསས本Drawing.དདདདདད.       ";
4410     OH_Drawing_TypographyHandlerAddText(handler, text);
4411     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4412     const float indents[2] = {500.0, 55.1};
4413     int indentSize = 2;
4414     OH_Drawing_TypographySetIndents(typography, indentSize, indents);
4415     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4416     double longestLine = OH_Drawing_TypographyGetLongestLine(typography);
4417     double longestLineIndent = OH_Drawing_TypographyGetLongestLineWithIndent(typography);
4418     double lineCount = OH_Drawing_TypographyGetLineCount(typography);
4419     double maxLineWidth = 0.0;
4420     double maxLineWidthIndent = 0.0;
4421     for (int i = 0; i < lineCount; i++) {
4422         double lineWidth = OH_Drawing_TypographyGetLineWidth(typography, i);
4423         maxLineWidth = std::max(maxLineWidth, lineWidth);
4424         double indent = OH_Drawing_TypographyGetIndentsWithIndex(typography, i);
4425         maxLineWidthIndent = std::max(maxLineWidthIndent, lineWidth + indent);
4426     }
4427     EXPECT_NEAR(longestLine, maxLineWidth, FLOAT_DATA_EPSILON);
4428     EXPECT_NEAR(longestLineIndent, maxLineWidthIndent, 0.0001);
4429     EXPECT_NEAR(longestLine, 739.896423, FLOAT_DATA_EPSILON);
4430     EXPECT_NEAR(longestLineIndent, 799.999756, FLOAT_DATA_EPSILON);
4431 
4432     double minIntrinsicWidth = OH_Drawing_TypographyGetMinIntrinsicWidth(typography);
4433     double maxIntrinsicWidth = OH_Drawing_TypographyGetMaxIntrinsicWidth(typography);
4434     EXPECT_NEAR(minIntrinsicWidth, 349.772766, FLOAT_DATA_EPSILON);
4435     EXPECT_NEAR(maxIntrinsicWidth, 3338.310059, FLOAT_DATA_EPSILON);
4436     OH_Drawing_DestroyTypography(typography);
4437     OH_Drawing_DestroyTypographyStyle(typoStyle);
4438     OH_Drawing_DestroyTypographyHandler(handler);
4439     OH_Drawing_DestroyTextStyle(txtStyle);
4440 }
4441 
4442 /*
4443 * @tc.name: TypographyGetLineTextRangeTest001
4444 * @tc.desc: test for typography mutiple lines,but set Set end line spaces and ellipsis
4445 * @tc.type: FUNC
4446 */
4447 HWTEST_F(NdkTypographyTest, TypographyGetLineTextRangeTest001, TestSize.Level0)
4448 {
4449     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4450     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4451     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x11, 0x11, 0xFF));
4452     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4453     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 4);
4454     OH_Drawing_TypographyCreate* handler =
4455         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4456     const char *elipss = "...";
4457     OH_Drawing_SetTypographyTextEllipsis(typoStyle, elipss);
4458     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, 2);
4459     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4460     const char *text = "这是一个排版信息دددھساسااساساس获取接口的测试文本:Hello World     \n是版信息获取接测试文本Drawing.";
4461     OH_Drawing_TypographyHandlerAddText(handler, text);
4462     text = "这是一个排版信息བསདབད获取接口的སངབངསབ测试文lo World这是一个 ..... \u1234排版信息的测试文སསསས本Drawing.དདདདདད.       ";
4463     OH_Drawing_TypographyHandlerAddText(handler, text);
4464     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4465     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4466     double longestLine = OH_Drawing_TypographyGetLongestLine(typography);
4467     double lineCount = OH_Drawing_TypographyGetLineCount(typography);
4468     double maxLineWidth = 0.0;
4469     for (int i = 0; i < lineCount; i++) {
4470         double lineWidth = OH_Drawing_TypographyGetLineWidth(typography, i);
4471         maxLineWidth = std::max(maxLineWidth, lineWidth);
4472     }
4473     OH_Drawing_Range *range1 = OH_Drawing_TypographyGetLineTextRange(typography, 1, false);
4474     EXPECT_EQ(55, OH_Drawing_GetStartFromRange(range1));
4475     EXPECT_EQ(93, OH_Drawing_GetEndFromRange(range1));
4476     OH_Drawing_Range *range2 = OH_Drawing_TypographyGetLineTextRange(typography, 1, true);
4477     EXPECT_EQ(55, OH_Drawing_GetStartFromRange(range2));
4478     EXPECT_EQ(98, OH_Drawing_GetEndFromRange(range2));
4479     EXPECT_NEAR(longestLine, maxLineWidth, FLOAT_DATA_EPSILON);
4480     OH_Drawing_PositionAndAffinity* posAAClusrterDown =
4481         OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 80, 0);
4482     int affinityClusterDown = OH_Drawing_GetAffinityFromPositionAndAffinity(posAAClusrterDown);
4483     int aPositionClusterDown = OH_Drawing_GetPositionFromPositionAndAffinity(posAAClusrterDown);
4484     EXPECT_EQ(0, affinityClusterDown);
4485     EXPECT_EQ(2, aPositionClusterDown);
4486     OH_Drawing_PositionAndAffinity* posAAClusrterUp =
4487         OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 100, 100);
4488     int affinityClusterUp = OH_Drawing_GetAffinityFromPositionAndAffinity(posAAClusrterUp);
4489     int aPositionClusterUp = OH_Drawing_GetPositionFromPositionAndAffinity(posAAClusrterUp);
4490     EXPECT_EQ(1, affinityClusterUp);
4491     EXPECT_EQ(25, aPositionClusterUp);
4492     OH_Drawing_DestroyTypography(typography);
4493     OH_Drawing_DestroyTypographyStyle(typoStyle);
4494     OH_Drawing_DestroyTypographyHandler(handler);
4495     OH_Drawing_DestroyTextStyle(txtStyle);
4496 }
4497 
4498 /*
4499 * @tc.name: TypographyGetLineTextRangeTest002
4500 * @tc.desc: test for typography mutiple lines,but set Set end line spaces and ellipsis
4501 * @tc.type: FUNC
4502 */
4503 HWTEST_F(NdkTypographyTest, TypographyGetLineTextRangeTest002, TestSize.Level0)
4504 {
4505     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4506     OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
4507     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x11, 0x11, 0xFF));
4508     OH_Drawing_SetTextStyleFontSize(txtStyle, 50);
4509     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 4);
4510     OH_Drawing_TypographyCreate* handler =
4511         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4512     const char *elipss = "...";
4513     OH_Drawing_SetTypographyTextEllipsis(typoStyle, elipss);
4514     OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, 2);
4515     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4516     const char *text = "这是一个排版信息دددھساسااساساس获取接口的测试文本:Hello World     \n是版信息获取接测试文本Drawing.";
4517     OH_Drawing_TypographyHandlerAddText(handler, text);
4518     text = "这是一个排版信息བསདབད获取接口的སངབངསབ测试文lo World这是一个 ..... \u1234排版信息的测试文སསསས本Drawing.དདདདདད.       ";
4519     OH_Drawing_TypographyHandlerAddText(handler, text);
4520 
4521     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4522     OH_Drawing_Range *range1 = OH_Drawing_TypographyGetLineTextRange(typography, 0, false);
4523     EXPECT_EQ(0, OH_Drawing_GetStartFromRange(range1));
4524     EXPECT_EQ(0, OH_Drawing_GetEndFromRange(range1));
4525     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4526 
4527     double lineCount = OH_Drawing_TypographyGetLineCount(typography);
4528     OH_Drawing_Range *range2 = OH_Drawing_TypographyGetLineTextRange(typography, lineCount, false);
4529     EXPECT_EQ(0, OH_Drawing_GetStartFromRange(range2));
4530     EXPECT_EQ(0, OH_Drawing_GetEndFromRange(range2));
4531     OH_Drawing_DestroyTypography(typography);
4532     OH_Drawing_DestroyTypographyStyle(typoStyle);
4533     OH_Drawing_DestroyTypographyHandler(handler);
4534     OH_Drawing_DestroyTextStyle(txtStyle);
4535 }
4536 
4537 /*
4538  * @tc.name: TypographyBadgeTypeTest001
4539  * @tc.desc: Test for text's super script
4540  * @tc.type: FUNC
4541  */
4542 HWTEST_F(NdkTypographyTest, TypographyBadgeTypeTest001, TestSize.Level0)
4543 {
4544     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4545     ASSERT_NE(typoStyle, nullptr);
4546     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
4547     ASSERT_NE(txtStyle, nullptr);
4548     OH_Drawing_TypographyCreate* handler =
4549         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4550     ASSERT_NE(handler, nullptr);
4551     OH_Drawing_TypographyCreate* superTxtHandler =
4552         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4553     ASSERT_NE(superTxtHandler, nullptr);
4554 
4555     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF));
4556     OH_Drawing_SetTextStyleFontSize(txtStyle, DEFAULT_FONT_SIZE);
4557     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
4558     OH_Drawing_SetTextStyleBadgeType(txtStyle, OH_Drawing_TextBadgeType::TEXT_BADGE_NONE);
4559 
4560     OH_Drawing_TextStyle* superTxtStyle = OH_Drawing_CreateTextStyle();
4561     ASSERT_NE(superTxtStyle, nullptr);
4562     OH_Drawing_SetTextStyleFontSize(superTxtStyle, DEFAULT_FONT_SIZE);
4563     OH_Drawing_SetTextStyleFontWeight(superTxtStyle, FONT_WEIGHT_400);
4564     OH_Drawing_SetTextStyleBadgeType(superTxtStyle, OH_Drawing_TextBadgeType::TEXT_SUPERSCRIPT);
4565 
4566     const char* text = "OpenHarmony";
4567     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4568     OH_Drawing_TypographyHandlerAddText(handler, text);
4569     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4570     ASSERT_NE(typography, nullptr);
4571     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4572 
4573     OH_Drawing_TypographyHandlerPushTextStyle(superTxtHandler, superTxtStyle);
4574     OH_Drawing_TypographyHandlerAddText(superTxtHandler, text);
4575     OH_Drawing_Typography* superTxtTypography = OH_Drawing_CreateTypography(superTxtHandler);
4576     ASSERT_NE(superTxtTypography, nullptr);
4577     OH_Drawing_TypographyLayout(superTxtTypography, MAX_WIDTH);
4578 
4579     EXPECT_TRUE(skia::textlayout::nearlyEqual(OH_Drawing_TypographyGetLongestLine(typography), 334.8996887));
4580     EXPECT_TRUE(skia::textlayout::nearlyEqual(OH_Drawing_TypographyGetLongestLine(superTxtTypography), 217.6851959));
4581     OH_Drawing_DestroyTypography(typography);
4582     OH_Drawing_DestroyTypographyHandler(handler);
4583     OH_Drawing_DestroyTextStyle(txtStyle);
4584 
4585     OH_Drawing_DestroyTypography(superTxtTypography);
4586     OH_Drawing_DestroyTypographyHandler(superTxtHandler);
4587     OH_Drawing_DestroyTextStyle(superTxtStyle);
4588 }
4589 
4590 /*
4591  * @tc.name: TypographyBadgeTypeTest002
4592  * @tc.desc: Test for text's sub script
4593  * @tc.type: FUNC
4594  */
4595 HWTEST_F(NdkTypographyTest, TypographyBadgeTypeTest002, TestSize.Level0)
4596 {
4597     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4598     ASSERT_NE(typoStyle, nullptr);
4599     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
4600     ASSERT_NE(txtStyle, nullptr);
4601     OH_Drawing_TypographyCreate* handler =
4602         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4603     ASSERT_NE(handler, nullptr);
4604     OH_Drawing_TypographyCreate* subTxtHandler =
4605         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4606     ASSERT_NE(subTxtHandler, nullptr);
4607 
4608     OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF));
4609     OH_Drawing_SetTextStyleFontSize(txtStyle, DEFAULT_FONT_SIZE);
4610     OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
4611     OH_Drawing_SetTextStyleBadgeType(txtStyle, OH_Drawing_TextBadgeType::TEXT_BADGE_NONE);
4612 
4613     OH_Drawing_TextStyle* subTxtStyle = OH_Drawing_CreateTextStyle();
4614     ASSERT_NE(subTxtStyle, nullptr);
4615     OH_Drawing_SetTextStyleFontSize(subTxtStyle, DEFAULT_FONT_SIZE);
4616     OH_Drawing_SetTextStyleFontWeight(subTxtStyle, FONT_WEIGHT_400);
4617     OH_Drawing_SetTextStyleBadgeType(subTxtStyle, OH_Drawing_TextBadgeType::TEXT_SUBSCRIPT);
4618 
4619     const char* text = "你好世界";
4620     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4621     OH_Drawing_TypographyHandlerAddText(handler, text);
4622     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4623     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4624 
4625     OH_Drawing_TypographyHandlerPushTextStyle(subTxtHandler, subTxtStyle);
4626     OH_Drawing_TypographyHandlerAddText(subTxtHandler, text);
4627     OH_Drawing_Typography* subTxtTypography = OH_Drawing_CreateTypography(subTxtHandler);
4628     ASSERT_NE(subTxtTypography, nullptr);
4629     OH_Drawing_TypographyLayout(subTxtTypography, MAX_WIDTH);
4630 
4631     EXPECT_TRUE(skia::textlayout::nearlyEqual(OH_Drawing_TypographyGetLongestLine(typography), 200));
4632     EXPECT_TRUE(skia::textlayout::nearlyEqual(OH_Drawing_TypographyGetLongestLine(subTxtTypography), 130)),
4633     OH_Drawing_DestroyTypography(typography);
4634     OH_Drawing_DestroyTypographyHandler(handler);
4635     OH_Drawing_DestroyTextStyle(txtStyle);
4636 
4637     OH_Drawing_DestroyTypography(subTxtTypography);
4638     OH_Drawing_DestroyTypographyHandler(subTxtHandler);
4639     OH_Drawing_DestroyTextStyle(subTxtStyle);
4640 }
4641 
4642 /*
4643  * @tc.name: TypographyBadgeTypeTest003
4644  * @tc.desc: Test for text's badge valid params
4645  * @tc.type: FUNC
4646  */
4647 HWTEST_F(NdkTypographyTest, TypographyBadgeTypeTest003, TestSize.Level0)
4648 {
4649     EXPECT_NO_FATAL_FAILURE(OH_Drawing_SetTextStyleBadgeType(nullptr, OH_Drawing_TextBadgeType::TEXT_BADGE_NONE));
4650 }
4651 
4652 /*
4653  * @tc.name: TypographyVerticalTest001
4654  * @tc.desc: Test for vertical align valid params
4655  * @tc.type: FUNC
4656  */
4657 HWTEST_F(NdkTypographyTest, TypographyVerticalTest001, TestSize.Level0)
4658 {
4659     EXPECT_NO_FATAL_FAILURE(OH_Drawing_SetTypographyVerticalAlignment(nullptr,
4660         OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_BOTTOM));
4661 }
4662 
PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment align,bool addPlaceholder,OH_Drawing_PlaceholderVerticalAlignment placeholderAlign=OH_Drawing_PlaceholderVerticalAlignment::ALIGNMENT_ABOVE_BASELINE)4663 OH_Drawing_Typography* PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment align, bool addPlaceholder,
4664     OH_Drawing_PlaceholderVerticalAlignment placeholderAlign =
4665     OH_Drawing_PlaceholderVerticalAlignment::ALIGNMENT_ABOVE_BASELINE)
4666 {
4667     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4668     OH_Drawing_SetTypographyVerticalAlignment(typoStyle, align);
4669     OH_Drawing_TypographyCreate* handler =
4670         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4671 
4672     if (addPlaceholder) {
4673         OH_Drawing_PlaceholderSpan placeholderSpan{20, 20, placeholderAlign, TEXT_BASELINE_IDEOGRAPHIC, 0};
4674         OH_Drawing_TypographyHandlerAddPlaceholder(handler, &placeholderSpan);
4675     }
4676     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
4677     OH_Drawing_SetTextStyleFontSize(txtStyle, DEFAULT_FONT_SIZE);
4678     const char* text = "ohos";
4679     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4680     OH_Drawing_TypographyHandlerAddText(handler, text);
4681     OH_Drawing_SetTextStyleFontSize(txtStyle, DEFAULT_FONT_SIZE + DEFAULT_FONT_SIZE);
4682     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4683     OH_Drawing_TypographyHandlerAddText(handler, text);
4684     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4685     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4686     double position[2] = { 10.0, 15.0 };    // 10.0 and 15.0 were used for testing
4687     OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
4688     OH_Drawing_BitmapFormat cFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE };
4689     // Just used for testing
4690     uint32_t width = 20;
4691     uint32_t height = 40;
4692     OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
4693     OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
4694     OH_Drawing_CanvasBind(cCanvas, cBitmap);
4695     OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
4696     OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
4697     return typography;
4698 }
4699 
CompareRunBoundsBetweenTwoParagraphs(OH_Drawing_Typography * defaultParagraph,OH_Drawing_Typography * comparedParagraph)4700 bool CompareRunBoundsBetweenTwoParagraphs(OH_Drawing_Typography* defaultParagraph,
4701     OH_Drawing_Typography* comparedParagraph)
4702 {
4703     OH_Drawing_Array* defaultLines = OH_Drawing_TypographyGetTextLines(defaultParagraph);
4704     OH_Drawing_Array* comparedLines = OH_Drawing_TypographyGetTextLines(comparedParagraph);
4705     OH_Drawing_TextLine* defaultFirstLine = OH_Drawing_GetTextLineByIndex(defaultLines, 0);
4706     OH_Drawing_TextLine* comparedFirstLine = OH_Drawing_GetTextLineByIndex(comparedLines, 0);
4707     OH_Drawing_Array* defaultRuns = OH_Drawing_TextLineGetGlyphRuns(defaultFirstLine);
4708     OH_Drawing_Array* comparedRuns = OH_Drawing_TextLineGetGlyphRuns(comparedFirstLine);
4709     OH_Drawing_Run* defaultFirstRun = OH_Drawing_GetRunByIndex(defaultRuns, 0);
4710     OH_Drawing_Run* comparedFirstRun = OH_Drawing_GetRunByIndex(comparedRuns, 0);
4711     float ascent{0.0f};
4712     float descent{0.0f};
4713     float leading{0.0f};
4714     OH_Drawing_GetRunTypographicBounds(defaultFirstRun, &ascent, &descent, &leading);
4715     float comparedAscent{0.0f};
4716     float comparedDescent{0.0f};
4717     float comparedLeading{0.0f};
4718     OH_Drawing_GetRunTypographicBounds(comparedFirstRun, &comparedAscent, &comparedDescent, &comparedLeading);
4719     return skia::textlayout::nearlyEqual(ascent, comparedAscent) &&
4720         skia::textlayout::nearlyEqual(descent, comparedDescent);
4721 }
4722 
ComparePlaceholderRectsBetweenTwoParagraphs(OH_Drawing_Typography * defaultParagraph,OH_Drawing_Typography * comparedParagraph)4723 bool ComparePlaceholderRectsBetweenTwoParagraphs(OH_Drawing_Typography* defaultParagraph,
4724     OH_Drawing_Typography* comparedParagraph)
4725 {
4726     OH_Drawing_TextBox* defaultPlaceholderRect = OH_Drawing_TypographyGetRectsForPlaceholders(defaultParagraph);
4727     OH_Drawing_TextBox* comparedPlaceholderRect = OH_Drawing_TypographyGetRectsForPlaceholders(comparedParagraph);
4728     return skia::textlayout::nearlyEqual(OH_Drawing_GetTopFromTextBox(defaultPlaceholderRect, 0),
4729         OH_Drawing_GetTopFromTextBox(comparedPlaceholderRect, 0));
4730 }
4731 
4732 /*
4733  * @tc.name: TypographyVerticalTest002
4734  * @tc.desc: Test for vertical align
4735  * @tc.type: FUNC
4736  */
4737 HWTEST_F(NdkTypographyTest, TypographyVerticalTest002, TestSize.Level0)
4738 {
4739     OH_Drawing_Typography* typographyOne =
4740         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_BASELINE, false);
4741     ASSERT_NE(typographyOne, nullptr);
4742     OH_Drawing_Typography* topAlignTypography =
4743         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_TOP, false);
4744     ASSERT_NE(topAlignTypography, nullptr);
4745     OH_Drawing_Typography* typographyTwo =
4746         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_BASELINE, false);
4747     ASSERT_NE(typographyTwo, nullptr);
4748     OH_Drawing_Typography* centerAlignTypography =
4749         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_CENTER, false);
4750     ASSERT_NE(centerAlignTypography, nullptr);
4751     OH_Drawing_Typography* typographyThree =
4752         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_BASELINE, false);
4753     ASSERT_NE(typographyThree, nullptr);
4754     OH_Drawing_Typography* bottomAlignTypography =
4755         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_BOTTOM, false);
4756     ASSERT_NE(bottomAlignTypography, nullptr);
4757     OH_Drawing_Typography* typographyWithPlaceholder =
4758         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_TOP, true,
4759         OH_Drawing_PlaceholderVerticalAlignment::ALIGNMENT_ABOVE_BASELINE);
4760     ASSERT_NE(typographyWithPlaceholder, nullptr);
4761     OH_Drawing_Typography* followTypographyWithPlaceholder =
4762         PrepareParagraphForVerticalAlign(OH_Drawing_TextVerticalAlignment::TEXT_VERTICAL_ALIGNMENT_TOP, true,
4763         OH_Drawing_PlaceholderVerticalAlignment::ALIGNMENT_FOLLOW_PARAGRAPH);
4764     ASSERT_NE(followTypographyWithPlaceholder, nullptr);
4765     EXPECT_FALSE(CompareRunBoundsBetweenTwoParagraphs(typographyOne, topAlignTypography));
4766     EXPECT_FALSE(CompareRunBoundsBetweenTwoParagraphs(typographyTwo, centerAlignTypography));
4767     EXPECT_FALSE(CompareRunBoundsBetweenTwoParagraphs(typographyThree, bottomAlignTypography));
4768     EXPECT_FALSE(
4769         ComparePlaceholderRectsBetweenTwoParagraphs(typographyWithPlaceholder, followTypographyWithPlaceholder));
4770 }
4771 
4772 /*
4773  * @tc.name: OH_Drawing_TypographyInnerBalanceExceedMaxLinesTest
4774  * @tc.desc: Test for balance strategy exceed maxLines interface when layout line count equal to max line count
4775  * @tc.type: FUNC
4776  */
4777 HWTEST_F(NdkTypographyTest, TypographyBalanceStrategy001, TestSize.Level0)
4778 {
4779     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4780     ASSERT_NE(typoStyle, nullptr);
4781     // Test for balance strategy 2
4782     OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, 2);
4783     OH_Drawing_SetTypographyTextMaxLines(typoStyle, 1);
4784     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
4785     ASSERT_NE(txtStyle, nullptr);
4786     // Test for font size 16
4787     OH_Drawing_SetTextStyleFontSize(txtStyle, 16);
4788     OH_Drawing_TypographyCreate* handler =
4789         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4790     ASSERT_NE(handler, nullptr);
4791     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4792     const char* text = "测试: Balance exceed maxLines test";
4793     OH_Drawing_TypographyHandlerAddText(handler, text);
4794     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4795     ASSERT_NE(typography, nullptr);
4796     OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
4797     EXPECT_FALSE(OH_Drawing_TypographyDidExceedMaxLines(typography));
4798     OH_Drawing_DestroyTypographyStyle(typoStyle);
4799     OH_Drawing_DestroyTypographyHandler(handler);
4800     OH_Drawing_DestroyTypography(typography);
4801     OH_Drawing_DestroyTextStyle(txtStyle);
4802 }
4803 
4804 /*
4805  * @tc.name: OH_Drawing_TypographyInnerBalanceMaxLinesTest
4806  * @tc.desc: Test for balance strategy set maxLines limit
4807  * @tc.type: FUNC
4808  */
4809 HWTEST_F(NdkTypographyTest, TypographyBalanceStrategy002, TestSize.Level0)
4810 {
4811     OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
4812     ASSERT_NE(typoStyle, nullptr);
4813     // Test for balance strategy 2
4814     OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, 2);
4815     // Test for maxLines limit
4816     size_t maxLines{3};
4817     OH_Drawing_SetTypographyTextMaxLines(typoStyle, maxLines);
4818     OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
4819     ASSERT_NE(txtStyle, nullptr);
4820     // Test for font size 16
4821     OH_Drawing_SetTextStyleFontSize(txtStyle, 16);
4822     OH_Drawing_TypographyCreate* handler =
4823         OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
4824     ASSERT_NE(handler, nullptr);
4825     OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
4826     const char* text = "测试: Balance exceed maxLines test";
4827     OH_Drawing_TypographyHandlerAddText(handler, text);
4828     OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
4829     ASSERT_NE(typography, nullptr);
4830     // Test for layout width 50
4831     OH_Drawing_TypographyLayout(typography, 50);
4832     EXPECT_EQ(OH_Drawing_TypographyGetLineCount(typography), maxLines);
4833     OH_Drawing_DestroyTypographyStyle(typoStyle);
4834     OH_Drawing_DestroyTextStyle(txtStyle);
4835     OH_Drawing_DestroyTypographyHandler(handler);
4836     OH_Drawing_DestroyTypography(typography);
4837 }
4838 } // namespace OHOS