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 #ifndef ROSEN_SAMPLES_TEXGINE_FEATURE_TEST_FEATURE_TEST_FRAMEWORK_H 17 #define ROSEN_SAMPLES_TEXGINE_FEATURE_TEST_FEATURE_TEST_FRAMEWORK_H 18 19 #include <functional> 20 #include <list> 21 #include <memory> 22 #include <optional> 23 #include <string> 24 25 #include <texgine/typography.h> 26 27 #include "texgine_canvas.h" 28 29 struct FeatureTestOption { 30 // border 31 bool needBorder = true; 32 uint32_t colorBorder = 0xffff0000; // red 33 34 // margin 35 int32_t marginTop = 50; 36 int32_t marginLeft = 50; 37 38 // rainbow char 39 bool needRainbowChar = false; 40 }; 41 42 struct TypographyData { 43 std::shared_ptr<OHOS::Rosen::TextEngine::Typography> typography = nullptr; 44 std::string comment = ""; 45 size_t rainbowStart = 0; 46 size_t rainbowEnd = 1e9; 47 OHOS::Rosen::TextEngine::TextRectWidthStyle ws = OHOS::Rosen::TextEngine::TextRectWidthStyle::TIGHT; 48 OHOS::Rosen::TextEngine::TextRectHeightStyle hs = OHOS::Rosen::TextEngine::TextRectHeightStyle::TIGHT; 49 std::optional<bool> needRainbowChar = std::nullopt; 50 bool atNewline = false; 51 52 std::function<void( 53 const struct TypographyData &, OHOS::Rosen::TextEngine::TexgineCanvas &, double, double)> onPaint = nullptr; 54 }; 55 56 class TestFeature { 57 public: 58 explicit TestFeature(const std::string &testName); 59 virtual ~TestFeature() = default; 60 61 virtual void Layout() = 0; 62 63 /* 64 * @brief Returns the option in the feature test 65 */ GetFeatureTestOption()66 const struct FeatureTestOption &GetFeatureTestOption() const 67 { 68 return option_; 69 } 70 71 /* 72 * @brief Returns the list of TypographyData user setting in feature test 73 */ GetTypographies()74 const std::list<struct TypographyData> &GetTypographies() const 75 { 76 return typographies_; 77 } 78 GetTestName()79 const std::string &GetTestName() const 80 { 81 return testName_; 82 } 83 84 protected: 85 std::list<struct TypographyData> typographies_; 86 struct FeatureTestOption option_ = {}; 87 88 private: 89 std::string testName_ = {}; 90 }; 91 92 class FeatureTestCollection { 93 public: 94 ~FeatureTestCollection() = default; 95 static FeatureTestCollection &GetInstance(); 96 97 /* 98 * @brief Returns the list of all feature test 99 */ GetTests()100 const std::list<TestFeature*> &GetTests() const 101 { 102 return tests_; 103 } 104 105 /* 106 * @brief Add feature test to FeatureTestCollection 107 * @param test The pointer of feature test 108 */ 109 void RegisterTest(const TestFeature *test); 110 111 private: 112 FeatureTestCollection() = default; 113 FeatureTestCollection(const FeatureTestCollection &) = delete; 114 FeatureTestCollection(FeatureTestCollection &&) = delete; 115 FeatureTestCollection &operator=(const FeatureTestCollection &) = delete; 116 FeatureTestCollection &operator=(FeatureTestCollection &&) = delete; 117 118 std::list<TestFeature*> tests_; 119 }; 120 121 #endif // ROSEN_SAMPLES_TEXGINE_FEATURE_TEST_FEATURE_TEST_FRAMEWORK_H 122