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 SKTYPEFACE_OHOS_H 6 #define SKTYPEFACE_OHOS_H 7 #include <mutex> 8 9 #include "SkFontHost_FreeType_common.h" 10 #include "SkFontStyle.h" 11 #include "SkStream.h" 12 13 #include "FontInfo_ohos.h" 14 15 /*! 16 * \brief The implementation of SkTypeface for ohos platform 17 */ 18 class SK_API SkTypeface_OHOS : public SkTypeface_FreeType { 19 public: 20 SkTypeface_OHOS(const SkString& specifiedName, FontInfo& info); 21 explicit SkTypeface_OHOS(FontInfo& info); 22 virtual ~SkTypeface_OHOS() override = default; 23 const FontInfo* getFontInfo() const; 24 protected: 25 virtual std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override; 26 virtual std::unique_ptr<SkFontData> onMakeFontData() const override; 27 virtual void onGetFontDescriptor(SkFontDescriptor* descriptor, bool* isLocal) const override; 28 virtual void onGetFamilyName(SkString* familyName) const override; 29 30 #ifdef OHOS_SUPPORT 31 virtual void onGetFontPath(SkString* path) const override; 32 #endif 33 34 virtual sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override; 35 private: 36 mutable std::mutex mutex_; 37 void readStreamFromFile(const std::unique_ptr<FontInfo>& fontInfo) const; 38 SkString specifiedName; // specified family name which is defined in the configuration file 39 std::unique_ptr<FontInfo> fontInfo; // the font information of this typeface 40 }; 41 42 #endif /* SKTYPEFACE_OHOS_H */ 43