1 /*
2  * Copyright (c) 2024 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 ROSEN_TEXT_ADAPTER_TXT_FONT_COLLECTION_H
17 #define ROSEN_TEXT_ADAPTER_TXT_FONT_COLLECTION_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "rosen_text/font_collection.h"
23 
24 #include "txt/font_collection.h"
25 #ifdef USE_GRAPHIC_TEXT_GINE
26 #include "txt/asset_font_manager.h"
27 #endif
28 
29 #include "text/font_mgr.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 namespace AdapterTxt {
34 class FontCollection : public ::OHOS::Rosen::FontCollection {
35 public:
36     explicit FontCollection(std::shared_ptr<txt::FontCollection> fontCollection = nullptr);
37     ~FontCollection();
38     std::shared_ptr<txt::FontCollection> Get();
39 
40     void DisableFallback() override;
41     void DisableSystemFont() override;
42     std::shared_ptr<Drawing::Typeface> LoadFont(
43         const std::string &familyName, const uint8_t *data, size_t datalen) override;
44     std::shared_ptr<Drawing::Typeface> LoadThemeFont(
45         const std::string &familyName, const uint8_t *data, size_t datalen) override;
46     std::shared_ptr<Drawing::FontMgr> GetFontMgr() override;
47     bool RegisterTypeface(std::shared_ptr<Drawing::Typeface> typeface) override;
48 
49     void ClearCaches() override;
50 private:
51     std::shared_ptr<txt::FontCollection> fontCollection_ = nullptr;
52     std::shared_ptr<Drawing::FontMgr> dfmanager_ = nullptr;
53     std::unordered_map<uint32_t, std::shared_ptr<Drawing::Typeface>> typefaces_;
54     std::mutex mutex_;
55 };
56 } // namespace AdapterTxt
57 } // namespace Rosen
58 } // namespace OHOS
59 
60 #endif // ROSEN_TEXT_ADAPTER_TXT_FONT_COLLECTION_H
61