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

Side by Side Diff: src/ports/SkFontHost_linux.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 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 | « src/ports/SkFontHost_fontconfig.cpp ('k') | src/ports/SkFontHost_win.cpp » ('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 #include "SkFontHost.h" 8 #include "SkFontHost.h"
9 #include "SkFontHost_FreeType_common.h" 9 #include "SkFontHost_FreeType_common.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 *ttcIndex = this->getIndex(); 132 *ttcIndex = this->getIndex();
133 if (fStream.get()) { 133 if (fStream.get()) {
134 return fStream->duplicate(); 134 return fStream->duplicate();
135 } else { 135 } else {
136 return SkStream::NewFromFile(fPath.c_str()); 136 return SkStream::NewFromFile(fPath.c_str());
137 } 137 }
138 } 138 }
139 139
140 private: 140 private:
141 SkString fPath; 141 SkString fPath;
142 const SkAutoTUnref<SkStreamAsset> fStream; 142 const SkAutoTDelete<SkStreamAsset> fStream;
143 143
144 typedef SkTypeface_Custom INHERITED; 144 typedef SkTypeface_Custom INHERITED;
145 }; 145 };
146 146
147 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
148 148
149 /** 149 /**
150 * SkFontStyleSet_Custom 150 * SkFontStyleSet_Custom
151 * 151 *
152 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families. 152 * This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) { 276 for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
277 if (fFamilies[i]->fStyles[j] == familyMember) { 277 if (fFamilies[i]->fStyles[j] == familyMember) {
278 return fFamilies[i]->matchStyle(fontStyle); 278 return fFamilies[i]->matchStyle(fontStyle);
279 } 279 }
280 } 280 }
281 } 281 }
282 return NULL; 282 return NULL;
283 } 283 }
284 284
285 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE { 285 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE {
286 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); 286 return this->createFromStream(new SkMemoryStream(data), ttcIndex);
287 return this->createFromStream(stream, ttcIndex);
288 } 287 }
289 288
290 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER RIDE { 289 SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVER RIDE {
290 SkAutoTDelete<SkStream> streamDeleter(stream);
291 if (NULL == stream || stream->getLength() <= 0) { 291 if (NULL == stream || stream->getLength() <= 0) {
292 SkDELETE(stream);
293 return NULL; 292 return NULL;
294 } 293 }
295 294
296 bool isFixedPitch; 295 bool isFixedPitch;
297 SkFontStyle style; 296 SkFontStyle style;
298 SkString name; 297 SkString name;
299 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) { 298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch)) {
300 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na me, 299 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na me,
301 stream, ttcIndex)); 300 streamDeleter.detach(), ttcInd ex));
302 } else { 301 } else {
303 return NULL; 302 return NULL;
304 } 303 }
305 } 304 }
306 305
307 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR IDE { 306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERR IDE {
308 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 307 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
309 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL;
310 } 309 }
311 310
312 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 311 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
313 unsigned styleBits) const SK_OVER RIDE 312 unsigned styleBits) const SK_OVER RIDE
314 { 313 {
315 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; 314 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
316 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold 315 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
317 ? SkFontStyle::kBold_Weight 316 ? SkFontStyle::kBold_Weight
318 : SkFontStyle::kNormal_Weight, 317 : SkFontStyle::kNormal_Weight,
319 SkFontStyle::kNormal_Width, 318 SkFontStyle::kNormal_Width,
(...skipping 14 matching lines...) Expand all
334 } 333 }
335 334
336 private: 335 private:
337 336
338 void load_directory_fonts(const SkString& directory, const char* suffix) { 337 void load_directory_fonts(const SkString& directory, const char* suffix) {
339 SkOSFile::Iter iter(directory.c_str(), suffix); 338 SkOSFile::Iter iter(directory.c_str(), suffix);
340 SkString name; 339 SkString name;
341 340
342 while (iter.next(&name, false)) { 341 while (iter.next(&name, false)) {
343 SkString filename(SkOSPath::Join(directory.c_str(), name.c_str())); 342 SkString filename(SkOSPath::Join(directory.c_str(), name.c_str()));
344 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(filename.c_str() )); 343 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(filename.c_str( )));
345 if (!stream.get()) { 344 if (!stream.get()) {
346 SkDebugf("---- failed to open <%s>\n", filename.c_str()); 345 SkDebugf("---- failed to open <%s>\n", filename.c_str());
347 continue; 346 continue;
348 } 347 }
349 348
350 int numFaces; 349 int numFaces;
351 if (!fScanner.recognizedFont(stream, &numFaces)) { 350 if (!fScanner.recognizedFont(stream, &numFaces)) {
352 SkDebugf("---- failed to open <%s> as a font\n", filename.c_str( )); 351 SkDebugf("---- failed to open <%s> as a font\n", filename.c_str( ));
353 continue; 352 continue;
354 } 353 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 430
432 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies; 431 SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies;
433 SkFontStyleSet_Custom* gDefaultFamily; 432 SkFontStyleSet_Custom* gDefaultFamily;
434 SkTypeface* gDefaultNormal; 433 SkTypeface* gDefaultNormal;
435 SkTypeface_FreeType::Scanner fScanner; 434 SkTypeface_FreeType::Scanner fScanner;
436 }; 435 };
437 436
438 SkFontMgr* SkFontMgr::Factory() { 437 SkFontMgr* SkFontMgr::Factory() {
439 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX); 438 return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX);
440 } 439 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_fontconfig.cpp ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698