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 Info { 25 TextStyle style; 26 std::string textContent; 27 std::string title; 28 } g_infos[] = { 29 { 30 .textContent = "0xff000000", 31 .title = "default", 32 }, 33 { 34 .style = { .color = 0xffff0000 }, 35 .textContent = "0xffff0000", 36 .title = "不透明 红色", 37 }, 38 { 39 .style = { .color = 0xff00ffff }, 40 .textContent = "0xff00ffff", 41 .title = "不透明 绿色", 42 }, 43 { 44 .style = { .color = 0x77ff0000 }, 45 .textContent = "0x77ff0000", 46 .title = "透明 红色", 47 }, 48 { 49 .style = { .color = 0x7700ff00 }, 50 .textContent = "0x7700ff00", 51 .title = "透明 绿色", 52 } 53 }; 54 55 class TextColorTest : public TestFeature { 56 public: TextColorTest()57 TextColorTest() : TestFeature("TextColorTest") 58 { 59 } 60 Layout()61 void Layout() 62 { 63 for (auto &info : g_infos) { 64 auto builder = TypographyBuilder::Create(); 65 builder->PushStyle(info.style); 66 builder->AppendSpan(info.textContent); 67 68 auto typography = builder->Build(); 69 typography->Layout(200); // 200 means layout width 70 typographies_.push_back({ 71 .typography = typography 72 }); 73 } 74 } 75 } g_test; 76 } // namespace 77