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

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

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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/SkFontMgr_android.cpp ('k') | src/ports/SkFontMgr_fontconfig.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 "SkFontDescriptor.h" 8 #include "SkFontDescriptor.h"
9 #include "SkFontHost_FreeType_common.h" 9 #include "SkFontHost_FreeType_common.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override { 289 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons t override {
290 SkAutoTDelete<SkStreamAsset> stream(bareStream); 290 SkAutoTDelete<SkStreamAsset> stream(bareStream);
291 if (NULL == stream || stream->getLength() <= 0) { 291 if (NULL == stream || stream->getLength() <= 0) {
292 return NULL; 292 return NULL;
293 } 293 }
294 294
295 bool isFixedPitch; 295 bool isFixedPitch;
296 SkFontStyle style; 296 SkFontStyle style;
297 SkString name; 297 SkString name;
298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, NU LL)) { 298 if (fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, NU LL)) {
299 return SkNEW_ARGS(SkTypeface_Stream, (style, isFixedPitch, false, na me, 299 return new SkTypeface_Stream(style, isFixedPitch, false, name, strea m.detach(),
300 stream.detach(), ttcIndex)); 300 ttcIndex);
301 } else { 301 } else {
302 return NULL; 302 return NULL;
303 } 303 }
304 } 304 }
305 305
306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { 306 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
307 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); 307 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL; 308 return stream.get() ? this->createFromStream(stream.detach(), ttcIndex) : NULL;
309 } 309 }
310 310
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 SkFontMgr_Custom::Families* families) const override 346 SkFontMgr_Custom::Families* families) const override
347 { 347 {
348 load_directory_fonts(scanner, fBaseDirectory, ".ttf", families); 348 load_directory_fonts(scanner, fBaseDirectory, ".ttf", families);
349 load_directory_fonts(scanner, fBaseDirectory, ".ttc", families); 349 load_directory_fonts(scanner, fBaseDirectory, ".ttc", families);
350 load_directory_fonts(scanner, fBaseDirectory, ".otf", families); 350 load_directory_fonts(scanner, fBaseDirectory, ".otf", families);
351 load_directory_fonts(scanner, fBaseDirectory, ".pfb", families); 351 load_directory_fonts(scanner, fBaseDirectory, ".pfb", families);
352 352
353 if (families->empty()) { 353 if (families->empty()) {
354 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() ); 354 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() );
355 families->push_back().reset(family); 355 families->push_back().reset(family);
356 family->appendTypeface(SkNEW(SkTypeface_Empty)); 356 family->appendTypeface(new SkTypeface_Empty);
357 } 357 }
358 } 358 }
359 359
360 private: 360 private:
361 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es, 361 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es,
362 const char familyName[]) 362 const char familyName[])
363 { 363 {
364 for (int i = 0; i < families.count(); ++i) { 364 for (int i = 0; i < families.count(); ++i) {
365 if (families[i]->getFamilyName().equals(familyName)) { 365 if (families[i]->getFamilyName().equals(familyName)) {
366 return families[i].get(); 366 return families[i].get();
(...skipping 26 matching lines...) Expand all
393 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { 393 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
394 bool isFixedPitch; 394 bool isFixedPitch;
395 SkString realname; 395 SkString realname;
396 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin g 396 SkFontStyle style = SkFontStyle(); // avoid uninitialized warnin g
397 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF ixedPitch, NULL)) { 397 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isF ixedPitch, NULL)) {
398 SkDebugf("---- failed to open <%s> <%d> as a font\n", 398 SkDebugf("---- failed to open <%s> <%d> as a font\n",
399 filename.c_str(), faceIndex); 399 filename.c_str(), faceIndex);
400 continue; 400 continue;
401 } 401 }
402 402
403 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, ( 403 SkTypeface_Custom* tf = new SkTypeface_File(style, isFixedPitch,
404 style, 404 true, // system-fon t (cannot delete)
405 isFixedPitch, 405 realname, filename.c _str(), faceIndex);
406 true, // system-font (canno t delete)
407 realname,
408 filename.c_str(),
409 faceIndex));
410 406
411 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c _str()); 407 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c _str());
412 if (NULL == addTo) { 408 if (NULL == addTo) {
413 addTo = new SkFontStyleSet_Custom(realname); 409 addTo = new SkFontStyleSet_Custom(realname);
414 families->push_back().reset(addTo); 410 families->push_back().reset(addTo);
415 } 411 }
416 addTo->appendTypeface(tf); 412 addTo->appendTypeface(tf);
417 } 413 }
418 } 414 }
419 415
(...skipping 27 matching lines...) Expand all
447 SkFontMgr_Custom::Families* families) const override 443 SkFontMgr_Custom::Families* families) const override
448 { 444 {
449 for (int i = 0; i < fHeader->count; ++i) { 445 for (int i = 0; i < fHeader->count; ++i) {
450 const SkEmbeddedResource& fontEntry = fHeader->entries[i]; 446 const SkEmbeddedResource& fontEntry = fHeader->entries[i];
451 load_embedded_font(scanner, fontEntry.data, fontEntry.size, i, famil ies); 447 load_embedded_font(scanner, fontEntry.data, fontEntry.size, i, famil ies);
452 } 448 }
453 449
454 if (families->empty()) { 450 if (families->empty()) {
455 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() ); 451 SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString() );
456 families->push_back().reset(family); 452 families->push_back().reset(family);
457 family->appendTypeface(SkNEW(SkTypeface_Empty)); 453 family->appendTypeface(new SkTypeface_Empty);
458 } 454 }
459 } 455 }
460 456
461 private: 457 private:
462 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es, 458 static SkFontStyleSet_Custom* find_family(SkFontMgr_Custom::Families& famili es,
463 const char familyName[]) 459 const char familyName[])
464 { 460 {
465 for (int i = 0; i < families.count(); ++i) { 461 for (int i = 0; i < families.count(); ++i) {
466 if (families[i]->getFamilyName().equals(familyName)) { 462 if (families[i]->getFamilyName().equals(familyName)) {
467 return families[i].get(); 463 return families[i].get();
(...skipping 16 matching lines...) Expand all
484 480
485 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) { 481 for (int faceIndex = 0; faceIndex < numFaces; ++faceIndex) {
486 bool isFixedPitch; 482 bool isFixedPitch;
487 SkString realname; 483 SkString realname;
488 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning 484 SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
489 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed Pitch, NULL)) { 485 if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixed Pitch, NULL)) {
490 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac eIndex); 486 SkDebugf("---- failed to open <%d> <%d> as a font\n", index, fac eIndex);
491 return; 487 return;
492 } 488 }
493 489
494 SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_Stream, ( 490 SkTypeface_Custom* tf =
495 style, 491 new SkTypeface_Stream(style, isFixedPitch, true, // system- font (cannot delete)
496 isFixedPitch, 492 realname, stream.detach(), faceIndex);
497 true, // system-font (cannot de lete)
498 realname,
499 stream.detach(),
500 faceIndex));
501 493
502 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str ()); 494 SkFontStyleSet_Custom* addTo = find_family(*families, realname.c_str ());
503 if (NULL == addTo) { 495 if (NULL == addTo) {
504 addTo = new SkFontStyleSet_Custom(realname); 496 addTo = new SkFontStyleSet_Custom(realname);
505 families->push_back().reset(addTo); 497 families->push_back().reset(addTo);
506 } 498 }
507 addTo->appendTypeface(tf); 499 addTo->appendTypeface(tf);
508 } 500 }
509 } 501 }
510 502
511 const SkEmbeddedResourceHeader* fHeader; 503 const SkEmbeddedResourceHeader* fHeader;
512 }; 504 };
513 505
514 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) { 506 SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
515 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header)); 507 return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
516 } 508 }
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_android.cpp ('k') | src/ports/SkFontMgr_fontconfig.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698