1/*
2 * Copyright (c) 2022 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 "gtest/gtest.h"
17#include "drawing_bitmap.h"
18#include "drawing_brush.h"
19#include "drawing_canvas.h"
20#include "drawing_color.h"
21#include "drawing_font.h"
22#include "drawing_font_collection.h"
23#include "drawing_path.h"
24#include "drawing_pen.h"
25#include "drawing_text_declaration.h"
26#include "drawing_text_typography.h"
27#ifndef USE_GRAPHIC_TEXT_GINE
28#include "rosen_text/ui/typography.h"
29#include "rosen_text/ui/typography_create.h"
30#else
31#include "rosen_text/typography.h"
32#include "rosen_text/typography_create.h"
33#endif
34
35#include <string>
36#include <fstream>
37
38#ifndef USE_GRAPHIC_TEXT_GINE
39using namespace rosen;
40#else
41using namespace OHOS::Rosen;
42#endif
43using namespace testing;
44using namespace testing::ext;
45
46namespace OHOS {
47class OH_Drawing_TypographyTest : public testing::Test {
48};
49
50const double ARC_FONT_SIZE = 30;
51const double MAX_WIDTH = 800.0;
52const double RADIAN_TER = 180.0;
53const double LEFT_POS = 50.0;
54const double RIGHT_POS = 150.0;
55
56static TypographyStyle* ConvertToOriginalText(OH_Drawing_TypographyStyle* style)
57{
58    return reinterpret_cast<TypographyStyle*>(style);
59}
60
61static TextStyle* ConvertToOriginalText(OH_Drawing_TextStyle* style)
62{
63    return reinterpret_cast<TextStyle*>(style);
64}
65
66/*
67 * @tc.name: OH_Drawing_TypographyTest001
68 * @tc.desc: test for creating TypographyStyle
69 * @tc.type: FUNC
70 */
71HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest001, TestSize.Level1)
72{
73    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
74    EXPECT_EQ(typoStyle == nullptr, false);
75    OH_Drawing_DestroyTypographyStyle(typoStyle);
76}
77
78/*
79 * @tc.name: OH_Drawing_TypographyTest002
80 * @tc.desc: test for text direction
81 * @tc.type: FUNC
82 */
83HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest002, TestSize.Level1)
84{
85    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
86    OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);
87#ifndef USE_GRAPHIC_TEXT_GINE
88    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::LTR);
89#else
90    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::LTR);
91#endif
92    OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_RTL);
93#ifndef USE_GRAPHIC_TEXT_GINE
94    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::RTL);
95#else
96    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::RTL);
97#endif
98    OH_Drawing_SetTypographyTextDirection(typoStyle, -1);
99#ifndef USE_GRAPHIC_TEXT_GINE
100    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection_, TextDirection::LTR);
101#else
102    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textDirection, TextDirection::LTR);
103#endif
104}
105
106/*
107 * @tc.name: OH_Drawing_TypographyTest003
108 * @tc.desc: test for text alignment
109 * @tc.type: FUNC
110 */
111HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest003, TestSize.Level1)
112{
113    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
114    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);
115#ifndef USE_GRAPHIC_TEXT_GINE
116    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::LEFT);
117#else
118    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::LEFT);
119#endif
120    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_RIGHT);
121#ifndef USE_GRAPHIC_TEXT_GINE
122    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::RIGHT);
123#else
124    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::RIGHT);
125#endif
126    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_CENTER);
127#ifndef USE_GRAPHIC_TEXT_GINE
128    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::CENTER);
129#else
130    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::CENTER);
131#endif
132    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_JUSTIFY);
133#ifndef USE_GRAPHIC_TEXT_GINE
134    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::JUSTIFY);
135#else
136    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::JUSTIFY);
137#endif
138    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_START);
139#ifndef USE_GRAPHIC_TEXT_GINE
140    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::START);
141#else
142    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::START);
143#endif
144    OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_END);
145#ifndef USE_GRAPHIC_TEXT_GINE
146    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::END);
147#else
148    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::END);
149#endif
150    OH_Drawing_SetTypographyTextAlign(typoStyle, -1);
151#ifndef USE_GRAPHIC_TEXT_GINE
152    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign_, TextAlign::LEFT);
153#else
154    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textAlign, TextAlign::LEFT);
155#endif
156}
157
158/*
159 * @tc.name: OH_Drawing_TypographyTest004
160 * @tc.desc: test for max lines
161 * @tc.type: FUNC
162 */
163HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest004, TestSize.Level1)
164{
165    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
166    OH_Drawing_SetTypographyTextMaxLines(typoStyle, 100);
167#ifndef USE_GRAPHIC_TEXT_GINE
168    EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines_, 100);
169#else
170    EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines, 100);
171#endif
172    OH_Drawing_SetTypographyTextMaxLines(typoStyle, 200);
173#ifndef USE_GRAPHIC_TEXT_GINE
174    EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines_, 200);
175#else
176    EXPECT_EQ(ConvertToOriginalText(typoStyle)->maxLines, 200);
177#endif
178}
179
180/*
181 * @tc.name: OH_Drawing_TypographyTest005
182 * @tc.desc: test for creating text style
183 * @tc.type: FUNC
184 */
185HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest005, TestSize.Level1)
186{
187    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
188    EXPECT_EQ(txtStyle == nullptr, false);
189    OH_Drawing_DestroyTextStyle(txtStyle);
190}
191
192/*
193 * @tc.name: OH_Drawing_TypographyTest006
194 * @tc.desc: test for text color
195 * @tc.type: FUNC
196 */
197HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest006, TestSize.Level1)
198{
199    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
200    // black
201    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
202#ifndef USE_GRAPHIC_TEXT_GINE
203    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFF000000);
204#else
205    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFF000000);
206#endif
207    // red
208    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
209#ifndef USE_GRAPHIC_TEXT_GINE
210    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFFFF0000);
211#else
212    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFFFF0000);
213#endif
214    // blue
215    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF));
216#ifndef USE_GRAPHIC_TEXT_GINE
217    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color_, 0xFF0000FF);
218#else
219    EXPECT_EQ(ConvertToOriginalText(txtStyle)->color, 0xFF0000FF);
220#endif
221}
222
223/*
224 * @tc.name: OH_Drawing_TypographyTest007
225 * @tc.desc: test for font size
226 * @tc.type: FUNC
227 */
228HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest007, TestSize.Level1)
229{
230    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
231    OH_Drawing_SetTextStyleFontSize(txtStyle, 80);
232#ifndef USE_GRAPHIC_TEXT_GINE
233    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize_, 80);
234#else
235    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize, 80);
236#endif
237    OH_Drawing_SetTextStyleFontSize(txtStyle, 40);
238#ifndef USE_GRAPHIC_TEXT_GINE
239    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize_, 40);
240#else
241    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontSize, 40);
242#endif
243}
244
245/*
246 * @tc.name: OH_Drawing_TypographyTest008
247 * @tc.desc: test for font weight
248 * @tc.type: FUNC
249 */
250HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest008, TestSize.Level1)
251{
252    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
253    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_100);
254#ifndef USE_GRAPHIC_TEXT_GINE
255    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W100);
256#else
257    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W100);
258#endif
259    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_200);
260#ifndef USE_GRAPHIC_TEXT_GINE
261    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W200);
262#else
263    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W200);
264#endif
265    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_300);
266#ifndef USE_GRAPHIC_TEXT_GINE
267    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W300);
268#else
269    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W300);
270#endif
271    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
272#ifndef USE_GRAPHIC_TEXT_GINE
273    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W400);
274#else
275    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W400);
276#endif
277    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_500);
278#ifndef USE_GRAPHIC_TEXT_GINE
279    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W500);
280#else
281    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W500);
282#endif
283    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_600);
284#ifndef USE_GRAPHIC_TEXT_GINE
285    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W600);
286#else
287    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W600);
288#endif
289    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_700);
290#ifndef USE_GRAPHIC_TEXT_GINE
291    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W700);
292#else
293    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W700);
294#endif
295    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_800);
296#ifndef USE_GRAPHIC_TEXT_GINE
297    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W800);
298#else
299    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W800);
300#endif
301    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_900);
302#ifndef USE_GRAPHIC_TEXT_GINE
303    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W900);
304#else
305    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W900);
306#endif
307    OH_Drawing_SetTextStyleFontWeight(txtStyle, -1);
308#ifndef USE_GRAPHIC_TEXT_GINE
309    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight_, FontWeight::W400);
310#else
311    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontWeight, FontWeight::W400);
312#endif
313}
314
315/*
316 * @tc.name: OH_Drawing_TypographyTest009
317 * @tc.desc: test for baseline location
318 * @tc.type: FUNC
319 */
320HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest009, TestSize.Level1)
321{
322    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
323    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
324#ifndef USE_GRAPHIC_TEXT_GINE
325    EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::ALPHABETIC);
326#else
327    EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::ALPHABETIC);
328#endif
329    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_IDEOGRAPHIC);
330#ifndef USE_GRAPHIC_TEXT_GINE
331    EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::IDEOGRAPHIC);
332#else
333    EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::IDEOGRAPHIC);
334#endif
335    OH_Drawing_SetTextStyleBaseLine(txtStyle, -1);
336#ifndef USE_GRAPHIC_TEXT_GINE
337    EXPECT_EQ(ConvertToOriginalText(txtStyle)->textBaseline_, TextBaseline::ALPHABETIC);
338#else
339    EXPECT_EQ(ConvertToOriginalText(txtStyle)->baseline, TextBaseline::ALPHABETIC);
340#endif
341}
342
343/*
344 * @tc.name: OH_Drawing_TypographyTest010
345 * @tc.desc: test for text decoration
346 * @tc.type: FUNC
347 */
348HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest010, TestSize.Level1)
349{
350    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
351    OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_NONE);
352#ifndef USE_GRAPHIC_TEXT_GINE
353    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::NONE);
354#else
355    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::NONE);
356#endif
357    OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_UNDERLINE);
358#ifndef USE_GRAPHIC_TEXT_GINE
359    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::UNDERLINE);
360#else
361    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::UNDERLINE);
362#endif
363    OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_OVERLINE);
364#ifndef USE_GRAPHIC_TEXT_GINE
365    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::OVERLINE);
366#else
367    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::OVERLINE);
368#endif
369    OH_Drawing_SetTextStyleDecoration(txtStyle, TEXT_DECORATION_LINE_THROUGH);
370#ifndef USE_GRAPHIC_TEXT_GINE
371    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::LINETHROUGH);
372#else
373    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::LINE_THROUGH);
374#endif
375    OH_Drawing_SetTextStyleDecoration(txtStyle, -1);
376#ifndef USE_GRAPHIC_TEXT_GINE
377    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration_, TextDecoration::NONE);
378#else
379    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decoration, TextDecoration::NONE);
380#endif
381}
382
383/*
384 * @tc.name: OH_Drawing_TypographyTest011
385 * @tc.desc: test for text decoration color
386 * @tc.type: FUNC
387 */
388HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest011, TestSize.Level1)
389{
390    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
391    OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
392#ifndef USE_GRAPHIC_TEXT_GINE
393    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor_, 0xFF000000);
394#else
395    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor, 0xFF000000);
396#endif
397    OH_Drawing_SetTextStyleDecorationColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
398#ifndef USE_GRAPHIC_TEXT_GINE
399    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor_, 0xFFFF0000);
400#else
401    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationColor, 0xFFFF0000);
402#endif
403}
404
405/*
406 * @tc.name: OH_Drawing_TypographyTest012
407 * @tc.desc: test for font height
408 * @tc.type: FUNC
409 */
410HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest012, TestSize.Level1)
411{
412    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
413    OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.0);
414#ifndef USE_GRAPHIC_TEXT_GINE
415    EXPECT_EQ(ConvertToOriginalText(txtStyle)->height_, 0.0);
416#else
417    EXPECT_EQ(ConvertToOriginalText(txtStyle)->heightScale, 0.0);
418#endif
419}
420
421/*
422 * @tc.name: OH_Drawing_TypographyTest013
423 * @tc.desc: test for font families
424 * @tc.type: FUNC
425 */
426HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest013, TestSize.Level1)
427{
428    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
429    const char* fontFamilies[] = {"Roboto"};
430    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
431    std::vector<std::string> fontFamiliesResult = {"Roboto"};
432#ifndef USE_GRAPHIC_TEXT_GINE
433    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontFamilies_, fontFamiliesResult);
434#else
435    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontFamilies, fontFamiliesResult);
436#endif
437}
438
439/*
440 * @tc.name: OH_Drawing_TypographyTest014
441 * @tc.desc: test for font italic
442 * @tc.type: FUNC
443 */
444HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest014, TestSize.Level1)
445{
446    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
447    OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
448#ifndef USE_GRAPHIC_TEXT_GINE
449    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::NORMAL);
450#else
451    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::NORMAL);
452#endif
453    OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_ITALIC);
454#ifndef USE_GRAPHIC_TEXT_GINE
455    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::ITALIC);
456#else
457    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::ITALIC);
458#endif
459    OH_Drawing_SetTextStyleFontStyle(txtStyle, -1);
460#ifndef USE_GRAPHIC_TEXT_GINE
461    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle_, FontStyle::NORMAL);
462#else
463    EXPECT_EQ(ConvertToOriginalText(txtStyle)->fontStyle, FontStyle::NORMAL);
464#endif
465}
466
467/*
468 * @tc.name: OH_Drawing_TypographyTest015
469 * @tc.desc: test for font locale
470 * @tc.type: FUNC
471 */
472HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest015, TestSize.Level1)
473{
474    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
475    OH_Drawing_SetTextStyleLocale(txtStyle, "en");
476#ifndef USE_GRAPHIC_TEXT_GINE
477    EXPECT_EQ(ConvertToOriginalText(txtStyle)->locale_, "en");
478#else
479    EXPECT_EQ(ConvertToOriginalText(txtStyle)->locale, "en");
480#endif
481}
482
483/*
484 * @tc.name: OH_Drawing_TypographyTest016
485 * @tc.desc: test for typography
486 * @tc.type: FUNC
487 */
488HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest016, TestSize.Level1)
489{
490    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
491    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
492    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
493        OH_Drawing_CreateFontCollection());
494    EXPECT_TRUE(handler != nullptr);
495
496    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
497    double fontSize = 30;
498    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
499    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
500    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
501    const char* fontFamilies[] = {"Roboto"};
502    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
503    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
504
505    const char* text = "OpenHarmony\n";
506    OH_Drawing_TypographyHandlerAddText(handler, text);
507    OH_Drawing_TypographyHandlerPopTextStyle(handler);
508
509    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
510    const float indents[] = {1.2, 3.4};
511    OH_Drawing_TypographySetIndents(typography, 2, indents);
512    float indent = 3.4;
513    EXPECT_EQ(indent, OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
514    double maxWidth = 800.0;
515    OH_Drawing_TypographyLayout(typography, maxWidth);
516    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
517    double position[2] = {10.0, 15.0};
518    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
519    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
520    uint32_t width = 20;
521    uint32_t height = 40;
522    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
523    EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap));
524    EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap));
525
526    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
527    OH_Drawing_CanvasBind(cCanvas, cBitmap);
528    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
529
530    EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography) != 0.0, true);
531    EXPECT_EQ(OH_Drawing_TypographyGetLongestLine(typography) != 0.0, true);
532    EXPECT_EQ(OH_Drawing_TypographyGetMinIntrinsicWidth(typography) <=
533        OH_Drawing_TypographyGetMaxIntrinsicWidth(typography), true);
534    EXPECT_EQ(OH_Drawing_TypographyGetAlphabeticBaseline(typography) != 0.0, true);
535    EXPECT_EQ(OH_Drawing_TypographyGetIdeographicBaseline(typography) != 0.0, true);
536    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
537    OH_Drawing_DestroyTypography(typography);
538    OH_Drawing_DestroyTypographyHandler(handler);
539}
540
541/*
542 * @tc.name: OH_Drawing_TypographyTest017
543 * @tc.desc: test for break strategy
544 * @tc.type: FUNC
545 */
546HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest017, TestSize.Level1)
547{
548    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
549    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_GREEDY);
550#ifndef USE_GRAPHIC_TEXT_GINE
551    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy_, BreakStrategy::BreakStrategyGreedy);
552#else
553    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy, BreakStrategy::GREEDY);
554#endif
555    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_HIGH_QUALITY);
556#ifndef USE_GRAPHIC_TEXT_GINE
557    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy_, BreakStrategy::BreakStrategyHighQuality);
558#else
559    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy, BreakStrategy::HIGH_QUALITY);
560#endif
561    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_BALANCED);
562#ifndef USE_GRAPHIC_TEXT_GINE
563    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy_, BreakStrategy::BreakStrategyBalanced);
564#else
565    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy, BreakStrategy::BALANCED);
566#endif
567    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, -1);
568#ifndef USE_GRAPHIC_TEXT_GINE
569    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy_, BreakStrategy::BreakStrategyGreedy);
570#else
571    EXPECT_EQ(ConvertToOriginalText(typoStyle)->breakStrategy, BreakStrategy::GREEDY);
572#endif
573}
574
575/*
576 * @tc.name: OH_Drawing_TypographyTest018
577 * @tc.desc: test for word break type
578 * @tc.type: FUNC
579 */
580HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest018, TestSize.Level1)
581{
582    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
583    OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_NORMAL);
584#ifndef USE_GRAPHIC_TEXT_GINE
585    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType_, WordBreakType::WordBreakTypeNormal);
586#else
587    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType, WordBreakType::NORMAL);
588#endif
589    OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
590#ifndef USE_GRAPHIC_TEXT_GINE
591    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType_, WordBreakType::WordBreakTypeBreakAll);
592#else
593    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType, WordBreakType::BREAK_ALL);
594#endif
595    OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_WORD);
596#ifndef USE_GRAPHIC_TEXT_GINE
597    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType_, WordBreakType::WordBreakTypeBreakWord);
598#else
599    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType, WordBreakType::BREAK_WORD);
600#endif
601    OH_Drawing_SetTypographyTextWordBreakType(typoStyle, -1);
602#ifndef USE_GRAPHIC_TEXT_GINE
603    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType_, WordBreakType::WordBreakTypeBreakWord);
604#else
605    EXPECT_EQ(ConvertToOriginalText(typoStyle)->wordBreakType, WordBreakType::BREAK_WORD);
606#endif
607}
608
609/*
610 * @tc.name: OH_Drawing_TypographyTest019
611 * @tc.desc: test for ellipsis modal
612 * @tc.type: FUNC
613 */
614HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest019, TestSize.Level1)
615{
616    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
617    OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_HEAD);
618#ifndef USE_GRAPHIC_TEXT_GINE
619    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal_, EllipsisModal::HEAD);
620#else
621    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::HEAD);
622#endif
623    OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_MIDDLE);
624#ifndef USE_GRAPHIC_TEXT_GINE
625    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal_, EllipsisModal::MIDDLE);
626#else
627    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::MIDDLE);
628#endif
629    OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_TAIL);
630#ifndef USE_GRAPHIC_TEXT_GINE
631    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal_, EllipsisModal::TAIL);
632#else
633    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::TAIL);
634#endif
635    OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, -1);
636#ifndef USE_GRAPHIC_TEXT_GINE
637    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal_, EllipsisModal::TAIL);
638#else
639    EXPECT_EQ(ConvertToOriginalText(typoStyle)->ellipsisModal, EllipsisModal::TAIL);
640#endif
641}
642
643/*
644 * @tc.name: OH_Drawing_TypographyTest020
645 * @tc.desc: test for decoration style
646 * @tc.type: FUNC
647 */
648HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest020, TestSize.Level1)
649{
650    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
651    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_SOLID);
652#ifndef USE_GRAPHIC_TEXT_GINE
653    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::SOLID);
654#else
655    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::SOLID);
656#endif
657    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DOUBLE);
658#ifndef USE_GRAPHIC_TEXT_GINE
659    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::DOUBLE);
660#else
661    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DOUBLE);
662#endif
663    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DOTTED);
664#ifndef USE_GRAPHIC_TEXT_GINE
665    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::DOTTED);
666#else
667    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DOTTED);
668#endif
669    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_DASHED);
670#ifndef USE_GRAPHIC_TEXT_GINE
671    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::DASHED);
672#else
673    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::DASHED);
674#endif
675    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_WAVY);
676#ifndef USE_GRAPHIC_TEXT_GINE
677    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::WAVY);
678#else
679    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::WAVY);
680#endif
681    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, -1);
682#ifndef USE_GRAPHIC_TEXT_GINE
683    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle_, TextDecorationStyle::SOLID);
684#else
685    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationStyle, TextDecorationStyle::SOLID);
686#endif
687}
688
689/*
690 * @tc.name: OH_Drawing_TypographyTest021
691 * @tc.desc: test for decoration thickness scale
692 * @tc.type: FUNC
693 */
694HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest021, TestSize.Level1)
695{
696    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
697    OH_Drawing_SetTextStyleDecorationThicknessScale(txtStyle, 10);
698#ifndef USE_GRAPHIC_TEXT_GINE
699    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessMultiplier_, 10);
700#else
701    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessScale, 10);
702#endif
703    OH_Drawing_SetTextStyleDecorationThicknessScale(txtStyle, 20);
704#ifndef USE_GRAPHIC_TEXT_GINE
705    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessMultiplier_, 20);
706#else
707    EXPECT_EQ(ConvertToOriginalText(txtStyle)->decorationThicknessScale, 20);
708#endif
709}
710
711/*
712 * @tc.name: OH_Drawing_TypographyTest022
713 * @tc.desc: test for letter spacing
714 * @tc.type: FUNC
715 */
716HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest022, TestSize.Level1)
717{
718    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
719    OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 10);
720#ifndef USE_GRAPHIC_TEXT_GINE
721    EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing_, 10);
722#else
723    EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing, 10);
724#endif
725    OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 20);
726#ifndef USE_GRAPHIC_TEXT_GINE
727    EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing_, 20);
728#else
729    EXPECT_EQ(ConvertToOriginalText(txtStyle)->letterSpacing, 20);
730#endif
731}
732
733/*
734 * @tc.name: OH_Drawing_TypographyTest023
735 * @tc.desc: test for word spacing
736 * @tc.type: FUNC
737 */
738HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest023, TestSize.Level1)
739{
740    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
741    OH_Drawing_SetTextStyleWordSpacing(txtStyle, 10);
742#ifndef USE_GRAPHIC_TEXT_GINE
743    EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing_, 10);
744#else
745    EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing, 10);
746#endif
747    OH_Drawing_SetTextStyleWordSpacing(txtStyle, 20);
748#ifndef USE_GRAPHIC_TEXT_GINE
749    EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing_, 20);
750#else
751    EXPECT_EQ(ConvertToOriginalText(txtStyle)->wordSpacing, 20);
752#endif
753}
754
755/*
756 * @tc.name: OH_Drawing_TypographyTest024
757 * @tc.desc: test for ellipsis modal
758 * @tc.type: FUNC
759 */
760HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest024, TestSize.Level1)
761{
762    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
763    OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_HEAD);
764#ifndef USE_GRAPHIC_TEXT_GINE
765    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal_, EllipsisModal::HEAD);
766#else
767    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::HEAD);
768#endif
769    OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_MIDDLE);
770#ifndef USE_GRAPHIC_TEXT_GINE
771    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal_, EllipsisModal::MIDDLE);
772#else
773    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::MIDDLE);
774#endif
775    OH_Drawing_SetTextStyleEllipsisModal(txtStyle, ELLIPSIS_MODAL_TAIL);
776#ifndef USE_GRAPHIC_TEXT_GINE
777    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal_, EllipsisModal::TAIL);
778#else
779    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::TAIL);
780#endif
781    OH_Drawing_SetTextStyleEllipsisModal(txtStyle, -1);
782#ifndef USE_GRAPHIC_TEXT_GINE
783    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal_, EllipsisModal::TAIL);
784#else
785    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsisModal, EllipsisModal::TAIL);
786#endif
787}
788
789/*
790 * @tc.name: OH_Drawing_TypographyTest025
791 * @tc.desc: test for set ellipsis
792 * @tc.type: FUNC
793 */
794HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest025, TestSize.Level1)
795{
796    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
797    OH_Drawing_SetTextStyleEllipsis(txtStyle, "...");
798#ifndef USE_GRAPHIC_TEXT_GINE
799    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsis_, u"...");
800#else
801    EXPECT_EQ(ConvertToOriginalText(txtStyle)->ellipsis, u"...");
802#endif
803}
804
805/*
806 * @tc.name: OH_Drawing_TypographyTest026
807 * @tc.desc: test for typography and txtStyle
808 * @tc.type: FUNC
809 */
810HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest026, TestSize.Level1)
811{
812    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
813    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
814    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
815        OH_Drawing_CreateFontCollection());
816    EXPECT_TRUE(handler != nullptr);
817    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
818    double fontSize = 30;
819    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
820    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
821    bool halfLeading = true;
822    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
823    const char* fontFamilies[] = {"Roboto"};
824    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
825    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
826    const char* text = "OpenHarmony\n";
827    OH_Drawing_TypographyHandlerAddText(handler, text);
828    OH_Drawing_PlaceholderSpan placeholderSpan = {20, 40,
829        ALIGNMENT_OFFSET_AT_BASELINE, TEXT_BASELINE_ALPHABETIC, 10};
830    OH_Drawing_TypographyHandlerAddPlaceholder(handler, &placeholderSpan);
831    OH_Drawing_TypographyHandlerPopTextStyle(handler);
832    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
833    double maxWidth = 800.0;
834    OH_Drawing_TypographyLayout(typography, maxWidth);
835    double position[2] = {10.0, 15.0};
836    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
837    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
838    uint32_t width = 20;
839    uint32_t height = 40;
840    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
841    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
842    OH_Drawing_CanvasBind(cCanvas, cBitmap);
843    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
844    EXPECT_EQ(OH_Drawing_TypographyDidExceedMaxLines(typography) != true, true);
845    OH_Drawing_RectHeightStyle heightStyle = RECT_HEIGHT_STYLE_TIGHT;
846    OH_Drawing_RectWidthStyle widthStyle = RECT_WIDTH_STYLE_TIGHT;
847    EXPECT_EQ(OH_Drawing_TypographyGetRectsForRange(typography, 1, 2, heightStyle, widthStyle) != nullptr, true);
848    EXPECT_EQ(OH_Drawing_TypographyGetRectsForPlaceholders(typography) != nullptr, true);
849    EXPECT_EQ(OH_Drawing_TypographyGetGlyphPositionAtCoordinate(typography, 1, 0) != nullptr, true);
850    EXPECT_EQ(OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 1, 0) != nullptr, true);
851    EXPECT_EQ(OH_Drawing_TypographyGetWordBoundary(typography, 1) != nullptr, true);
852    EXPECT_EQ(OH_Drawing_TypographyGetLineTextRange(typography, 1, true) != nullptr, true);
853    EXPECT_EQ(OH_Drawing_TypographyGetLineCount(typography) != 0, true);
854    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
855    OH_Drawing_DestroyTypography(typography);
856    OH_Drawing_DestroyTypographyHandler(handler);
857}
858
859/*
860 * @tc.name: OH_Drawing_TypographyTest027
861 * @tc.desc: test for getting line info for text typography
862 * @tc.type: FUNC
863 */
864HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest027, TestSize.Level1)
865{
866    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
867    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
868    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
869        OH_Drawing_CreateFontCollection());
870    EXPECT_TRUE(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_EQ(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, nullptr), false);
901    EXPECT_EQ(OH_Drawing_TypographyGetLineInfo(typography, -1, oneLine, includeWhitespace, &lineMetrics), false);
902    EXPECT_EQ(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, &lineMetrics), true);
903    OH_Drawing_DestroyTypography(typography);
904    OH_Drawing_DestroyTypographyHandler(handler);
905}
906
907/*
908 * @tc.name: OH_Drawing_TypographyTest028
909 * @tc.desc: test for getting line info for text typography
910 * @tc.type: FUNC
911 */
912HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest028, TestSize.Level1)
913{
914    OH_Drawing_TextShadow* textShadow = OH_Drawing_CreateTextShadow();
915    EXPECT_EQ(textShadow == nullptr, false);
916    OH_Drawing_DestroyTextShadow(textShadow);
917    OH_Drawing_DestroyTextShadow(nullptr);
918}
919
920/*
921 * @tc.name: OH_Drawing_TypographyTest029
922 * @tc.desc: test for font weight of text typography
923 * @tc.type: FUNC
924 */
925HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest029, TestSize.Level1)
926{
927    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
928    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_100);
929#ifndef USE_GRAPHIC_TEXT_GINE
930    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W100);
931#else
932    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W100);
933#endif
934    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_200);
935#ifndef USE_GRAPHIC_TEXT_GINE
936    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W200);
937#else
938    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W200);
939#endif
940    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_300);
941#ifndef USE_GRAPHIC_TEXT_GINE
942    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W300);
943#else
944    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W300);
945#endif
946    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_400);
947#ifndef USE_GRAPHIC_TEXT_GINE
948    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W400);
949#else
950    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W400);
951#endif
952}
953
954/*
955 * @tc.name: OH_Drawing_TypographyTest030
956 * @tc.desc: test for font style of text typography
957 * @tc.type: FUNC
958 */
959HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest030, TestSize.Level1)
960{
961    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
962    OH_Drawing_SetTypographyTextFontStyle(typoStyle, FONT_STYLE_NORMAL);
963#ifndef USE_GRAPHIC_TEXT_GINE
964    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle_, FontStyle::NORMAL);
965#else
966    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::NORMAL);
967#endif
968    OH_Drawing_SetTypographyTextFontStyle(typoStyle, FONT_STYLE_ITALIC);
969#ifndef USE_GRAPHIC_TEXT_GINE
970    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle_, FontStyle::ITALIC);
971#else
972    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::ITALIC);
973#endif
974    OH_Drawing_SetTypographyTextFontStyle(typoStyle, -1);
975#ifndef USE_GRAPHIC_TEXT_GINE
976    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle_, FontStyle::NORMAL);
977#else
978    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontStyle, FontStyle::NORMAL);
979#endif
980}
981
982/*
983 * @tc.name: OH_Drawing_TypographyTest031
984 * @tc.desc: test for font family of text typography
985 * @tc.type: FUNC
986 */
987HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest031, TestSize.Level1)
988{
989    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
990    OH_Drawing_SetTypographyTextFontFamily(typoStyle, "monospace");
991#ifndef USE_GRAPHIC_TEXT_GINE
992    EXPECT_EQ(ConvertToOriginalText(typoStyle)-> fontFamily_, "monospace");
993#else
994    EXPECT_EQ(ConvertToOriginalText(typoStyle)-> fontFamily, "monospace");
995#endif
996}
997
998/*
999 * @tc.name: OH_Drawing_TypographyTest032
1000 * @tc.desc: test for font size of text typography
1001 * @tc.type: FUNC
1002 */
1003HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest032, TestSize.Level1)
1004{
1005    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1006    OH_Drawing_SetTypographyTextFontSize(typoStyle, 80);
1007#ifndef USE_GRAPHIC_TEXT_GINE
1008    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize_, 80);
1009#else
1010    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize, 80);
1011#endif
1012    OH_Drawing_SetTypographyTextFontSize(typoStyle, 40);
1013#ifndef USE_GRAPHIC_TEXT_GINE
1014    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize_, 40);
1015#else
1016    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontSize, 40);
1017#endif
1018}
1019
1020/*
1021 * @tc.name: OH_Drawing_TypographyTest033
1022 * @tc.desc: test for font height of text typography
1023 * @tc.type: FUNC
1024 */
1025HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest033, TestSize.Level1)
1026{
1027    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1028    OH_Drawing_SetTypographyTextFontHeight(typoStyle, 0.0);
1029#ifndef USE_GRAPHIC_TEXT_GINE
1030    EXPECT_EQ(ConvertToOriginalText(typoStyle)->height_, 0.0);
1031#else
1032    EXPECT_EQ(ConvertToOriginalText(typoStyle)->heightScale, 0.0);
1033#endif
1034}
1035
1036/*
1037 * @tc.name: OH_Drawing_TypographyTest034
1038 * @tc.desc: test for font weight of line style for text typography
1039 * @tc.type: FUNC
1040 */
1041HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest034, TestSize.Level1)
1042{
1043    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1044    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_100);
1045#ifndef USE_GRAPHIC_TEXT_GINE
1046    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W100);
1047#else
1048    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W100);
1049#endif
1050    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_200);
1051#ifndef USE_GRAPHIC_TEXT_GINE
1052    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W200);
1053#else
1054    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W200);
1055#endif
1056    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_300);
1057#ifndef USE_GRAPHIC_TEXT_GINE
1058    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W300);
1059#else
1060    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W300);
1061#endif
1062    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_400);
1063#ifndef USE_GRAPHIC_TEXT_GINE
1064    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W400);
1065#else
1066    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W400);
1067#endif
1068    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_500);
1069#ifndef USE_GRAPHIC_TEXT_GINE
1070    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W500);
1071#else
1072    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W500);
1073#endif
1074}
1075
1076/*
1077 * @tc.name: OH_Drawing_TypographyTest035
1078 * @tc.desc: test for font style of line style for text typography
1079 * @tc.type: FUNC
1080 */
1081HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest035, TestSize.Level1)
1082{
1083    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1084    OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, FONT_STYLE_NORMAL);
1085#ifndef USE_GRAPHIC_TEXT_GINE
1086    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle_, FontStyle::NORMAL);
1087#else
1088    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::NORMAL);
1089#endif
1090    OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, FONT_STYLE_ITALIC);
1091#ifndef USE_GRAPHIC_TEXT_GINE
1092    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle_, FontStyle::ITALIC);
1093#else
1094    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::ITALIC);
1095#endif
1096    OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, -1);
1097#ifndef USE_GRAPHIC_TEXT_GINE
1098    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle_, FontStyle::NORMAL);
1099#else
1100    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontStyle, FontStyle::NORMAL);
1101#endif
1102}
1103
1104/*
1105 * @tc.name: OH_Drawing_TypographyTest036
1106 * @tc.desc: test for font families of line style for text typography
1107 * @tc.type: FUNC
1108 */
1109HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest036, TestSize.Level1)
1110{
1111    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1112    const char* fontFamilies[] = {"Roboto"};
1113    OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle, 1, fontFamilies);
1114    std::vector<std::string> fontFamiliesResult = {"Roboto"};
1115#ifndef USE_GRAPHIC_TEXT_GINE
1116    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontFamilies_, fontFamiliesResult);
1117#else
1118    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontFamilies, fontFamiliesResult);
1119#endif
1120}
1121
1122/*
1123 * @tc.name: OH_Drawing_TypographyTest037
1124 * @tc.desc: test for font size of line style for text typography
1125 * @tc.type: FUNC
1126 */
1127HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest037, TestSize.Level1)
1128{
1129    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1130    OH_Drawing_SetTypographyTextLineStyleFontSize(typoStyle, 80);
1131#ifndef USE_GRAPHIC_TEXT_GINE
1132    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontSize_, 80);
1133#else
1134    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontSize, 80);
1135#endif
1136    OH_Drawing_SetTypographyTextLineStyleFontSize(typoStyle, 40);
1137#ifndef USE_GRAPHIC_TEXT_GINE
1138    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontSize_, 40);
1139#else
1140    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontSize, 40);
1141#endif
1142}
1143
1144/*
1145 * @tc.name: OH_Drawing_TypographyTest038
1146 * @tc.desc: test for font height of line style for text typography
1147 * @tc.type: FUNC
1148 */
1149HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest038, TestSize.Level1)
1150{
1151    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1152    OH_Drawing_SetTypographyTextLineStyleFontHeight(typoStyle, 0.0);
1153#ifndef USE_GRAPHIC_TEXT_GINE
1154    EXPECT_EQ(ConvertToOriginalText(typoStyle)->linestyleHeight_, 0.0);
1155#else
1156    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleHeightScale, 0.0);
1157#endif
1158}
1159
1160/*
1161 * @tc.name: OH_Drawing_TypographyTest039
1162 * @tc.desc: test for spacing scale of line style for text typography
1163 * @tc.type: FUNC
1164 */
1165HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest039, TestSize.Level1)
1166{
1167    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1168    OH_Drawing_SetTypographyTextLineStyleSpacingScale(typoStyle, 1.0);
1169#ifndef USE_GRAPHIC_TEXT_GINE
1170    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleSpacingScale_, 1.0);
1171#else
1172    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleSpacingScale, 1.0);
1173#endif
1174    OH_Drawing_SetTypographyTextLineStyleSpacingScale(typoStyle, 2.0);
1175#ifndef USE_GRAPHIC_TEXT_GINE
1176    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleSpacingScale_, 2.0);
1177#else
1178    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleSpacingScale, 2.0);
1179#endif
1180}
1181
1182/*
1183 * @tc.name: OH_Drawing_TypographyTest040
1184 * @tc.desc: test for line metrics for text typography
1185 * @tc.type: FUNC
1186 */
1187HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest040, TestSize.Level1)
1188{
1189    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1190    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1191    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1192        OH_Drawing_CreateFontCollection());
1193    EXPECT_TRUE(handler != nullptr);
1194    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1195    double fontSize = 30;
1196    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1197    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1198    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
1199    const char* fontFamilies[] = {"Roboto"};
1200    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1201    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1202    const char* text = "OpenHarmony\n";
1203    OH_Drawing_TypographyHandlerAddText(handler, text);
1204    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1205    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1206    double maxWidth = 800.0;
1207    OH_Drawing_TypographyLayout(typography, maxWidth);
1208    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
1209    double position[2] = {10.0, 15.0};
1210    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1211    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1212    uint32_t width = 20;
1213    uint32_t height = 40;
1214    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1215    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1216    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1217    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1218    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1219    OH_Drawing_FontDescriptor *descriptor = OH_Drawing_CreateFontDescriptor();
1220    OH_Drawing_FontParser* parser = OH_Drawing_CreateFontParser();
1221
1222    static const std::string FILE_NAME = "/system/fonts/visibility_list.json";
1223    std::ifstream fileStream(FILE_NAME.c_str());
1224    if (fileStream.is_open()) {
1225        size_t fontNum;
1226        char** list = OH_Drawing_FontParserGetSystemFontList(parser, &fontNum);
1227        EXPECT_EQ(list != nullptr, true);
1228        const char *name = "FZHeiT-SC Bold";
1229        EXPECT_EQ(OH_Drawing_FontParserGetFontByName(parser, name) != nullptr, true);
1230        OH_Drawing_DestroySystemFontList(list, fontNum);
1231    }
1232    OH_Drawing_DestroyFontParser(parser);
1233    OH_Drawing_DestroyFontDescriptor(descriptor);
1234    OH_Drawing_LineMetrics* vectorMetrics = OH_Drawing_TypographyGetLineMetrics(typography);
1235    EXPECT_EQ(vectorMetrics != nullptr, true);
1236    EXPECT_EQ(OH_Drawing_LineMetricsGetSize(vectorMetrics) != 0, true);
1237    OH_Drawing_DestroyLineMetrics(vectorMetrics);
1238    OH_Drawing_LineMetrics* metrics = new OH_Drawing_LineMetrics();
1239    EXPECT_EQ(OH_Drawing_TypographyGetLineMetricsAt(typography, 0, metrics), true);
1240    OH_Drawing_DestroyTypography(typography);
1241    OH_Drawing_DestroyTypographyHandler(handler);
1242}
1243
1244/*
1245 * @tc.name: OH_Drawing_TypographyTest041
1246 * @tc.desc: test for font weight of line style for text typography
1247 * @tc.type: FUNC
1248 */
1249HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest041, TestSize.Level1)
1250{
1251    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1252    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_600);
1253#ifndef USE_GRAPHIC_TEXT_GINE
1254    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W600);
1255#else
1256    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W600);
1257#endif
1258    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_700);
1259#ifndef USE_GRAPHIC_TEXT_GINE
1260    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W700);
1261#else
1262    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W700);
1263#endif
1264    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_800);
1265#ifndef USE_GRAPHIC_TEXT_GINE
1266    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W800);
1267#else
1268    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W800);
1269#endif
1270    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, FONT_WEIGHT_900);
1271#ifndef USE_GRAPHIC_TEXT_GINE
1272    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight_, FontWeight::W900);
1273#else
1274    EXPECT_EQ(ConvertToOriginalText(typoStyle)->lineStyleFontWeight, FontWeight::W900);
1275#endif
1276}
1277
1278/*
1279 * @tc.name: OH_Drawing_TypographyTest042
1280 * @tc.desc: test for text shadow for textstyle
1281 * @tc.type: FUNC
1282 */
1283HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest042, TestSize.Level1)
1284{
1285    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1286    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1287    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1288        OH_Drawing_CreateFontCollection());
1289    EXPECT_TRUE(handler != nullptr);
1290    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1291    double fontSize = 30;
1292    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1293    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1294    bool halfLeading = true;
1295    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1296    const char* fontFamilies[] = {"Roboto"};
1297    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1298    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1299    const char* text = "OpenHarmony\n";
1300    OH_Drawing_TypographyHandlerAddText(handler, text);
1301    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1302    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1303    double maxWidth = 800.0;
1304    OH_Drawing_TypographyLayout(typography, maxWidth);
1305    double position[2] = {10.0, 15.0};
1306    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1307    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1308    uint32_t width = 20;
1309    uint32_t height = 40;
1310    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1311    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1312    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1313    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1314    EXPECT_EQ(OH_Drawing_TextStyleGetShadows(txtStyle) != nullptr, true);
1315    OH_Drawing_TextStyleClearShadows(txtStyle);
1316    OH_Drawing_TextShadow* textshadows = OH_Drawing_TextStyleGetShadows(txtStyle);
1317    OH_Drawing_DestroyTextShadows(textshadows);
1318    OH_Drawing_DestroyTextShadows(nullptr);
1319    OH_Drawing_TextStyleAddShadow(txtStyle, nullptr);
1320    OH_Drawing_TextStyleAddShadow(txtStyle, OH_Drawing_CreateTextShadow());
1321    EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 0) != nullptr, true);
1322    EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 10000000) == nullptr, true);
1323    EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(nullptr, 0) == nullptr, true);
1324    EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyle), 1);
1325    EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(nullptr), 0);
1326    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1327    OH_Drawing_DestroyTypography(typography);
1328    OH_Drawing_DestroyTypographyHandler(handler);
1329}
1330
1331/*
1332 * @tc.name: OH_Drawing_TypographyTest043
1333 * @tc.desc: test for effectiveAlignment, isLineUnlimited, isEllipsized for text typography
1334 * @tc.type: FUNC
1335 */
1336HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest043, TestSize.Level1)
1337{
1338    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1339    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1340    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1341        OH_Drawing_CreateFontCollection());
1342    EXPECT_TRUE(handler != nullptr);
1343    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1344    double fontSize = 30;
1345    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1346    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1347    bool halfLeading = true;
1348    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1349    const char* fontFamilies[] = {"Roboto"};
1350    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1351    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1352    const char* text = "OpenHarmony\n";
1353    OH_Drawing_TypographyHandlerAddText(handler, text);
1354    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1355    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1356    double maxWidth = 800.0;
1357    OH_Drawing_TypographyLayout(typography, maxWidth);
1358    double position[2] = {10.0, 15.0};
1359    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1360    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1361    uint32_t width = 20;
1362    uint32_t height = 40;
1363    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1364    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1365    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1366    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1367    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1368    OH_Drawing_Font_Metrics fontmetrics;
1369    EXPECT_EQ(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics), true);
1370    EXPECT_EQ(OH_Drawing_TextStyleGetFontMetrics(nullptr, txtStyle, &fontmetrics), false);
1371    OH_Drawing_DisableFontCollectionFallback(OH_Drawing_CreateFontCollection());
1372    OH_Drawing_DisableFontCollectionFallback(nullptr);
1373    OH_Drawing_DisableFontCollectionSystemFont(OH_Drawing_CreateFontCollection());
1374    OH_Drawing_SetTypographyTextEllipsis(typoStyle, text);
1375    OH_Drawing_SetTypographyTextLocale(typoStyle, text);
1376    OH_Drawing_SetTypographyTextSplitRatio(typoStyle, fontSize);
1377    OH_Drawing_TypographyGetTextStyle(typoStyle);
1378    EXPECT_EQ(OH_Drawing_TypographyGetEffectiveAlignment(typoStyle) >= 0, true);
1379    EXPECT_EQ(OH_Drawing_TypographyIsLineUnlimited(typoStyle) != 0, true);
1380    EXPECT_EQ(OH_Drawing_TypographyIsEllipsized(typoStyle) != 0, true);
1381    OH_Drawing_SetTypographyTextStyle(typoStyle, txtStyle);
1382    OH_Drawing_DestroyTypography(typography);
1383    OH_Drawing_DestroyTypographyHandler(handler);
1384}
1385
1386/*
1387 * @tc.name: OH_Drawing_TypographyTest044
1388 * @tc.desc: test for foreground brush for textstyle
1389 * @tc.type: FUNC
1390 */
1391HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest044, TestSize.Level1)
1392{
1393    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1394    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1395    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1396        OH_Drawing_CreateFontCollection());
1397    EXPECT_TRUE(handler != nullptr);
1398    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1399    double fontSize = 30;
1400    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1401    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1402    bool halfLeading = true;
1403    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1404    const char* fontFamilies[] = {"Roboto"};
1405    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1406    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1407    const char* text = "OpenHarmony\n";
1408    OH_Drawing_TypographyHandlerAddText(handler, text);
1409    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1410    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1411    double maxWidth = 800.0;
1412    OH_Drawing_TypographyLayout(typography, maxWidth);
1413    double position[2] = {10.0, 15.0};
1414    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1415    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1416    uint32_t width = 20;
1417    uint32_t height = 40;
1418    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1419    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1420    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1421    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1422    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1423    OH_Drawing_Brush *foregroundBrush = OH_Drawing_BrushCreate();
1424    uint8_t alpha = 128;
1425    OH_Drawing_BrushSetAlpha(foregroundBrush, alpha);
1426    OH_Drawing_SetTextStyleForegroundBrush(txtStyle, nullptr);
1427    OH_Drawing_SetTextStyleForegroundBrush(txtStyle, foregroundBrush);
1428    OH_Drawing_Brush *resForegroundBrush = OH_Drawing_BrushCreate();
1429    OH_Drawing_TextStyleGetForegroundBrush(txtStyle, nullptr);
1430    OH_Drawing_TextStyleGetForegroundBrush(txtStyle, resForegroundBrush);
1431    EXPECT_EQ(OH_Drawing_BrushGetAlpha(resForegroundBrush), alpha);
1432    OH_Drawing_BrushDestroy(resForegroundBrush);
1433    OH_Drawing_BrushDestroy(foregroundBrush);
1434    OH_Drawing_DestroyTypography(typography);
1435    OH_Drawing_DestroyTypographyHandler(handler);
1436}
1437
1438/*
1439 * @tc.name: OH_Drawing_TypographyTest045
1440 * @tc.desc: test for background brush for textstyle
1441 * @tc.type: FUNC
1442 */
1443HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest045, TestSize.Level1)
1444{
1445    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1446    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1447    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1448        OH_Drawing_CreateFontCollection());
1449    EXPECT_TRUE(handler != nullptr);
1450    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1451    double fontSize = 30;
1452    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1453    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1454    bool halfLeading = true;
1455    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1456    const char* fontFamilies[] = {"Roboto"};
1457    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1458    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1459    const char* text = "OpenHarmony\n";
1460    OH_Drawing_TypographyHandlerAddText(handler, text);
1461    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1462    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1463    double maxWidth = 800.0;
1464    OH_Drawing_TypographyLayout(typography, maxWidth);
1465    double position[2] = {10.0, 15.0};
1466    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1467    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1468    uint32_t width = 20;
1469    uint32_t height = 40;
1470    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1471    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1472    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1473    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1474    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1475    OH_Drawing_Brush *backgroundBrush = OH_Drawing_BrushCreate();
1476    uint8_t backgroundAlpha = 64;
1477    OH_Drawing_BrushSetAlpha(backgroundBrush, backgroundAlpha);
1478    OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, nullptr);
1479    OH_Drawing_SetTextStyleBackgroundBrush(txtStyle, backgroundBrush);
1480    OH_Drawing_Brush *resBackgroundBrush = OH_Drawing_BrushCreate();
1481    OH_Drawing_TextStyleGetBackgroundBrush(txtStyle, nullptr);
1482    OH_Drawing_TextStyleGetBackgroundBrush(txtStyle, resBackgroundBrush);
1483    EXPECT_EQ(OH_Drawing_BrushGetAlpha(resBackgroundBrush), backgroundAlpha);
1484    OH_Drawing_BrushDestroy(resBackgroundBrush);
1485    OH_Drawing_BrushDestroy(backgroundBrush);
1486    OH_Drawing_DestroyTypography(typography);
1487    OH_Drawing_DestroyTypographyHandler(handler);
1488}
1489
1490/*
1491 * @tc.name: OH_Drawing_TypographyTest046
1492 * @tc.desc: test for background pen for textstyle
1493 * @tc.type: FUNC
1494 */
1495HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest046, TestSize.Level1)
1496{
1497    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1498    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1499    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1500        OH_Drawing_CreateFontCollection());
1501    EXPECT_TRUE(handler != nullptr);
1502    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1503    double fontSize = 30;
1504    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1505    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1506    bool halfLeading = true;
1507    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1508    const char* fontFamilies[] = {"Roboto"};
1509    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1510    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1511    const char* text = "OpenHarmony\n";
1512    OH_Drawing_TypographyHandlerAddText(handler, text);
1513    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1514    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1515    double maxWidth = 800.0;
1516    OH_Drawing_TypographyLayout(typography, maxWidth);
1517    double position[2] = {10.0, 15.0};
1518    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1519    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1520    uint32_t width = 20;
1521    uint32_t height = 40;
1522    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1523    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1524    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1525    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1526    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1527    OH_Drawing_Pen *backgroundPen = OH_Drawing_PenCreate();
1528    float backgroundPenWidth = 10;
1529    OH_Drawing_PenSetWidth(backgroundPen, backgroundPenWidth);
1530    OH_Drawing_SetTextStyleBackgroundPen(txtStyle, nullptr);
1531    OH_Drawing_SetTextStyleBackgroundPen(txtStyle, backgroundPen);
1532    OH_Drawing_Pen *resBackgroundPen = OH_Drawing_PenCreate();
1533    OH_Drawing_TextStyleGetBackgroundPen(txtStyle, nullptr);
1534    OH_Drawing_TextStyleGetBackgroundPen(txtStyle, resBackgroundPen);
1535    EXPECT_EQ(OH_Drawing_PenGetWidth(resBackgroundPen), backgroundPenWidth);
1536    OH_Drawing_PenDestroy(resBackgroundPen);
1537    OH_Drawing_PenDestroy(backgroundPen);
1538    OH_Drawing_DestroyTypography(typography);
1539    OH_Drawing_DestroyTypographyHandler(handler);
1540}
1541
1542/*
1543 * @tc.name: OH_Drawing_TypographyTest047
1544 * @tc.desc: test for foreground pen for textstyle
1545 * @tc.type: FUNC
1546 */
1547HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest047, TestSize.Level1)
1548{
1549    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1550    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1551    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1552        OH_Drawing_CreateFontCollection());
1553    EXPECT_TRUE(handler != nullptr);
1554    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
1555    double fontSize = 30;
1556    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
1557    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
1558    bool halfLeading = true;
1559    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1560    const char* fontFamilies[] = {"Roboto"};
1561    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1562    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
1563    const char* text = "OpenHarmony\n";
1564    OH_Drawing_TypographyHandlerAddText(handler, text);
1565    OH_Drawing_TypographyHandlerPopTextStyle(handler);
1566    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1567    double maxWidth = 800.0;
1568    OH_Drawing_TypographyLayout(typography, maxWidth);
1569    double position[2] = {10.0, 15.0};
1570    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
1571    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
1572    uint32_t width = 20;
1573    uint32_t height = 40;
1574    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
1575    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
1576    OH_Drawing_CanvasBind(cCanvas, cBitmap);
1577    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
1578    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
1579    OH_Drawing_Pen *foregroundPen = OH_Drawing_PenCreate();
1580    float foregroundPenWidth = 20;
1581    OH_Drawing_PenSetWidth(foregroundPen, foregroundPenWidth);
1582    OH_Drawing_SetTextStyleForegroundPen(txtStyle, nullptr);
1583    OH_Drawing_SetTextStyleForegroundPen(txtStyle, foregroundPen);
1584    OH_Drawing_Pen *resForegroundPen = OH_Drawing_PenCreate();
1585    OH_Drawing_TextStyleGetForegroundPen(txtStyle, nullptr);
1586    OH_Drawing_TextStyleGetForegroundPen(txtStyle, resForegroundPen);
1587    EXPECT_EQ(OH_Drawing_PenGetWidth(resForegroundPen), foregroundPenWidth);
1588    OH_Drawing_PenDestroy(resForegroundPen);
1589    OH_Drawing_PenDestroy(foregroundPen);
1590    OH_Drawing_DestroyTypography(typography);
1591    OH_Drawing_DestroyTypographyHandler(handler);
1592}
1593
1594/*
1595 * @tc.name: OH_Drawing_TypographyTest048
1596 * @tc.desc: test for font weight for text typography
1597 * @tc.type: FUNC
1598 */
1599HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest048, TestSize.Level1)
1600{
1601    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1602    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_500);
1603#ifndef USE_GRAPHIC_TEXT_GINE
1604    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W500);
1605#else
1606    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W500);
1607#endif
1608    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_600);
1609#ifndef USE_GRAPHIC_TEXT_GINE
1610    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W600);
1611#else
1612    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W600);
1613#endif
1614    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_700);
1615#ifndef USE_GRAPHIC_TEXT_GINE
1616    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W700);
1617#else
1618    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W700);
1619#endif
1620    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_800);
1621#ifndef USE_GRAPHIC_TEXT_GINE
1622    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W800);
1623#else
1624    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W800);
1625#endif
1626    OH_Drawing_SetTypographyTextFontWeight(typoStyle, FONT_WEIGHT_900);
1627#ifndef USE_GRAPHIC_TEXT_GINE
1628    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight_, FontWeight::W900);
1629#else
1630    EXPECT_EQ(ConvertToOriginalText(typoStyle)->fontWeight, FontWeight::W900);
1631#endif
1632}
1633
1634/*
1635 * @tc.name: OH_Drawing_TypographyTest049
1636 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1637 * @tc.type: FUNC
1638 */
1639HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest049, TestSize.Level1)
1640{
1641    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1642    bool halfLeading = true;
1643    OH_Drawing_SetTypographyTextHalfLeading(typoStyle, halfLeading);
1644    OH_Drawing_SetTypographyTextLineStyleHalfLeading(typoStyle, halfLeading);
1645    bool uselineStyle = true;
1646    OH_Drawing_SetTypographyTextUseLineStyle(typoStyle, uselineStyle);
1647    bool linestyleOnly = false;
1648    OH_Drawing_SetTypographyTextLineStyleOnly(typoStyle, linestyleOnly);
1649}
1650
1651
1652/*
1653 * @tc.name: OH_Drawing_TypographyTest050
1654 * @tc.desc: test for getting numbers for textstyle
1655 * @tc.type: FUNC
1656 */
1657HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest050, TestSize.Level1)
1658{
1659    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1660    OH_Drawing_SetTextStyleColor(txtStyle, 1);
1661    EXPECT_EQ(OH_Drawing_TextStyleGetColor(txtStyle), 1);
1662    EXPECT_EQ(OH_Drawing_TextStyleGetColor(nullptr), 0xFFFFFFFF);
1663    OH_Drawing_SetTextStyleDecorationStyle(txtStyle, TEXT_DECORATION_STYLE_SOLID);
1664    EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(txtStyle), 0);
1665    EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(nullptr), TEXT_DECORATION_STYLE_SOLID);
1666    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_100);
1667    EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyle), 0);
1668    EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(nullptr), FONT_WEIGHT_400);
1669    OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
1670    EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyle), 0);
1671    EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(nullptr), FONT_STYLE_NORMAL);
1672    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
1673    EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(txtStyle), 0);
1674    EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(nullptr), TEXT_BASELINE_ALPHABETIC);
1675    const char* fontFamilies[] = {"Roboto"};
1676    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
1677    size_t fontFamiliesNumber;
1678    char** fontFamiliesList = OH_Drawing_TextStyleGetFontFamilies(txtStyle, &fontFamiliesNumber);
1679    EXPECT_EQ(fontFamiliesList != nullptr, true);
1680    EXPECT_EQ(OH_Drawing_TextStyleGetFontFamilies(nullptr, &fontFamiliesNumber) == nullptr, true);
1681    OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, fontFamiliesNumber);
1682    OH_Drawing_SetTextStyleFontSize(txtStyle, 60); // 60 means font size for test
1683    EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(txtStyle), 60);
1684    EXPECT_EQ(OH_Drawing_TextStyleGetFontSize(nullptr), 0.0);
1685    OH_Drawing_SetTextStyleLetterSpacing(txtStyle, 20); // 20 means letter spacing for test
1686    EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(txtStyle), 20);
1687    EXPECT_EQ(OH_Drawing_TextStyleGetLetterSpacing(nullptr), 0.0);
1688    OH_Drawing_SetTextStyleWordSpacing(txtStyle, 80); // 80 means word spacing for test
1689    EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(txtStyle), 80);
1690    EXPECT_EQ(OH_Drawing_TextStyleGetWordSpacing(nullptr), 0.0);
1691    OH_Drawing_SetTextStyleFontHeight(txtStyle, 0.0); // 0.0 means font height for test
1692    EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(txtStyle), 0.0);
1693    EXPECT_EQ(OH_Drawing_TextStyleGetFontHeight(nullptr), 0.0);
1694    bool halfLeading = true;
1695    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
1696    EXPECT_EQ(OH_Drawing_TextStyleGetHalfLeading(txtStyle), true);
1697    EXPECT_EQ(OH_Drawing_TextStyleGetHalfLeading(nullptr), false);
1698    OH_Drawing_SetTextStyleLocale(txtStyle, "en");
1699    EXPECT_EQ(std::strcmp(OH_Drawing_TextStyleGetLocale(txtStyle), "en"), 0);
1700    EXPECT_EQ(OH_Drawing_TextStyleGetLocale(nullptr) == nullptr, true);
1701}
1702
1703/*
1704 * @tc.name: OH_Drawing_TypographyTest051
1705 * @tc.desc: test for getting line info for text typography
1706 * @tc.type: FUNC
1707 */
1708HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest051, TestSize.Level1)
1709{
1710    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
1711    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1712    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
1713        OH_Drawing_CreateFontCollection());
1714    OH_Drawing_RectStyle_Info rectStyleInfo = {1, 1.5, 1.5, 1.5, 1.5}; // 1.5 means corner radius for test
1715    int styleId = 1; // 1 means styleId for test
1716    OH_Drawing_TextStyleSetBackgroundRect(txtStyle, nullptr, styleId);
1717    OH_Drawing_TextStyleSetBackgroundRect(nullptr, &rectStyleInfo, styleId);
1718    OH_Drawing_TextStyleSetBackgroundRect(txtStyle, &rectStyleInfo, styleId);
1719    uint32_t symbol = 2; // 2 means symbol for test
1720    OH_Drawing_TypographyHandlerAddSymbol(handler, symbol);
1721    const char* key1 = "宋体";
1722    int value1 = 1; // 1 for test
1723    OH_Drawing_TextStyleAddFontFeature(nullptr, key1, value1);
1724    OH_Drawing_TextStyleAddFontFeature(txtStyle, nullptr, value1);
1725    OH_Drawing_TextStyleAddFontFeature(txtStyle, key1, value1);
1726    const char* key2 = "斜体";
1727    int value2 = 2; // 2 for test
1728    OH_Drawing_TextStyleAddFontFeature(txtStyle, key2, value2);
1729    const char* key3 = "方体";
1730    int value3 = 3; // 3 for test
1731    OH_Drawing_TextStyleAddFontFeature(txtStyle, key3, value3);
1732    EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 3); // 3 means font feature size for test
1733    EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(nullptr), 0);
1734    OH_Drawing_FontFeature* fontFeaturesArray = OH_Drawing_TextStyleGetFontFeatures(txtStyle);
1735    EXPECT_EQ(fontFeaturesArray != nullptr, true);
1736    EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatures(nullptr) == nullptr, true);
1737    OH_Drawing_TextStyleDestroyFontFeatures(fontFeaturesArray, OH_Drawing_TextStyleGetFontFeatureSize(txtStyle));
1738    OH_Drawing_TextStyleDestroyFontFeatures(nullptr, OH_Drawing_TextStyleGetFontFeatureSize(txtStyle));
1739    OH_Drawing_TextStyleClearFontFeature(txtStyle);
1740    OH_Drawing_TextStyleClearFontFeature(nullptr);
1741    EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 0);
1742    double lineShift = 1.5; // 1.5 means baseline shift for test
1743    OH_Drawing_TextStyleSetBaselineShift(nullptr, lineShift);
1744    EXPECT_EQ(OH_Drawing_TextStyleGetBaselineShift(nullptr), 0.0);
1745    OH_Drawing_TextStyleSetBaselineShift(txtStyle, lineShift);
1746    EXPECT_EQ(OH_Drawing_TextStyleGetBaselineShift(txtStyle), 1.5);
1747}
1748
1749/*
1750 * @tc.name: OH_Drawing_TypographyTest052
1751 * @tc.desc: test for setting the mode of leading over and under text
1752 * @tc.type: FUNC
1753 */
1754HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest052, TestSize.Level1)
1755{
1756    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1757    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_ALL);
1758    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::ALL);
1759    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_FIRST_ASCENT);
1760    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_FIRST_ASCENT);
1761    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_LAST_ASCENT);
1762    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_LAST_ASCENT);
1763    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_ALL);
1764    EXPECT_EQ(ConvertToOriginalText(typoStyle)->textHeightBehavior, TextHeightBehavior::DISABLE_ALL);
1765}
1766
1767/*
1768 * @tc.name: OH_Drawing_TypographyTest053
1769 * @tc.desc: test for getting the mode of leading over and under text
1770 * @tc.type: FUNC
1771 */
1772HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest053, TestSize.Level1)
1773{
1774    EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(nullptr) == TEXT_HEIGHT_ALL, true);
1775    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1776    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_ALL);
1777    EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(typoStyle) == TEXT_HEIGHT_ALL, true);
1778    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_FIRST_ASCENT);
1779    EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(typoStyle) == TEXT_HEIGHT_DISABLE_FIRST_ASCENT, true);
1780    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_LAST_ASCENT);
1781    EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(typoStyle) == TEXT_HEIGHT_DISABLE_LAST_ASCENT, true);
1782    OH_Drawing_TypographyTextSetHeightBehavior(typoStyle, TEXT_HEIGHT_DISABLE_ALL);
1783    EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(typoStyle) == TEXT_HEIGHT_DISABLE_ALL, true);
1784}
1785
1786/*
1787 * @tc.name: OH_Drawing_TypographyTest054
1788 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1789 * @tc.type: FUNC
1790 */
1791HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest054, TestSize.Level1)
1792{
1793    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1794    OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
1795    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);
1796    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1797    OH_Drawing_TypographyMarkDirty(typography);
1798    OH_Drawing_TypographyMarkDirty(nullptr);
1799    OH_Drawing_DestroyTypographyStyle(typoStyle);
1800    OH_Drawing_DestroyFontCollection(fontCollection);
1801    OH_Drawing_DestroyTypographyHandler(handler);
1802    OH_Drawing_DestroyTypography(typography);
1803    typoStyle = nullptr;
1804    fontCollection = nullptr;
1805    handler = nullptr;
1806    typography = nullptr;
1807    EXPECT_TRUE(typoStyle == nullptr);
1808    EXPECT_TRUE(fontCollection == nullptr);
1809    EXPECT_TRUE(handler == nullptr);
1810    EXPECT_TRUE(typography == nullptr);
1811}
1812
1813/*
1814 * @tc.name: OH_Drawing_TypographyTest055
1815 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1816 * @tc.type: FUNC
1817 */
1818HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest055, TestSize.Level1)
1819{
1820    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1821    OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
1822    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);
1823    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1824    int32_t result = OH_Drawing_TypographyGetUnresolvedGlyphsCount(typography);
1825    EXPECT_TRUE(result != 0);
1826    result = OH_Drawing_TypographyGetUnresolvedGlyphsCount(nullptr);
1827    EXPECT_TRUE(result == 0);
1828    OH_Drawing_DestroyTypographyStyle(typoStyle);
1829    OH_Drawing_DestroyFontCollection(fontCollection);
1830    OH_Drawing_DestroyTypographyHandler(handler);
1831    OH_Drawing_DestroyTypography(typography);
1832    typoStyle = nullptr;
1833    fontCollection = nullptr;
1834    handler = nullptr;
1835    typography = nullptr;
1836    EXPECT_TRUE(typoStyle == nullptr);
1837    EXPECT_TRUE(fontCollection == nullptr);
1838    EXPECT_TRUE(handler == nullptr);
1839    EXPECT_TRUE(typography == nullptr);
1840}
1841
1842/*
1843 * @tc.name: OH_Drawing_TypographyTest056
1844 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1845 * @tc.type: FUNC
1846 */
1847HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest056, TestSize.Level1)
1848{
1849    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1850    OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
1851    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, fontCollection);
1852    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
1853    size_t from = 10; // 10 means font size for test
1854    size_t to = 11; // 11 means font size for test
1855    float fontSize = 1.0; // 1.0 means font size for test
1856    OH_Drawing_TypographyUpdateFontSize(typography, from, to, fontSize);
1857    OH_Drawing_TypographyUpdateFontSize(nullptr, from, to, fontSize);
1858    OH_Drawing_DestroyTypographyStyle(typoStyle);
1859    OH_Drawing_DestroyFontCollection(fontCollection);
1860    OH_Drawing_DestroyTypographyHandler(handler);
1861    OH_Drawing_DestroyTypography(typography);
1862    typoStyle = nullptr;
1863    fontCollection = nullptr;
1864    handler = nullptr;
1865    typography = nullptr;
1866    EXPECT_TRUE(typoStyle == nullptr);
1867    EXPECT_TRUE(fontCollection == nullptr);
1868    EXPECT_TRUE(handler == nullptr);
1869    EXPECT_TRUE(typography == nullptr);
1870}
1871
1872/*
1873 * @tc.name: OH_Drawing_TypographyTest057
1874 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1875 * @tc.type: FUNC
1876 */
1877HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest057, TestSize.Level1)
1878{
1879    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1880    bool useLineStyle = true;
1881    OH_Drawing_SetTypographyTextUseLineStyle(typoStyle, useLineStyle);
1882    bool result = OH_Drawing_TypographyTextGetLineStyle(typoStyle);
1883    EXPECT_TRUE(result == true);
1884    result = OH_Drawing_TypographyTextGetLineStyle(nullptr);
1885    EXPECT_TRUE(result == false);
1886    OH_Drawing_DestroyTypographyStyle(typoStyle);
1887    typoStyle = nullptr;
1888    EXPECT_TRUE(typoStyle == nullptr);
1889}
1890
1891/*
1892 * @tc.name: OH_Drawing_TypographyTest058
1893 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1894 * @tc.type: FUNC
1895 */
1896HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest058, TestSize.Level1)
1897{
1898    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1899    int weight = FONT_WEIGHT_100;
1900    OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle, weight);
1901    OH_Drawing_FontWeight result = OH_Drawing_TypographyTextlineStyleGetFontWeight(typoStyle);
1902    EXPECT_TRUE(result == FONT_WEIGHT_100);
1903    result = OH_Drawing_TypographyTextlineStyleGetFontWeight(nullptr);
1904    EXPECT_TRUE(result == FONT_WEIGHT_400);
1905    OH_Drawing_DestroyTypographyStyle(typoStyle);
1906    typoStyle = nullptr;
1907    EXPECT_TRUE(typoStyle == nullptr);
1908}
1909
1910/*
1911 * @tc.name: OH_Drawing_TypographyTest059
1912 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1913 * @tc.type: FUNC
1914 */
1915HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest059, TestSize.Level1)
1916{
1917    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1918    int fontStyle = FONT_STYLE_ITALIC;
1919    OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle, fontStyle);
1920    OH_Drawing_FontStyle result = OH_Drawing_TypographyTextlineStyleGetFontStyle(typoStyle);
1921    EXPECT_TRUE(result == FONT_STYLE_ITALIC);
1922    result = OH_Drawing_TypographyTextlineStyleGetFontStyle(nullptr);
1923    EXPECT_TRUE(result == FONT_STYLE_NORMAL);
1924    OH_Drawing_DestroyTypographyStyle(typoStyle);
1925    typoStyle = nullptr;
1926    EXPECT_TRUE(typoStyle == nullptr);
1927}
1928
1929/*
1930 * @tc.name: OH_Drawing_TypographyTest060
1931 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1932 * @tc.type: FUNC
1933 */
1934HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest060, TestSize.Level1)
1935{
1936    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1937    size_t fontNum = 1; // 1 means font number for test
1938    const char* fontFamilies[] = {"Roboto"};
1939    int fontFamiliesNumber = 1; // 1 means font families number for test
1940    OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle, fontFamiliesNumber, fontFamilies);
1941    char** result = OH_Drawing_TypographyTextlineStyleGetFontFamilies(typoStyle, &fontNum);
1942    EXPECT_TRUE(result != nullptr);
1943    result = OH_Drawing_TypographyTextlineStyleGetFontFamilies(nullptr, &fontNum);
1944    EXPECT_TRUE(result == nullptr);
1945    OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(result, fontNum);
1946    OH_Drawing_DestroyTypographyStyle(typoStyle);
1947    typoStyle = nullptr;
1948    EXPECT_TRUE(typoStyle == nullptr);
1949}
1950
1951/*
1952 * @tc.name: OH_Drawing_TypographyTest061
1953 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1954 * @tc.type: FUNC
1955 */
1956HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest061, TestSize.Level1)
1957{
1958    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1959    double result = OH_Drawing_TypographyTextlineStyleGetFontSize(typoStyle);
1960    // 14.0 Fontsize default value
1961    EXPECT_TRUE(result == 14.0);
1962    result = OH_Drawing_TypographyTextlineStyleGetFontSize(nullptr);
1963    EXPECT_TRUE(result == 0);
1964    OH_Drawing_DestroyTypographyStyle(typoStyle);
1965    typoStyle = nullptr;
1966    EXPECT_TRUE(typoStyle == nullptr);
1967}
1968
1969/*
1970 * @tc.name: OH_Drawing_TypographyTest062
1971 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1972 * @tc.type: FUNC
1973 */
1974HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest062, TestSize.Level1)
1975{
1976    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1977    double result = OH_Drawing_TypographyTextlineStyleGetHeightScale(typoStyle);
1978    EXPECT_TRUE(result == 1.0); // 1.0 means enable the font height for line styles in text layout only
1979    result = OH_Drawing_TypographyTextlineStyleGetHeightScale(nullptr);
1980    EXPECT_TRUE(result == 0);
1981    OH_Drawing_DestroyTypographyStyle(typoStyle);
1982    typoStyle = nullptr;
1983    EXPECT_TRUE(typoStyle == nullptr);
1984}
1985
1986/*
1987 * @tc.name: OH_Drawing_TypographyTest063
1988 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
1989 * @tc.type: FUNC
1990 */
1991HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest063, TestSize.Level1)
1992{
1993    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
1994    // 2.0 measn font height for test
1995    double lineStyleFontHeight = 2.0;
1996    OH_Drawing_SetTypographyTextLineStyleFontHeight(typoStyle, lineStyleFontHeight);
1997    bool result = OH_Drawing_TypographyTextlineStyleGetHeightOnly(typoStyle);
1998    EXPECT_TRUE(result == true);
1999    result = OH_Drawing_TypographyTextlineStyleGetHeightOnly(nullptr);
2000    EXPECT_TRUE(result == false);
2001    OH_Drawing_DestroyTypographyStyle(typoStyle);
2002    typoStyle = nullptr;
2003    EXPECT_TRUE(typoStyle == nullptr);
2004}
2005
2006/*
2007 * @tc.name: OH_Drawing_TypographyTest064
2008 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2009 * @tc.type: FUNC
2010 */
2011HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest064, TestSize.Level1)
2012{
2013    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2014    bool lineStyleHalfLeading = true;
2015    OH_Drawing_SetTypographyTextLineStyleHalfLeading(typoStyle, lineStyleHalfLeading);
2016    bool result = OH_Drawing_TypographyTextlineStyleGetHalfLeading(typoStyle);
2017    EXPECT_TRUE(result == true);
2018    result = OH_Drawing_TypographyTextlineStyleGetHalfLeading(nullptr);
2019    EXPECT_TRUE(result == false);
2020    OH_Drawing_DestroyTypographyStyle(typoStyle);
2021    typoStyle = nullptr;
2022    EXPECT_TRUE(typoStyle == nullptr);
2023}
2024
2025/*
2026 * @tc.name: OH_Drawing_TypographyTest065
2027 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2028 * @tc.type: FUNC
2029 */
2030HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest065, TestSize.Level1)
2031{
2032    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2033    double result = OH_Drawing_TypographyTextlineStyleGetSpacingScale(typoStyle);
2034    // -1.0 for test
2035    EXPECT_TRUE(result == -1.0);
2036    result = OH_Drawing_TypographyTextlineStyleGetSpacingScale(nullptr);
2037    EXPECT_TRUE(result == 0);
2038    OH_Drawing_DestroyTypographyStyle(typoStyle);
2039    typoStyle = nullptr;
2040    EXPECT_TRUE(typoStyle == nullptr);
2041}
2042
2043/*
2044 * @tc.name: OH_Drawing_TypographyTest066
2045 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2046 * @tc.type: FUNC
2047 */
2048HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest066, TestSize.Level1)
2049{
2050    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2051    int direction = TEXT_DIRECTION_RTL;
2052    OH_Drawing_SetTypographyTextDirection(typoStyle, direction);
2053    OH_Drawing_TextDirection result = OH_Drawing_TypographyGetTextDirection(typoStyle);
2054    EXPECT_TRUE(result == TEXT_DIRECTION_RTL);
2055    result = OH_Drawing_TypographyGetTextDirection(nullptr);
2056    EXPECT_TRUE(result == TEXT_DIRECTION_LTR);
2057    OH_Drawing_DestroyTypographyStyle(typoStyle);
2058    typoStyle = nullptr;
2059    EXPECT_TRUE(typoStyle == nullptr);
2060}
2061
2062/*
2063 * @tc.name: OH_Drawing_TypographyTest067
2064 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2065 * @tc.type: FUNC
2066 */
2067HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest067, TestSize.Level1)
2068{
2069    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2070    size_t result = OH_Drawing_TypographyGetTextMaxLines(typoStyle);
2071    EXPECT_TRUE(result != 0);
2072    result = OH_Drawing_TypographyGetTextMaxLines(nullptr);
2073    EXPECT_TRUE(result == 0);
2074    OH_Drawing_DestroyTypographyStyle(typoStyle);
2075    typoStyle = nullptr;
2076    EXPECT_TRUE(typoStyle == nullptr);
2077}
2078
2079/*
2080 * @tc.name: OH_Drawing_TypographyTest068
2081 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2082 * @tc.type: FUNC
2083 */
2084HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest068, TestSize.Level1)
2085{
2086    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2087    char* result = OH_Drawing_TypographyGetTextEllipsis(typoStyle);
2088    EXPECT_TRUE(result != nullptr);
2089    result = OH_Drawing_TypographyGetTextEllipsis(nullptr);
2090    EXPECT_TRUE(result == nullptr);
2091    OH_Drawing_TypographyDestroyEllipsis(result);
2092    OH_Drawing_DestroyTypographyStyle(typoStyle);
2093    typoStyle = nullptr;
2094    EXPECT_TRUE(typoStyle == nullptr);
2095}
2096
2097/*
2098 * @tc.name: OH_Drawing_TypographyTest069
2099 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2100 * @tc.type: FUNC
2101 */
2102HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest069, TestSize.Level1)
2103{
2104    OH_Drawing_TypographyStyle* from = OH_Drawing_CreateTypographyStyle();
2105    OH_Drawing_TypographyStyle* to = OH_Drawing_CreateTypographyStyle();
2106    bool result = OH_Drawing_TypographyStyleEquals(from, to);
2107    EXPECT_TRUE(result == true);
2108    result = OH_Drawing_TypographyStyleEquals(nullptr, to);
2109    EXPECT_TRUE(result == false);
2110    result = OH_Drawing_TypographyStyleEquals(from, nullptr);
2111    EXPECT_TRUE(result == false);
2112    OH_Drawing_DestroyTypographyStyle(from);
2113    OH_Drawing_DestroyTypographyStyle(to);
2114    from = nullptr;
2115    to = nullptr;
2116    EXPECT_TRUE(from == nullptr);
2117    EXPECT_TRUE(to == nullptr);
2118}
2119
2120/*
2121 * @tc.name: OH_Drawing_TypographyTest070
2122 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2123 * @tc.type: FUNC
2124 */
2125HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest070, TestSize.Level1)
2126{
2127    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2128    OH_Drawing_SetTypographyTextLineStyleOnly(typoStyle, true);
2129    bool result = OH_Drawing_TypographyTextlineGetStyleOnly(typoStyle);
2130    EXPECT_TRUE(result == true);
2131    result = OH_Drawing_TypographyTextlineGetStyleOnly(nullptr);
2132    EXPECT_TRUE(result == false);
2133    OH_Drawing_DestroyTypographyStyle(typoStyle);
2134    typoStyle = nullptr;
2135    EXPECT_TRUE(typoStyle == nullptr);
2136}
2137
2138/*
2139 * @tc.name: OH_Drawing_TypographyTest071
2140 * @tc.desc: test for halfleading, uselinestyle linestyleonly of text typography
2141 * @tc.type: FUNC
2142 */
2143HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest071, TestSize.Level1)
2144{
2145    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2146    int align = TEXT_ALIGN_RIGHT;
2147    OH_Drawing_SetTypographyTextAlign(typoStyle, align);
2148    OH_Drawing_TextAlign result = OH_Drawing_TypographyGetTextAlign(typoStyle);
2149    EXPECT_TRUE(result == TEXT_ALIGN_RIGHT);
2150    result= OH_Drawing_TypographyGetTextAlign(nullptr);
2151    EXPECT_TRUE(result == TEXT_ALIGN_LEFT);
2152    OH_Drawing_DestroyTypographyStyle(typoStyle);
2153    typoStyle = nullptr;
2154    EXPECT_TRUE(typoStyle == nullptr);
2155}
2156
2157/*
2158 * @tc.name: OH_Drawing_TypographyTest072
2159 * @tc.desc: test for create and releases the memory occupied by system font configuration information
2160 * @tc.type: FUNC
2161 */
2162HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest072, TestSize.Level1)
2163{
2164    OH_Drawing_FontConfigInfoErrorCode code = ERROR_FONT_CONFIG_INFO_UNKNOWN;
2165    OH_Drawing_FontConfigInfo* configJsonInfo = OH_Drawing_GetSystemFontConfigInfo(&code);
2166    if (configJsonInfo != nullptr) {
2167        EXPECT_EQ(code, SUCCESS_FONT_CONFIG_INFO);
2168    } else {
2169        EXPECT_NE(code, SUCCESS_FONT_CONFIG_INFO);
2170    }
2171    OH_Drawing_DestroySystemFontConfigInfo(configJsonInfo);
2172    configJsonInfo = nullptr;
2173}
2174
2175/*
2176 * @tc.name: OH_Drawing_TypographyTest073
2177 * @tc.desc: test for getting all font metrics array from current line
2178 * @tc.type: FUNC
2179 */
2180HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest073, TestSize.Level1)
2181{
2182    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2183    EXPECT_TRUE(typoStyle != nullptr);
2184    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2185    EXPECT_TRUE(txtStyle != nullptr);
2186    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2187        OH_Drawing_CreateFontCollection());
2188    EXPECT_TRUE(handler != nullptr);
2189    size_t charNumber = 0;
2190    const char* text = "OpenHarmony\n";
2191    OH_Drawing_TypographyHandlerAddText(handler, text);
2192    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2193    EXPECT_TRUE(typography != nullptr);
2194    OH_Drawing_Font_Metrics* StartLineFont = OH_Drawing_TypographyGetLineFontMetrics(typography, 1, &charNumber);
2195    EXPECT_TRUE(StartLineFont == nullptr);
2196    OH_Drawing_TypographyDestroyLineFontMetrics(StartLineFont);
2197    OH_Drawing_DestroyTypography(typography);
2198    OH_Drawing_DestroyTypographyHandler(handler);
2199    OH_Drawing_DestroyTypographyStyle(typoStyle);
2200    OH_Drawing_DestroyTextStyle(txtStyle);
2201}
2202
2203/*
2204 * @tc.name: OH_Drawing_TypographyTest074
2205 * @tc.desc: test for getting and setting strut style
2206 * @tc.type: FUNC
2207 */
2208HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest074, TestSize.Level1)
2209{
2210    OH_Drawing_TypographyStyle *typoStyle = OH_Drawing_CreateTypographyStyle();
2211    OH_Drawing_StrutStyle *strutstyle = new OH_Drawing_StrutStyle();
2212    strutstyle->weight = FONT_WEIGHT_400;
2213    strutstyle->style = FONT_STYLE_ITALIC;
2214    // 17.0 For size
2215    strutstyle->size = 17.0;
2216    // 2.0 For heightScale
2217    strutstyle->heightScale = 2;
2218    strutstyle->heightOverride = true;
2219    strutstyle->halfLeading = true;
2220    // 3.0 For leading
2221    strutstyle->leading = 3.0;
2222    strutstyle->forceStrutHeight = true;
2223    // 4 For families size
2224    strutstyle->familiesSize = 4;
2225    strutstyle->families = (char**)malloc(strutstyle->familiesSize*sizeof(char*));
2226    const char *temp[] = {"1", "2", "3", "4"};
2227    for (int i = 0; i < strutstyle->familiesSize; i++) {
2228        // 2 For families member size
2229        strutstyle->families[i] = (char*)malloc(2*sizeof(char));
2230        strcpy_s(strutstyle->families[i], 2, temp[i]);
2231    }
2232    OH_Drawing_SetTypographyStyleTextStrutStyle(typoStyle, strutstyle);
2233    EXPECT_EQ(OH_Drawing_TypographyStyleGetStrutStyle(typoStyle) != nullptr, true);
2234    OH_Drawing_TypographyStyleDestroyStrutStyle(strutstyle);
2235    OH_Drawing_DestroyTypographyStyle(typoStyle);
2236}
2237
2238/*
2239 * @tc.name: OH_Drawing_TypographyTest075
2240 * @tc.desc: test for the two TextStyle objects have matching properties
2241 * @tc.type: FUNC
2242 */
2243HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest075, TestSize.Level1)
2244{
2245    OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2246    OH_Drawing_TextStyle *txtStyleCompare = OH_Drawing_CreateTextStyle();
2247    bool result = OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES);
2248    EXPECT_TRUE(result == true);
2249    OH_Drawing_SetTextStyleLocale(txtStyle, "en");
2250    result = OH_Drawing_TextStyleIsAttributeMatched(txtStyle, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES);
2251    EXPECT_TRUE(result == false);
2252    EXPECT_EQ(OH_Drawing_TextStyleIsAttributeMatched(nullptr, txtStyleCompare, TEXT_STYLE_ALL_ATTRIBUTES), false);
2253    EXPECT_EQ(OH_Drawing_TextStyleIsAttributeMatched(txtStyle, nullptr, TEXT_STYLE_ALL_ATTRIBUTES), false);
2254    OH_Drawing_DestroyTextStyle(txtStyle);
2255    OH_Drawing_DestroyTextStyle(txtStyleCompare);
2256}
2257
2258/*
2259 * @tc.name: OH_Drawing_TypographyTest076
2260 * @tc.desc: test for sets and gets isPlaceholder for TextStyle objects
2261 * @tc.type: FUNC
2262 */
2263HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest076, TestSize.Level1)
2264{
2265    EXPECT_EQ(OH_Drawing_TextStyleIsPlaceholder(nullptr), false);
2266    OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2267    EXPECT_EQ(OH_Drawing_TextStyleIsPlaceholder(txtStyle), false);
2268    OH_Drawing_TextStyleSetPlaceholder(nullptr);
2269    OH_Drawing_TextStyleSetPlaceholder(txtStyle);
2270    EXPECT_EQ(OH_Drawing_TextStyleIsPlaceholder(txtStyle), true);
2271    EXPECT_EQ(ConvertToOriginalText(txtStyle)->isPlaceholder, true);
2272    OH_Drawing_DestroyTextStyle(txtStyle);
2273}
2274
2275/*
2276 * @tc.name: OH_Drawing_TypographyTest077
2277 * @tc.desc: test for gets the typoStyle alignment mode and whether to enable text prompts
2278 * @tc.type: FUNC
2279 */
2280HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest077, TestSize.Level1)
2281{
2282    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2283    EXPECT_EQ(OH_Drawing_TypographyStyleGetEffectiveAlignment(typoStyle), TEXT_ALIGN_LEFT);
2284    EXPECT_EQ(OH_Drawing_TypographyStyleIsHintEnabled(typoStyle), false);
2285    OH_Drawing_DestroyTypographyStyle(typoStyle);
2286}
2287
2288/*
2289 * @tc.name: OH_Drawing_TypographyTest078
2290 * @tc.desc: test for strutstyle equals
2291 * @tc.type: FUNC
2292 */
2293HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest078, TestSize.Level1)
2294{
2295    OH_Drawing_StrutStyle* from = new OH_Drawing_StrutStyle();
2296    OH_Drawing_StrutStyle* to = new OH_Drawing_StrutStyle();
2297    bool result = OH_Drawing_TypographyStyleStrutStyleEquals(from, to);
2298    EXPECT_TRUE(result == true);
2299    result = OH_Drawing_TypographyStyleStrutStyleEquals(nullptr, to);
2300    EXPECT_TRUE(result == false);
2301    result = OH_Drawing_TypographyStyleStrutStyleEquals(from, nullptr);
2302    EXPECT_TRUE(result == false);
2303    OH_Drawing_TypographyStyleDestroyStrutStyle(from);
2304    OH_Drawing_TypographyStyleDestroyStrutStyle(to);
2305    from = nullptr;
2306    to = nullptr;
2307    EXPECT_TRUE(from == nullptr);
2308    EXPECT_TRUE(to == nullptr);
2309}
2310
2311/*
2312 * @tc.name: OH_Drawing_TypographyTest079
2313 * @tc.desc: test for setting the hinting of text typography
2314 * @tc.type: FUNC
2315 */
2316HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest079, TestSize.Level1)
2317{
2318    OH_Drawing_TypographyStyle *typoStyle = OH_Drawing_CreateTypographyStyle();
2319    OH_Drawing_TypographyStyleSetHintsEnabled(typoStyle, true);
2320    EXPECT_EQ(ConvertToOriginalText(typoStyle)->hintingIsOn, true);
2321    OH_Drawing_DestroyTypographyStyle(typoStyle);
2322}
2323
2324/*
2325 * @tc.name: OH_Drawing_TypographyTest080
2326 * @tc.desc: test for whether two TextStyle objects are equal
2327 * @tc.type: FUNC
2328 */
2329HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest080, TestSize.Level1)
2330{
2331    OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2332    OH_Drawing_TextStyle *txtStyleCompare = OH_Drawing_CreateTextStyle();
2333    bool result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2334    EXPECT_TRUE(result == true);
2335    OH_Drawing_SetTextStyleColor(txtStyle, 1);
2336    result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2337    EXPECT_TRUE(result == false);
2338    OH_Drawing_SetTextStyleColor(txtStyleCompare, 1);
2339    result = OH_Drawing_TextStyleIsEqual(txtStyle, txtStyleCompare);
2340    EXPECT_TRUE(result == true);
2341    EXPECT_EQ(OH_Drawing_TextStyleIsEqual(nullptr, txtStyleCompare), false);
2342    EXPECT_EQ(OH_Drawing_TextStyleIsEqual(txtStyle, nullptr), false);
2343    EXPECT_EQ(OH_Drawing_TextStyleIsEqual(nullptr, nullptr), true);
2344    OH_Drawing_DestroyTextStyle(txtStyle);
2345    OH_Drawing_DestroyTextStyle(txtStyleCompare);
2346}
2347
2348/*
2349 * @tc.name: OH_Drawing_TypographyTest081
2350 * @tc.desc: test for getting and setting text style
2351 * @tc.type: FUNC
2352 */
2353HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest081, TestSize.Level1)
2354{
2355    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2356    EXPECT_NE(txtStyle, nullptr);
2357    OH_Drawing_FontStyleStruct normalStyle;
2358    normalStyle.weight = FONT_WEIGHT_400;
2359    normalStyle.width = FONT_WIDTH_NORMAL;
2360    normalStyle.slant = FONT_STYLE_NORMAL;
2361    OH_Drawing_SetTextStyleFontStyleStruct(txtStyle, normalStyle);
2362
2363    OH_Drawing_FontStyleStruct style = OH_Drawing_TextStyleGetFontStyleStruct(txtStyle);
2364    EXPECT_EQ(style.weight, normalStyle.weight);
2365    EXPECT_EQ(style.width, normalStyle.width);
2366    EXPECT_EQ(style.slant, normalStyle.slant);
2367    OH_Drawing_DestroyTextStyle(txtStyle);
2368}
2369
2370/*
2371 * @tc.name: OH_Drawing_TypographyTest082
2372 * @tc.desc: test for getting and setting typography style
2373 * @tc.type: FUNC
2374 */
2375HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest082, TestSize.Level1)
2376{
2377    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2378    EXPECT_NE(typoStyle, nullptr);
2379    OH_Drawing_FontStyleStruct normalStyle;
2380    normalStyle.weight = FONT_WEIGHT_400;
2381    normalStyle.width = FONT_WIDTH_NORMAL;
2382    normalStyle.slant = FONT_STYLE_NORMAL;
2383    OH_Drawing_SetTypographyStyleFontStyleStruct(typoStyle, normalStyle);
2384
2385    OH_Drawing_FontStyleStruct style = OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyle);
2386    EXPECT_EQ(style.weight, normalStyle.weight);
2387    EXPECT_EQ(style.width, normalStyle.width);
2388    EXPECT_EQ(style.slant, normalStyle.slant);
2389    OH_Drawing_DestroyTypographyStyle(typoStyle);
2390}
2391
2392/*
2393 * @tc.name: OH_Drawing_TypographyTest083
2394 * @tc.desc: test for the font properties of two TextStyle objects are equal
2395 * @tc.type: FUNC
2396 */
2397HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest083, TestSize.Level1)
2398{
2399    OH_Drawing_TextStyle *txtStyle = OH_Drawing_CreateTextStyle();
2400    OH_Drawing_TextStyle *txtStyleCompare = OH_Drawing_CreateTextStyle();
2401    OH_Drawing_SetTextStyleLocale(txtStyle, "en");
2402    OH_Drawing_SetTextStyleLocale(txtStyleCompare, "en");
2403    bool result = OH_Drawing_TextStyleIsEqualByFont(txtStyle, txtStyleCompare);
2404    EXPECT_TRUE(result == true);
2405    OH_Drawing_SetTextStyleLocale(txtStyle, "ch");
2406    result = OH_Drawing_TextStyleIsEqualByFont(txtStyle, txtStyleCompare);
2407    EXPECT_TRUE(result == false);
2408    EXPECT_EQ(OH_Drawing_TextStyleIsEqualByFont(nullptr, txtStyleCompare), false);
2409    EXPECT_EQ(OH_Drawing_TextStyleIsEqualByFont(txtStyle, nullptr), false);
2410    OH_Drawing_DestroyTextStyle(txtStyle);
2411    OH_Drawing_DestroyTextStyle(txtStyleCompare);
2412}
2413
2414/*
2415 * @tc.name: OH_Drawing_TypographyTest084
2416 * @tc.desc: test for BREAK_STRATEGY_GREEDY
2417 * @tc.type: FUNC
2418 */
2419HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest084, TestSize.Level1)
2420{
2421    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2422    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2423    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_GREEDY);
2424    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2425        OH_Drawing_CreateFontCollection());
2426    EXPECT_TRUE(handler != nullptr);
2427    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2428    const char* text = "breakStrategyTest breakStrategy breakStrategyGreedyTest";
2429    OH_Drawing_TypographyHandlerAddText(handler, text);
2430    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2431    // {1.2, 3.4} for unit test
2432    const float indents[] = {1.2, 3.4};
2433    OH_Drawing_TypographySetIndents(typography, 2, indents);
2434    // 300.0 for unit test
2435    double maxWidth = 300.0;
2436    OH_Drawing_TypographyLayout(typography, maxWidth);
2437    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2438}
2439
2440/*
2441 * @tc.name: OH_Drawing_TypographyTest085
2442 * @tc.desc: test for BREAK_STRATEGY_BALANCED
2443 * @tc.type: FUNC
2444 */
2445HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest085, TestSize.Level1)
2446{
2447    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2448    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2449    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_BALANCED);
2450    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2451        OH_Drawing_CreateFontCollection());
2452    EXPECT_TRUE(handler != nullptr);
2453    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2454    const char* text = "breakStrategyTest breakStrategy breakStrategyBALANCEDTest";
2455    OH_Drawing_TypographyHandlerAddText(handler, text);
2456    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2457    // {1.2, 3.4} for unit test
2458    const float indents[] = {1.2, 3.4};
2459    OH_Drawing_TypographySetIndents(typography, 2, indents);
2460    // 300.0 for unit test
2461    double maxWidth = 300.0;
2462    OH_Drawing_TypographyLayout(typography, maxWidth);
2463    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2464}
2465
2466/*
2467 * @tc.name: OH_Drawing_TypographyTest086
2468 * @tc.desc: test for BREAK_STRATEGY_HIGH_QUALITY
2469 * @tc.type: FUNC
2470 */
2471HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest086, TestSize.Level1)
2472{
2473    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2474    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2475    OH_Drawing_SetTypographyTextBreakStrategy(typoStyle, BREAK_STRATEGY_HIGH_QUALITY);
2476    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2477        OH_Drawing_CreateFontCollection());
2478    EXPECT_TRUE(handler != nullptr);
2479    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2480    const char* text = "breakStrategyTest breakStrategy breakStrategyHighQualityTest";
2481    OH_Drawing_TypographyHandlerAddText(handler, text);
2482    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2483    // {1.2, 3.4} for unit test
2484    const float indents[] = {1.2, 3.4};
2485    OH_Drawing_TypographySetIndents(typography, 2, indents);
2486    // 300.0 for unit test
2487    double maxWidth = 300.0;
2488    OH_Drawing_TypographyLayout(typography, maxWidth);
2489    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2490}
2491
2492/*
2493 * @tc.name: OH_Drawing_TypographyTest102
2494 * @tc.desc: test for the font parser
2495 * @tc.type: FUNC
2496 */
2497HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest102, TestSize.Level1)
2498{
2499    OH_Drawing_FontParser* parser = OH_Drawing_CreateFontParser();
2500    static const std::string FILE_NAME = "/system/fonts/visibility_list.json";
2501    std::ifstream fileStream(FILE_NAME.c_str());
2502    if (fileStream.is_open()) {
2503        size_t fontNum;
2504        char** list = OH_Drawing_FontParserGetSystemFontList(parser, &fontNum);
2505        EXPECT_EQ(list != nullptr, true);
2506        EXPECT_EQ(OH_Drawing_FontParserGetSystemFontList(nullptr, &fontNum) == nullptr, true);
2507        const char *name = "FZHeiT-SC Bold";
2508        EXPECT_EQ(OH_Drawing_FontParserGetFontByName(parser, name) != nullptr, true);
2509        EXPECT_EQ(OH_Drawing_FontParserGetFontByName(nullptr, name) == nullptr, true);
2510        OH_Drawing_DestroySystemFontList(list, fontNum);
2511        OH_Drawing_DestroySystemFontList(nullptr, fontNum);
2512    }
2513    OH_Drawing_DestroyFontParser(parser);
2514}
2515
2516/*
2517 * @tc.name: OH_Drawing_TypographyTest103
2518 * @tc.desc: test arc text drawing
2519 * @tc.type: FUNC
2520 */
2521HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest103, TestSize.Level1)
2522{
2523    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2524    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2525    OH_Drawing_TypographyCreate* handler =
2526        OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2527    EXPECT_TRUE(handler != nullptr);
2528    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
2529    OH_Drawing_SetTextStyleFontSize(txtStyle, ARC_FONT_SIZE);
2530    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
2531    bool halfLeading = true;
2532    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
2533    const char* fontFamilies[] = { "Roboto" };
2534    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2535    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2536    const char* text = "OpenHarmony\n";
2537    OH_Drawing_TypographyHandlerAddText(handler, text);
2538    OH_Drawing_TypographyHandlerPopTextStyle(handler);
2539    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2540    OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2541    OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
2542    OH_Drawing_PathArcTo(cPath, LEFT_POS, LEFT_POS, RIGHT_POS, RIGHT_POS, 0, RADIAN_TER);
2543
2544    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
2545    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
2546    OH_Drawing_CanvasDrawPath(cCanvas, cPath);
2547    OH_Drawing_TypographyPaintOnPath(typography, cCanvas, cPath, ARC_FONT_SIZE, ARC_FONT_SIZE);
2548    OH_Drawing_Font_Metrics fontmetrics;
2549    EXPECT_EQ(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics), true);
2550    OH_Drawing_SetTypographyTextStyle(typoStyle, txtStyle);
2551    OH_Drawing_DestroyTypography(typography);
2552    OH_Drawing_DestroyTypographyHandler(handler);
2553    OH_Drawing_DestroyTypographyStyle(typoStyle);
2554    OH_Drawing_DestroyTextStyle(txtStyle);
2555    OH_Drawing_PathDestroy(cPath);
2556    OH_Drawing_CanvasDestroy(cCanvas);
2557}
2558
2559/*
2560 * @tc.name: OH_Drawing_TypographyTest104
2561 * @tc.desc: test arc text offset
2562 * @tc.type: FUNC
2563 */
2564HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest104, TestSize.Level1)
2565{
2566    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2567    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2568    OH_Drawing_TypographyCreate* handler =
2569        OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
2570    EXPECT_TRUE(handler != nullptr);
2571    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
2572    OH_Drawing_SetTextStyleFontSize(txtStyle, ARC_FONT_SIZE);
2573    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
2574    bool halfLeading = true;
2575    OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
2576    const char* fontFamilies[] = { "Roboto" };
2577    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2578    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2579    const char* text = "OpenHarmony\n";
2580    OH_Drawing_TypographyHandlerAddText(handler, text);
2581    OH_Drawing_TypographyHandlerPopTextStyle(handler);
2582    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2583    OH_Drawing_TypographyLayout(typography, MAX_WIDTH);
2584    OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
2585    OH_Drawing_PathArcTo(cPath, LEFT_POS, LEFT_POS, RIGHT_POS, RIGHT_POS, 0, RADIAN_TER);
2586
2587    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
2588    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
2589    OH_Drawing_CanvasDrawPath(cCanvas, cPath);
2590    OH_Drawing_TypographyPaintOnPath(typography, cCanvas, cPath, ARC_FONT_SIZE, ARC_FONT_SIZE);
2591    OH_Drawing_Font_Metrics fontmetrics;
2592    EXPECT_EQ(OH_Drawing_TextStyleGetFontMetrics(typography, txtStyle, &fontmetrics), true);
2593    OH_Drawing_SetTypographyTextStyle(typoStyle, txtStyle);
2594    OH_Drawing_DestroyTypography(typography);
2595    OH_Drawing_DestroyTypographyHandler(handler);
2596    OH_Drawing_DestroyTypographyStyle(typoStyle);
2597    OH_Drawing_DestroyTextStyle(txtStyle);
2598    OH_Drawing_PathDestroy(cPath);
2599    OH_Drawing_CanvasDestroy(cCanvas);
2600}
2601
2602/*
2603 * @tc.name: OH_Drawing_TypographyTest105
2604 * @tc.desc: test for the text box
2605 * @tc.type: FUNC
2606 */
2607HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTest105, TestSize.Level1)
2608{
2609    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2610    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2611        OH_Drawing_CreateFontCollection());
2612    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2613    OH_Drawing_TextBox* textBox = OH_Drawing_TypographyGetRectsForPlaceholders(typography);
2614    OH_Drawing_GetLeftFromTextBox(textBox, 0);
2615    OH_Drawing_GetRightFromTextBox(textBox, 0);
2616    OH_Drawing_GetTopFromTextBox(textBox, 0);
2617    OH_Drawing_GetBottomFromTextBox(textBox, 0);
2618    EXPECT_EQ(OH_Drawing_GetTextDirectionFromTextBox(textBox, 0), 0);
2619    EXPECT_EQ(OH_Drawing_GetSizeOfTextBox(textBox), 0);
2620
2621    OH_Drawing_PositionAndAffinity* positionAndAffinity =
2622        OH_Drawing_TypographyGetGlyphPositionAtCoordinate(typography, 1, 0);
2623    OH_Drawing_GetPositionFromPositionAndAffinity(positionAndAffinity);
2624    OH_Drawing_GetAffinityFromPositionAndAffinity(positionAndAffinity);
2625
2626    OH_Drawing_Range* range = OH_Drawing_TypographyGetWordBoundary(typography, 1);
2627    OH_Drawing_GetStartFromRange(range);
2628    OH_Drawing_GetEndFromRange(range);
2629    OH_Drawing_TypographyGetLineHeight(typography, 1);
2630    OH_Drawing_TypographyGetLineWidth(typography, 1);
2631}
2632
2633/*
2634 * @tc.name: OH_Drawing_TypographyTestWithIndent
2635 * @tc.desc: test for typography
2636 * @tc.type: FUNC
2637 */
2638HWTEST_F(OH_Drawing_TypographyTest, OH_Drawing_TypographyTestWithIndent, TestSize.Level1)
2639{
2640    OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
2641    OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
2642    OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
2643        OH_Drawing_CreateFontCollection());
2644    EXPECT_TRUE(handler != nullptr);
2645
2646    OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
2647    double fontSize = 30;
2648    OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
2649    OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
2650    OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
2651    const char* fontFamilies[] = {"Roboto"};
2652    OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
2653    OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
2654
2655    const char* text = "OpenHarmony\n";
2656    OH_Drawing_TypographyHandlerAddText(handler, text);
2657    OH_Drawing_TypographyHandlerPopTextStyle(handler);
2658    OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
2659    const float indents[] = {1.2, 3.4};
2660    OH_Drawing_TypographySetIndents(typography, 2, indents);
2661    float indent = 3.4;
2662    EXPECT_EQ(indent, OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
2663    double maxWidth = 800.0;
2664    OH_Drawing_TypographyLayout(typography, maxWidth);
2665    EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
2666    double position[2] = {10.0, 15.0};
2667    OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
2668    OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
2669    uint32_t width = 20;
2670    uint32_t height = 40;
2671    OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
2672    EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap));
2673    EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap));
2674
2675    OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
2676    OH_Drawing_CanvasBind(cCanvas, cBitmap);
2677    OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
2678
2679    EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography) != 0.0, true);
2680    EXPECT_EQ(OH_Drawing_TypographyGetLongestLineWithIndent(typography) != 0.0, true);
2681    EXPECT_EQ(OH_Drawing_TypographyGetMinIntrinsicWidth(typography) <=
2682        OH_Drawing_TypographyGetMaxIntrinsicWidth(typography), true);
2683    EXPECT_EQ(OH_Drawing_TypographyGetAlphabeticBaseline(typography) != 0.0, true);
2684    EXPECT_EQ(OH_Drawing_TypographyGetIdeographicBaseline(typography) != 0.0, true);
2685    OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
2686    OH_Drawing_DestroyTypography(typography);
2687    OH_Drawing_DestroyTypographyHandler(handler);
2688}
2689}