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 #include "rosen_text/hm_symbol_txt.h"
17 
18 #define RENDER_SINGLE 0
19 #define RENDER_MULTIPLE_COLOR 1
20 #define RENDER_MULTIPLE_OPACITY 2
21 
22 namespace OHOS {
23 namespace Rosen {
24 
25 // the symbol animation type mapping table
26 static const std::map<uint32_t, Drawing::DrawingEffectStrategy> EFFECT_TYPES = {
27     {0, Drawing::DrawingEffectStrategy::NONE},
28     {1, Drawing::DrawingEffectStrategy::SCALE},
29     {2, Drawing::DrawingEffectStrategy::VARIABLE_COLOR},
30     {3, Drawing::DrawingEffectStrategy::APPEAR},
31     {4, Drawing::DrawingEffectStrategy::DISAPPEAR},
32     {5, Drawing::DrawingEffectStrategy::BOUNCE},
33     {6, Drawing::DrawingEffectStrategy::PULSE},
34     {7, Drawing::DrawingEffectStrategy::REPLACE_APPEAR}
35 };
36 
SetRenderColor(const std::vector<Drawing::DrawingSColor> & colorList)37 void HMSymbolTxt::SetRenderColor(const std::vector<Drawing::DrawingSColor>& colorList)
38 {
39     colorList_.clear();
40     colorList_ = colorList;
41 }
42 
SetRenderColor(const std::vector<Drawing::Color> & colorList)43 void HMSymbolTxt::SetRenderColor(const std::vector<Drawing::Color>& colorList)
44 {
45     colorList_.clear();
46     for (auto color: colorList) {
47         Drawing::DrawingSColor colorIt = {color.GetAlphaF(), color.GetRed(), color.GetGreen(), color.GetBlue()};
48         colorList_.push_back(colorIt);
49     }
50 }
51 
SetRenderColor(const Drawing::Color & color)52 void HMSymbolTxt::SetRenderColor(const Drawing::Color& color)
53 {
54     colorList_.clear();
55     Drawing::DrawingSColor colorIt = {color.GetAlphaF(), color.GetRed(), color.GetGreen(), color.GetBlue()};
56     colorList_ = {colorIt};
57 }
58 
SetRenderColor(const Drawing::DrawingSColor & colorList)59 void HMSymbolTxt::SetRenderColor(const Drawing::DrawingSColor& colorList)
60 {
61     colorList_.clear();
62     colorList_ = {colorList};
63 }
64 
SetRenderMode(const uint32_t & renderMode)65 void HMSymbolTxt::SetRenderMode(const uint32_t& renderMode)
66 {
67     switch (renderMode) {
68         case RENDER_SINGLE:
69             renderMode_ = Drawing::DrawingSymbolRenderingStrategy::SINGLE;
70             break;
71         case RENDER_MULTIPLE_OPACITY:
72             renderMode_ = Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_OPACITY;
73             break;
74         case RENDER_MULTIPLE_COLOR:
75             renderMode_ = Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_COLOR;
76             break;
77         default:
78             break;
79     }
80 }
81 
SetSymbolEffect(const uint32_t & effectStrategy)82 void HMSymbolTxt::SetSymbolEffect(const uint32_t& effectStrategy)
83 {
84     auto iter = EFFECT_TYPES.find(effectStrategy);
85     if (iter != EFFECT_TYPES.end()) {
86         effectStrategy_ = iter->second;
87     }
88 }
89 
GetRenderColor() const90 std::vector<Drawing::DrawingSColor> HMSymbolTxt::GetRenderColor() const
91 {
92     return colorList_;
93 }
94 
GetRenderMode() const95 Drawing::DrawingSymbolRenderingStrategy HMSymbolTxt::GetRenderMode() const
96 {
97     return renderMode_;
98 }
99 
GetEffectStrategy() const100 Drawing::DrawingEffectStrategy HMSymbolTxt::GetEffectStrategy() const
101 {
102     return effectStrategy_;
103 }
104 
SetAnimationMode(const uint16_t animationMode)105 void HMSymbolTxt::SetAnimationMode(const uint16_t animationMode)
106 {
107     animationMode_ = animationMode > 0 ? 1 : 0; // 1 is whole or iteratuve, 0 is hierarchical or cumulative
108 }
109 
SetRepeatCount(const int repeatCount)110 void HMSymbolTxt::SetRepeatCount(const int repeatCount)
111 {
112     repeatCount_ = repeatCount;
113 }
114 
SetAnimationStart(const bool animationStart)115 void HMSymbolTxt::SetAnimationStart(const bool animationStart)
116 {
117     animationStart_ = animationStart;
118 }
119 
GetAnimationMode() const120 uint16_t HMSymbolTxt::GetAnimationMode() const
121 {
122     return animationMode_;
123 }
124 
GetRepeatCount() const125 int HMSymbolTxt::GetRepeatCount() const
126 {
127     return repeatCount_;
128 }
129 
GetAnimationStart() const130 bool HMSymbolTxt::GetAnimationStart() const
131 {
132     return animationStart_;
133 }
134 
SetVisualMode(const VisualMode visual)135 void HMSymbolTxt::SetVisualMode(const VisualMode visual)
136 {
137     visualMap_.clear();
138     if (visual == VisualMode::VISUAL_SMALL) {
139         visualMap_["ss01"] = 1;
140     }
141 
142     if (visual == VisualMode::VISUAL_LARGER) {
143         visualMap_["ss02"] = 1;
144     }
145 }
146 
GetVisualMap() const147 std::map<std::string, int> HMSymbolTxt::GetVisualMap() const
148 {
149     return visualMap_;
150 }
151 
152 // set common subtype of symbol animation attribute
SetCommonSubType(Drawing::DrawingCommonSubType commonSubType)153 void HMSymbolTxt::SetCommonSubType(Drawing::DrawingCommonSubType commonSubType)
154 {
155     commonSubType_ = commonSubType;
156 }
157 
GetCommonSubType() const158 Drawing::DrawingCommonSubType HMSymbolTxt::GetCommonSubType() const
159 {
160     return commonSubType_;
161 }
162 } // namespace Rosen
163 } // namespace OHOS