• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "core/common/font_loader.h"
17 
18 namespace OHOS::Ace {
19 
FontLoader(const std::string & familyName,const std::string & familySrc)20 FontLoader::FontLoader(const std::string& familyName, const std::string& familySrc)
21     : familyName_(familyName), familySrc_(familySrc) {}
FontLoader(const std::string & familyName,const std::vector<std::string> & familySrcArray)22 FontLoader::FontLoader(const std::string& familyName, const std::vector<std::string>& familySrcArray)
23     : familyName_(familyName), familySrcArray_(familySrcArray) {}
24 
GetFamilyName() const25 const std::string& FontLoader::GetFamilyName() const
26 {
27     return familyName_;
28 }
29 
SetOnLoaded(const WeakPtr<RenderNode> & node,const std::function<void ()> & callback)30 void FontLoader::SetOnLoaded(const WeakPtr<RenderNode>& node, const std::function<void()>& callback)
31 {
32     CHECK_NULL_VOID(callback);
33     if (isLoaded_) {
34         callback();
35     } else {
36         callbacks_.emplace(node, callback);
37     }
38 }
39 
RemoveCallback(const WeakPtr<RenderNode> & node)40 void FontLoader::RemoveCallback(const WeakPtr<RenderNode>& node)
41 {
42     callbacks_.erase(node);
43 }
44 
SetVariationChanged(const std::function<void ()> & variationChanged)45 void FontLoader::SetVariationChanged(const std::function<void()>& variationChanged)
46 {
47     variationChanged_ = variationChanged;
48 }
49 
RemoveCallbackNG(const WeakPtr<NG::UINode> & node)50 void FontLoader::RemoveCallbackNG(const WeakPtr<NG::UINode>& node)
51 {
52     callbacksNG_.erase(node);
53 }
54 
SetOnLoadedNG(const WeakPtr<NG::UINode> & node,const std::function<void ()> & callback)55 void FontLoader::SetOnLoadedNG(const WeakPtr<NG::UINode>& node, const std::function<void()>& callback)
56 {
57     CHECK_NULL_VOID(callback);
58     if (isLoaded_) {
59         return;
60     } else {
61         callbacksNG_.emplace(node, callback);
62     }
63 }
64 
65 } // namespace OHOS::Ace
66