• 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 FONT_CONFIG_H
17 #define FONT_CONFIG_H
18 
19 #include <string>
20 #include <vector>
21 #include <include/core/SkString.h>
22 #include <map>
23 
24 struct cJSON;
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 cJSON* root);
38     cJSON* CheckConfigFile(const char* fname) const;
39     static char* GetFileData(const char* fname, int& size);
40 
41 private:
42     std::vector<std::string> fontSet_;
43     std::string rootPath_;
44 };
45 
46 typedef struct AdjustInfo {
47     int origValue;
48     int newValue;
49 } AdjustInfo;
50 using AdjustSet = std::vector<AdjustInfo>;
51 
52 typedef struct AliasInfo {
53     std::string familyName;
54     int weight;
55 } AliasInfo;
56 using AliasSet = std::vector<AliasInfo>;
57 
58 typedef struct FallbackInfo {
59     std::string familyName;
60     std::string font;
61 } FallbackInfo;
62 using FallbackInfoSet = std::vector<FallbackInfo>;
63 
64 typedef struct FallbackGroup {
65     std::string groupName;
66     FallbackInfoSet fallbackInfoSet;
67 } FallbackGroup;
68 using FallbackGroupSet = std::vector<FallbackGroup>;
69 
70 typedef struct FontGenericInfo {
71     std::string familyName;
72     AliasSet aliasSet;
73     AdjustSet adjustSet;
74 } FontGenericInfo;
75 using GenericSet = std::vector<FontGenericInfo>;
76 
77 typedef struct FontConfigJsonInfo {
78     std::vector<std::string> fontDirSet;
79     GenericSet genericSet;
80     FallbackGroupSet fallbackGroupSet;
81 } FontConfigJsonInfo;
82 
83 using FontFileMap = std::map<std::string, std::string>;
84 
85 class FontConfigJson : public FontConfig {
86 public:
87     FontConfigJson() = default;
88     int ParseFile(const char* fname = nullptr);
89     int ParseFontFileMap(const char* fname = nullptr);
GetFontConfigJsonInfo()90     std::shared_ptr<FontConfigJsonInfo> GetFontConfigJsonInfo()
91     {
92         return fontPtr;
93     }
GetFontFileMap()94     std::shared_ptr<FontFileMap> GetFontFileMap()
95     {
96         return fontFileMap;
97     }
98     // for test
99     void Dump() const override;
100 
101 private:
102     int ParseConfigList(const char* fname);
103     int ParseConfigListPath(const char* fname);
104     int ParseGeneric(const cJSON* root, const char* key);
105     int ParseAlias(const cJSON* root, FontGenericInfo &genericInfo);
106     int ParseAdjust(const cJSON* root, FontGenericInfo &genericInfo);
107     int ParseFallback(const cJSON* root, const char* key);
108     int ParseFontMap(const cJSON* root, const char* key);
109     int ParseDir(const cJSON* root);
110     void AnalyseFontDir(const cJSON* root);
111     int ParseAdjustArr(const cJSON* arr, FontGenericInfo &genericInfo);
112     int ParseAliasArr(const cJSON* arr, FontGenericInfo &genericInfo);
113     void DumpFontDir() const;
114     void DumpGeneric() const;
115     void DumpForbak() const;
116     void DumpAlias(const AliasSet &aliasSet) const;
117     void DumpAjdust(const AdjustSet &adjustSet) const;
118     void DumpFontFileMap() const;
119 
120     std::shared_ptr<FontConfigJsonInfo> fontPtr = nullptr;
121     std::shared_ptr<FontFileMap> fontFileMap = nullptr;
122 };
123 } // namespace TextEngine
124 } // namespace Rosen
125 } // namespace OHOS
126 #endif /* FONT_CONFIG_H */
127