1 /*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, Hardware
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <fstream>
17 #include <string>
18 #include "gtest/gtest.h"
19 #include "drawing_brush.h"
20 #include "drawing_font.h"
21 #include "drawing_point.h"
22 #include "drawing_text_typography.h"
23 #include "drawing_font_collection.h"
24 #include "drawing_register_font.h"
25 #include "drawing_text_declaration.h"
26 #include "drawing_bitmap.h"
27 #include "drawing_canvas.h"
28 #include "drawing_color.h"
29 #include "drawing_path.h"
30 #include "drawing_pen.h"
31 #include "rosen_text/typography.h"
32 #include "rosen_text/typography_create.h"
33
34 #define NUM_10 10
35 #define NUM_52 52
36 #define NUM_100 100
37 #define NUM_1200 1200
38
39 using namespace testing;
40 using namespace testing::ext;
41
42 namespace OHOS {
43 static const char* FONT_FAMILY = "Roboto-Black";
44 static const char* FONT_PATH = "/data/Roboto-Black.ttf";
45 constexpr static float FLOAT_DATA_EPSILON = 1e-6f;
46 namespace Rosen {
47 namespace Drawing {
48 class NativeFontTest : public testing::Test {
49 public:
50 static void SetUpTestCase();
51 static void TearDownTestCase();
52 void SetUp() override;
53 void TearDown() override;
54 };
55
SetUpTestCase()56 void NativeFontTest::SetUpTestCase() {}
TearDownTestCase()57 void NativeFontTest::TearDownTestCase() {}
SetUp()58 void NativeFontTest::SetUp() {}
TearDown()59 void NativeFontTest::TearDown() {}
60
61 /*
62 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontMeasureText_015
63 * @tc.name : NativeFontTest_FontMeasureText015
64 * @tc.desc : test for the textbox.
65 * @tc.size : MediumTest
66 * @tc.type : Function
67 * @tc.level : Level 1
68 */
69 HWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText015, Function | MediumTest | Level1)
70 {
71 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
72 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
73 OH_Drawing_CreateFontCollection());
74 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
75 OH_Drawing_TextBox* textBox = OH_Drawing_TypographyGetRectsForPlaceholders(typography);
76 EXPECT_EQ(textBox == nullptr, false);
77 OH_Drawing_DestroyTypographyStyle(typoStyle);
78 OH_Drawing_DestroyTypographyHandler(handler);
79 OH_Drawing_DestroyTypography(typography);
80 OH_Drawing_TypographyDestroyTextBox(textBox);
81 }
82
83 /*
84 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontMeasureText_016
85 * @tc.name : NativeFontTest_FontMeasureText016
86 * @tc.desc : test for the textshadow.
87 * @tc.size : MediumTest
88 * @tc.type : Function
89 * @tc.level : Level 1
90 */
91 HWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText016, Function | MediumTest | Level1)
92 {
93 OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
94 uint32_t color = 0;
95 OH_Drawing_Point* offset = OH_Drawing_PointCreate(0, 0);
96 double blurRadius = 0.0;
97 OH_Drawing_SetTextShadow(shadow, color, offset, blurRadius);
98 OH_Drawing_DestroyTextShadow(shadow);
99 OH_Drawing_PointDestroy(offset);
100 EXPECT_TRUE(shadow != nullptr);
101 }
102
103 /*
104 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontMeasureText_017
105 * @tc.name : NativeFontTest_FontMeasureText017
106 * @tc.desc : test for the fontVariation.
107 * @tc.size : MediumTest
108 * @tc.type : Function
109 * @tc.level : Level 1
110 */
111 HWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText017, Function | MediumTest | Level1)
112 {
113 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
114 EXPECT_EQ(txtStyle == nullptr, false);
115 const char* key = "宋体";
116 int value = 1;
117 OH_Drawing_TextStyleAddFontFeature(txtStyle, key, value);
118 OH_Drawing_TextStyleAddFontVariation(txtStyle, key, value);
119 EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 1);
120 OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
121 OH_Drawing_ClearFontCaches(fontCollection);
122 EXPECT_EQ(fontCollection == nullptr, false);
123 OH_Drawing_DestroyFontCollection(fontCollection);
124 OH_Drawing_DestroyTextStyle(txtStyle);
125 }
126
127 /*
128 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_NativeDrawingRegisterFontTest_001
129 * @tc.name : NativeDrawingRegisterFontTest001
130 * @tc.desc : test for register font
131 * @tc.size : MediumTest
132 * @tc.type : Function
133 * @tc.level : Level 1
134 */
135 HWTEST_F(NativeFontTest, NativeDrawingRegisterFontTest001, Function | MediumTest | Level1)
136 {
137 OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
138 uint32_t errorCode = OH_Drawing_RegisterFont(fontCollection, FONT_FAMILY, FONT_PATH);
139 std::ifstream fileStream(FONT_PATH);
140 if (fileStream.is_open()) {
141 EXPECT_EQ(errorCode, 0);
142 fileStream.close();
143 } else {
144 EXPECT_EQ(errorCode, 1);
145 }
146 OH_Drawing_DestroyFontCollection(fontCollection);
147 }
148
149 /*
150 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_NativeDrawingRegisterFontTest_002
151 * @tc.name : NativeDrawingRegisterFontTest002
152 * @tc.desc : test for register font
153 * @tc.size : MediumTest
154 * @tc.type : Function
155 * @tc.level : Level 1
156 */
157 HWTEST_F(NativeFontTest, NativeDrawingRegisterFontTest002, Function | MediumTest | Level1)
158 {
159 OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
160 uint32_t errorCode = OH_Drawing_RegisterFontBuffer(fontCollection, FONT_FAMILY, nullptr, 128);
161 std::ifstream fileStream(FONT_PATH);
162 if (fileStream.is_open()) {
163 EXPECT_EQ(errorCode, 0);
164 fileStream.close();
165 } else {
166 EXPECT_EQ(errorCode, 6);
167 }
168 OH_Drawing_DestroyFontCollection(fontCollection);
169 }
170
171 /*
172 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontCollectionTest_001
173 * @tc.name : OH_Drawing_FontCollectionTest001
174 * @tc.desc : test for creating fontCollection
175 * @tc.size : MediumTest
176 * @tc.type : Function
177 * @tc.level : Level 1
178 */
179 HWTEST_F(NativeFontTest, OH_Drawing_FontCollectionTest001, Function | MediumTest | Level1)
180 {
181 OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
182 EXPECT_EQ(fontCollection == nullptr, false);
183 OH_Drawing_DestroyFontCollection(fontCollection);
184 OH_Drawing_FontCollection* sharedFontCollection = OH_Drawing_CreateSharedFontCollection();
185 EXPECT_EQ(sharedFontCollection == nullptr, false);
186 OH_Drawing_DisableFontCollectionFallback(sharedFontCollection);
187 OH_Drawing_DisableFontCollectionSystemFont(sharedFontCollection);
188 OH_Drawing_DestroyFontCollection(sharedFontCollection);
189 }
190
191 /*
192 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyLargeValueTest_016
193 * @tc.name : OHDrawingTypographyLargeValueTest016
194 * @tc.desc : test for typography
195 * @tc.size : MediumTest
196 * @tc.type : Function
197 * @tc.level : Level 1
198 */
199 HWTEST_F(NativeFontTest, OHDrawingTypographyLargeValueTest016, Function | MediumTest | Level1)
200 {
201 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
202 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
203 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
204 OH_Drawing_CreateFontCollection());
205 EXPECT_TRUE(handler != nullptr);
206
207 OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
208 double fontSize = 30;
209 OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
210 OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
211 OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
212 const char* fontFamilies[] = {"Roboto"};
213 OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
214 OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
215
216 const char* text = "OpenHarmony\n";
217 OH_Drawing_TypographyHandlerAddText(handler, text);
218 OH_Drawing_TypographyHandlerPopTextStyle(handler);
219
220 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
221 const float indents[] = {1.2, 3.4};
222 OH_Drawing_TypographySetIndents(typography, 2, indents);
223 float indent = 3.4;
224 EXPECT_EQ(indent, OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
225 double maxWidth = 2160.0;
226 OH_Drawing_TypographyLayout(typography, maxWidth);
227 EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
228 double position[2] = {10.0, 15.0};
229 OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
230 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
231 uint32_t width = 20;
232 uint32_t height = 40;
233 OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
234 EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap));
235 EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap));
236
237 OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
238 OH_Drawing_CanvasBind(cCanvas, cBitmap);
239 OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
240
241 EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography) != 0.0, true);
242 EXPECT_EQ(OH_Drawing_TypographyGetLongestLine(typography) != 0.0, true);
243 EXPECT_EQ(OH_Drawing_TypographyGetMinIntrinsicWidth(typography) <=
244 OH_Drawing_TypographyGetMaxIntrinsicWidth(typography), true);
245 EXPECT_EQ(OH_Drawing_TypographyGetAlphabeticBaseline(typography) != 0.0, true);
246 EXPECT_EQ(OH_Drawing_TypographyGetIdeographicBaseline(typography) != 0.0, true);
247 OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
248 OH_Drawing_DestroyTypography(typography);
249 OH_Drawing_DestroyTypographyHandler(handler);
250 }
251
252 /*
253 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyLargeValueTest_026
254 * @tc.name : OHDrawingTypographyLargeValueTest026
255 * @tc.desc : test for typography and txtStyle
256 * @tc.size : MediumTest
257 * @tc.type : Function
258 * @tc.level : Level 1
259 */
260 HWTEST_F(NativeFontTest, OHDrawingTypographyLargeValueTest026, Function | MediumTest | Level1)
261 {
262 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
263 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
264 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
265 OH_Drawing_CreateFontCollection());
266 EXPECT_TRUE(handler != nullptr);
267 OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
268 double fontSize = 30;
269 OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
270 OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
271 bool halfLeading = true;
272 OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
273 const char* fontFamilies[] = {"Roboto"};
274 OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
275 OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
276 const char* text = "OpenHarmony\n";
277 OH_Drawing_TypographyHandlerAddText(handler, text);
278 OH_Drawing_PlaceholderSpan placeholderSpan = {20, 40,
279 ALIGNMENT_OFFSET_AT_BASELINE, TEXT_BASELINE_ALPHABETIC, 10};
280 OH_Drawing_TypographyHandlerAddPlaceholder(handler, &placeholderSpan);
281 OH_Drawing_TypographyHandlerPopTextStyle(handler);
282 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
283 double maxWidth = 2160.0;
284 OH_Drawing_TypographyLayout(typography, maxWidth);
285 double position[2] = {10.0, 15.0};
286 OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
287 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
288 uint32_t width = 20;
289 uint32_t height = 40;
290 OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
291 OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
292 OH_Drawing_CanvasBind(cCanvas, cBitmap);
293 OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
294 EXPECT_EQ(OH_Drawing_TypographyDidExceedMaxLines(typography) != true, true);
295 OH_Drawing_RectHeightStyle heightStyle = RECT_HEIGHT_STYLE_TIGHT;
296 OH_Drawing_RectWidthStyle widthStyle = RECT_WIDTH_STYLE_TIGHT;
297 EXPECT_EQ(OH_Drawing_TypographyGetRectsForRange(typography, 1, 2, heightStyle, widthStyle) != nullptr, true);
298 EXPECT_EQ(OH_Drawing_TypographyGetRectsForPlaceholders(typography) != nullptr, true);
299 EXPECT_EQ(OH_Drawing_TypographyGetGlyphPositionAtCoordinate(typography, 1, 0) != nullptr, true);
300 EXPECT_EQ(OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(typography, 1, 0) != nullptr, true);
301 EXPECT_EQ(OH_Drawing_TypographyGetWordBoundary(typography, 1) != nullptr, true);
302 EXPECT_EQ(OH_Drawing_TypographyGetLineTextRange(typography, 1, true) != nullptr, true);
303 EXPECT_EQ(OH_Drawing_TypographyGetLineCount(typography) != 0, true);
304 OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
305 OH_Drawing_DestroyTypography(typography);
306 OH_Drawing_DestroyTypographyHandler(handler);
307 }
308
309 /*
310 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyLargeValueTest_027
311 * @tc.name : OHDrawingTypographyLargeValueTest027
312 * @tc.desc : test for getting line info for text typography
313 * @tc.size : MediumTest
314 * @tc.type : Function
315 * @tc.level : Level 1
316 */
317 HWTEST_F(NativeFontTest, OHDrawingTypographyLargeValueTest027, Function | MediumTest | Level1)
318 {
319 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
320 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
321 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
322 OH_Drawing_CreateFontCollection());
323 EXPECT_TRUE(handler != nullptr);
324 OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
325 double fontSize = 30;
326 OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
327 OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
328 bool halfLeading = true;
329 OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
330 const char* fontFamilies[] = {"Roboto"};
331 OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
332 OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
333 const char* text = "OpenHarmony\n";
334 OH_Drawing_TypographyHandlerAddText(handler, text);
335 OH_Drawing_TypographyHandlerPopTextStyle(handler);
336 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
337 double maxWidth = 2160.0;
338 OH_Drawing_TypographyLayout(typography, maxWidth);
339 double position[2] = {10.0, 15.0};
340 OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
341 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
342 uint32_t width = 20;
343 uint32_t height = 40;
344 OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
345 OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
346 OH_Drawing_CanvasBind(cCanvas, cBitmap);
347 OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
348 OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
349 int lineNum = 0;
350 bool oneLine = true;
351 bool includeWhitespace = true;
352 OH_Drawing_LineMetrics lineMetrics;
353 EXPECT_EQ(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, nullptr), false);
354 EXPECT_EQ(OH_Drawing_TypographyGetLineInfo(typography, -1, oneLine, includeWhitespace, &lineMetrics), false);
355 EXPECT_EQ(OH_Drawing_TypographyGetLineInfo(typography, lineNum, oneLine, includeWhitespace, &lineMetrics), true);
356 OH_Drawing_DestroyTypography(typography);
357 OH_Drawing_DestroyTypographyHandler(handler);
358 }
359
360 /*
361 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyLargeValueTest_042
362 * @tc.name : OHDrawingTypographyLargeValueTest042
363 * @tc.desc : test for text shadow for textstyle
364 * @tc.size : MediumTest
365 * @tc.type : Function
366 * @tc.level : Level 1
367 */
368 HWTEST_F(NativeFontTest, OHDrawingTypographyLargeValueTest042, Function | MediumTest | Level1)
369 {
370 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
371 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
372 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
373 OH_Drawing_CreateFontCollection());
374 EXPECT_TRUE(handler != nullptr);
375 OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
376 double fontSize = 30;
377 OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
378 OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
379 bool halfLeading = true;
380 OH_Drawing_SetTextStyleHalfLeading(txtStyle, halfLeading);
381 const char* fontFamilies[] = {"Roboto"};
382 OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
383 OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
384 const char* text = "OpenHarmony\n";
385 OH_Drawing_TypographyHandlerAddText(handler, text);
386 OH_Drawing_TypographyHandlerPopTextStyle(handler);
387 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
388 double maxWidth = 2160.0;
389 OH_Drawing_TypographyLayout(typography, maxWidth);
390 double position[2] = {10.0, 15.0};
391 OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
392 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
393 uint32_t width = 20;
394 uint32_t height = 40;
395 OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
396 OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
397 OH_Drawing_CanvasBind(cCanvas, cBitmap);
398 OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
399 EXPECT_EQ(OH_Drawing_TextStyleGetShadows(txtStyle) != nullptr, true);
400 OH_Drawing_TextStyleClearShadows(txtStyle);
401 OH_Drawing_TextShadow* textshadows = OH_Drawing_TextStyleGetShadows(txtStyle);
402 OH_Drawing_DestroyTextShadows(textshadows);
403 OH_Drawing_DestroyTextShadows(nullptr);
404 OH_Drawing_TextStyleAddShadow(txtStyle, nullptr);
405 OH_Drawing_TextStyleAddShadow(txtStyle, OH_Drawing_CreateTextShadow());
406 EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 0) != nullptr, true);
407 EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(txtStyle, 10000000) == nullptr, true);
408 EXPECT_EQ(OH_Drawing_TextStyleGetShadowWithIndex(nullptr, 0) == nullptr, true);
409 EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyle), 1);
410 EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(nullptr), 0);
411 OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
412 OH_Drawing_DestroyTypography(typography);
413 OH_Drawing_DestroyTypographyHandler(handler);
414 }
415
416 /*
417 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyLargeValueTestWithIndent
418 * @tc.name : OHDrawingTypographyLargeValueTestWithIndent
419 * @tc.desc : test for typography
420 * @tc.size : MediumTest
421 * @tc.type : Function
422 * @tc.level : Level 1
423 */
424 HWTEST_F(NativeFontTest, OHDrawingTypographyLargeValueTestWithIndent, Function | MediumTest | Level1)
425 {
426 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
427 OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
428 OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
429 OH_Drawing_CreateFontCollection());
430 EXPECT_TRUE(handler != nullptr);
431
432 OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
433 double fontSize = 30;
434 OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
435 OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
436 OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
437 const char* fontFamilies[] = {"Roboto"};
438 OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
439 OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
440
441 const char* text = "OpenHarmony\n";
442 OH_Drawing_TypographyHandlerAddText(handler, text);
443 OH_Drawing_TypographyHandlerPopTextStyle(handler);
444 OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
445 const float indents[] = {1.2, 3.4};
446 OH_Drawing_TypographySetIndents(typography, 2, indents);
447 float indent = 3.4;
448 EXPECT_EQ(indent, OH_Drawing_TypographyGetIndentsWithIndex(typography, 1));
449 double maxWidth = 2160.0;
450 OH_Drawing_TypographyLayout(typography, maxWidth);
451 EXPECT_EQ(maxWidth, OH_Drawing_TypographyGetMaxWidth(typography));
452 double position[2] = {10.0, 15.0};
453 OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
454 OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
455 uint32_t width = 20;
456 uint32_t height = 40;
457 OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
458 EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(cBitmap));
459 EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(cBitmap));
460
461 OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
462 OH_Drawing_CanvasBind(cCanvas, cBitmap);
463 OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
464
465 EXPECT_EQ(OH_Drawing_TypographyGetHeight(typography) != 0.0, true);
466 EXPECT_EQ(OH_Drawing_TypographyGetLongestLineWithIndent(typography) != 0.0, true);
467 EXPECT_EQ(OH_Drawing_TypographyGetMinIntrinsicWidth(typography) <=
468 OH_Drawing_TypographyGetMaxIntrinsicWidth(typography), true);
469 EXPECT_EQ(OH_Drawing_TypographyGetAlphabeticBaseline(typography) != 0.0, true);
470 EXPECT_EQ(OH_Drawing_TypographyGetIdeographicBaseline(typography) != 0.0, true);
471 OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
472 OH_Drawing_DestroyTypography(typography);
473 OH_Drawing_DestroyTypographyHandler(handler);
474 }
475
476 /*
477 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_CreateTextTab_001
478 * @tc.name : OHDrawingCreateTextTab001
479 * @tc.desc : test for the text tab create and destroy
480 * @tc.size : MediumTest
481 * @tc.type : Function
482 * @tc.level : Level 0
483 */
484 HWTEST_F(NativeFontTest, OHDrawingCreateTextTab001, Function | MediumTest | Level0)
485 {
486 OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
487 EXPECT_NE(textTab, nullptr);
488 OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_END, -1.0);
489 EXPECT_NE(textTab2, nullptr);
490 OH_Drawing_DestroyTextTab(textTab);
491 OH_Drawing_DestroyTextTab(textTab2);
492 }
493
494 /*
495 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_CreateTextTab_002
496 * @tc.name : OHDrawingCreateTextTab002
497 * @tc.desc : test for get alignment of the text tab
498 * @tc.size : MediumTest
499 * @tc.type : Function
500 * @tc.level : Level 0
501 */
502 HWTEST_F(NativeFontTest, OHDrawingCreateTextTab002, Function | MediumTest | Level0)
503 {
504 OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
505 EXPECT_EQ(OH_Drawing_GetTextTabAlignment(textTab), TEXT_ALIGN_LEFT);
506 OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_JUSTIFY, 0.0);
507 EXPECT_EQ(OH_Drawing_GetTextTabAlignment(textTab), TEXT_ALIGN_LEFT);
508 EXPECT_EQ(OH_Drawing_GetTextTabAlignment(nullptr), TEXT_ALIGN_LEFT);
509 OH_Drawing_DestroyTextTab(textTab);
510 OH_Drawing_DestroyTextTab(textTab2);
511 }
512
513 /*
514 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_CreateTextTab_003
515 * @tc.name : OHDrawingCreateTextTab003
516 * @tc.desc : test for get location of the text tab
517 * @tc.size : MediumTest
518 * @tc.type : Function
519 * @tc.level : Level 0
520 */
521 HWTEST_F(NativeFontTest, OHDrawingCreateTextTab003, Function | MediumTest | Level0)
522 {
523 OH_Drawing_TextTab* textTab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, 0.0);
524 EXPECT_EQ(OH_Drawing_GetTextTabLocation(textTab), 0.0);
525 OH_Drawing_DestroyTextTab(textTab);
526 OH_Drawing_TextTab* textTab2 = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, -100.0);
527 EXPECT_EQ(OH_Drawing_GetTextTabLocation(textTab2), -100.0);
528 EXPECT_EQ(OH_Drawing_GetTextTabLocation(nullptr), 0.0);
529 OH_Drawing_DestroyTextTab(textTab2);
530 }
531
532 /*
533 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyTest_001
534 * @tc.name : TypographyTest001
535 * @tc.desc : test for text tab with left alignment
536 * @tc.size : MediumTest
537 * @tc.type : Function
538 * @tc.level : Level 0
539 */
540 HWTEST_F(NativeFontTest, TypographyTest001, Function | MediumTest | Level0)
541 {
542 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
543 OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
544 OH_Drawing_SetTypographyTextMaxLines(typoStyle, NUM_10);
545
546 OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_LEFT, NUM_100);
547 OH_Drawing_SetTypographyTextTab(typoStyle, tab);
548
549 OH_Drawing_TypographyCreate *handler =
550 OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
551 OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
552 OH_Drawing_SetTextStyleFontSize(textStyle, NUM_52);
553 OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
554
555 const char *text = "Hello\tWorld\tHello";
556 OH_Drawing_TypographyHandlerAddText(handler, text);
557 OH_Drawing_TypographyHandlerPopTextStyle(handler);
558
559 OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
560 OH_Drawing_TypographyLayout(typography, NUM_1200);
561
562 double width = OH_Drawing_TypographyGetLongestLine(typography);
563 EXPECT_NEAR(width, 522.772095, FLOAT_DATA_EPSILON);
564
565 // branch coverage
566 OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
567
568 OH_Drawing_DestroyTypography(typography);
569 OH_Drawing_DestroyTextStyle(textStyle);
570 OH_Drawing_DestroyTypographyHandler(handler);
571 OH_Drawing_DestroyTextTab(tab);
572 OH_Drawing_DestroyTypographyStyle(typoStyle);
573 }
574
575 /*
576 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyTest_002
577 * @tc.name : TypographyTest002
578 * @tc.desc : test for text tab with left alignment
579 * @tc.size : MediumTest
580 * @tc.type : Function
581 * @tc.level : Level 0
582 */
583 HWTEST_F(NativeFontTest, TypographyTest002, Function | MediumTest | Level0)
584 {
585 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
586 OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
587 OH_Drawing_SetTypographyTextMaxLines(typoStyle, NUM_10);
588
589 OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_RIGHT, NUM_100);
590 OH_Drawing_SetTypographyTextTab(typoStyle, tab);
591
592 OH_Drawing_TypographyCreate *handler =
593 OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
594 OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
595 OH_Drawing_SetTextStyleFontSize(textStyle, NUM_52);
596 OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
597
598 const char *text = "Hello\tWorld\tHello";
599 OH_Drawing_TypographyHandlerAddText(handler, text);
600 OH_Drawing_TypographyHandlerPopTextStyle(handler);
601
602 OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
603 OH_Drawing_TypographyLayout(typography, NUM_1200);
604
605 double width = OH_Drawing_TypographyGetLongestLine(typography);
606 EXPECT_NEAR(width, 386.828308, FLOAT_DATA_EPSILON);
607
608 // branch coverage
609 OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
610
611 OH_Drawing_DestroyTypography(typography);
612 OH_Drawing_DestroyTextStyle(textStyle);
613 OH_Drawing_DestroyTypographyHandler(handler);
614 OH_Drawing_DestroyTextTab(tab);
615 OH_Drawing_DestroyTypographyStyle(typoStyle);
616 }
617
618 /*
619 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyTest_003
620 * @tc.name : TypographyTest003
621 * @tc.desc : test for text tab with center alignment
622 * @tc.size : MediumTest
623 * @tc.type : Function
624 * @tc.level : Level 0
625 */
626 HWTEST_F(NativeFontTest, TypographyTest003, Function | MediumTest | Level0)
627 {
628 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
629 OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
630 OH_Drawing_SetTypographyTextMaxLines(typoStyle, NUM_10);
631
632 OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, NUM_100);
633 OH_Drawing_SetTypographyTextTab(typoStyle, tab);
634
635 OH_Drawing_TypographyCreate *handler =
636 OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
637 OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
638 OH_Drawing_SetTextStyleFontSize(textStyle, NUM_52);
639 OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
640
641 const char *text = "Hello\tWorld\tHello";
642 OH_Drawing_TypographyHandlerAddText(handler, text);
643 OH_Drawing_TypographyHandlerPopTextStyle(handler);
644
645 OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
646 OH_Drawing_TypographyLayout(typography, NUM_1200);
647
648 double width = OH_Drawing_TypographyGetLongestLine(typography);
649 EXPECT_NEAR(width, 393.414185, FLOAT_DATA_EPSILON);
650
651 // branch coverage
652 OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
653
654 OH_Drawing_DestroyTypography(typography);
655 OH_Drawing_DestroyTextStyle(textStyle);
656 OH_Drawing_DestroyTypographyHandler(handler);
657 OH_Drawing_DestroyTextTab(tab);
658 OH_Drawing_DestroyTypographyStyle(typoStyle);
659 }
660
661 /*
662 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyTest_004
663 * @tc.name : TypographyTest004
664 * @tc.desc : test for setting both the texttab and text layout direction
665 * @tc.size : MediumTest
666 * @tc.type : Function
667 * @tc.level : Level 0
668 */
669 HWTEST_F(NativeFontTest, TypographyTest004, Function | MediumTest | Level0)
670 {
671 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
672 OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
673 OH_Drawing_SetTypographyTextMaxLines(typoStyle, NUM_10);
674 OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_CENTER);
675
676 OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, NUM_100);
677 OH_Drawing_SetTypographyTextTab(typoStyle, tab);
678
679 OH_Drawing_TypographyCreate *handler =
680 OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
681 OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
682 OH_Drawing_SetTextStyleFontSize(textStyle, NUM_52);
683 OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
684
685 const char *text = "Hello\tWorld\tHello";
686 OH_Drawing_TypographyHandlerAddText(handler, text);
687 OH_Drawing_TypographyHandlerPopTextStyle(handler);
688
689 OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
690 OH_Drawing_TypographyLayout(typography, NUM_1200);
691
692 double width = OH_Drawing_TypographyGetLongestLine(typography);
693 EXPECT_NEAR(width, 414.388336, FLOAT_DATA_EPSILON);
694
695 // branch coverage
696 OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
697
698 OH_Drawing_DestroyTypography(typography);
699 OH_Drawing_DestroyTextStyle(textStyle);
700 OH_Drawing_DestroyTypographyHandler(handler);
701 OH_Drawing_DestroyTextTab(tab);
702 OH_Drawing_DestroyTypographyStyle(typoStyle);
703 }
704
705 /*
706 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_TypographyTest_005
707 * @tc.name : TypographyTest005
708 * @tc.desc : test for setting both the texttab and ellipsis
709 * @tc.size : MediumTest
710 * @tc.type : Function
711 * @tc.level : Level 0
712 */
713 HWTEST_F(NativeFontTest, TypographyTest005, Function | MediumTest | Level0)
714 {
715 OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
716 OH_Drawing_SetTypographyTextWordBreakType(typoStyle, WORD_BREAK_TYPE_BREAK_ALL);
717 OH_Drawing_SetTypographyTextMaxLines(typoStyle, NUM_10);
718 OH_Drawing_SetTypographyTextEllipsis(typoStyle, "...");
719 OH_Drawing_SetTypographyTextEllipsisModal(typoStyle, ELLIPSIS_MODAL_TAIL);
720
721 OH_Drawing_TextTab* tab = OH_Drawing_CreateTextTab(TEXT_ALIGN_CENTER, NUM_100);
722 OH_Drawing_SetTypographyTextTab(typoStyle, tab);
723
724 OH_Drawing_TypographyCreate *handler =
725 OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateSharedFontCollection());
726 OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle();
727 OH_Drawing_SetTextStyleFontSize(textStyle, NUM_52);
728 OH_Drawing_TypographyHandlerPushTextStyle(handler, textStyle);
729
730 const char *text = "Hello\tWorld\tHello";
731 OH_Drawing_TypographyHandlerAddText(handler, text);
732 OH_Drawing_TypographyHandlerPopTextStyle(handler);
733
734 OH_Drawing_Typography *typography = OH_Drawing_CreateTypography(handler);
735 OH_Drawing_TypographyLayout(typography, NUM_1200);
736
737 double width = OH_Drawing_TypographyGetLongestLine(typography);
738 EXPECT_NEAR(width, 414.388336, FLOAT_DATA_EPSILON);
739
740 // branch coverage
741 OH_Drawing_SetTypographyTextTab(typoStyle, nullptr);
742
743 OH_Drawing_DestroyTypography(typography);
744 OH_Drawing_DestroyTextStyle(textStyle);
745 OH_Drawing_DestroyTypographyHandler(handler);
746 OH_Drawing_DestroyTextTab(tab);
747 OH_Drawing_DestroyTypographyStyle(typoStyle);
748 }
749
750 /*
751 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontGetTextPath_001
752 * @tc.name : FontGetTextPath001
753 * @tc.desc : test for common character of textpath
754 * @tc.size : MediumTest
755 * @tc.type : Function
756 * @tc.level : Level 0
757 */
758 HWTEST_F(NativeFontTest, FontGetTextPath001, Function | MediumTest | Level0)
759 {
760 OH_Drawing_Font* font = OH_Drawing_FontCreate();
761 EXPECT_NE(font, nullptr);
762 const char* str = "Hello 中文";
763 size_t length = std::char_traits<char>::length(str);
764 float x = 12.0f;
765 float y = 150.0f;
766 OH_Drawing_Path* path = OH_Drawing_PathCreate();
767 ASSERT_NE(path, nullptr);
768 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, str, sizeof(char) * length, TEXT_ENCODING_UTF8, x, y, path),
769 OH_DRAWING_SUCCESS);
770 ASSERT_NE(path, nullptr);
771 EXPECT_TRUE(OH_Drawing_PathGetLength(path, false) > 0);
772 if (path != nullptr) {
773 OH_Drawing_PathDestroy(path);
774 }
775 OH_Drawing_FontDestroy(font);
776 }
777
778 /*
779 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontGetTextPath_002
780 * @tc.name : FontGetTextPath002
781 * @tc.desc : test for UTF16 and UTF32 character of textpath
782 * @tc.size : MediumTest
783 * @tc.type : Function
784 * @tc.level : Level 0
785 */
786 HWTEST_F(NativeFontTest, FontGetTextPath002, Function | MediumTest | Level0)
787 {
788 OH_Drawing_Font* font = OH_Drawing_FontCreate();
789 EXPECT_NE(font, nullptr);
790
791 float x = 12.0f;
792 float y = 150.0f;
793 const char16_t* u16str = u"Hello 中文";
794 size_t u16strLen = std::char_traits<char16_t>::length(u16str);
795 OH_Drawing_Path* path = OH_Drawing_PathCreate();
796 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, u16str, sizeof(char16_t) * u16strLen, TEXT_ENCODING_UTF16, x, y, path),
797 OH_DRAWING_SUCCESS);
798 ASSERT_NE(path, nullptr);
799 float u16PathLen = OH_Drawing_PathGetLength(path, false);
800
801 const char32_t* u32str = U"Hello 中文";
802 size_t u32strLen = std::char_traits<char32_t>::length(u32str);
803 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, u32str, sizeof(char32_t) * u32strLen, TEXT_ENCODING_UTF32, x, y, path),
804 OH_DRAWING_SUCCESS);
805 ASSERT_NE(path, nullptr);
806 float u32PathLen = OH_Drawing_PathGetLength(path, false);
807 ASSERT_TRUE(u16PathLen > 0 && u32PathLen > 0);
808 ASSERT_EQ(u16PathLen, u32PathLen);
809 if (path != nullptr) {
810 OH_Drawing_PathDestroy(path);
811 }
812 OH_Drawing_FontDestroy(font);
813 }
814
815 /*
816 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontGetTextPath_003
817 * @tc.name : FontGetTextPath003
818 * @tc.desc : test for space character of textpath
819 * @tc.size : MediumTest
820 * @tc.type : Function
821 * @tc.level : Level 0
822 */
823 HWTEST_F(NativeFontTest, FontGetTextPath003, Function | MediumTest | Level0)
824 {
825 OH_Drawing_Font* font = OH_Drawing_FontCreate();
826 EXPECT_NE(font, nullptr);
827 const char* space = " ";
828 size_t length = std::char_traits<char>::length(space);
829 float x = 12.0f;
830 float y = 150.0f;
831 OH_Drawing_Path* path = OH_Drawing_PathCreate();
832 ASSERT_NE(path, nullptr);
833 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, space, sizeof(char) * length, TEXT_ENCODING_UTF8, x, y, path),
834 OH_DRAWING_SUCCESS);
835 ASSERT_NE(path, nullptr);
836 EXPECT_TRUE(OH_Drawing_PathGetLength(path, false) == 0);
837 EXPECT_FALSE(OH_Drawing_PathIsClosed(path, false));
838 if (path != nullptr) {
839 OH_Drawing_PathDestroy(path);
840 }
841 OH_Drawing_FontDestroy(font);
842 }
843
844 /*
845 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontGetTextPath_004
846 * @tc.name : FontGetTextPath004
847 * @tc.desc : test for negative coordinates of textpath
848 * @tc.size : MediumTest
849 * @tc.type : Function
850 * @tc.level : Level 0
851 */
852 HWTEST_F(NativeFontTest, FontGetTextPath004, Function | MediumTest | Level0)
853 {
854 OH_Drawing_Font* font = OH_Drawing_FontCreate();
855 EXPECT_NE(font, nullptr);
856 const char* str = "Hello 中文";
857 size_t length = std::char_traits<char>::length(str);
858 float x = -1.0f;
859 float y = -1.0f;
860 OH_Drawing_Path* path = OH_Drawing_PathCreate();
861 ASSERT_NE(path, nullptr);
862 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, str, sizeof(char) * length, TEXT_ENCODING_UTF8, x, y, path),
863 OH_DRAWING_SUCCESS);
864 ASSERT_NE(path, nullptr);
865 if (path != nullptr) {
866 EXPECT_TRUE(OH_Drawing_PathGetLength(path, false) > 0);
867 OH_Drawing_PathDestroy(path);
868 }
869 OH_Drawing_FontDestroy(font);
870 }
871
872 /*
873 * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_FontGetTextPath_005
874 * @tc.name : FontGetTextPath005
875 * @tc.desc : test for conversion of glyphsID to path
876 * @tc.size : MediumTest
877 * @tc.type : Function
878 * @tc.level : Level 0
879 */
880 HWTEST_F(NativeFontTest, FontGetTextPath005, Function | MediumTest | Level0)
881 {
882 OH_Drawing_Font* font = OH_Drawing_FontCreate();
883 EXPECT_NE(font, nullptr);
884 const char* str = "Hello 中文";
885 uint32_t count = 0;
886 count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8);
887 EXPECT_NE(count, 0);
888 uint16_t glyphs[count];
889 OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count);
890
891 float x = 12.0f;
892 float y = 150.0f;
893 OH_Drawing_Path* path = OH_Drawing_PathCreate();
894 ASSERT_NE(path, nullptr);
895 EXPECT_EQ(OH_Drawing_FontGetTextPath(font, glyphs, sizeof(glyphs), TEXT_ENCODING_GLYPH_ID, x, y, path),
896 OH_DRAWING_SUCCESS);
897 ASSERT_NE(path, nullptr);
898 if (path != nullptr) {
899 EXPECT_TRUE(OH_Drawing_PathGetLength(path, false) > 0);
900 OH_Drawing_PathDestroy(path);
901 }
902 OH_Drawing_FontDestroy(font);
903 }
904 } // namespace Drawing
905 } // namespace Rosen
906 } // namespace OHOS