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

Side by Side Diff: include/core/SkTypeface.h

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make vc++ happy. 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkTypeface_DEFINED 8 #ifndef SkTypeface_DEFINED
9 #define SkTypeface_DEFINED 9 #define SkTypeface_DEFINED
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return 0. 86 return 0.
87 */ 87 */
88 static SkFontID UniqueID(const SkTypeface* face); 88 static SkFontID UniqueID(const SkTypeface* face);
89 89
90 /** Returns true if the two typefaces reference the same underlying font, 90 /** Returns true if the two typefaces reference the same underlying font,
91 handling either being null (treating null as the default font) 91 handling either being null (treating null as the default font)
92 */ 92 */
93 static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); 93 static bool Equal(const SkTypeface* facea, const SkTypeface* faceb);
94 94
95 /** 95 /**
96 * Returns a ref() to the default typeface. The caller must call unref() 96 * Returns a ref() to the default typeface. The caller must call unref()
tomhudson 2016/04/29 21:10:36 If we don't update these comments now, we'll need
bungeman-skia 2016/04/29 22:03:23 Yeah, these static methods are legacy as far as I'
97 * when they are done referencing the object. Never returns NULL. 97 * when they are done referencing the object. Never returns NULL.
98 */ 98 */
99 static SkTypeface* RefDefault(Style style = SkTypeface::kNormal); 99 static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal);
100 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
101 static SkTypeface* RefDefault(Style style = SkTypeface::kNormal) {
102 return MakeDefault(style).release();
103 }
104 #endif
100 105
101 /** Return a new reference to the typeface that most closely matches the 106 /** Return a new reference to the typeface that most closely matches the
102 requested familyName and style. Pass null as the familyName to return 107 requested familyName and style. Pass null as the familyName to return
103 the default font for the requested style. Will never return null 108 the default font for the requested style. Will never return null
104 109
105 @param familyName May be NULL. The name of the font family. 110 @param familyName May be NULL. The name of the font family.
106 @param style The style (normal, bold, italic) of the typeface. 111 @param style The style (normal, bold, italic) of the typeface.
107 @return reference to the closest-matching typeface. Call must call 112 @return reference to the closest-matching typeface. Call must call
108 unref() when they are done. 113 unref() when they are done.
109 */ 114 */
110 static SkTypeface* CreateFromName(const char familyName[], Style style); 115 static sk_sp<SkTypeface> MakeFromName(const char familyName[], Style style);
116 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
117 static SkTypeface* CreateFromName(const char familyName[], Style style) {
118 return MakeFromName(familyName, style).release();
119 }
120 #endif
111 121
112 /** Return a new reference to the typeface that most closely matches the 122 /** Return a new reference to the typeface that most closely matches the
113 requested typeface and specified Style. Use this call if you want to 123 requested typeface and specified Style. Use this call if you want to
114 pick a new style from the same family of the existing typeface. 124 pick a new style from the same family of the existing typeface.
115 If family is NULL, this selects from the default font's family. 125 If family is NULL, this selects from the default font's family.
116 126
117 @param family May be NULL. The name of the existing type face. 127 @param family May be NULL. The name of the existing type face.
118 @param s The style (normal, bold, italic) of the type face. 128 @param s The style (normal, bold, italic) of the type face.
119 @return reference to the closest-matching typeface. Call must call 129 @return reference to the closest-matching typeface. Call must call
120 unref() when they are done. 130 unref() when they are done.
121 */ 131 */
122 static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); 132 static sk_sp<SkTypeface> MakeFromTypeface(SkTypeface* family, Style);
133 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
134 static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style style) {
135 return MakeFromTypeface(const_cast<SkTypeface*>(family), style).release( );
136 }
137 #endif
123 138
124 /** Return a new typeface given a file. If the file does not exist, or is 139 /** Return a new typeface given a file. If the file does not exist, or is
125 not a valid font file, returns null. 140 not a valid font file, returns null.
126 */ 141 */
127 static SkTypeface* CreateFromFile(const char path[], int index = 0); 142 static sk_sp<SkTypeface> MakeFromFile(const char path[], int index = 0);
143 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
144 static SkTypeface* CreateFromFile(const char path[], int index = 0) {
145 return MakeFromFile(path, index).release();
146 }
147 #endif
128 148
129 /** Return a new typeface given a stream. If the stream is 149 /** Return a new typeface given a stream. If the stream is
130 not a valid font file, returns null. Ownership of the stream is 150 not a valid font file, returns null. Ownership of the stream is
131 transferred, so the caller must not reference it again. 151 transferred, so the caller must not reference it again.
132 */ 152 */
133 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); 153 static sk_sp<SkTypeface> MakeFromStream(SkStreamAsset* stream, int index = 0 );
154 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
155 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0) {
156 return MakeFromStream(stream, index).release();
157 }
158 #endif
134 159
135 /** Return a new typeface given font data and configuration. If the data 160 /** Return a new typeface given font data and configuration. If the data
136 is not valid font data, returns null. Ownership of the font data is 161 is not valid font data, returns null. Ownership of the font data is
137 transferred, so the caller must not reference it again. 162 transferred, so the caller must not reference it again.
138 */ 163 */
139 static SkTypeface* CreateFromFontData(SkFontData*); 164 static sk_sp<SkTypeface> MakeFromFontData(SkFontData*);
165 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
166 static SkTypeface* CreateFromFontData(SkFontData* fd) {
167 return MakeFromFontData(fd).release();
168 }
169 #endif
140 170
141 /** Write a unique signature to a stream, sufficient to reconstruct a 171 /** Write a unique signature to a stream, sufficient to reconstruct a
142 typeface referencing the same font when Deserialize is called. 172 typeface referencing the same font when Deserialize is called.
143 */ 173 */
144 void serialize(SkWStream*) const; 174 void serialize(SkWStream*) const;
145 175
146 /** Given the data previously written by serialize(), return a new instance 176 /** Given the data previously written by serialize(), return a new instance
147 to a typeface referring to the same font. If that font is not available, 177 to a typeface referring to the same font. If that font is not available,
148 return null. If an instance is returned, the caller is responsible for 178 return null. If an instance is returned, the caller is responsible for
149 calling unref() when they are done with it. 179 calling unref() when they are done with it.
150 Does not affect ownership of SkStream. 180 Does not affect ownership of SkStream.
151 */ 181 */
152 static SkTypeface* Deserialize(SkStream*); 182 static sk_sp<SkTypeface> MakeDeserialize(SkStream*);
183 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
184 static SkTypeface* Deserialize(SkStream* stream) {
185 return MakeDeserialize(stream).release();
186 }
187 #endif
153 188
154 enum Encoding { 189 enum Encoding {
155 kUTF8_Encoding, 190 kUTF8_Encoding,
156 kUTF16_Encoding, 191 kUTF16_Encoding,
157 kUTF32_Encoding 192 kUTF32_Encoding
158 }; 193 };
159 194
160 /** 195 /**
161 * Given an array of character codes, of the specified encoding, 196 * Given an array of character codes, of the specified encoding,
162 * optionally return their corresponding glyph IDs (if glyphs is not NULL). 197 * optionally return their corresponding glyph IDs (if glyphs is not NULL).
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if 423 @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
389 glyphIDs is NULL. 424 glyphIDs is NULL.
390 @return The returned object has already been referenced. 425 @return The returned object has already been referenced.
391 */ 426 */
392 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( 427 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
393 PerGlyphInfo, 428 PerGlyphInfo,
394 const uint32_t* glyphIDs = NULL, 429 const uint32_t* glyphIDs = NULL,
395 uint32_t glyphIDsCount = 0) const; 430 uint32_t glyphIDsCount = 0) const;
396 431
397 private: 432 private:
398 static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int, not a Style.
399 static void DeleteDefault(SkTypeface*);
400
401 SkOncePtr<SkRect> fLazyBounds; 433 SkOncePtr<SkRect> fLazyBounds;
402 SkFontID fUniqueID; 434 SkFontID fUniqueID;
403 SkFontStyle fStyle; 435 SkFontStyle fStyle;
404 bool fIsFixedPitch; 436 bool fIsFixedPitch;
405 437
406 friend class SkPaint; 438 friend class SkPaint;
407 friend class SkGlyphCache; // GetDefaultTypeface 439 friend class SkGlyphCache; // GetDefaultTypeface
408 440
409 typedef SkWeakRefCnt INHERITED; 441 typedef SkWeakRefCnt INHERITED;
410 }; 442 };
411 443
412 #endif 444 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698