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 FONT_MANAGER_FONT_CONFIG_H 17 #define FONT_MANAGER_FONT_CONFIG_H 18 #include <mutex> 19 #include <string> 20 #include <vector> 21 22 #include "cJSON.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace FontManager { 27 class FontConfig { 28 public: FontConfig(const std::string & fontPath)29 explicit FontConfig(const std::string &fontPath) : ConfigPath_(fontPath){}; 30 ~FontConfig() = default; 31 bool InsertFontRecord(const std::string &fontPath, const std::vector<std::string> &fullNames); 32 bool DeleteFontRecord(const std::string &fontPath); 33 int GetInstalledFontsNum(); 34 std::string GetFontFileByName(const std::string &fullName); 35 36 private: 37 char *GetFileData(const std::string &filePath, long &size); 38 std::string CheckConfigFile(const std::string &fontPath); 39 cJSON *ConstructCJSON(const std::string &fontFullPath, const std::vector<std::string> &fullName); 40 std::unordered_map<std::string, std::vector<std::string>> GetFontsMap(const std::string &filePath); 41 bool WriteToFile(char *jsonData); 42 private: 43 std::unordered_map<std::string, std::vector<std::string>> fontsMap_; 44 std::string ConfigPath_; 45 std::mutex configLock_; 46 std::mutex fontsMapLock_; 47 }; 48 } // namespace FontManager 49 } // namespace Global 50 } // namespace OHOS 51 #endif // FONT_MANAGER_FONT_CONFIG_H 52