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_COMPONENTS_FONT_ROSEN_FONT_LOADER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_ROSEN_FONT_LOADER_H
18 
19 #include "core/common/font_loader.h"
20 #include "core/common/rosen/rosen_asset_manager.h"
21 
22 namespace OHOS::Ace {
23 
24 extern const char FONT_SRC_NETWORK[5];
25 extern const char FONT_SRC_RESOURCE[9];
26 
27 class RosenFontLoader : public FontLoader {
28     DECLARE_ACE_TYPE(RosenFontLoader, FontLoader);
29 
30 public:
31     RosenFontLoader(const std::string& familyName, const std::string& familySrc);
32     ~RosenFontLoader() override = default;
33 
34     void AddFont(const RefPtr<PipelineBase>& context, const std::string& bundleName = "",
35         const std::string& moduleName = "") override;
36     void SetDefaultFontFamily(const char* fontFamily, const char* familySrc) override;
37 
38 private:
39     void LoadFromNetwork(const RefPtr<PipelineBase>& context);
40     void LoadFromResource(
41         const RefPtr<PipelineBase>& context, const std::string& bundleName = "", const std::string& moduleName = "");
42     void LoadFromAsset(const RefPtr<PipelineBase>& context);
43     void LoadFromFile(const RefPtr<PipelineBase>& context);
44     RefPtr<Asset> GetAssetFromFile(const std::string& fileName) const;
45     std::string RemovePathHead(const std::string& uri);
46     void PostLoadFontTask(const std::vector<uint8_t>& fontData, const RefPtr<PipelineBase>& context);
47     void NotifyCallbacks();
48 };
49 
50 } // namespace OHOS::Ace
51 
52 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_ROSEN_FONT_LOADER_H
53