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