• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FLUTTER_FONT_COLLECTION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FLUTTER_FONT_COLLECTION_H
18 
19 #include <future>
20 #include <mutex>
21 
22 #include "flutter/common/task_runners.h"
23 #include "flutter/lib/ui/text/font_collection.h"
24 
25 #include "base/utils/macros.h"
26 #include "base/utils/noncopyable.h"
27 #include "core/components/font/font_collection.h"
28 
29 namespace OHOS::Ace {
30 
31 class ACE_EXPORT FlutterFontCollection : public FontCollection {
32 public:
33     static FlutterFontCollection& GetInstance();
34 
35     std::shared_ptr<txt::FontCollection> GetFontCollection() override;
36 
37     void LoadFontFromList(const uint8_t* fontData, size_t length, std::string familyName);
38 
39     void CreateFontCollection(const fml::RefPtr<fml::TaskRunner>& ioTaskRunner);
40 
41     void VaryFontCollectionWithFontWeightScale(float fontWeightScale);
42 
43     void LoadSystemFont();
44 
45     void SetIsZawgyiMyanmar(bool isZawgyiMyanmar);
46 
47     void UnloadFont();
48 
49 private:
50     std::unique_ptr<flutter::FontCollection> fontCollection_;
51     std::vector<std::string> families_;
52 
53     std::promise<bool> promise_;
54     std::shared_future<bool> future_ = promise_.get_future();
55     bool isInit_ = false;
56     bool isCompleted_ = false;
57     bool isUseFlutterEngine = true;
58     bool isZawgyiMyanmar_ = false;
59     std::once_flag fontFlag_;
60 
61     static FlutterFontCollection instance;
62 };
63 
64 } // namespace OHOS::Ace
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_FLUTTER_FONT_COLLECTION_H
67