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 FONT_CONFIG_H 17 #define FONT_CONFIG_H 18 19 #include <json/json.h> 20 #include <string> 21 #include <vector> 22 #include <include/core/SkString.h> 23 #include <map> 24 25 namespace OHOS { 26 namespace Rosen { 27 namespace TextEngine { 28 class FontConfig { 29 public: 30 explicit FontConfig(const char* fname = nullptr); 31 virtual ~FontConfig() = default; 32 virtual void Dump() const; 33 std::vector<std::string> GetFontSet() const; 34 35 protected: 36 int ParseConfig(const char* fname); 37 int ParseFont(const Json::Value& root); 38 int CheckConfigFile(const char* fname, Json::Value& root) const; 39 static char* GetFileData(const char* fname, int& size); 40 41 private: 42 std::vector<std::string> fontSet_; 43 }; 44 45 typedef struct AdjustInfo { 46 int origValue; 47 int newValue; 48 } AdjustInfo; 49 using AdjustSet = std::vector<AdjustInfo>; 50 51 typedef struct AliasInfo { 52 std::string familyName; 53 int weight; 54 } AliasInfo; 55 using AliasSet = std::vector<AliasInfo>; 56 57 typedef struct FallbackInfo { 58 std::string familyName; 59 std::string font; 60 } FallbackInfo; 61 using FallbackInfoSet = std::vector<FallbackInfo>; 62 63 typedef struct FallbackGroup { 64 std::string groupName; 65 FallbackInfoSet fallbackInfoSet; 66 } FallbackGroup; 67 using FallbackGroupSet = std::vector<FallbackGroup>; 68 69 typedef struct FontGenericInfo { 70 std::string familyName; 71 AliasSet aliasSet; 72 AdjustSet adjustSet; 73 } FontGenericInfo; 74 using GenericSet = std::vector<FontGenericInfo>; 75 76 typedef struct FontConfigJsonInfo { 77 std::vector<std::string> fontDirSet; 78 GenericSet genericSet; 79 FallbackGroupSet fallbackGroupSet; 80 } FontConfigJsonInfo; 81 82 class FontConfigJson : public FontConfig { 83 public: 84 FontConfigJson() = default; 85 int ParseFile(const char* fname = nullptr); GetFontConfigJsonInfo()86 std::shared_ptr<FontConfigJsonInfo> GetFontConfigJsonInfo() 87 { 88 return fontPtr; 89 } 90 91 // for test 92 void Dump() const override; 93 94 private: 95 int ParseConfigList(const char* fname); 96 int ParseFontDir(const Json::Value& root); 97 int ParseGeneric(const Json::Value& root); 98 int ParseAlias(const Json::Value& root, FontGenericInfo &genericInfo); 99 int ParseAdjust(const Json::Value& root, FontGenericInfo &genericInfo); 100 int ParseFallback(const Json::Value& root); 101 int ParseFallbackItem(const Json::Value& root, FallbackInfo &fallbackInfo); 102 int ParseDir(const Json::Value &root); 103 int ParseFallbakArr(const Json::Value& arr, int i, const char* key); 104 int CheckGeneric(const Json::Value& root, const char* key); 105 int ParseAliasArr(const Json::Value& arr, const char* key, FontGenericInfo &genericInfo); 106 void DumpFontDir() const; 107 void DumpGeneric() const; 108 void DumpForbak() const; 109 void DumpAlias(const AliasSet &aliasSet) const; 110 void DumpAjdust(const AdjustSet &adjustSet) const; 111 112 std::shared_ptr<FontConfigJsonInfo> fontPtr = nullptr; 113 }; 114 } // namespace TextEngine 115 } // namespace Rosen 116 } // namespace OHOS 117 #endif /* FONT_CONFIG_H */ 118