• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 ROSEN_MODULES_TEXGINE_EXPORT_SYMBOL_ANIMATION_SYMBOL_NODE_BUILD_H
17 #define ROSEN_MODULES_TEXGINE_EXPORT_SYMBOL_ANIMATION_SYMBOL_NODE_BUILD_H
18 
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 #include <utility>
23 
24 #include "drawing.h"
25 #include "symbol_engine/hm_symbol_txt.h"
26 #include "rosen_text/symbol_animation_config.h"
27 #include "common/rs_vector4.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace SPText {
32 
33 class SymbolNodeBuild {
34 public:
35     SymbolNodeBuild(const RSAnimationSetting &animationSetting, const RSHMSymbolData &symbolData,
36     const RSEffectStrategy &effectStrategy, const std::pair<float, float> &offset);
37 
38     void AddWholeAnimation(const RSHMSymbolData &symbolData, const Vector4f &nodeBounds,
39         std::shared_ptr<TextEngine::SymbolAnimationConfig> symbolAnimationConfig);
40 
41     void AddHierarchicalAnimation(const RSHMSymbolData &symbolData, const Vector4f &nodeBounds,
42         const std::vector<RSGroupSetting> &groupSettings,
43         std::shared_ptr<TextEngine::SymbolAnimationConfig> symbolAnimationConfig);
44 
45     static void MergeDrawingPath(RSPath& multPath, const RSRenderGroup& group, std::vector<RSPath>& pathLayers);
46 
47     static std::shared_ptr<SymbolGradient> CreateGradient(
48         const std::shared_ptr<SymbolGradient>& gradient);
49 
~SymbolNodeBuild()50     ~SymbolNodeBuild() {}
51     bool DecomposeSymbolAndDraw();
52     void ClearAnimation();
SetAnimation(const std::function<bool (const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig> &)> & animationFunc)53     void SetAnimation(
54         const std::function<bool(const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)>&
55         animationFunc)
56     {
57         animationFunc_ = animationFunc;
58     }
59 
SetSymbolId(uint64_t symbolSpanId)60     void SetSymbolId(uint64_t symbolSpanId)
61     {
62         symblSpanId_ = symbolSpanId;
63     }
64 
SetAnimationMode(uint16_t animationMode)65     void SetAnimationMode(uint16_t animationMode)
66     {
67         animationMode_ = animationMode > 0 ? 1 : 0; // 1 is whole or add, 0 is hierarchical or iterate
68     }
69 
SetRepeatCount(int repeatCount)70     void SetRepeatCount(int repeatCount)
71     {
72         repeatCount_ = repeatCount;
73     }
74 
SetAnimationStart(bool animationStart)75     void SetAnimationStart(bool animationStart)
76     {
77         animationStart_ = animationStart;
78     }
79 
SetCurrentAnimationHasPlayed(bool currentAnimationHasPlayed)80     void SetCurrentAnimationHasPlayed(bool currentAnimationHasPlayed)
81     {
82         currentAnimationHasPlayed_ = currentAnimationHasPlayed;
83     }
84 
SetCommonSubType(Drawing::DrawingCommonSubType commonSubType)85     void SetCommonSubType(Drawing::DrawingCommonSubType commonSubType)
86     {
87         commonSubType_ = commonSubType;
88     }
89 
SetSlope(double slope)90     void SetSlope(double slope)
91     {
92         slope_ = slope;
93     }
94 
SetGradients(const std::vector<std::shared_ptr<SymbolGradient>> & gradients)95     void SetGradients(const std::vector<std::shared_ptr<SymbolGradient>>& gradients)
96     {
97         gradients_ = gradients;
98     }
99 
SetRenderMode(RSSymbolRenderingStrategy renderMode)100     void SetRenderMode(RSSymbolRenderingStrategy renderMode)
101     {
102         renderMode_ = renderMode;
103     }
104 
SetDisableSlashColor(std::shared_ptr<SymbolGradient> color)105     void SetDisableSlashColor(std::shared_ptr<SymbolGradient> color)
106     {
107         disableSlashColor_ = color;
108     }
109 
SetSymbolShadow(const std::optional<SymbolShadow> & symbolShadow)110     void SetSymbolShadow(const std::optional<SymbolShadow>& symbolShadow)
111     {
112         symbolShadow_ = symbolShadow;
113     }
114 
115 private:
116     RSAnimationSetting animationSetting_;
117     RSHMSymbolData symbolData_;
118     RSEffectStrategy effectStrategy_ = RSEffectStrategy::NONE;
119     float offsetX_ = 0.0f;
120     float offsetY_ = 0.0f;
121     uint16_t animationMode_ = 0;
122     int repeatCount_ = 1;
123     Drawing::DrawingCommonSubType commonSubType_ = Drawing::DrawingCommonSubType::DOWN;
124 
125     std::function<bool(const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)>
126         animationFunc_ = nullptr;
127     uint64_t symblSpanId_ = 0;
128     double slope_ = 0.0;
129     bool animationStart_ = false;
130     bool currentAnimationHasPlayed_ = false;
131 
132     RSSymbolRenderingStrategy renderMode_ = RSSymbolRenderingStrategy::SINGLE;
133     std::vector<std::shared_ptr<SymbolGradient>> gradients_;
134     std::shared_ptr<SymbolGradient> disableSlashColor_ = nullptr;
135     std::optional<SymbolShadow> symbolShadow_;
136 
137     void SetSymbolNodeColors(const TextEngine::SymbolNode& symbolNode, TextEngine::SymbolNode& outSymbolNode);
138 
139     void UpdateGradient(const std::vector<RSRenderGroup>& groups,
140         std::vector<RSPath>& pathLayers, const RSPath& path);
141 };
142 }
143 }
144 }
145 
146 #endif