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_TYPE = 1,
34     VARIABLE_COLOR_TYPE = 2,
35     APPEAR_TYPE = 3,
36     DISAPPEAR_TYPE = 4,
37     BOUNCE_TYPE = 5,
38     PULSE_TYPE = 6,
39     REPLACE_APPEAR_TYPE = 7,
40     REPLACE_DISAPPEAR_TYPE = 8,
41 };
42 
43 enum DrawingCurveType {
44     INVALID_CURVE_TYPE = 0,
45     SPRING = 1,
46     LINEAR = 2,
47     FRICTION = 3,
48     SHARP = 4,
49 };
50 
51 enum DrawingCommonSubType {
52     DOWN = 0,
53     UP = 1,
54 };
55 
56 struct DrawingPiecewiseParameter {
57     DrawingCurveType curveType = DrawingCurveType::INVALID_CURVE_TYPE;
58     std::map<std::string, float> curveArgs;
59     uint32_t duration = 0;
60     int delay = 0;
61     std::map<std::string, std::vector<float>> properties;
62 };
63 
64 struct DrawingAnimationPara {
65     uint16_t animationMode = 0; // 0 is default value, is byLayer effect
66     DrawingCommonSubType commonSubType = DrawingCommonSubType::DOWN;
67     std::vector<std::vector<DrawingPiecewiseParameter>> groupParameters;
68 };
69 
70 struct DrawingAnimationInfo {
71     DrawingAnimationType animationType = DrawingAnimationType::INVALID_ANIMATION_TYPE;
72     std::map<uint32_t, DrawingAnimationPara> animationParas;
73 };
74 
75 struct DrawingSColor {
76     float a = 1.f;
77     U8CPU r = 0;
78     U8CPU g = 0;
79     U8CPU b = 0;
80 };
81 
82 struct DrawingGroupInfo {
83     std::vector<size_t> layerIndexes;
84     std::vector<size_t> maskIndexes;
85 };
86 
87 struct DrawingGroupSetting {
88     std::vector<DrawingGroupInfo> groupInfos;
89     int animationIndex = -1; // -1 is default value, the level has no effecet
90 };
91 
92 struct DrawingAnimationSetting {
93     std::vector<DrawingAnimationType> animationTypes;
94     std::vector<DrawingGroupSetting> groupSettings;
95 };
96 
97 struct DrawingRenderGroup {
98     std::vector<DrawingGroupInfo> groupInfos;
99     DrawingSColor color;
100 };
101 
102 enum DrawingEffectStrategy {
103     NONE = 0,
104     SCALE = 1,
105     VARIABLE_COLOR = 2,
106     APPEAR = 3,
107     DISAPPEAR = 4,
108     BOUNCE = 5,
109     PULSE = 6,
110     REPLACE_APPEAR = 7,
111     REPLACE_DISAPPEAR = 8,
112 };
113 
114 struct DrawingSymbolLayers {
115     uint16_t symbolGlyphId = 0;
116     std::vector<std::vector<size_t>> layers;
117     std::vector<DrawingRenderGroup> renderGroups;
118 };
119 
120 enum DrawingSymbolRenderingStrategy {
121     SINGLE = 0,
122     MULTIPLE_COLOR = 1,
123     MULTIPLE_OPACITY = 2,
124 };
125 
126 struct DrawingSymbolLayersGroups {
127     uint16_t symbolGlyphId = 0;
128     std::vector<std::vector<size_t>> layers;
129     std::map<DrawingSymbolRenderingStrategy, std::vector<DrawingRenderGroup>> renderModeGroups;
130     std::vector<DrawingAnimationSetting> animationSettings;
131 };
132 
133 struct DrawingHMSymbolData {
134 public:
135     DrawingSymbolLayers symbolInfo_;
136     Path path_;
137     uint64_t symbolId = 0; // span id in paragraph
138 };
139 
140 class DRAWING_API DrawingHMSymbol {
141 public:
142     static void PathOutlineDecompose(const Path& path, std::vector<Path>& paths);
143 
144     static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap,
145         const std::vector<Path>& paths, std::vector<Path>& multPaths);
146 };
147 } // namespace Drawing
148 } // namespace Rosen
149 } // namespace OHOS
150 #endif