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