1 /* 2 * Copyright (c) 2023 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 <texgine/system_font_provider.h> 17 #include <texgine/typography_builder.h> 18 19 #include "feature_test_framework.h" 20 21 using namespace OHOS::Rosen::TextEngine; 22 23 namespace { 24 struct TestInfo { 25 std::string title; 26 std::string text = "华为鸿蒙系统是一款全新的面向全场景的分布式操作系统,创造一个超级虚拟终端互联的世界。"; 27 TextStyle style; 28 } g_testInfos[] = { 29 { 30 .title = "default", 31 .style = { 32 } 33 }, 34 { 35 .title = "italic", 36 .style = { 37 .fontStyle = FontStyle::ITALIC, 38 } 39 }, 40 { 41 .title = "W100 thin", 42 .style = { 43 .fontWeight = FontWeight::W100, 44 } 45 }, 46 { 47 .title = "W200", 48 .style = { 49 .fontWeight = FontWeight::W200, 50 } 51 }, 52 { 53 .title = "W300", 54 .style = { 55 .fontWeight = FontWeight::W300, 56 } 57 }, 58 { 59 .title = "W400 normal", 60 .style = { 61 .fontWeight = FontWeight::W400, 62 } 63 }, 64 { 65 .title = "W500", 66 .style = { 67 .fontWeight = FontWeight::W500, 68 } 69 }, 70 { 71 .title = "W600", 72 .style = { 73 .fontWeight = FontWeight::W600, 74 } 75 }, 76 { 77 .title = "W700 bold", 78 .style = { 79 .fontWeight = FontWeight::W700, 80 } 81 }, 82 { 83 .title = "W800", 84 .style = { 85 .fontWeight = FontWeight::W800, 86 } 87 }, 88 { 89 .title = "W900", 90 .style = { 91 .fontWeight = FontWeight::W900, 92 } 93 }, 94 { 95 .title = "W700 bold", 96 .style = { 97 .fontWeight = FontWeight::W700, 98 .fontStyle = FontStyle::ITALIC, 99 } 100 }, 101 }; 102 103 class WeightStyleTest : public TestFeature { 104 public: WeightStyleTest()105 WeightStyleTest() : TestFeature("WeightStyleTest") 106 { 107 } 108 Layout()109 void Layout() 110 { 111 for (auto &[title, text, style] : g_testInfos) { 112 auto builder = TypographyBuilder::Create(); 113 builder->PushStyle(style); 114 builder->AppendSpan(text); 115 116 auto typography = builder->Build(); 117 typography->Layout(200); // 200 means layout width 118 typographies_.push_back({ 119 .typography = typography, 120 .comment = title, 121 }); 122 } 123 } 124 } g_test; 125 } // namespace 126