1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd.. All rights reserved. 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 SYMBOL_CONFIG_PARSER_H 17 #define SYMBOL_CONFIG_PARSER_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <json/json.h> 22 #include <mutex> 23 #include <unordered_map> 24 25 #include "symbol_engine/drawing.h" 26 #include "text/hm_symbol.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace Symbol { 31 32 class SymbolConfigParser { 33 public: 34 static bool ParseSymbolConfig(const Json::Value& root, 35 std::unordered_map<uint16_t, RSSymbolLayersGroups>& symbolConfig, 36 std::unordered_map<RSAnimationType, RSAnimationInfo>& animationInfos); 37 static bool ParseSymbolLayersGrouping( 38 const Json::Value& root, std::unordered_map<uint16_t, RSSymbolLayersGroups>& symbolConfig); 39 static bool ParseSymbolAnimations( 40 const Json::Value& root, std::unordered_map<RSAnimationType, RSAnimationInfo>& animationInfos); 41 42 private: 43 static bool ParseOneSymbolNativeCase(const char* key, const Json::Value& root, uint16_t& nativeGlyphId); 44 static void ParseComponets(const Json::Value& root, std::vector<size_t>& components); 45 static void SymbolGlyphCase(const char* key, const Json::Value& root, RSSymbolLayersGroups& symbolLayersGroups); 46 static void ParseLayers(const Json::Value& root, std::vector<std::vector<size_t>>& layers); 47 static void ParseOneSymbolLayerCase(const char* key, const Json::Value& root, 48 RSSymbolLayersGroups& symbolLayersGroups); 49 static void ParseOneSymbolRenderCase(const char* key, const Json::Value& root, 50 RSSymbolLayersGroups& symbolLayersGroups); 51 static void ParseRenderModes(const Json::Value& root, std::map<RSSymbolRenderingStrategy, 52 std::vector<RSRenderGroup>>& renderModesGroups); 53 static void ParseRenderGroups(const Json::Value& root, std::vector<RSRenderGroup>& renderGroups); 54 static void ParseDefaultColor(const char* defaultColor, RSRenderGroup& renderGroup); 55 static void ParseGroupIndexes(const Json::Value& root, std::vector<RSGroupInfo>& groupInfos); 56 static void ParseLayerOrMaskIndexes(const Json::Value& root, std::vector<size_t>& indexes); 57 static void ParseOneSymbolAnimateCase(const char* key, const Json::Value& root, 58 RSSymbolLayersGroups& symbolLayersGroups); 59 static void ParseAnimationSettings(const Json::Value& root, std::vector<RSAnimationSetting>& animationSettings); 60 static void ParseAnimationSetting(const Json::Value& root, RSAnimationSetting& animationSetting); 61 static void ParseAnimationTypes(const Json::Value& root, std::vector<RSAnimationType>& animationTypes); 62 static void ParseAnimationType(const std::string& animationTypeStr, RSAnimationType& animationType); 63 static void ParseGroupSettings(const Json::Value& root, std::vector<RSGroupSetting>& groupSettings); 64 static void ParseGroupSetting(const Json::Value& root, RSGroupSetting& groupSetting); 65 static void ParseOneSymbol(const Json::Value& root, 66 std::unordered_map<uint16_t, RSSymbolLayersGroups>& symbolConfig); 67 static uint32_t EncodeAnimationAttribute(uint16_t groupSum, uint16_t animationMode, RSCommonSubType commonSubType); 68 static void ParseSymbolAnimationParas(const Json::Value& root, 69 std::map<uint32_t, RSAnimationPara>& animationParas); 70 static void ParseSymbolAnimationPara(const Json::Value& root, RSAnimationPara& animationPara); 71 static void ParseSymbolCommonSubType(const char* key, const Json::Value& root, RSAnimationPara& animationPara); 72 static void MatchCommonSubType(const std::string& subTypeStr, RSCommonSubType& commonSubType); 73 static void ParseSymbolGroupParas(const char* key, const Json::Value& root, RSAnimationPara& animationPara); 74 static void ParseSymbolPiecewisePara(const Json::Value& root, RSPiecewiseParameter& piecewiseParameter); 75 static void PiecewiseParaCurveCase(const char* key, const Json::Value& root, 76 RSPiecewiseParameter& piecewiseParameter); 77 static void PiecewiseParaDurationCase(const char* key, const Json::Value& root, 78 RSPiecewiseParameter& piecewiseParameter); 79 static void PiecewiseParaDelayCase(const char* key, const Json::Value& root, 80 RSPiecewiseParameter& piecewiseParameter); 81 static void ParseSymbolCurveArgs(const char* key, const Json::Value& root, 82 RSPiecewiseParameter& piecewiseParameter); 83 static void ParseSymbolProperties(const char* key, const Json::Value& root, 84 RSPiecewiseParameter& piecewiseParameter); 85 }; 86 } // namespace Symbol 87 } // namespace Rosen 88 } // namespace OHOS 89 #endif // SYMBOL_CONFIG_PARSER_H