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 * 2021.2.10 SkFontMgr on ohos. 7 * Copyright (c) 2021 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> onMakeFromFontData(std::unique_ptr<SkFontData> data) const override; 48 virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; 49 50 virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override; 51 52 private: 53 std::shared_ptr<FontConfig_OHOS> fontConfig = nullptr; // the pointer of FontConfig_OHOS 54 SkTypeface_FreeType::Scanner fontScanner; // the scanner to parse a font file 55 int familyCount = 0; // the count of font style sets in generic family list 56 57 int compareLangs(const SkString& langs, const char* bcp47[], int bcp47Count, const int tps[]) const; 58 sk_sp<SkTypeface> makeTypeface(std::unique_ptr<SkStreamAsset> stream, 59 const SkFontArguments& args, const char path[]) const; 60 sk_sp<SkTypeface> makeTypeface(SkFontData* fontData) const; 61 SkTypeface* findTypeface(const FallbackSetPos& fallbackItem, const SkFontStyle& style, 62 const char* bcp47[], int bcp47Count, 63 SkUnichar character) const; 64 }; 65 66 SK_API sk_sp<SkFontMgr> SkFontMgr_New_OHOS(const char* path); 67 68 #endif /* SKFONTMGR_OHOS_H */ 69