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 SkFontMgr_OHOS : public SkFontMgr {
23 public:
24 explicit SkFontMgr_OHOS(const char* path = nullptr);
25 virtual ~SkFontMgr_OHOS() override = default;
26 protected:
27 virtual int onCountFamilies() const override;
28 virtual void onGetFamilyName(int index, SkString* familyName) const override;
29 virtual SkFontStyleSet* onCreateStyleSet(int index)const override;
30
31 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
32
33 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
34 const SkFontStyle& style) const override;
35 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
36 const char* bcp47[], int bcp47Count,
37 SkUnichar character) const override;
38
39 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface,
40 const SkFontStyle& style) const override;
41
42 virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override;
43 virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
44 int ttcIndex) const override;
45 virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
46 const SkFontArguments& args) const override;
47 virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
48
49 virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override;
50
51 private:
52 std::shared_ptr<FontConfig_OHOS> fontConfig = nullptr; // the pointer of FontConfig_OHOS
53 SkTypeface_FreeType::Scanner fontScanner; // the scanner to parse a font file
54 int familyCount = 0; // the count of font style sets in generic family list
55
56 int compareLangs(const SkString& langs, const char* bcp47[], int bcp47Count, const int tps[]) const;
57 sk_sp<SkTypeface> makeTypeface(std::unique_ptr<SkStreamAsset> stream,
58 const SkFontArguments& args, const char path[]) const;
59 SkTypeface* findTypeface(const FallbackSetPos& fallbackItem, const SkFontStyle& style,
60 const char* bcp47[], int bcp47Count,
61 SkUnichar character) 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.json");
67 }
68
69 #endif /* SKFONTMGR_OHOS_H */
70