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 HM_SYMBOL_H 17 #define HM_SYMBOL_H 18 19 #include <cstdint> 20 #include <map> 21 #include <string> 22 #include <vector> 23 24 #include "draw/path.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 typedef unsigned U8CPU; 30 31 enum DrawingAnimationType { 32 INVALID_ANIMATION_TYPE = 0, 33 SCALE_EFFECT = 1, 34 VARIABLE_COLOR = 2, 35 }; 36 37 enum DrawingAnimationSubType { 38 INVALID_ANIMATION_SUB_TYPE = 0, 39 UNIT = 1, 40 VARIABLE_3_GROUP = 2, 41 VARIABLE_4_GROUP = 3, 42 }; 43 44 enum DrawingCurveType { 45 INVALID_CURVE_TYPE = 0, 46 SPRING = 1, 47 LINEAR = 2, 48 }; 49 50 struct DrawingPiecewiseParameter { 51 DrawingCurveType curveType; 52 std::map<std::string, double> curveArgs; 53 uint32_t duration; 54 uint32_t delay; 55 std::map<std::string, std::vector<double>> properties; 56 }; 57 58 struct DrawingAnimationPara { 59 uint32_t animationMode; 60 DrawingAnimationSubType subType; 61 std::vector<std::vector<DrawingPiecewiseParameter>> groupParameters; 62 }; 63 64 struct DrawingAnimationInfo { 65 DrawingAnimationType animationType; 66 std::vector<DrawingAnimationPara> animationParas; 67 }; 68 69 struct DrawingSColor { 70 float a = 1.f; 71 U8CPU r = 0; 72 U8CPU g = 0; 73 U8CPU b = 0; 74 }; 75 76 struct DrawingGroupInfo { 77 std::vector<size_t> layerIndexes; 78 std::vector<size_t> maskIndexes; 79 }; 80 81 struct DrawingGroupSetting { 82 std::vector<DrawingGroupInfo> groupInfos; 83 uint32_t animationIndex; 84 }; 85 86 struct DrawingAnimationSetting { 87 DrawingAnimationType animationType; 88 DrawingAnimationSubType animationSubType; 89 uint32_t animationMode; 90 std::vector<DrawingGroupSetting> groupSettings; 91 }; 92 93 struct DrawingRenderGroup { 94 std::vector<DrawingGroupInfo> groupInfos; 95 DrawingSColor color; 96 }; 97 98 enum DrawingEffectStrategy { 99 INVALID_EFFECT_STRATEGY = 0, 100 NONE = 1, 101 SCALE = 2, 102 HIERARCHICAL = 3, 103 }; 104 105 struct DrawingSymbolLayers { 106 uint32_t symbolGlyphId; 107 std::vector<std::vector<size_t>> layers; 108 std::vector<DrawingRenderGroup> renderGroups; 109 DrawingEffectStrategy effect; 110 DrawingAnimationSetting animationSetting; 111 }; 112 113 enum DrawingSymbolRenderingStrategy { 114 INVALID_RENDERING_STRATEGY = 0, 115 SINGLE = 1, 116 MULTIPLE_COLOR = 2, 117 MULTIPLE_OPACITY = 3, 118 }; 119 120 struct DrawingSymbolLayersGroups { 121 uint32_t symbolGlyphId; 122 std::vector<std::vector<size_t>> layers; 123 std::map<DrawingSymbolRenderingStrategy, std::vector<DrawingRenderGroup>> renderModeGroups; 124 std::vector<DrawingAnimationSetting> animationSettings; 125 }; 126 127 struct DrawingHMSymbolData { 128 public: 129 DrawingSymbolLayers symbolInfo_; 130 Path path_; 131 uint64_t symbolId = 0; // span id in paragraph 132 }; 133 134 class DRAWING_API DrawingHMSymbol { 135 public: 136 static void PathOutlineDecompose(const Path& path, std::vector<Path>& paths); 137 138 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 139 const std::vector<Path>& paths, std::vector<Path>& multPaths); 140 }; 141 } // namespace Drawing 142 } // namespace Rosen 143 } // namespace OHOS 144 #endif