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

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: 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 unified diff | Download patch
« no previous file with comments | « include/core/SkPaint.h ('k') | include/ports/SkFontConfigInterface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 resolve it to the default font and return its uniqueID. Will never 85 resolve it to the default font and return its uniqueID. Will never
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 /** Returns the default typeface, which is never nullptr. */
96 * Returns a ref() to the default typeface. The caller must call unref() 96 static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal);
97 * when they are done referencing the object. Never returns NULL. 97 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
98 */ 98 static SkTypeface* RefDefault(Style style = SkTypeface::kNormal) {
99 static SkTypeface* RefDefault(Style style = SkTypeface::kNormal); 99 return MakeDefault(style).release();
100 }
101 #endif
100 102
101 /** Return a new reference to the typeface that most closely matches the 103 /** Return the typeface that most closely matches the requested familyName a nd style.
102 requested familyName and style. Pass null as the familyName to return 104 Pass nullptr as the familyName to request the default font for the reque sted style.
103 the default font for the requested style. Will never return null 105 Will never return nullptr.
104 106
105 @param familyName May be NULL. The name of the font family. 107 @param familyName May be NULL. The name of the font family.
106 @param style The style (normal, bold, italic) of the typeface. 108 @param style The style (normal, bold, italic) of the typeface.
107 @return reference to the closest-matching typeface. Call must call 109 @return the closest-matching typeface.
108 unref() when they are done.
109 */ 110 */
110 static SkTypeface* CreateFromName(const char familyName[], Style style); 111 static sk_sp<SkTypeface> MakeFromName(const char familyName[], Style style);
112 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
113 static SkTypeface* CreateFromName(const char familyName[], Style style) {
114 return MakeFromName(familyName, style).release();
115 }
116 #endif
111 117
112 /** Return a new reference to the typeface that most closely matches the 118 /** Return the typeface that most closely matches the requested typeface and style.
113 requested typeface and specified Style. Use this call if you want to 119 Use this to pick a new style from the same family of the existing typefa ce.
114 pick a new style from the same family of the existing typeface. 120 If family is nullptr, this selects from the default font's family.
115 If family is NULL, this selects from the default font's family.
116 121
117 @param family May be NULL. The name of the existing type face. 122 @param family May be NULL. The name of the existing type face.
118 @param s The style (normal, bold, italic) of the type face. 123 @param s The style (normal, bold, italic) of the type face.
119 @return reference to the closest-matching typeface. Call must call 124 @return the closest-matching typeface.
120 unref() when they are done.
121 */ 125 */
122 static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); 126 static sk_sp<SkTypeface> MakeFromTypeface(SkTypeface* family, Style);
127 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
128 static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style style) {
129 return MakeFromTypeface(const_cast<SkTypeface*>(family), style).release( );
130 }
131 #endif
123 132
124 /** Return a new typeface given a file. If the file does not exist, or is 133 /** Return a new typeface given a file. If the file does not exist, or is
125 not a valid font file, returns null. 134 not a valid font file, returns nullptr.
126 */ 135 */
127 static SkTypeface* CreateFromFile(const char path[], int index = 0); 136 static sk_sp<SkTypeface> MakeFromFile(const char path[], int index = 0);
137 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
138 static SkTypeface* CreateFromFile(const char path[], int index = 0) {
139 return MakeFromFile(path, index).release();
140 }
141 #endif
128 142
129 /** Return a new typeface given a stream. If the stream is 143 /** Return a new typeface given a stream. If the stream is
130 not a valid font file, returns null. Ownership of the stream is 144 not a valid font file, returns nullptr. Ownership of the stream is
131 transferred, so the caller must not reference it again. 145 transferred, so the caller must not reference it again.
132 */ 146 */
133 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); 147 static sk_sp<SkTypeface> MakeFromStream(SkStreamAsset* stream, int index = 0 );
148 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
149 static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0) {
150 return MakeFromStream(stream, index).release();
151 }
152 #endif
134 153
135 /** Return a new typeface given font data and configuration. If the data 154 /** 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 155 is not valid font data, returns nullptr. Ownership of the font data is
137 transferred, so the caller must not reference it again. 156 transferred, so the caller must not reference it again.
138 */ 157 */
139 static SkTypeface* CreateFromFontData(SkFontData*); 158 static sk_sp<SkTypeface> MakeFromFontData(SkFontData*);
159 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
160 static SkTypeface* CreateFromFontData(SkFontData* fd) {
161 return MakeFromFontData(fd).release();
162 }
163 #endif
140 164
141 /** Write a unique signature to a stream, sufficient to reconstruct a 165 /** Write a unique signature to a stream, sufficient to reconstruct a
142 typeface referencing the same font when Deserialize is called. 166 typeface referencing the same font when Deserialize is called.
143 */ 167 */
144 void serialize(SkWStream*) const; 168 void serialize(SkWStream*) const;
145 169
146 /** Given the data previously written by serialize(), return a new instance 170 /** 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, 171 of 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 172 return nullptr.
149 calling unref() when they are done with it.
150 Does not affect ownership of SkStream. 173 Does not affect ownership of SkStream.
151 */ 174 */
152 static SkTypeface* Deserialize(SkStream*); 175 static sk_sp<SkTypeface> MakeDeserialize(SkStream*);
176 #ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
177 static SkTypeface* Deserialize(SkStream* stream) {
178 return MakeDeserialize(stream).release();
179 }
180 #endif
153 181
154 enum Encoding { 182 enum Encoding {
155 kUTF8_Encoding, 183 kUTF8_Encoding,
156 kUTF16_Encoding, 184 kUTF16_Encoding,
157 kUTF32_Encoding 185 kUTF32_Encoding
158 }; 186 };
159 187
160 /** 188 /**
161 * Given an array of character codes, of the specified encoding, 189 * Given an array of character codes, of the specified encoding,
162 * optionally return their corresponding glyph IDs (if glyphs is not NULL). 190 * 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 416 @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
389 glyphIDs is NULL. 417 glyphIDs is NULL.
390 @return The returned object has already been referenced. 418 @return The returned object has already been referenced.
391 */ 419 */
392 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( 420 SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
393 PerGlyphInfo, 421 PerGlyphInfo,
394 const uint32_t* glyphIDs = NULL, 422 const uint32_t* glyphIDs = NULL,
395 uint32_t glyphIDsCount = 0) const; 423 uint32_t glyphIDsCount = 0) const;
396 424
397 private: 425 private:
398 static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int, not a Style.
399 static void DeleteDefault(SkTypeface*);
400
401 SkFontID fUniqueID; 426 SkFontID fUniqueID;
402 SkFontStyle fStyle; 427 SkFontStyle fStyle;
403 mutable SkRect fBounds; 428 mutable SkRect fBounds;
404 mutable SkOnce fBoundsOnce; 429 mutable SkOnce fBoundsOnce;
405 bool fIsFixedPitch; 430 bool fIsFixedPitch;
406 431
407 friend class SkPaint; 432 friend class SkPaint;
408 friend class SkGlyphCache; // GetDefaultTypeface 433 friend class SkGlyphCache; // GetDefaultTypeface
409 434
410 typedef SkWeakRefCnt INHERITED; 435 typedef SkWeakRefCnt INHERITED;
411 }; 436 };
412 437
413 #endif 438 #endif
OLDNEW
« 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