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 ShadowTestData { 25 std::string text; 26 TextStyle style; 27 } g_datas[] = { 28 { 29 .text = "阴影对照.", 30 .style = {}, 31 }, 32 { 33 .text = "阴影数量1.", 34 .style = { 35 .shadows = { { .offsetX = 4, .offsetY = 4, }, }, 36 }, 37 }, 38 { 39 .text = "阴影数量4.", 40 .style = { 41 .shadows = { 42 { .offsetX = +4, .offsetY = +4, }, 43 { .offsetX = +4, .offsetY = -4, }, 44 { .offsetX = -4, .offsetY = +4, }, 45 { .offsetX = -4, .offsetY = -4, }, 46 }, 47 }, 48 }, 49 { 50 .text = "阴影X偏移量0.", 51 .style = { .shadows = { { .offsetX = 0, }, }, }, 52 }, 53 { 54 .text = "阴影X偏移量15.", 55 .style = { .shadows = { { .offsetX = 15, }, }, }, 56 }, 57 { 58 .text = "阴影X偏移量-15.", 59 .style = { .shadows = { { .offsetX = -15, }, }, }, 60 }, 61 { 62 .text = "阴影Y偏移量0.", 63 .style = { .shadows = { { .offsetY = 0, }, }, }, 64 }, 65 { 66 .text = "阴影Y偏移量15.", 67 .style = { .shadows = { { .offsetY = 15, }, }, }, 68 }, 69 { 70 .text = "阴影Y偏移量-15.", 71 .style = { .shadows = { { .offsetY = -15, }, }, }, 72 }, 73 { 74 .text = "阴影模糊半径0.", 75 .style = { 76 .shadows = { 77 { .offsetX = 2, .offsetY = 2, .color = SK_ColorBLACK, .blurLeave = 0, }, 78 }, 79 }, 80 }, 81 { 82 .text = "阴影模糊半径2.", 83 .style = { 84 .shadows = { 85 { .offsetX = 2, .offsetY = 2, .color = SK_ColorBLACK, .blurLeave = 2, }, 86 }, 87 }, 88 }, 89 { 90 .text = "阴影模糊半径8.", 91 .style = { 92 .shadows = { 93 { .offsetX = 2, .offsetY = 2, .color = SK_ColorBLACK, .blurLeave = 8, }, 94 }, 95 }, 96 }, 97 { 98 .text = "阴影模糊半径32.", 99 .style = { 100 .shadows = { 101 { .offsetX = 2, .offsetY = 2, .color = SK_ColorBLACK, .blurLeave = 32, }, 102 }, 103 }, 104 }, 105 { 106 .text = "阴影颜色红色.", 107 .style = { 108 .shadows = { 109 { .offsetX = 2, .offsetY = 2, .color = SK_ColorRED, }, 110 }, 111 }, 112 }, 113 }; 114 115 class ShadowTest : public TestFeature { 116 public: ShadowTest()117 ShadowTest() : TestFeature("ShadowTest") 118 { 119 } 120 Layout()121 void Layout() 122 { 123 for (auto &[text, style] : g_datas) { 124 auto builder = TypographyBuilder::Create(); 125 builder->PushStyle(style); 126 builder->AppendSpan(text); 127 auto typography = builder->Build(); 128 typography->Layout(300); // 300 means layout width 129 typographies_.push_back({ 130 .typography = typography, 131 }); 132 } 133 } 134 } g_test; 135 } // namespace 136