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 "third_party/skia/include/core/SkCanvas.h" 23 #include "third_party/skia/include/core/SkFont.h" 24 #include "third_party/skia/include/core/SkFontMetrics.h" 25 #include "third_party/skia/include/core/SkMaskFilter.h" 26 #include "third_party/skia/include/core/SkPaint.h" 27 #include "third_party/skia/include/core/SkTextBlob.h" 28 #include "third_party/skia/include/core/SkTypeface.h" 29 #include "third_party/skia/include/core/SkTypes.h" 30 #include "third_party/skia/include/core/SkPaint.h" 31 #include "third_party/skia/include/pathops/SkPathOps.h" 32 #include "third_party/skia/include/effects/SkDashPathEffect.h" 33 #include "third_party/skia/include/effects/SkDiscretePathEffect.h" 34 35 enum AnimationType { 36 INVALID_ANIMATION_TYPE = 0, 37 SCALE_EFFECT = 1, 38 VARIABLE_COLOR = 2, 39 }; 40 41 enum AnimationSubType { 42 INVALID_ANIMATION_SUB_TYPE = 0, 43 UNIT = 1, 44 VARIABLE_3_GROUP = 2, 45 VARIABLE_4_GROUP = 3, 46 }; 47 48 enum CurveType { 49 INVALID_CURVE_TYPE = 0, 50 SPRING = 1, 51 LINEAR = 2, 52 }; 53 54 using PiecewiseParameter = struct PiecewiseParameter { 55 CurveType curveType; 56 std::map<std::string, double_t> curveArgs; 57 uint32_t duration; 58 int delay; 59 std::map<std::string, std::vector<double_t>> properties; 60 }; 61 62 using AnimationPara = struct AnimationPara { 63 uint32_t animationMode; 64 AnimationSubType subType; 65 std::vector<std::vector<PiecewiseParameter>> groupParameters; 66 }; 67 68 using AnimationInfo = struct AnimationInfo { 69 AnimationType animationType; 70 std::vector<AnimationPara> animationParas; 71 }; 72 73 using SColor = struct SColor { 74 float a = 1; 75 U8CPU r = 0; 76 U8CPU g = 0; 77 U8CPU b = 0; 78 }; 79 80 using GroupInfo = struct GroupInfo { 81 std::vector<size_t> layerIndexes; 82 std::vector<size_t> maskIndexes; 83 }; 84 85 using GroupSetting = struct GroupSetting { 86 std::vector<GroupInfo> groupInfos; 87 uint32_t animationIndex; 88 }; 89 90 using AnimationSetting = struct AnimationSetting { 91 AnimationType animationType; 92 AnimationSubType animationSubType; 93 uint32_t animationMode; 94 std::vector<GroupSetting> groupSettings; 95 }; 96 97 using RenderGroup = struct RenderGroup { 98 std::vector<GroupInfo> groupInfos; 99 SColor color; 100 }; 101 102 enum EffectStrategy { 103 INVALID_EFFECT_STRATEGY = 0, 104 NONE = 1, 105 SCALE = 2, 106 HIERARCHICAL = 3, 107 }; 108 109 using SymbolLayers = struct SymbolLayers { 110 uint32_t symbolGlyphId; 111 std::vector<std::vector<size_t>> layers; 112 std::vector<RenderGroup> renderGroups; 113 EffectStrategy effect; 114 AnimationSetting animationSetting; 115 }; 116 117 enum SymbolRenderingStrategy { 118 INVALID_RENDERING_STRATEGY = 0, 119 SINGLE = 1, 120 MULTIPLE_COLOR = 2, 121 MULTIPLE_OPACITY = 3, 122 }; 123 124 125 using SymbolLayersGroups = struct SymbolLayersGroups { 126 uint32_t symbolGlyphId; 127 std::vector<std::vector<size_t>> layers; 128 std::map<SymbolRenderingStrategy, std::vector<RenderGroup>> renderModeGroups; 129 std::vector<AnimationSetting> animationSettings; 130 }; 131 132 class SK_API HMSymbolData 133 { 134 public: 135 SymbolLayers symbolInfo_; 136 SkPath path_; 137 uint64_t symbolId_ = 0; 138 }; 139 140 class SK_API HMSymbol 141 { 142 public: HMSymbol()143 HMSymbol(){}; 144 ~HMSymbol()145 ~HMSymbol(){}; 146 147 static void PathOutlineDecompose(const SkPath& path, std::vector<SkPath>& paths); 148 149 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 150 const std::vector<SkPath>& paths, std::vector<SkPath>& multPaths); 151 }; 152 153 #endif