• 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_DYNAMIC_FONT_PROVIDER_H
17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_DYNAMIC_FONT_PROVIDER_H
18 
19 #include <map>
20 
21 #include "texgine/ifont_provider.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace TextEngine {
26 /*
27  * @brief DynamicFontProvider is a FontProvider that can load fonts dynamically.
28  *        DynamicFontProvider can accept font typed memory buffer.
29  */
30 class DynamicFontProvider : virtual public IFontProvider {
31 public:
32     /*
33      * @brief Create DynamicFontProvider instance.
34      * @return DynamicFontProvider
35      */
36     static std::shared_ptr<DynamicFontProvider> Create() noexcept(true);
37 
38     /*
39      * @brief Load font from data, if familyName is empty, it will use the name that comes
40      *        with the font file.
41      * @param familyName  The name of the font family you want,
42      *                    empty String by default means use the name that
43      *                    comes with the font file.
44      * @param data        The font data pointer.
45      * @param datalen     The font data length.
46      * @return            0 if success
47      *                    1 if the arguments are invalid
48      *                    2 if the call to the internal API fails
49      */
50     int LoadFont(const std::string& familyName, const void *data, size_t datalen) noexcept(true);
51 
52     std::shared_ptr<VariantFontStyleSet> MatchFamily(const std::string& familyName) noexcept(true) override;
53 
54 private:
55     void ReportMemoryUsage(const std::string& member, const bool needThis) const override;
56 
57     std::map<std::string, std::shared_ptr<VariantFontStyleSet>> fontStyleSetMap_;
58 };
59 } // namespace TextEngine
60 } // namespace Rosen
61 } // namespace OHOS
62 
63 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_DYNAMIC_FONT_PROVIDER_H
64