Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: include/core/SkTypeface.h

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | include/ports/SkFontConfigInterface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkTypeface.h
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index f22d2bd14f6c0ed2e48cff9599ec26c5a55be5cd..3a47bd2bb3f3997adb6cdc2df342b13e17d74464 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;
« no previous file with comments | « include/core/SkPaint.h ('k') | include/ports/SkFontConfigInterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698