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 #include "HmSymbolConfig_ohos.h" 17 18 namespace skia::text { 19 std::function<int(const char* filePath)> HmSymbolConfig_OHOS::fLoadSymbolConfigFunc; 20 std::mutex HmSymbolConfig_OHOS::fMutex; 21 SetLoadSymbolConfig(std::function<int (const char * filePath)> & loadSymbolConfigFunc)22void HmSymbolConfig_OHOS::SetLoadSymbolConfig(std::function<int(const char* filePath)>& loadSymbolConfigFunc) 23 { 24 std::lock_guard<std::mutex> lock(fMutex); 25 fLoadSymbolConfigFunc = loadSymbolConfigFunc; 26 } 27 ClearLoadSymbolConfig()28void HmSymbolConfig_OHOS::ClearLoadSymbolConfig() 29 { 30 std::lock_guard<std::mutex> lock(fMutex); 31 fLoadSymbolConfigFunc = nullptr; 32 } 33 LoadSymbolConfig(const char * fileName,SkString fileDir)34int HmSymbolConfig_OHOS::LoadSymbolConfig(const char* fileName, SkString fileDir) 35 { 36 std::lock_guard<std::mutex> lock(fMutex); 37 if (!fLoadSymbolConfigFunc) { 38 return ERROR_CONFIG_FUN_NOT_DEFINED; 39 } 40 if (fileName == nullptr || strlen(fileName) == 0) { 41 return ERROR_CONFIG_NOT_FOUND; 42 } 43 if (fileDir.size() == 0) { 44 fileDir.append("."); 45 } 46 std::string fullname(fileDir.c_str(), fileDir.size()); 47 char separator = '/'; 48 #if defined(SK_BUILD_FONT_MGR_FOR_PREVIEW_WIN) 49 separator = '\\'; 50 #endif 51 if (fileDir[fileDir.size() - 1] != separator) { 52 fullname += separator; 53 } 54 std::string fNameStr(fileName, strlen(fileName)); 55 fullname += fNameStr; 56 57 return fLoadSymbolConfigFunc(fullname.c_str()); 58 } 59 } // namespace skia::text