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