1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, Hardware 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "gtest/gtest.h" 17f6603c60Sopenharmony_ci#include "drawing_brush.h" 18f6603c60Sopenharmony_ci#include "drawing_font.h" 19f6603c60Sopenharmony_ci#include "drawing_point.h" 20f6603c60Sopenharmony_ci#include "drawing_text_typography.h" 21f6603c60Sopenharmony_ci#include "drawing_font_collection.h" 22f6603c60Sopenharmony_ci 23f6603c60Sopenharmony_ciusing namespace testing; 24f6603c60Sopenharmony_ciusing namespace testing::ext; 25f6603c60Sopenharmony_ci 26f6603c60Sopenharmony_cinamespace OHOS { 27f6603c60Sopenharmony_cinamespace Rosen { 28f6603c60Sopenharmony_cinamespace Drawing { 29f6603c60Sopenharmony_ciclass NativeFontTest : public testing::Test { 30f6603c60Sopenharmony_cipublic: 31f6603c60Sopenharmony_ci static void SetUpTestCase(); 32f6603c60Sopenharmony_ci static void TearDownTestCase(); 33f6603c60Sopenharmony_ci void SetUp() override; 34f6603c60Sopenharmony_ci void TearDown() override; 35f6603c60Sopenharmony_ci}; 36f6603c60Sopenharmony_ci 37f6603c60Sopenharmony_civoid NativeFontTest::SetUpTestCase() {} 38f6603c60Sopenharmony_civoid NativeFontTest::TearDownTestCase() {} 39f6603c60Sopenharmony_civoid NativeFontTest::SetUp() {} 40f6603c60Sopenharmony_civoid NativeFontTest::TearDown() {} 41f6603c60Sopenharmony_ci 42f6603c60Sopenharmony_ci/* 43f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetMetrics001 44f6603c60Sopenharmony_ci * @tc.desc: test for GetMetrics. 45f6603c60Sopenharmony_ci * @tc.size : MediumTest 46f6603c60Sopenharmony_ci * @tc.type : Function 47f6603c60Sopenharmony_ci * @tc.level : Level 1 48f6603c60Sopenharmony_ci */ 49f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetMetrics001, TestSize.Level1) 50f6603c60Sopenharmony_ci{ 51f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 52f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 53f6603c60Sopenharmony_ci OH_Drawing_Font_Metrics cFontMetrics; 54f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetMetrics(font, &cFontMetrics) >= 0); 55f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetMetrics(font, nullptr) < 0); 56f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetMetrics(nullptr, nullptr) < 0); 57f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 58f6603c60Sopenharmony_ci} 59f6603c60Sopenharmony_ci 60f6603c60Sopenharmony_ci/* 61f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_IsAndSetBaselineSnap002 62f6603c60Sopenharmony_ci * @tc.desc: test for SetBaselineSnap and IsBaselineSnap. 63f6603c60Sopenharmony_ci * @tc.size : MediumTest 64f6603c60Sopenharmony_ci * @tc.type : Function 65f6603c60Sopenharmony_ci * @tc.level : Level 1 66f6603c60Sopenharmony_ci */ 67f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_IsAndSetBaselineSnap002, TestSize.Level1) 68f6603c60Sopenharmony_ci{ 69f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 70f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 71f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(nullptr, true); 72f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsBaselineSnap(nullptr), false); 73f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(nullptr, false); 74f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsBaselineSnap(nullptr), false); 75f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(font, true); 76f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsBaselineSnap(font), true); 77f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(font, false); 78f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsBaselineSnap(font), false); 79f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 80f6603c60Sopenharmony_ci} 81f6603c60Sopenharmony_ci 82f6603c60Sopenharmony_ci/* 83f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_IsAndSetSubpixel003 84f6603c60Sopenharmony_ci * @tc.desc: test for SetSubpixel and IsSubpixel. 85f6603c60Sopenharmony_ci * @tc.size : MediumTest 86f6603c60Sopenharmony_ci * @tc.type : Function 87f6603c60Sopenharmony_ci * @tc.level : Level 1 88f6603c60Sopenharmony_ci */ 89f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_IsAndSetSubpixel003, TestSize.Level1) 90f6603c60Sopenharmony_ci{ 91f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 92f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 93f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(nullptr, false); 94f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsSubpixel(nullptr), false); 95f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(nullptr, true); 96f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsSubpixel(nullptr), false); 97f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(font, true); 98f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsSubpixel(font), true); 99f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(font, false); 100f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsSubpixel(font), false); 101f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 102f6603c60Sopenharmony_ci} 103f6603c60Sopenharmony_ci 104f6603c60Sopenharmony_ci/* 105f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_TextToGlyphs004 106f6603c60Sopenharmony_ci * @tc.desc: test for TextToGlyphs. 107f6603c60Sopenharmony_ci * @tc.size : MediumTest 108f6603c60Sopenharmony_ci * @tc.type : Function 109f6603c60Sopenharmony_ci * @tc.level : Level 1 110f6603c60Sopenharmony_ci */ 111f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_TextToGlyphs004, TestSize.Level1) 112f6603c60Sopenharmony_ci{ 113f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 114f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 100); // 100 means font text size 115f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 116f6603c60Sopenharmony_ci const char *str = "hello world"; 117f6603c60Sopenharmony_ci uint32_t count = 0; 118f6603c60Sopenharmony_ci count = OH_Drawing_FontCountText(font, str, strlen(str), OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8); 119f6603c60Sopenharmony_ci EXPECT_EQ(11, count); // 11 means str length 120f6603c60Sopenharmony_ci 121f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 122f6603c60Sopenharmony_ci int glyphsCount = 0; 123f6603c60Sopenharmony_ci glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, 0, 124f6603c60Sopenharmony_ci OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8, glyphs, 0); 125f6603c60Sopenharmony_ci EXPECT_EQ(0, glyphsCount); 126f6603c60Sopenharmony_ci 127f6603c60Sopenharmony_ci glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), 128f6603c60Sopenharmony_ci OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8, glyphs, count); 129f6603c60Sopenharmony_ci EXPECT_EQ(11, glyphsCount); // 11 means glyphsCount 130f6603c60Sopenharmony_ci 131f6603c60Sopenharmony_ci float widths[50] = {0.f}; // 50 means widths array number 132f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, widths); 133f6603c60Sopenharmony_ci EXPECT_EQ(58.0, widths[0]); // 58.0 means glyphs[0] width 134f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 135f6603c60Sopenharmony_ci} 136f6603c60Sopenharmony_ci 137f6603c60Sopenharmony_ci/* 138f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_SetAndGetScaleX005 139f6603c60Sopenharmony_ci * @tc.desc: test for SetAndGetScaleX. 140f6603c60Sopenharmony_ci * @tc.size : MediumTest 141f6603c60Sopenharmony_ci * @tc.type : Function 142f6603c60Sopenharmony_ci * @tc.level : Level 1 143f6603c60Sopenharmony_ci */ 144f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_SetAndGetScaleX005, TestSize.Level1) 145f6603c60Sopenharmony_ci{ 146f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 147f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 148f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(nullptr, 2); 149f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetScaleX(nullptr) == -1); 150f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetScaleX(font) == 1); 151f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, 2); 152f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetScaleX(font) == 2); 153f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 154f6603c60Sopenharmony_ci} 155f6603c60Sopenharmony_ci 156f6603c60Sopenharmony_ci/* 157f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetAndSetEdging006 158f6603c60Sopenharmony_ci * @tc.desc: test for GetAndSetEdging. 159f6603c60Sopenharmony_ci * @tc.size : MediumTest 160f6603c60Sopenharmony_ci * @tc.type : Function 161f6603c60Sopenharmony_ci * @tc.level : Level 1 162f6603c60Sopenharmony_ci */ 163f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetAndSetEdging006, TestSize.Level1) 164f6603c60Sopenharmony_ci{ 165f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 166f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 167f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(font), OH_Drawing_FontEdging::FONT_EDGING_ANTI_ALIAS); 168f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(nullptr), OH_Drawing_FontEdging::FONT_EDGING_ALIAS); 169f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(nullptr, OH_Drawing_FontEdging::FONT_EDGING_ALIAS); 170f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(font), OH_Drawing_FontEdging::FONT_EDGING_ANTI_ALIAS); 171f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(font, OH_Drawing_FontEdging::FONT_EDGING_ALIAS); 172f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(font), OH_Drawing_FontEdging::FONT_EDGING_ALIAS); 173f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(font, OH_Drawing_FontEdging::FONT_EDGING_ANTI_ALIAS); 174f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(font), OH_Drawing_FontEdging::FONT_EDGING_ANTI_ALIAS); 175f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(font, OH_Drawing_FontEdging::FONT_EDGING_SUBPIXEL_ANTI_ALIAS); 176f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontGetEdging(font), OH_Drawing_FontEdging::FONT_EDGING_SUBPIXEL_ANTI_ALIAS); 177f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 178f6603c60Sopenharmony_ci} 179f6603c60Sopenharmony_ci 180f6603c60Sopenharmony_ci/* 181f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetAndSetForceAutoHinting007 182f6603c60Sopenharmony_ci * @tc.desc: test for GetAndSetForceAutoHinting. 183f6603c60Sopenharmony_ci * @tc.size : MediumTest 184f6603c60Sopenharmony_ci * @tc.type : Function 185f6603c60Sopenharmony_ci * @tc.level : Level 1 186f6603c60Sopenharmony_ci */ 187f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetAndSetForceAutoHinting007, TestSize.Level1) 188f6603c60Sopenharmony_ci{ 189f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 190f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 191f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsForceAutoHinting(nullptr), false); 192f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(nullptr, true); 193f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsForceAutoHinting(font), false); 194f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(font, true); 195f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsForceAutoHinting(font), true); 196f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(font, false); 197f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_FontIsForceAutoHinting(font), false); 198f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 199f6603c60Sopenharmony_ci} 200f6603c60Sopenharmony_ci 201f6603c60Sopenharmony_ci/* 202f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetAndSetHinting008 203f6603c60Sopenharmony_ci * @tc.desc: test for GetHinting and SetHinting. 204f6603c60Sopenharmony_ci * @tc.size : MediumTest 205f6603c60Sopenharmony_ci * @tc.type : Function 206f6603c60Sopenharmony_ci * @tc.level : Level 1 207f6603c60Sopenharmony_ci */ 208f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetAndSetHinting008, TestSize.Level1) 209f6603c60Sopenharmony_ci{ 210f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 211f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 212f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetHinting(nullptr) == OH_Drawing_FontHinting::FONT_HINTING_NONE); 213f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(font, OH_Drawing_FontHinting::FONT_HINTING_NONE); 214f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetHinting(font) == OH_Drawing_FontHinting::FONT_HINTING_NONE); 215f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(font, OH_Drawing_FontHinting::FONT_HINTING_SLIGHT); 216f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetHinting(font) == OH_Drawing_FontHinting::FONT_HINTING_SLIGHT); 217f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(font, OH_Drawing_FontHinting::FONT_HINTING_SLIGHT); 218f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetHinting(font) == OH_Drawing_FontHinting::FONT_HINTING_SLIGHT); 219f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 220f6603c60Sopenharmony_ci} 221f6603c60Sopenharmony_ci 222f6603c60Sopenharmony_ci/* 223f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetAndSetEmbeddedBitmaps009 224f6603c60Sopenharmony_ci * @tc.desc: test for GetEmbeddedBitmaps and SetEmbeddedBitmaps. 225f6603c60Sopenharmony_ci * @tc.size : MediumTest 226f6603c60Sopenharmony_ci * @tc.type : Function 227f6603c60Sopenharmony_ci * @tc.level : Level 1 228f6603c60Sopenharmony_ci */ 229f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetAndSetEmbeddedBitmaps009, TestSize.Level1) 230f6603c60Sopenharmony_ci{ 231f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 232f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 233f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontIsEmbeddedBitmaps(nullptr) == false); 234f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(font, true); 235f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontIsEmbeddedBitmaps(font) == true); 236f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(font, false); 237f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontIsEmbeddedBitmaps(font) == false); 238f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 239f6603c60Sopenharmony_ci} 240f6603c60Sopenharmony_ci 241f6603c60Sopenharmony_ci/* 242f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetTextSize010 243f6603c60Sopenharmony_ci * @tc.desc: test for GetTextSize. 244f6603c60Sopenharmony_ci * @tc.size : MediumTest 245f6603c60Sopenharmony_ci * @tc.type : Function 246f6603c60Sopenharmony_ci * @tc.level : Level 1 247f6603c60Sopenharmony_ci */ 248f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetTextSize010, TestSize.Level1) 249f6603c60Sopenharmony_ci{ 250f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 251f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 252f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 100); 253f6603c60Sopenharmony_ci float size = OH_Drawing_FontGetTextSize(font); 254f6603c60Sopenharmony_ci EXPECT_EQ(size, 100); 255f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 256f6603c60Sopenharmony_ci} 257f6603c60Sopenharmony_ci 258f6603c60Sopenharmony_ci/* 259f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_GetTextSkewX011 260f6603c60Sopenharmony_ci * @tc.desc: test for GetTextSkewX. 261f6603c60Sopenharmony_ci * @tc.size : MediumTest 262f6603c60Sopenharmony_ci * @tc.type : Function 263f6603c60Sopenharmony_ci * @tc.level : Level 1 264f6603c60Sopenharmony_ci */ 265f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_GetTextSkewX011, TestSize.Level1) 266f6603c60Sopenharmony_ci{ 267f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 268f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 269f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, 10); 270f6603c60Sopenharmony_ci float size = OH_Drawing_FontGetTextSkewX(font); 271f6603c60Sopenharmony_ci EXPECT_EQ(size, 10); 272f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 273f6603c60Sopenharmony_ci} 274f6603c60Sopenharmony_ci 275f6603c60Sopenharmony_ci/* 276f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_IsLinearText012 277f6603c60Sopenharmony_ci * @tc.desc: test for IsLinearText. 278f6603c60Sopenharmony_ci * @tc.size : MediumTest 279f6603c60Sopenharmony_ci * @tc.type : Function 280f6603c60Sopenharmony_ci * @tc.level : Level 1 281f6603c60Sopenharmony_ci */ 282f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_IsLinearText012, TestSize.Level1) 283f6603c60Sopenharmony_ci{ 284f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 285f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 286f6603c60Sopenharmony_ci bool ret = OH_Drawing_FontIsLinearText(font); 287f6603c60Sopenharmony_ci EXPECT_EQ(ret, false); 288f6603c60Sopenharmony_ci OH_Drawing_FontSetLinearText(font, true); 289f6603c60Sopenharmony_ci ret = OH_Drawing_FontIsLinearText(font); 290f6603c60Sopenharmony_ci EXPECT_EQ(ret, true); 291f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 292f6603c60Sopenharmony_ci} 293f6603c60Sopenharmony_ci 294f6603c60Sopenharmony_ci/* 295f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_SetFakeBoldText013 296f6603c60Sopenharmony_ci * @tc.desc: test for SetFakeBoldText. 297f6603c60Sopenharmony_ci * @tc.size : MediumTest 298f6603c60Sopenharmony_ci * @tc.type : Function 299f6603c60Sopenharmony_ci * @tc.level : Level 1 300f6603c60Sopenharmony_ci */ 301f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_SetFakeBoldText013, TestSize.Level1) 302f6603c60Sopenharmony_ci{ 303f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 304f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 305f6603c60Sopenharmony_ci bool ret = OH_Drawing_FontIsFakeBoldText(font); 306f6603c60Sopenharmony_ci EXPECT_EQ(ret, false); 307f6603c60Sopenharmony_ci OH_Drawing_FontSetFakeBoldText(font, true); 308f6603c60Sopenharmony_ci ret = OH_Drawing_FontIsFakeBoldText(font); 309f6603c60Sopenharmony_ci EXPECT_EQ(ret, true); 310f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 311f6603c60Sopenharmony_ci} 312f6603c60Sopenharmony_ci 313f6603c60Sopenharmony_ci/* 314f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_FontMeasureText014 315f6603c60Sopenharmony_ci * @tc.desc: test for FontMeasureText. 316f6603c60Sopenharmony_ci * @tc.type: FUNC 317f6603c60Sopenharmony_ci * @tc.require: AR000GTO5R 318f6603c60Sopenharmony_ci */ 319f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText014, TestSize.Level1) 320f6603c60Sopenharmony_ci{ 321f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 322f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 323f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 50); 324f6603c60Sopenharmony_ci const char* str = "hello world"; 325f6603c60Sopenharmony_ci float textWidth = 0.f; 326f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 327f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureText(nullptr, str, strlen(str), 328f6603c60Sopenharmony_ci OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8, nullptr, &textWidth); 329f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 330f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 331f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureText(font, str, 0, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8, 332f6603c60Sopenharmony_ci nullptr, &textWidth); 333f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 334f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 335f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureText(font, str, strlen(str), OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8, 336f6603c60Sopenharmony_ci nullptr, &textWidth); 337f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 338f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 254.0); // 254.0 is textWidth 339f6603c60Sopenharmony_ci 340f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 341f6603c60Sopenharmony_ci} 342f6603c60Sopenharmony_ci 343f6603c60Sopenharmony_ci 344f6603c60Sopenharmony_ci/* 345f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_FontMeasureText015 346f6603c60Sopenharmony_ci * @tc.desc: test for the textbox. 347f6603c60Sopenharmony_ci * @tc.type: FUNC 348f6603c60Sopenharmony_ci */ 349f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText015, TestSize.Level1) 350f6603c60Sopenharmony_ci{ 351f6603c60Sopenharmony_ci OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle(); 352f6603c60Sopenharmony_ci OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, 353f6603c60Sopenharmony_ci OH_Drawing_CreateFontCollection()); 354f6603c60Sopenharmony_ci OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler); 355f6603c60Sopenharmony_ci OH_Drawing_TextBox* textBox = OH_Drawing_TypographyGetRectsForPlaceholders(typography); 356f6603c60Sopenharmony_ci EXPECT_EQ(textBox == nullptr, false); 357f6603c60Sopenharmony_ci OH_Drawing_DestroyTypographyStyle(typoStyle); 358f6603c60Sopenharmony_ci OH_Drawing_DestroyTypographyHandler(handler); 359f6603c60Sopenharmony_ci OH_Drawing_DestroyTypography(typography); 360f6603c60Sopenharmony_ci OH_Drawing_TypographyDestroyTextBox(textBox); 361f6603c60Sopenharmony_ci} 362f6603c60Sopenharmony_ci 363f6603c60Sopenharmony_ci/* 364f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_FontMeasureText016 365f6603c60Sopenharmony_ci * @tc.desc: test for the textshadow. 366f6603c60Sopenharmony_ci * @tc.type: FUNC 367f6603c60Sopenharmony_ci */ 368f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText016, TestSize.Level1) 369f6603c60Sopenharmony_ci{ 370f6603c60Sopenharmony_ci OH_Drawing_TextShadow* shadow = OH_Drawing_CreateTextShadow(); 371f6603c60Sopenharmony_ci uint32_t color = 0; 372f6603c60Sopenharmony_ci OH_Drawing_Point* offset = OH_Drawing_PointCreate(0, 0); 373f6603c60Sopenharmony_ci double blurRadius = 0.0; 374f6603c60Sopenharmony_ci OH_Drawing_SetTextShadow(shadow, color, offset, blurRadius); 375f6603c60Sopenharmony_ci OH_Drawing_DestroyTextShadow(shadow); 376f6603c60Sopenharmony_ci OH_Drawing_PointDestroy(offset); 377f6603c60Sopenharmony_ci EXPECT_TRUE(shadow != nullptr); 378f6603c60Sopenharmony_ci} 379f6603c60Sopenharmony_ci 380f6603c60Sopenharmony_ci/* 381f6603c60Sopenharmony_ci * @tc.name: NativeFontTest_FontMeasureText017 382f6603c60Sopenharmony_ci * @tc.desc: test for the fontVariation. 383f6603c60Sopenharmony_ci * @tc.type: FUNC 384f6603c60Sopenharmony_ci */ 385f6603c60Sopenharmony_ciHWTEST_F(NativeFontTest, NativeFontTest_FontMeasureText017, TestSize.Level1) 386f6603c60Sopenharmony_ci{ 387f6603c60Sopenharmony_ci OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle(); 388f6603c60Sopenharmony_ci EXPECT_EQ(txtStyle == nullptr, false); 389f6603c60Sopenharmony_ci const char* key = "宋体"; 390f6603c60Sopenharmony_ci int value = 1; 391f6603c60Sopenharmony_ci OH_Drawing_TextStyleAddFontFeature(txtStyle, key, value); 392f6603c60Sopenharmony_ci OH_Drawing_TextStyleAddFontVariation(txtStyle, key, value); 393f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_TextStyleGetFontFeatureSize(txtStyle), 1); 394f6603c60Sopenharmony_ci OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection(); 395f6603c60Sopenharmony_ci OH_Drawing_ClearFontCaches(fontCollection); 396f6603c60Sopenharmony_ci EXPECT_EQ(fontCollection == nullptr, false); 397f6603c60Sopenharmony_ci OH_Drawing_DestroyFontCollection(fontCollection); 398f6603c60Sopenharmony_ci OH_Drawing_DestroyTextStyle(txtStyle); 399f6603c60Sopenharmony_ci} 400f6603c60Sopenharmony_ci 401f6603c60Sopenharmony_ci} // namespace Drawing 402f6603c60Sopenharmony_ci} // namespace Rosen 403f6603c60Sopenharmony_ci} // namespace OHOS