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

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

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

Powered by Google App Engine
This is Rietveld 408576698