From 592273965a7fc7fc403252e420d15f6555b8f25d Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 26 Sep 2017 09:46:08 -0400 Subject: Revert "Revert "migrate to sk_sp for SkFontMgr API"" This reverts commit f40ae1a4b5365620463bd63b5140bd3fc78894a1. Bug: skia: Change-Id: I752606de92ea405d6e50219c98030409b00a2841 Reviewed-on: https://skia-review.googlesource.com/51160 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- include/ports/SkFontMgr.h | 59 ++++++++++++++++++++++++++++++-------- include/ports/SkFontMgr_indirect.h | 9 +++--- 2 files changed, 51 insertions(+), 17 deletions(-) (limited to 'include/ports') diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index b13e113a2e..08e406a97d 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -95,26 +95,28 @@ public: * or NULL if the data is not recognized. The caller must call unref() on * the returned object if it is not null. */ - SkTypeface* createFromData(SkData*, int ttcIndex = 0) const; + sk_sp makeFromData(sk_sp, int ttcIndex = 0) const; /** * Create a typeface for the specified stream and TTC index * (pass 0 for none) or NULL if the stream is not recognized. The caller * must call unref() on the returned object if it is not null. */ - SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const; + sk_sp makeFromStream(std::unique_ptr, int ttcIndex = 0) const; - // deprecated, use SkFontArguments instead. +#ifdef SK_SUPPORT_LEGACY_FONTMGR_API using FontParameters = SkFontArguments; +#endif + /* Experimental, API subject to change. */ - SkTypeface* createFromStream(SkStreamAsset*, const SkFontArguments&) const; + sk_sp makeFromStream(std::unique_ptr, const SkFontArguments&) const; /** * Create a typeface from the specified font data. * Will return NULL if the typeface could not be created. * The caller must call unref() on the returned object if it is not null. */ - SkTypeface* createFromFontData(std::unique_ptr) const; + sk_sp makeFromFontData(std::unique_ptr) const; /** * Create a typeface for the specified fileName and TTC index @@ -122,9 +124,18 @@ public: * not recognized. The caller must call unref() on the returned object * if it is not null. */ - SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const; + sk_sp makeFromFile(const char path[], int ttcIndex = 0) const; + + sk_sp legacyMakeTypeface(const char familyName[], SkFontStyle style) const; +#ifdef SK_SUPPORT_LEGACY_FONTMGR_API + SkTypeface* createFromData(SkData* data, int ttcIndex = 0) const; + SkTypeface* createFromStream(SkStreamAsset* strm, int ttcIndex = 0) const; + SkTypeface* createFromStream(SkStreamAsset* strm, const SkFontArguments& args) const; + SkTypeface* createFromFontData(std::unique_ptr fd) const; + SkTypeface* createFromFile(const char path[], int ttcIndex = 0) const; SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) const; +#endif /** Return the default fontmgr. */ static sk_sp RefDefault(); @@ -145,14 +156,38 @@ protected: virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, const SkFontStyle&) const = 0; - virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0; - virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0; - // TODO: make pure virtual. +#ifdef SK_SUPPORT_LEGACY_FONTMGR_API + // legacy virtuals + virtual SkTypeface* onCreateFromData(SkData*, int) const { return nullptr; } + virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int) const { return nullptr; } virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const; virtual SkTypeface* onCreateFromFontData(std::unique_ptr) const; - virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0; - - virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0; + virtual SkTypeface* onCreateFromFile(const char[], int) const { return nullptr; } + virtual SkTypeface* onLegacyCreateTypeface(const char[], SkFontStyle) const { + return nullptr; + } + + // new virtuals express as calling legacy versions + + virtual sk_sp onMakeFromData(sk_sp data, int ttcIndex) const; + virtual sk_sp onMakeFromStreamIndex(std::unique_ptr strm, + int ttcIndex) const; + virtual sk_sp onMakeFromStreamArgs(std::unique_ptr strm, + const SkFontArguments& args) const; + virtual sk_sp onMakeFromFontData(std::unique_ptr fd) const; + virtual sk_sp onMakeFromFile(const char path[], int ttcIndex) const; + virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const; +#else + virtual sk_sp onMakeFromData(sk_sp, int ttcIndex) const = 0; + virtual sk_sp onMakeFromStreamIndex(std::unique_ptr, + int ttcIndex) const = 0; + virtual sk_sp onMakeFromStreamArgs(std::unique_ptr, + const SkFontArguments&) const; + virtual sk_sp onMakeFromFontData(std::unique_ptr) const; + virtual sk_sp onMakeFromFile(const char path[], int ttcIndex) const = 0; + + virtual sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const = 0; +#endif private: diff --git a/include/ports/SkFontMgr_indirect.h b/include/ports/SkFontMgr_indirect.h index 251d74a83a..04e903ed14 100644 --- a/include/ports/SkFontMgr_indirect.h +++ b/include/ports/SkFontMgr_indirect.h @@ -50,11 +50,10 @@ protected: SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, const SkFontStyle& fontStyle) const override; - SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override; - SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override; - SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override; - - SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override; + sk_sp onMakeFromStreamIndex(std::unique_ptr, int ttcIndex) const override; + sk_sp onMakeFromFile(const char path[], int ttcIndex) const override; + sk_sp onMakeFromData(sk_sp, int ttcIndex) const override; + sk_sp onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override; private: SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const; -- cgit v1.2.3