• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <securec.h>
17 
18 #include "drawing_brush.h"
19 #include "drawing_font_collection.h"
20 #include "drawing_pen.h"
21 #include "drawing_point.h"
22 #include "drawing_text_typography.h"
23 #include "gtest/gtest.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace {
29 constexpr static float FLOAT_DATA_EPSILON = 1e-6f;
30 const double DOUBLE_TEST_SIZE_NOT_DEFAULT = 20.0;
31 const float FLOAT_TEST_SIZE_NOT_DEFAULT = 10.0f;
32 const int INT_TEST_SIZE_NOT_DEFAULT = 2;
33 
34 } // namespace
35 class NDKTextStyleCopyTest : public testing::Test {
36 public:
37     void TearDown() override;
38 
39 protected:
40     OH_Drawing_FontCollection* fontCollection_ {nullptr};
41     OH_Drawing_TextStyle* txtStyle_ {nullptr};
42     OH_Drawing_TypographyCreate* handler_ {nullptr};
43     OH_Drawing_Typography* typography_ {nullptr};
44     OH_Drawing_TypographyStyle* typoStyle_ {nullptr};
45 
46     OH_Drawing_TextStyle* txtStyleCopy_ {nullptr};
47     OH_Drawing_TypographyStyle* typoStyleCopy_ {nullptr};
48 };
49 
TearDown()50 void NDKTextStyleCopyTest::TearDown()
51 {
52     if (fontCollection_ != nullptr) {
53         OH_Drawing_DestroyFontCollection(fontCollection_);
54         fontCollection_ = nullptr;
55     }
56     if (txtStyle_ != nullptr) {
57         OH_Drawing_DestroyTextStyle(txtStyle_);
58         txtStyle_ = nullptr;
59     }
60     if (handler_ != nullptr) {
61         OH_Drawing_DestroyTypographyHandler(handler_);
62         handler_ = nullptr;
63     }
64     if (typography_ != nullptr) {
65         OH_Drawing_DestroyTypography(typography_);
66         typography_ = nullptr;
67     }
68     if (typoStyle_ != nullptr) {
69         OH_Drawing_DestroyTypographyStyle(typoStyle_);
70         typoStyle_ = nullptr;
71     }
72     if (txtStyleCopy_ != nullptr) {
73         OH_Drawing_DestroyTextStyle(txtStyleCopy_);
74         txtStyleCopy_ = nullptr;
75     }
76     if (typoStyleCopy_ != nullptr) {
77         OH_Drawing_DestroyTypographyStyle(typoStyleCopy_);
78         typoStyleCopy_ = nullptr;
79     }
80 }
81 
82 /*
83  * @tc.name: CopyTextStyle001
84  * @tc.desc: test for copy text style:base
85  * @tc.type: FUNC
86  */
87 HWTEST_F(NDKTextStyleCopyTest, CopyTextStyle001, TestSize.Level0)
88 {
89     txtStyle_ = OH_Drawing_CreateTextStyle();
90     ASSERT_NE(txtStyle_, nullptr);
91 
92     OH_Drawing_SetTextStyleColor(txtStyle_, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0xFF));
93     OH_Drawing_SetTextStyleDecorationStyle(txtStyle_, TEXT_DECORATION_STYLE_DOTTED);
94     OH_Drawing_SetTextStyleFontWeight(txtStyle_, FONT_WEIGHT_900);
95     OH_Drawing_SetTextStyleFontStyle(txtStyle_, FONT_STYLE_ITALIC);
96     OH_Drawing_SetTextStyleBaseLine(txtStyle_, TEXT_BASELINE_IDEOGRAPHIC);
97     const char* fontFamilies[] = { "Text", "Text2" };
98     int fontFamiliesNumBefore = 2;
99     OH_Drawing_SetTextStyleFontFamilies(txtStyle_, fontFamiliesNumBefore, fontFamilies);
100     OH_Drawing_SetTextStyleFontSize(txtStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
101     OH_Drawing_SetTextStyleLetterSpacing(txtStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
102     OH_Drawing_SetTextStyleWordSpacing(txtStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
103     OH_Drawing_SetTextStyleFontHeight(txtStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
104     OH_Drawing_SetTextStyleLocale(txtStyle_, "TestLocal");
105     OH_Drawing_TextStyleSetBaselineShift(txtStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
106     OH_Drawing_TextStyleSetPlaceholder(txtStyle_);
107 
108     txtStyleCopy_ = OH_Drawing_CopyTextStyle(txtStyle_);
109     ASSERT_NE(txtStyleCopy_, nullptr);
110 
111     EXPECT_EQ(OH_Drawing_TextStyleGetColor(txtStyleCopy_), 0xFF00FFFF);
112     EXPECT_EQ(OH_Drawing_TextStyleGetDecorationStyle(txtStyleCopy_), TEXT_DECORATION_STYLE_DOTTED);
113     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyleCopy_), FONT_WEIGHT_900);
114     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyleCopy_), FONT_STYLE_ITALIC);
115     EXPECT_EQ(OH_Drawing_TextStyleGetBaseline(txtStyleCopy_), TEXT_BASELINE_IDEOGRAPHIC);
116     size_t fontFamiliesNumAfter;
117     char** fontFamiliesList = OH_Drawing_TextStyleGetFontFamilies(txtStyleCopy_, &fontFamiliesNumAfter);
118     EXPECT_EQ(fontFamiliesNumAfter, fontFamiliesNumBefore);
119     EXPECT_NE(fontFamiliesList, nullptr);
120     EXPECT_NEAR(OH_Drawing_TextStyleGetFontSize(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
121     EXPECT_NEAR(OH_Drawing_TextStyleGetLetterSpacing(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
122     EXPECT_NEAR(OH_Drawing_TextStyleGetWordSpacing(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
123     EXPECT_NEAR(OH_Drawing_TextStyleGetFontHeight(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
124     EXPECT_EQ(std::strcmp(OH_Drawing_TextStyleGetLocale(txtStyleCopy_), "TestLocal"), 0);
125     EXPECT_NEAR(OH_Drawing_TextStyleGetBaselineShift(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
126     EXPECT_TRUE(OH_Drawing_TextStyleIsPlaceholder(txtStyleCopy_));
127     OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, fontFamiliesNumAfter);
128 }
129 
130 /*
131  * @tc.name: CopyTextStyle002
132  * @tc.desc: test for copy text style: FontStyleStruct、AddFontFeature
133  * @tc.type: FUNC
134  */
135 HWTEST_F(NDKTextStyleCopyTest, CopyTextStyle002, TestSize.Level0)
136 {
137     txtStyle_ = OH_Drawing_CreateTextStyle();
138     ASSERT_NE(txtStyle_, nullptr);
139 
140     OH_Drawing_FontStyleStruct fontStyle;
141     fontStyle.slant = FONT_STYLE_ITALIC;
142     fontStyle.weight = FONT_WEIGHT_600;
143     fontStyle.width = FONT_WIDTH_EXTRA_EXPANDED;
144     OH_Drawing_SetTextStyleFontStyleStruct(txtStyle_, fontStyle);
145     const char* tag = "frac";
146     const char* tag2 = "test";
147     OH_Drawing_TextStyleAddFontFeature(txtStyle_, tag, INT_TEST_SIZE_NOT_DEFAULT);
148     OH_Drawing_TextStyleAddFontFeature(txtStyle_, tag2, INT_TEST_SIZE_NOT_DEFAULT);
149 
150     txtStyleCopy_ = OH_Drawing_CopyTextStyle(txtStyle_);
151     ASSERT_NE(txtStyleCopy_, nullptr);
152 
153     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(txtStyleCopy_).weight, FONT_WEIGHT_600);
154     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(txtStyleCopy_).slant, FONT_STYLE_ITALIC);
155     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyleStruct(txtStyleCopy_).width, FONT_WIDTH_EXTRA_EXPANDED);
156     EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyleCopy_), 2); // Set 2 font features
157 }
158 
159 /*
160  * @tc.name: CopyTextStyle003
161  * @tc.desc: test for copy text style: brush
162  * @tc.type: FUNC
163  */
164 HWTEST_F(NDKTextStyleCopyTest, CopyTextStyle003, TestSize.Level0)
165 {
166     txtStyle_ = OH_Drawing_CreateTextStyle();
167     ASSERT_NE(txtStyle_, nullptr);
168 
169     OH_Drawing_Brush* backgroundBrush = OH_Drawing_BrushCreate();
170     OH_Drawing_Brush* foregroundBrush = OH_Drawing_BrushCreate();
171     ASSERT_NE(backgroundBrush, nullptr);
172     ASSERT_NE(foregroundBrush, nullptr);
173     OH_Drawing_BrushSetColor(backgroundBrush, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0xFF));
174     OH_Drawing_BrushSetColor(foregroundBrush, OH_Drawing_ColorSetArgb(0xFF, 0x01, 0xFF, 0xFF));
175     OH_Drawing_SetTextStyleBackgroundBrush(txtStyle_, backgroundBrush);
176     OH_Drawing_SetTextStyleForegroundBrush(txtStyle_, foregroundBrush);
177 
178     txtStyleCopy_ = OH_Drawing_CopyTextStyle(txtStyle_);
179     ASSERT_NE(txtStyleCopy_, nullptr);
180 
181     OH_Drawing_Brush* backgroundBrushCopy = OH_Drawing_BrushCreate();
182     OH_Drawing_Brush* foregroundBrushCopy = OH_Drawing_BrushCreate();
183     ASSERT_NE(backgroundBrushCopy, nullptr);
184     ASSERT_NE(foregroundBrushCopy, nullptr);
185     OH_Drawing_TextStyleGetBackgroundBrush(txtStyleCopy_, backgroundBrushCopy);
186     OH_Drawing_TextStyleGetForegroundBrush(txtStyleCopy_, foregroundBrushCopy);
187     EXPECT_EQ(OH_Drawing_BrushGetColor(backgroundBrushCopy), 0xFF00FFFF);
188     EXPECT_EQ(OH_Drawing_BrushGetColor(foregroundBrushCopy), 0xFF01FFFF);
189 
190     // 修改复制之后的brush的color不会影响copy前brush的颜色
191     OH_Drawing_BrushSetColor(backgroundBrushCopy, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
192     EXPECT_EQ(OH_Drawing_BrushGetColor(backgroundBrushCopy), 0xFF000000);
193     EXPECT_EQ(OH_Drawing_BrushGetColor(backgroundBrush), 0xFF00FFFF);
194     OH_Drawing_BrushDestroy(backgroundBrush);
195     OH_Drawing_BrushDestroy(foregroundBrush);
196     OH_Drawing_BrushDestroy(backgroundBrushCopy);
197     OH_Drawing_BrushDestroy(foregroundBrushCopy);
198 }
199 
200 /*
201  * @tc.name: CopyTextStyle004
202  * @tc.desc: test for copy text style: pen
203  * @tc.type: FUNC
204  */
205 HWTEST_F(NDKTextStyleCopyTest, CopyTextStyle004, TestSize.Level0)
206 {
207     txtStyle_ = OH_Drawing_CreateTextStyle();
208     ASSERT_NE(txtStyle_, nullptr);
209 
210     OH_Drawing_Pen* backgroundPen = OH_Drawing_PenCreate();
211     OH_Drawing_Pen* foregroundPen = OH_Drawing_PenCreate();
212     ASSERT_NE(backgroundPen, nullptr);
213     ASSERT_NE(foregroundPen, nullptr);
214     OH_Drawing_PenSetColor(backgroundPen, OH_Drawing_ColorSetArgb(0xFF, 0x02, 0xFF, 0xFF));
215     OH_Drawing_PenSetColor(foregroundPen, OH_Drawing_ColorSetArgb(0xFF, 0x03, 0xFF, 0xFF));
216     OH_Drawing_SetTextStyleBackgroundPen(txtStyle_, backgroundPen);
217     OH_Drawing_SetTextStyleForegroundPen(txtStyle_, foregroundPen);
218 
219     OH_Drawing_CopyTextStyle(nullptr);
220     txtStyleCopy_ = OH_Drawing_CopyTextStyle(txtStyle_);
221     ASSERT_NE(txtStyleCopy_, nullptr);
222 
223     OH_Drawing_Pen* backgroundPenCopy = OH_Drawing_PenCreate();
224     OH_Drawing_Pen* foregroundPenCopy = OH_Drawing_PenCreate();
225     ASSERT_NE(backgroundPenCopy, nullptr);
226     ASSERT_NE(foregroundPenCopy, nullptr);
227     OH_Drawing_TextStyleGetBackgroundPen(txtStyleCopy_, backgroundPenCopy);
228     OH_Drawing_TextStyleGetForegroundPen(txtStyleCopy_, foregroundPenCopy);
229     EXPECT_EQ(OH_Drawing_PenGetColor(backgroundPenCopy), 0xFF02FFFF);
230     EXPECT_EQ(OH_Drawing_PenGetColor(foregroundPenCopy), 0xFF03FFFF);
231 
232     // 修改复制之后的pen的color不会影响copy前pen的颜色
233     OH_Drawing_PenSetColor(backgroundPenCopy, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
234     EXPECT_EQ(OH_Drawing_PenGetColor(backgroundPenCopy), 0xFF000000);
235     EXPECT_EQ(OH_Drawing_PenGetColor(backgroundPen), 0xFF02FFFF);
236     OH_Drawing_PenDestroy(backgroundPen);
237     OH_Drawing_PenDestroy(foregroundPen);
238     OH_Drawing_PenDestroy(backgroundPenCopy);
239     OH_Drawing_PenDestroy(foregroundPenCopy);
240 }
241 
242 /*
243  * @tc.name: CopyTextShadow001
244  * @tc.desc: test for copy text shadow and copy textstyle with shadow
245  * @tc.type: FUNC
246  */
247 HWTEST_F(NDKTextStyleCopyTest, CopyTextShadow001, TestSize.Level0)
248 {
249     OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
250     ASSERT_NE(shadow, nullptr);
251     OH_Drawing_Point* offset = OH_Drawing_PointCreate(FLOAT_TEST_SIZE_NOT_DEFAULT, FLOAT_TEST_SIZE_NOT_DEFAULT);
252     ASSERT_NE(offset, nullptr);
253     double blurRadius = DOUBLE_TEST_SIZE_NOT_DEFAULT;
254     OH_Drawing_SetTextShadow(shadow, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00), offset, blurRadius);
255     OH_Drawing_TextShadow* shadowCopy = OH_Drawing_CopyTextShadow(shadow);
256     OH_Drawing_CopyTextShadow(nullptr);
257     txtStyle_ = OH_Drawing_CreateTextStyle();
258     ASSERT_NE(txtStyle_, nullptr);
259     OH_Drawing_TextStyleAddShadow(txtStyle_, shadow);
260     OH_Drawing_TextStyleAddShadow(txtStyle_, shadowCopy);
261 
262     txtStyleCopy_ = OH_Drawing_CopyTextStyle(txtStyle_);
263     ASSERT_NE(txtStyleCopy_, nullptr);
264     OH_Drawing_TextShadow* shadowsCopy = OH_Drawing_TextStyleGetShadows(txtStyleCopy_);
265     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyleCopy_), OH_Drawing_TextStyleGetShadowCount(txtStyle_));
266     OH_Drawing_PointDestroy(offset);
267     OH_Drawing_DestroyTextShadow(shadow);
268     OH_Drawing_DestroyTextShadow(shadowCopy);
269     OH_Drawing_DestroyTextShadows(shadowsCopy);
270 }
271 
272 /*
273  * @tc.name: CopyTypographStyle001
274  * @tc.desc: test for copy typography style
275  * @tc.type: FUNC
276  */
277 HWTEST_F(NDKTextStyleCopyTest, CopyTypographStyle001, TestSize.Level0)
278 {
279     typoStyle_ = OH_Drawing_CreateTypographyStyle();
280     ASSERT_NE(typoStyle_, nullptr);
281 
282     OH_Drawing_SetTypographyTextFontHeight(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
283     OH_Drawing_SetTypographyTextUseLineStyle(typoStyle_, true);
284     OH_Drawing_SetTypographyTextLineStyleFontWeight(typoStyle_, FONT_WEIGHT_600);
285     OH_Drawing_SetTypographyTextLineStyleFontStyle(typoStyle_, FONT_STYLE_ITALIC);
286     const char* fontFamilies[] = { "Text1", "Text2" };
287     int fontFamiliesNumBefore = 2;
288     OH_Drawing_SetTypographyTextLineStyleFontFamilies(typoStyle_, fontFamiliesNumBefore, fontFamilies);
289     OH_Drawing_SetTypographyTextLineStyleFontSize(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
290     OH_Drawing_SetTypographyTextLineStyleFontHeight(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
291     OH_Drawing_SetTypographyTextLineStyleHalfLeading(typoStyle_, true);
292     OH_Drawing_SetTypographyTextLineStyleSpacingScale(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
293     OH_Drawing_SetTypographyTextLineStyleOnly(typoStyle_, true);
294     OH_Drawing_SetTypographyTextAlign(typoStyle_, TEXT_ALIGN_CENTER);
295     OH_Drawing_SetTypographyTextDirection(typoStyle_, TEXT_DIRECTION_RTL);
296     OH_Drawing_SetTypographyTextMaxLines(typoStyle_, INT_TEST_SIZE_NOT_DEFAULT);
297     OH_Drawing_SetTypographyTextEllipsis(typoStyle_, "...");
298     OH_Drawing_TypographyTextSetHeightBehavior(typoStyle_, TEXT_HEIGHT_DISABLE_LAST_ASCENT);
299     OH_Drawing_TypographyStyleSetHintsEnabled(typoStyle_, true);
300 
301     typoStyleCopy_ = OH_Drawing_CopyTypographyStyle(typoStyle_);
302     ASSERT_NE(typoStyleCopy_, nullptr);
303 
304     EXPECT_TRUE(OH_Drawing_TypographyTextGetLineStyle(typoStyleCopy_));
305     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontWeight(typoStyleCopy_), FONT_WEIGHT_600);
306     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontStyle(typoStyleCopy_), FONT_STYLE_ITALIC);
307     size_t num;
308     char** fontFamiliesList = OH_Drawing_TypographyTextlineStyleGetFontFamilies(typoStyleCopy_, &num);
309     EXPECT_EQ(num, fontFamiliesNumBefore);
310     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetFontSize(typoStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT);
311     EXPECT_TRUE(OH_Drawing_TypographyTextlineStyleGetHeightOnly(typoStyleCopy_));
312     EXPECT_NEAR(OH_Drawing_TypographyTextlineStyleGetHeightScale(typoStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT,
313         FLOAT_DATA_EPSILON);
314     EXPECT_TRUE(OH_Drawing_TypographyTextlineStyleGetHalfLeading(typoStyleCopy_));
315     EXPECT_EQ(OH_Drawing_TypographyTextlineStyleGetSpacingScale(typoStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT);
316     EXPECT_TRUE(OH_Drawing_TypographyTextlineGetStyleOnly(typoStyleCopy_));
317     EXPECT_EQ(OH_Drawing_TypographyGetTextAlign(typoStyleCopy_), TEXT_ALIGN_CENTER);
318     EXPECT_EQ(OH_Drawing_TypographyGetTextDirection(typoStyleCopy_), TEXT_DIRECTION_RTL);
319     EXPECT_EQ(OH_Drawing_TypographyGetTextMaxLines(typoStyleCopy_), INT_TEST_SIZE_NOT_DEFAULT);
320     EXPECT_EQ(std::strcmp(OH_Drawing_TypographyGetTextEllipsis(typoStyleCopy_), "..."), 0);
321     EXPECT_EQ(OH_Drawing_TypographyTextGetHeightBehavior(typoStyleCopy_), TEXT_HEIGHT_DISABLE_LAST_ASCENT);
322     EXPECT_TRUE(OH_Drawing_TypographyStyleIsHintEnabled(typoStyleCopy_));
323     OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, num);
324 }
325 
326 /*
327  * @tc.name: CopyTypographStyle002
328  * @tc.desc: test for copy typography style:FontWeight、FontStyle、FontFamily、FontSize、FontHeight
329  * @tc.type: FUNC
330  */
331 HWTEST_F(NDKTextStyleCopyTest, CopyTypographStyle002, TestSize.Level0)
332 {
333     typoStyle_ = OH_Drawing_CreateTypographyStyle();
334     ASSERT_NE(typoStyle_, nullptr);
335 
336     OH_Drawing_SetTypographyTextFontWeight(typoStyle_, FONT_WEIGHT_900);
337     OH_Drawing_SetTypographyTextFontStyle(typoStyle_, FONT_STYLE_ITALIC);
338     OH_Drawing_SetTypographyTextFontFamily(typoStyle_, "Test");
339     OH_Drawing_SetTypographyTextFontSize(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
340     OH_Drawing_SetTypographyTextFontHeight(typoStyle_, DOUBLE_TEST_SIZE_NOT_DEFAULT);
341 
342     OH_Drawing_CopyTypographyStyle(nullptr);
343     typoStyleCopy_ = OH_Drawing_CopyTypographyStyle(typoStyle_);
344     ASSERT_NE(typoStyleCopy_, nullptr);
345 
346     txtStyleCopy_ = OH_Drawing_TypographyGetTextStyle(typoStyleCopy_);
347     ASSERT_NE(txtStyleCopy_, nullptr);
348     EXPECT_EQ(OH_Drawing_TextStyleGetFontWeight(txtStyleCopy_), FONT_WEIGHT_900);
349     EXPECT_EQ(OH_Drawing_TextStyleGetFontStyle(txtStyleCopy_), FONT_STYLE_ITALIC);
350     size_t fontFamiliesNumAfter;
351     char** fontFamiliesList = OH_Drawing_TextStyleGetFontFamilies(txtStyleCopy_, &fontFamiliesNumAfter);
352     EXPECT_EQ(fontFamiliesNumAfter, 1);
353     EXPECT_NEAR(OH_Drawing_TextStyleGetFontSize(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
354     EXPECT_NEAR(OH_Drawing_TextStyleGetFontHeight(txtStyleCopy_), DOUBLE_TEST_SIZE_NOT_DEFAULT, FLOAT_DATA_EPSILON);
355     OH_Drawing_TextStyleDestroyFontFamilies(fontFamiliesList, fontFamiliesNumAfter);
356 }
357 
358 /*
359  * @tc.name: CopyTypographStyle003
360  * @tc.desc: test for copy typography style: FontStyleStruct
361  * @tc.type: FUNC
362  */
363 HWTEST_F(NDKTextStyleCopyTest, CopyTypographStyle003, TestSize.Level0)
364 {
365     typoStyle_ = OH_Drawing_CreateTypographyStyle();
366     ASSERT_NE(typoStyle_, nullptr);
367     OH_Drawing_FontStyleStruct normalStyle;
368     normalStyle.weight = FONT_WEIGHT_600;
369     normalStyle.width = FONT_WIDTH_EXTRA_EXPANDED;
370     normalStyle.slant = FONT_STYLE_ITALIC;
371     OH_Drawing_SetTypographyStyleFontStyleStruct(typoStyle_, normalStyle);
372 
373     typoStyleCopy_ = OH_Drawing_CopyTypographyStyle(typoStyle_);
374     ASSERT_NE(typoStyleCopy_, nullptr);
375     EXPECT_EQ(OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyleCopy_).weight, FONT_WEIGHT_600);
376     EXPECT_EQ(OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyleCopy_).slant, FONT_STYLE_ITALIC);
377     EXPECT_EQ(OH_Drawing_TypographyStyleGetFontStyleStruct(typoStyleCopy_).width, FONT_WIDTH_EXTRA_EXPANDED);
378 }
379 
380 /*
381  * @tc.name: CopyTypographStyle004
382  * @tc.desc: test for copy text shadow: typographystyle->textstyle->shadow
383  * @tc.type: FUNC
384  */
385 HWTEST_F(NDKTextStyleCopyTest, CopyTypographStyle004, TestSize.Level0)
386 {
387     OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow();
388     ASSERT_NE(shadow, nullptr);
389     OH_Drawing_Point* offset = OH_Drawing_PointCreate(FLOAT_TEST_SIZE_NOT_DEFAULT, FLOAT_TEST_SIZE_NOT_DEFAULT);
390     ASSERT_NE(offset, nullptr);
391     double blurRadius = DOUBLE_TEST_SIZE_NOT_DEFAULT;
392     OH_Drawing_SetTextShadow(shadow, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00), offset, blurRadius);
393     OH_Drawing_TextShadow* shadowCopy = OH_Drawing_CopyTextShadow(shadow);
394     txtStyle_ = OH_Drawing_CreateTextStyle();
395     ASSERT_NE(txtStyle_, nullptr);
396     OH_Drawing_TextStyleAddShadow(txtStyle_, shadow);
397     OH_Drawing_TextStyleAddShadow(txtStyle_, shadow);
398     OH_Drawing_TextStyleAddShadow(txtStyle_, shadowCopy);
399 
400     typoStyle_ = OH_Drawing_CreateTypographyStyle();
401     ASSERT_NE(typoStyle_, nullptr);
402     OH_Drawing_SetTypographyTextStyle(typoStyle_, txtStyle_);
403     typoStyleCopy_ = OH_Drawing_CopyTypographyStyle(typoStyle_);
404     ASSERT_NE(typoStyleCopy_, nullptr);
405 
406     // 接口OH_Drawing_TypographyGetTextStyle与OH_Drawing_SetTypographyTextStyle并不是配套接口。
407     // set的是insideTextstyle,但是get是兜底的textstyle属性。
408     txtStyleCopy_ = OH_Drawing_TypographyGetTextStyle(typoStyleCopy_);
409     ASSERT_NE(txtStyleCopy_, nullptr);
410     OH_Drawing_TextShadow* shadowsCopy = OH_Drawing_TextStyleGetShadows(txtStyleCopy_);
411     ASSERT_NE(shadowsCopy, nullptr);
412     EXPECT_NE(OH_Drawing_TextStyleGetShadowCount(txtStyleCopy_), OH_Drawing_TextStyleGetShadowCount(txtStyle_));
413     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyleCopy_), 0);
414     EXPECT_EQ(OH_Drawing_TextStyleGetShadowCount(txtStyle_), 3); // 3是因为OH_Drawing_TextStyleAddShadow加了三个shadow。
415     OH_Drawing_PointDestroy(offset);
416     OH_Drawing_DestroyTextShadow(shadow);
417     OH_Drawing_DestroyTextShadow(shadowCopy);
418     OH_Drawing_DestroyTextShadows(shadowsCopy);
419 }
420 } // namespace OHOS