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