1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SYMBOL_CONSTANTS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_SYMBOL_CONSTANTS_H 18 19 #include <cstdint> 20 #include "core/components/common/properties/color.h" 21 22 namespace OHOS::Ace { 23 24 enum class SymbolEffectType { 25 NONE = 0, 26 SCALE, 27 HIERARCHICAL, 28 APPEAR, 29 DISAPPEAR, 30 BOUNCE, 31 PULSE, 32 REPLACE, 33 DISABLE, 34 QUICK_REPLACE, 35 }; 36 37 enum class CommonSubType { 38 DOWN = 0, 39 UP, 40 }; 41 42 enum class ScopeType { 43 LAYER = 0, 44 WHOLE, 45 }; 46 47 enum class FillStyle { 48 CUMULATIVE = 0, 49 ITERATIVE, 50 }; 51 52 enum class SymbolType { 53 SYSTEM = 0, 54 CUSTOM, 55 }; 56 57 enum class SymbolGradientType { 58 NONE = 0, 59 COLOR_SHADER, 60 RADIAL_GRADIENT, 61 LINEAR_GRADIENT, 62 }; 63 64 enum class GradientDefinedStatus { 65 GRADIENT_TYPE = 1, 66 GRADIENT_DEFAULT_COLOR = 2 67 }; 68 69 enum class SDKGradientDirection { 70 Left, 71 Top, 72 Right, 73 Bottom, 74 LeftTop, 75 LeftBottom, 76 RightTop, 77 RightBottom, 78 None 79 }; 80 81 static const std::unordered_map<SDKGradientDirection, float> GRADIENT_DIRECTION_TO_ANGLE = { 82 {SDKGradientDirection::Left, 270.0f}, 83 {SDKGradientDirection::Top, 0.0f}, 84 {SDKGradientDirection::Right, 90.0f}, 85 {SDKGradientDirection::Bottom, 180.0f}, 86 {SDKGradientDirection::LeftTop, 315.0f}, 87 {SDKGradientDirection::LeftBottom, 225.0f}, 88 {SDKGradientDirection::RightTop, 45.0f}, 89 {SDKGradientDirection::RightBottom, 135.0f}, 90 {SDKGradientDirection::None, 180.0f} 91 }; 92 93 struct SymbolGradient { 94 SymbolGradientType type = SymbolGradientType::NONE; 95 GradientDefinedStatus gradientType = GradientDefinedStatus::GRADIENT_DEFAULT_COLOR; 96 std::vector<Color> symbolColor; 97 std::vector<float> symbolOpacities; 98 bool repeating = false; 99 std::optional<float> angle; 100 std::optional<Dimension> radius; 101 std::optional<Dimension> radialCenterX; 102 std::optional<Dimension> radialCenterY; 103 104 bool operator==(const SymbolGradient& other) const 105 { 106 return type == other.type && 107 radialCenterX == other.radialCenterX && 108 radialCenterY == other.radialCenterY && 109 symbolColor == other.symbolColor && 110 symbolOpacities.size() == other.symbolOpacities.size() && 111 std::equal(symbolOpacities.begin(), symbolOpacities.end(), other.symbolOpacities.begin(), 112 [](float a, float b) { return NearZero(a - b); }) && 113 repeating == other.repeating && 114 gradientType == other.gradientType && 115 ((!angle && !other.angle) || (angle && other.angle && NearZero(*angle - *other.angle))) && 116 radius == other.radius; 117 } 118 }; 119 120 struct SymbolShadow { 121 Color color = Color::BLACK; 122 std::pair<float, float> offset{0.0f, 0.0f}; 123 float radius = 0.0f; 124 bool operator==(const SymbolShadow& other) const 125 { 126 return color == other.color && 127 NearZero(offset.first - other.offset.first) && 128 NearZero(offset.second - other.offset.second) && 129 NearZero(radius - other.radius); 130 } 131 IsDefaultSymbolShadow132 bool IsDefault() const 133 { 134 return color == Color::BLACK && 135 NearZero(offset.first) && 136 NearZero(offset.second) && 137 NearZero(radius); 138 } 139 }; 140 141 } // namespace OHOS::Ace 142 143 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_CONSTANTS_H 144