• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_FONT_PROVIDERS_H
17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_FONT_PROVIDERS_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "texgine/ifont_provider.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace TextEngine {
29 class FontCollection;
30 
31 /*
32  * @brief FontProviders providers an interface for developers to determine the order in
33  *        which fonts are used.
34  *        Texgine is provided with the internal function of generate font collection by
35  *        using font families.
36  *        The order in which fonts are used in generating depends on the order in which
37  *        the collection is appended with FontProvider.
38  */
39 class FontProviders {
40 public:
41     FontProviders() = default;
42     /*
43      * @brief Allocates an empty FontProviders.
44      */
45     static std::shared_ptr<FontProviders> Create() noexcept(true);
46 
47     /*
48      * @brief Allocates a FontProviders that have only one FontProvider which is SystemFontProvider.
49      *        The first FontProvider in the allocated FontProviders is SystemFontProvider,
50      *        add additional FontProvider can be appended if necessary.
51      */
52     static std::shared_ptr<FontProviders> SystemFontOnly() noexcept(true);
53 
54     /*
55      * @brief Append FontProvider into FontProviders.
56      * @param provider  FontProvider that's going to be appended to the FontProviders
57      *                  FontProvider cannot be appended repeatedly
58      */
59     void AppendFontProvider(const std::shared_ptr<IFontProvider>& provider) noexcept(true);
60 
61     /*
62      * @brief Disable find and use fallback font.
63      */
64     void DisableFallback();
65 
66     /*
67      * @brief Generate font collection based on parameter font families and FontProvider that
68      *        has been appended.
69      * @param families  A family vector for selecting fonts from FontProviders
70      * @return          FontCollection from selected fonts
71      */
72     std::shared_ptr<FontCollection> GenerateFontCollection(
73         const std::vector<std::string>& families) const noexcept(true);
74 
Clear()75     void Clear()
76     {
77         fontStyleSetCache_.clear();
78     }
79 
80 private:
81     friend void ReportMemoryUsage(const std::string& member, const FontProviders& that, const bool needThis);
82 
83     FontProviders(const FontProviders&) = delete;
84     FontProviders(FontProviders&&) = delete;
85     FontProviders& operator=(const FontProviders&) = delete;
86     FontProviders& operator=(FontProviders&&) = delete;
87 
88     bool enableFallback_ = true;
89     std::vector<std::shared_ptr<IFontProvider>> providers_ = {};
90 
91     mutable std::map<std::string, std::shared_ptr<VariantFontStyleSet>> fontStyleSetCache_ = {};
92 };
93 } // namespace TextEngine
94 } // namespace Rosen
95 } // namespace OHOS
96 
97 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_FONT_PROVIDERS_H
98