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 #ifndef LIB_RS_SRC_HM_SYMBOL_H_ 16 #define LIB_RS_SRC_HM_SYMBOL_H_ 17 #include <iostream> 18 #include <vector> 19 #include <string> 20 #include <map> 21 22 #include "SkPath.h" 23 24 enum AnimationType { 25 INVALID_ANIMATION_TYPE = 0, 26 SCALE_TYPE = 1, 27 VARIABLE_COLOR_TYPE = 2, 28 APPEAR_TYPE = 3, 29 DISAPPEAR_TYPE = 4, 30 BOUNCE_TYPE = 5, 31 PULSE_TYPE = 6, 32 REPLACE_APPEAR_TYPE = 7, 33 REPLACE_DISAPPEAR_TYPE = 8, 34 DISABLE_TYPE = 9, 35 QUICK_REPLACE_APPEAR_TYPE = 10, 36 QUICK_REPLACE_DISAPPEAR_TYPE = 11, 37 }; 38 39 enum CurveType { 40 INVALID_CURVE_TYPE = 0, 41 SPRING = 1, 42 LINEAR = 2, 43 FRICTION = 3, 44 SHARP = 4, 45 }; 46 47 enum CommonSubType { 48 DOWN = 0, 49 UP = 1, 50 }; 51 52 using PiecewiseParameter = struct PiecewiseParameter { 53 CurveType curveType = CurveType::INVALID_CURVE_TYPE; 54 std::map<std::string, float> curveArgs; 55 uint32_t duration = 0; 56 int delay = 0; 57 std::map<std::string, std::vector<float>> properties; 58 }; 59 60 using AnimationPara = struct AnimationPara { 61 uint16_t animationMode = 0; // 0 is default value, is byLayer effect 62 CommonSubType commonSubType = CommonSubType::DOWN; 63 std::vector<std::vector<PiecewiseParameter>> groupParameters; 64 }; 65 66 using AnimationInfo = struct AnimationInfo { 67 AnimationType animationType = AnimationType::INVALID_ANIMATION_TYPE; 68 std::map<uint32_t, AnimationPara> animationParas; 69 }; 70 71 using SColor = struct SColor { 72 float a = 1; 73 U8CPU r = 0; 74 U8CPU g = 0; 75 U8CPU b = 0; 76 }; 77 78 using GroupInfo = struct GroupInfo { 79 std::vector<size_t> layerIndexes; 80 std::vector<size_t> maskIndexes; 81 }; 82 83 using GroupSetting = struct GroupSetting { 84 std::vector<GroupInfo> groupInfos; 85 int animationIndex = -1; // -1 is default value, the level has no effecet 86 }; 87 88 using AnimationSetting = struct AnimationSetting { 89 std::vector<AnimationType> animationTypes; 90 std::vector<GroupSetting> groupSettings; 91 CommonSubType commonSubType = CommonSubType::DOWN; 92 double slope = 0.0; 93 }; 94 95 using RenderGroup = struct RenderGroup { 96 std::vector<GroupInfo> groupInfos; 97 SColor color; 98 }; 99 100 enum EffectStrategy { 101 NONE = 0, 102 SCALE = 1, 103 VARIABLE_COLOR = 2, 104 APPEAR = 3, 105 DISAPPEAR = 4, 106 BOUNCE = 5, 107 PULSE = 6, 108 REPLACE_APPEAR = 7, 109 REPLACE_DISAPPEAR = 8, 110 QUICK_REPLACE_APPEAR = 10, 111 QUICK_REPLACE_DISAPPEAR = 11, 112 }; 113 114 using SymbolLayers = struct SymbolLayers { 115 uint16_t symbolGlyphId = 0; 116 std::vector<std::vector<size_t>> layers; 117 std::vector<RenderGroup> renderGroups; 118 }; 119 120 enum SymbolRenderingStrategy { 121 SINGLE = 0, 122 MULTIPLE_COLOR = 1, 123 MULTIPLE_OPACITY = 2, 124 }; 125 126 127 using SymbolLayersGroups = struct SymbolLayersGroups { 128 uint16_t symbolGlyphId = 0; 129 std::vector<std::vector<size_t>> layers; 130 std::map<SymbolRenderingStrategy, std::vector<RenderGroup>> renderModeGroups; 131 std::vector<AnimationSetting> animationSettings; 132 }; 133 134 class SK_API HMSymbolData 135 { 136 public: 137 SymbolLayers symbolInfo_; 138 SkPath path_; 139 uint64_t symbolId_ = 0; 140 }; 141 142 class SK_API HMSymbol 143 { 144 public: HMSymbol()145 HMSymbol(){}; 146 ~HMSymbol()147 ~HMSymbol(){}; 148 149 static void PathOutlineDecompose(const SkPath& path, std::vector<SkPath>& paths); 150 151 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 152 const std::vector<SkPath>& paths, std::vector<SkPath>& multPaths); 153 }; 154 155 #endif