diff options
author | bungeman <bungeman@google.com> | 2016-05-12 10:09:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-12 10:09:31 -0700 |
commit | 13b9c95295f4c5732e34574789e721a6bc08f7b4 (patch) | |
tree | c3ef0aa2af9890c03cb79968f32166af39fba9ba /include | |
parent | 40d21de8b6620d724f34bdc85af1dcb593d33fe0 (diff) |
Move SkTypeface to sk_sp.
Committed: https://skia.googlesource.com/skia/+/6296da736fbf40aae881650c239420f64e576c3f
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1933393002
Review-Url: https://codereview.chromium.org/1933393002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkFont.h | 18 | ||||
-rw-r--r-- | include/core/SkPaint.h | 4 | ||||
-rw-r--r-- | include/core/SkTypeface.h | 87 | ||||
-rw-r--r-- | include/ports/SkFontConfigInterface.h | 9 |
4 files changed, 74 insertions, 44 deletions
diff --git a/include/core/SkFont.h b/include/core/SkFont.h index e4ebebb244..6c231c963a 100644 --- a/include/core/SkFont.h +++ b/include/core/SkFont.h @@ -117,17 +117,17 @@ public: kLCD_MaskType, }; - static SkFont* Create(SkTypeface*, SkScalar size, MaskType, uint32_t flags); - static SkFont* Create(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, - MaskType, uint32_t flags); + static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, MaskType, uint32_t flags); + static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, + MaskType, uint32_t flags); /** * Return a font with the same attributes of this font, but with the specified size. * If size is not supported (e.g. <= 0 or non-finite) NULL will be returned. */ - SkFont* cloneWithSize(SkScalar size) const; + sk_sp<SkFont> makeWithSize(SkScalar size) const; - SkTypeface* getTypeface() const { return fTypeface; } + SkTypeface* getTypeface() const { return fTypeface.get(); } SkScalar getSize() const { return fSize; } SkScalar getScaleX() const { return fScaleX; } SkScalar getSkewX() const { return fSkewX; } @@ -145,17 +145,17 @@ public: SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) const; - static SkFont* Testing_CreateFromPaint(const SkPaint&); + static sk_sp<SkFont> Testing_CreateFromPaint(const SkPaint&); private: enum { kAllFlags = 0xFF, }; - SkFont(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, uint32_t flags); - virtual ~SkFont(); + SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, + uint32_t flags); - SkTypeface* fTypeface; + sk_sp<SkTypeface> fTypeface; SkScalar fSize; SkScalar fScaleX; SkScalar fSkewX; diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 7367fc642d..293ffedc12 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -614,8 +614,10 @@ public: paint @return typeface */ - SkTypeface* setTypeface(SkTypeface* typeface); void setTypeface(sk_sp<SkTypeface>); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + SkTypeface* setTypeface(SkTypeface* typeface); +#endif /** Get the paint's rasterizer (or NULL). <p /> diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index f22d2bd14f..3a47bd2bb3 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -92,51 +92,75 @@ public: */ static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); - /** - * Returns a ref() to the default typeface. The caller must call unref() - * when they are done referencing the object. Never returns NULL. - */ - static SkTypeface* RefDefault(Style style = SkTypeface::kNormal); + /** Returns the default typeface, which is never nullptr. */ + static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* RefDefault(Style style = SkTypeface::kNormal) { + return MakeDefault(style).release(); + } +#endif - /** Return a new reference to the typeface that most closely matches the - requested familyName and style. Pass null as the familyName to return - the default font for the requested style. Will never return null + /** Return the typeface that most closely matches the requested familyName and style. + Pass nullptr as the familyName to request the default font for the requested style. + Will never return nullptr. @param familyName May be NULL. The name of the font family. @param style The style (normal, bold, italic) of the typeface. - @return reference to the closest-matching typeface. Call must call - unref() when they are done. + @return the closest-matching typeface. */ - static SkTypeface* CreateFromName(const char familyName[], Style style); + static sk_sp<SkTypeface> MakeFromName(const char familyName[], Style style); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* CreateFromName(const char familyName[], Style style) { + return MakeFromName(familyName, style).release(); + } +#endif - /** Return a new reference to the typeface that most closely matches the - requested typeface and specified Style. Use this call if you want to - pick a new style from the same family of the existing typeface. - If family is NULL, this selects from the default font's family. + /** Return the typeface that most closely matches the requested typeface and style. + Use this to pick a new style from the same family of the existing typeface. + If family is nullptr, this selects from the default font's family. @param family May be NULL. The name of the existing type face. @param s The style (normal, bold, italic) of the type face. - @return reference to the closest-matching typeface. Call must call - unref() when they are done. + @return the closest-matching typeface. */ - static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); + static sk_sp<SkTypeface> MakeFromTypeface(SkTypeface* family, Style); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style style) { + return MakeFromTypeface(const_cast<SkTypeface*>(family), style).release(); + } +#endif /** Return a new typeface given a file. If the file does not exist, or is - not a valid font file, returns null. + not a valid font file, returns nullptr. */ - static SkTypeface* CreateFromFile(const char path[], int index = 0); + static sk_sp<SkTypeface> MakeFromFile(const char path[], int index = 0); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* CreateFromFile(const char path[], int index = 0) { + return MakeFromFile(path, index).release(); + } +#endif /** Return a new typeface given a stream. If the stream is - not a valid font file, returns null. Ownership of the stream is + not a valid font file, returns nullptr. Ownership of the stream is transferred, so the caller must not reference it again. */ - static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); + static sk_sp<SkTypeface> MakeFromStream(SkStreamAsset* stream, int index = 0); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0) { + return MakeFromStream(stream, index).release(); + } +#endif /** Return a new typeface given font data and configuration. If the data - is not valid font data, returns null. Ownership of the font data is + is not valid font data, returns nullptr. Ownership of the font data is transferred, so the caller must not reference it again. */ - static SkTypeface* CreateFromFontData(SkFontData*); + static sk_sp<SkTypeface> MakeFromFontData(SkFontData*); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* CreateFromFontData(SkFontData* fd) { + return MakeFromFontData(fd).release(); + } +#endif /** Write a unique signature to a stream, sufficient to reconstruct a typeface referencing the same font when Deserialize is called. @@ -144,12 +168,16 @@ public: void serialize(SkWStream*) const; /** Given the data previously written by serialize(), return a new instance - to a typeface referring to the same font. If that font is not available, - return null. If an instance is returned, the caller is responsible for - calling unref() when they are done with it. + of a typeface referring to the same font. If that font is not available, + return nullptr. Does not affect ownership of SkStream. */ - static SkTypeface* Deserialize(SkStream*); + static sk_sp<SkTypeface> MakeDeserialize(SkStream*); +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR + static SkTypeface* Deserialize(SkStream* stream) { + return MakeDeserialize(stream).release(); + } +#endif enum Encoding { kUTF8_Encoding, @@ -395,9 +423,6 @@ private: uint32_t glyphIDsCount = 0) const; private: - static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int, not a Style. - static void DeleteDefault(SkTypeface*); - SkFontID fUniqueID; SkFontStyle fStyle; mutable SkRect fBounds; diff --git a/include/ports/SkFontConfigInterface.h b/include/ports/SkFontConfigInterface.h index 9f98e356d2..dfa5bd0b13 100644 --- a/include/ports/SkFontConfigInterface.h +++ b/include/ports/SkFontConfigInterface.h @@ -97,12 +97,15 @@ public: * * The default implementation simply returns a new typeface built using data obtained from * openStream(), but derived classes may implement more complex caching schemes. - * - * Callers are responsible for unref-ing the result. */ + virtual sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity) { + return SkTypeface::MakeFromStream(this->openStream(identity), identity.fTTCIndex); + } +#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR virtual SkTypeface* createTypeface(const FontIdentity& identity) { - return SkTypeface::CreateFromStream(this->openStream(identity), identity.fTTCIndex); + return this->makeTypeface(identity).release(); } +#endif /** * Return a singleton instance of a direct subclass that calls into |