1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FONT_LOADER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FONT_LOADER_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/pipeline/pipeline_base.h" 21 22 namespace OHOS::Ace { 23 24 class FontLoader : public virtual AceType { 25 DECLARE_ACE_TYPE(FontLoader, AceType); 26 27 public: 28 FontLoader(const std::string& familyName, const std::string& familySrc); 29 ~FontLoader() override = default; 30 31 virtual void AddFont(const RefPtr<PipelineBase>& context, const std::string& bundleName = "", 32 const std::string& moduleName = "") = 0; 33 SetDefaultFontFamily(const char * fontFamily,const char * familySrc)34 virtual void SetDefaultFontFamily(const char* fontFamily, const char* familySrc) 35 { 36 return; 37 } 38 39 static RefPtr<FontLoader> Create(const std::string& familyName, const std::string& familySrc); 40 41 const std::string& GetFamilyName() const; 42 void SetOnLoaded(const WeakPtr<RenderNode>& node, const std::function<void()>& callback); 43 void RemoveCallback(const WeakPtr<RenderNode>& node); 44 void SetVariationChanged(const std::function<void()>& variationChanged); 45 46 void SetOnLoadedNG(const WeakPtr<NG::UINode>& node, const std::function<void()>& callback); 47 void RemoveCallbackNG(const WeakPtr<NG::UINode>& node); 48 49 protected: 50 std::string familyName_; 51 std::string familySrc_; 52 std::map<WeakPtr<RenderNode>, std::function<void()>> callbacks_; 53 std::map<WeakPtr<NG::UINode>, std::function<void()>> callbacksNG_; 54 bool isLoaded_ = false; 55 std::function<void()> variationChanged_; 56 }; 57 58 } // namespace OHOS::Ace 59 60 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FONT_LOADER_H 61