aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-09-25 13:21:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-25 19:45:09 +0000
commit4bf296be2821d2bdd0afabae9fdfe18e7e9b59cb (patch)
treeada1341d6943d4e8b91b5d9da331ac82873c3677 /include
parentd6c04d9a05c1b4066c09083a673d7d3cf61a3aa6 (diff)
migrate to sk_sp for SkFontMgr API
Bug: skia: Change-Id: I1bf2a13537f67938cdc9956080065d10ea0bd1d8 Reviewed-on: https://skia-review.googlesource.com/48740 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/ports/SkFontMgr.h59
-rw-r--r--include/ports/SkFontMgr_indirect.h9
2 files changed, 51 insertions, 17 deletions
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<SkTypeface> makeFromData(sk_sp<SkData>, 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<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, 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<SkTypeface> makeFromStream(std::unique_ptr<SkStreamAsset>, 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<SkFontData>) const;
+ sk_sp<SkTypeface> makeFromFontData(std::unique_ptr<SkFontData>) 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<SkTypeface> makeFromFile(const char path[], int ttcIndex = 0) const;
+
+ sk_sp<SkTypeface> 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<SkFontData> 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<SkFontMgr> 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<SkFontData>) 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<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const;
+ virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> strm,
+ int ttcIndex) const;
+ virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> strm,
+ const SkFontArguments& args) const;
+ virtual sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData> fd) const;
+ virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const;
+ virtual sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const;
+#else
+ virtual sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const = 0;
+ virtual sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
+ int ttcIndex) const = 0;
+ virtual sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
+ const SkFontArguments&) const;
+ virtual sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const;
+ virtual sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const = 0;
+
+ virtual sk_sp<SkTypeface> 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<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
private:
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;