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 "texgine/system_font_provider.h" 17 18 #include <mutex> 19 20 #include "texgine_exception.h" 21 #include "texgine/utils/exlog.h" 22 #include "variant_font_style_set.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 namespace TextEngine { GetInstance()27std::shared_ptr<SystemFontProvider> SystemFontProvider::GetInstance() noexcept(true) 28 { 29 if (sfp == nullptr) { 30 static std::mutex mutex; 31 std::lock_guard<std::mutex> lock(mutex); 32 if (sfp == nullptr) { 33 sfp.reset(new SystemFontProvider()); 34 } 35 } 36 return sfp; 37 } 38 MatchFamily(const std::string & familyName)39std::shared_ptr<VariantFontStyleSet> SystemFontProvider::MatchFamily(const std::string &familyName) noexcept(true) 40 { 41 auto fontMgr = TexgineFontManager::RefDefault(); 42 if (fontMgr == nullptr || fontMgr->GetFontMgr() == nullptr) { 43 LOGEX_FUNC_LINE(ERROR) << "fontMgr is nullptr!"; 44 return nullptr; 45 } 46 47 auto fontStyleSet = fontMgr->MatchFamily(familyName.c_str()); 48 if (fontStyleSet == nullptr || fontStyleSet->GetFontStyleSet() == nullptr) { 49 LOGEX_FUNC_LINE_DEBUG() << "fontStyleSet is nullptr!"; 50 } 51 52 return std::make_shared<VariantFontStyleSet>(fontStyleSet); 53 } 54 } // namespace TextEngine 55 } // namespace Rosen 56 } // namespace OHOS 57