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 StyledText { 25 std::string text; 26 TextStyle style; 27 } g_texts[] = { 28 { 29 .text = "Decoration对照", 30 .style = {}, 31 }, 32 { 33 .text = "Decoration上划线", 34 .style = { 35 .decoration = TextDecoration::OVERLINE, 36 }, 37 }, 38 { 39 .text = "Decoration删除线", 40 .style = { 41 .decoration = TextDecoration::LINE_THROUGH, 42 }, 43 }, 44 { 45 .text = "Decoration下划线", 46 .style = { 47 .decoration = TextDecoration::UNDERLINE, 48 }, 49 }, 50 { 51 .text = "Decoration两两混合1", 52 .style = { 53 .decoration = TextDecoration::OVERLINE | 54 TextDecoration::LINE_THROUGH, 55 }, 56 }, 57 { 58 .text = "Decoration两两混合2", 59 .style = { 60 .decoration = TextDecoration::OVERLINE | 61 TextDecoration::UNDERLINE, 62 }, 63 }, 64 { 65 .text = "Decoration两两混合3", 66 .style = { 67 .decoration = TextDecoration::LINE_THROUGH | 68 TextDecoration::UNDERLINE, 69 }, 70 }, 71 { 72 .text = "Decoration全混合", 73 .style = { 74 .decoration = TextDecoration::OVERLINE | 75 TextDecoration::LINE_THROUGH | 76 TextDecoration::UNDERLINE, 77 }, 78 }, 79 { 80 .text = "Decoration实下滑线", 81 .style = { 82 .decoration = TextDecoration::UNDERLINE, 83 .decorationStyle = TextDecorationStyle::SOLID, 84 }, 85 }, 86 { 87 .text = "Decoration虚下滑线", 88 .style = { 89 .decoration = TextDecoration::UNDERLINE, 90 .decorationStyle = TextDecorationStyle::DASHED, 91 }, 92 }, 93 { 94 .text = "Decoration点下滑线", 95 .style = { 96 .decoration = TextDecoration::UNDERLINE, 97 .decorationStyle = TextDecorationStyle::DOTTED, 98 }, 99 }, 100 { 101 .text = "Decoration波浪下滑线", 102 .style = { 103 .decoration = TextDecoration::UNDERLINE, 104 .decorationStyle = TextDecorationStyle::WAVY, 105 }, 106 }, 107 { 108 .text = "Decoration双实下滑线", 109 .style = { 110 .decoration = TextDecoration::UNDERLINE, 111 .decorationStyle = TextDecorationStyle::DOUBLE, 112 }, 113 }, 114 { 115 .text = "Decoration粗下滑线", 116 .style = { 117 .decoration = TextDecoration::UNDERLINE, 118 .decorationThicknessScale = 5.0f, 119 }, 120 }, 121 { 122 .text = "Decoration红下划线", 123 .style = { 124 .decoration = TextDecoration::UNDERLINE, 125 .decorationColor = 0xffff0000, 126 }, 127 }, 128 }; 129 130 class DecorationTest : public TestFeature { 131 public: DecorationTest()132 DecorationTest() : TestFeature("DecorationTest") 133 { 134 } 135 Layout()136 void Layout() 137 { 138 option_.needBorder = false; 139 140 TypographyStyle tStyle; 141 for (auto &[text, style] : g_texts) { 142 auto builder = TypographyBuilder::Create(tStyle); 143 builder->PushStyle(style); 144 builder->AppendSpan(text); 145 auto typography = builder->Build(); 146 double widthLimit = 200.0; 147 typography->Layout(widthLimit); 148 typographies_.push_back({ 149 .typography = typography, 150 }); 151 } 152 } 153 } g_test; 154 } // namespace 155