OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTypes.h" // Keep this before any #ifdef ... | 9 #include "SkTypes.h" // Keep this before any #ifdef ... |
10 | 10 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) | 422 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) |
423 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; | 423 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; |
424 #else | 424 #else |
425 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); | 425 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); |
426 #endif | 426 #endif |
427 | 427 |
428 class SkTypeface_Mac : public SkTypeface { | 428 class SkTypeface_Mac : public SkTypeface { |
429 public: | 429 public: |
430 SkTypeface_Mac(const SkFontStyle& fs, bool isFixedPitch, | 430 SkTypeface_Mac(const SkFontStyle& fs, bool isFixedPitch, |
431 CTFontRef fontRef, const char requestedName[], bool isLocalSt ream, | 431 CTFontRef fontRef, const char requestedName[], bool isLocalSt ream, |
432 CGFontRef originatingCGFontRef = NULL) | 432 CFTypeRef resourceRef = NULL) |
reed1
2015/06/08 19:01:40
remove default argness?
bungeman-skia
2015/06/08 19:14:40
Done.
| |
433 : SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch) | 433 : SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch) |
434 , fRequestedName(requestedName) | 434 , fRequestedName(requestedName) |
435 , fFontRef(fontRef) // caller has already called CFRetain for us | 435 , fFontRef(fontRef) // caller has already called CFRetain for us |
436 , fOriginatingCGFontRef(originatingCGFontRef) | 436 , fOriginatingCFTypeRef(resourceRef) // caller has already called CFReta in for us |
437 , fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontC olorGlyphsTrait)) | 437 , fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontC olorGlyphsTrait)) |
438 , fIsLocalStream(isLocalStream) | 438 , fIsLocalStream(isLocalStream) |
439 { | 439 { |
440 SkASSERT(fontRef); | 440 SkASSERT(fontRef); |
441 } | 441 } |
442 | 442 |
443 SkString fRequestedName; | 443 SkString fRequestedName; |
444 AutoCFRelease<CTFontRef> fFontRef; | 444 AutoCFRelease<CTFontRef> fFontRef; |
445 AutoCFRelease<CGFontRef> fOriginatingCGFontRef; | 445 AutoCFRelease<CFTypeRef> fOriginatingCFTypeRef; |
446 const bool fHasColorGlyphs; | 446 const bool fHasColorGlyphs; |
447 | 447 |
448 protected: | 448 protected: |
449 int onGetUPEM() const override; | 449 int onGetUPEM() const override; |
450 SkStreamAsset* onOpenStream(int* ttcIndex) const override; | 450 SkStreamAsset* onOpenStream(int* ttcIndex) const override; |
451 SkFontData* onCreateFontData() const override; | 451 SkFontData* onCreateFontData() const override; |
452 void onGetFamilyName(SkString* familyName) const override; | 452 void onGetFamilyName(SkString* familyName) const override; |
453 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; | 453 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
454 int onGetTableTags(SkFontTableTag tags[]) const override; | 454 int onGetTableTags(SkFontTableTag tags[]) const override; |
455 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 455 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
456 size_t length, void* data) const override; | 456 size_t length, void* data) const override; |
457 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; | 457 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; |
458 void onFilterRec(SkScalerContextRec*) const override; | 458 void onFilterRec(SkScalerContextRec*) const override; |
459 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; | 459 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; |
460 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 460 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
461 PerGlyphInfo, | 461 PerGlyphInfo, |
462 const uint32_t*, uint32_t) const override; | 462 const uint32_t*, uint32_t) const override; |
463 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 463 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
464 int glyphCount) const override; | 464 int glyphCount) const override; |
465 int onCountGlyphs() const override; | 465 int onCountGlyphs() const override; |
466 | 466 |
467 private: | 467 private: |
468 bool fIsLocalStream; | 468 bool fIsLocalStream; |
469 | 469 |
470 typedef SkTypeface INHERITED; | 470 typedef SkTypeface INHERITED; |
471 }; | 471 }; |
472 | 472 |
473 /** Creates a typeface without searching the cache. Takes ownership of the CTFon tRef. */ | 473 /** Creates a typeface without searching the cache. Takes ownership of the CTFon tRef. */ |
474 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isL ocalStream, | 474 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isL ocalStream, |
475 CGFontRef originatingCGFontRef = NULL) | 475 CFTypeRef resourceRef = NULL) |
reed1
2015/06/08 19:01:40
since its internal, lets remove the defaultness of
bungeman-skia
2015/06/08 19:14:40
Done.
| |
476 { | 476 { |
477 SkASSERT(fontRef); | 477 SkASSERT(fontRef); |
478 bool isFixedPitch; | 478 bool isFixedPitch; |
479 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); | 479 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); |
480 | 480 |
481 return new SkTypeface_Mac(style, isFixedPitch, fontRef, name, isLocalStream, | 481 return new SkTypeface_Mac(style, isFixedPitch, fontRef, name, isLocalStream, resourceRef); |
482 originatingCGFontRef); | |
483 } | 482 } |
484 | 483 |
485 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont ext) { | 484 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont ext) { |
486 CTFontRef self = (CTFontRef)context; | 485 CTFontRef self = (CTFontRef)context; |
487 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; | 486 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; |
488 | 487 |
489 return CFEqual(self, other); | 488 return CFEqual(self, other); |
490 } | 489 } |
491 | 490 |
492 /** Creates a typeface from a name, searching the cache. */ | 491 /** Creates a typeface from a name, searching the cache. */ |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 | 561 |
563 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); | 562 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); |
564 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { | 563 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { |
565 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; | 564 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; |
566 return macface ? macface->fFontRef.get() : NULL; | 565 return macface ? macface->fFontRef.get() : NULL; |
567 } | 566 } |
568 | 567 |
569 /* This function is visible on the outside. It first searches the cache, and if | 568 /* This function is visible on the outside. It first searches the cache, and if |
570 * not found, returns a new entry (after adding it to the cache). | 569 * not found, returns a new entry (after adding it to the cache). |
571 */ | 570 */ |
572 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { | 571 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef) { |
573 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)fontRef); | 572 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)fontRef); |
574 if (!face) { | 573 if (!face) { |
575 CFRetain(fontRef); | 574 CFRetain(fontRef); |
576 face = NewFromFontRef(fontRef, NULL, false); | 575 if (resourceRef) { |
576 CFRetain(resourceRef); | |
577 } | |
578 face = NewFromFontRef(fontRef, NULL, false, resourceRef); | |
577 SkTypefaceCache::Add(face, face->fontStyle()); | 579 SkTypefaceCache::Add(face, face->fontStyle()); |
578 } | 580 } |
579 return face; | 581 return face; |
580 } | 582 } |
581 | 583 |
582 struct NameStyle { | 584 struct NameStyle { |
583 const char* fName; | 585 const char* fName; |
584 SkFontStyle fStyle; | 586 SkFontStyle fStyle; |
585 }; | 587 }; |
586 | 588 |
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2480 } | 2482 } |
2481 return face; | 2483 return face; |
2482 } | 2484 } |
2483 }; | 2485 }; |
2484 | 2486 |
2485 /////////////////////////////////////////////////////////////////////////////// | 2487 /////////////////////////////////////////////////////////////////////////////// |
2486 | 2488 |
2487 SkFontMgr* SkFontMgr::Factory() { | 2489 SkFontMgr* SkFontMgr::Factory() { |
2488 return SkNEW(SkFontMgr_Mac); | 2490 return SkNEW(SkFontMgr_Mac); |
2489 } | 2491 } |
OLD | NEW |