• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  * 2023.4.23 SkFontMgr on ohos.
7  *           Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
8  */
9 
10 #ifndef SKFONTMGR_OHOS_H
11 #define SKFONTMGR_OHOS_H
12 
13 #include "FontConfig_ohos.h"
14 #include "SkFontDescriptor.h"
15 #include "SkFontMgr.h"
16 #include "SkFontStyleSet_ohos.h"
17 
18 /*!
19  * \brief To implement the SkFontMgr for ohos platform
20  */
21 class SK_API SkFontMgr_OHOS : public SkFontMgr {
22 public:
23     explicit SkFontMgr_OHOS(const char* path = nullptr);
24     ~SkFontMgr_OHOS() override = default;
25 
26     int GetFontFullName(int fontFd, std::vector<SkByteArray> &fullnameVec) override;
27 protected:
28     int onCountFamilies() const override;
29     void onGetFamilyName(int index, SkString* familyName) const override;
30     SkFontStyleSet* onCreateStyleSet(int index)const override;
31 
32     SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
33 
34     SkTypeface* onMatchFamilyStyle(const char familyName[],
35                                            const SkFontStyle& style) const override;
36     SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
37                                                     const char* bcp47[], int bcp47Count,
38                                                     SkUnichar character) const override;
39 
40     SkTypeface* onMatchFaceStyle(const SkTypeface* typeface,
41                                          const SkFontStyle& style) const override;
42 
43     sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override;
44     sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
45                                                     int ttcIndex) const override;
46     sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
47                                                    const SkFontArguments& args) const override;
48     sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
49 
50     sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override;
51 
52 #ifdef OHOS_SUPPORT
53     std::vector<sk_sp<SkTypeface>> onGetSystemFonts() const override;
54 #endif
55 
56 private:
57     std::shared_ptr<FontConfig_OHOS> fFontConfig = nullptr; // the pointer of FontConfig_OHOS
58     SkTypeface_FreeType::Scanner fFontScanner; // the scanner to parse a font file
59     int fFamilyCount = 0; // the count of font style sets in generic family list
60 
61     static int compareLangs(const std::string& langs, const char* bcp47[], int bcp47Count);
62     sk_sp<SkTypeface> makeTypeface(std::unique_ptr<SkStreamAsset> stream,
63                                     const SkFontArguments& args, const char path[]) const;
64     SkTypeface* findTypeface(const SkFontStyle& style,
65                              const char* bcp47[], int bcp47Count,
66                              SkUnichar character) const;
67     SkTypeface* findSpecialTypeface(SkUnichar character, const SkFontStyle& style) const;
68 };
69 
70 SK_API sk_sp<SkFontMgr> SkFontMgr_New_OHOS(const char* path);
SkFontMgr_New_OHOS()71 SK_API sk_sp<SkFontMgr> SkFontMgr_New_OHOS() {
72     return SkFontMgr_New_OHOS("/system/etc/fontconfig_ohos.json");
73 }
74 
75 
76 #endif /* SKFONTMGR_OHOS_H */
77