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