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_IFONT_PROVIDER_H
17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_IFONT_PROVIDER_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "texgine/utils/memory_object.h"
23 #include "texgine_font_manager.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace TextEngine {
28 class VariantFontStyleSet;
29 
30 /*
31  * @brief IFontProvider is abstraction for a source of fonts. Subclasses can be backed by
32  *        a memory font, or a font directory, or a font file, or network fonts manager,
33  *        or something else.
34  */
35 class IFontProvider : public MemoryObject {
36 public:
37     virtual ~IFontProvider() = default;
38 
39     /*
40      * @brief Returns FontStyleSet when familyName can correspond to a FontStyleSet.
41      *        This may return nullptr if there is no FontStyleSet correspond to familyName.
42      */
43     virtual std::shared_ptr<VariantFontStyleSet> MatchFamily(const std::string& familyName) noexcept(true) = 0;
44 
45 protected:
46     IFontProvider() = default;
47 
48 private:
49     friend void ReportMemoryUsage(const std::string& member, const IFontProvider& that, const bool needThis);
50     void ReportMemoryUsage(const std::string& member, const bool needThis) const override;
51 
52     IFontProvider(const IFontProvider&) = delete;
53     IFontProvider(IFontProvider&&) = delete;
54     IFontProvider& operator=(const IFontProvider&) = delete;
55     IFontProvider& operator=(const IFontProvider&&) = delete;
56 };
57 } // namespace TextEngine
58 } // namespace Rosen
59 } // namespace OHOS
60 
61 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_IFONT_PROVIDER_H
62