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 "SkFontDescriptor.h"
14 #include "SkFontMgr.h"
15
16 #include "FontConfig_ohos.h"
17 #include "SkFontStyleSet_ohos.h"
18
19 /*!
20 * \brief To implement the SkFontMgr for ohos platform
21 */
22 class SK_API SkFontMgr_OHOS : public SkFontMgr {
23 public:
24 explicit SkFontMgr_OHOS(const char* path = nullptr);
25 virtual ~SkFontMgr_OHOS() override = default;
26
27 int GetFontFullName(int fontFd, std::vector<SkByteArray> &fullnameVec) override;
28 protected:
29 virtual int onCountFamilies() const override;
30 virtual void onGetFamilyName(int index, SkString* familyName) const override;
31 virtual SkFontStyleSet* onCreateStyleSet(int index)const override;
32
33 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
34
35 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
36 const SkFontStyle& style) const override;
37 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
38 const char* bcp47[], int bcp47Count,
39 SkUnichar character) const override;
40
41 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface,
42 const SkFontStyle& style) const override;
43
44 virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override;
45 virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
46 int ttcIndex) const override;
47 virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
48 const SkFontArguments& args) const override;
49 virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
50
51 virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override;
52
53 #ifdef OHOS_SUPPORT
54 std::vector<sk_sp<SkTypeface>> onGetSystemFonts() const override;
55 #endif
56
57 private:
58 std::shared_ptr<FontConfig_OHOS> fontConfig = nullptr; // the pointer of FontConfig_OHOS
59 SkTypeface_FreeType::Scanner fontScanner; // the scanner to parse a font file
60 int familyCount = 0; // the count of font style sets in generic family list
61
62 int compareLangs(const SkString& langs, const char* bcp47[], int bcp47Count, const int tps[]) const;
63 sk_sp<SkTypeface> makeTypeface(std::unique_ptr<SkStreamAsset> stream,
64 const SkFontArguments& args, const char path[]) const;
65 SkTypeface* findTypeface(const FallbackSetPos& fallbackItem, const SkFontStyle& style,
66 const char* bcp47[], int bcp47Count,
67 SkUnichar character) 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.json");
73 }
74
75 #endif /* SKFONTMGR_OHOS_H */
76