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