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 <vector> | 9 #include <vector> |
10 #ifdef SK_BUILD_FOR_MAC | 10 #ifdef SK_BUILD_FOR_MAC |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 419 } |
420 if (fs.isItalic()) { | 420 if (fs.isItalic()) { |
421 style |= SkTypeface::kItalic; | 421 style |= SkTypeface::kItalic; |
422 } | 422 } |
423 return (SkTypeface::Style)style; | 423 return (SkTypeface::Style)style; |
424 } | 424 } |
425 | 425 |
426 class SkTypeface_Mac : public SkTypeface { | 426 class SkTypeface_Mac : public SkTypeface { |
427 public: | 427 public: |
428 SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch, | 428 SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch, |
429 CTFontRef fontRef, const char name[]) | 429 CTFontRef fontRef, const char name[], bool isLocalStream) |
430 : SkTypeface(style, fontID, isFixedPitch) | 430 : SkTypeface(style, fontID, isFixedPitch) |
431 , fName(name) | 431 , fName(name) |
432 , fFontRef(fontRef) // caller has already called CFRetain for us | 432 , fFontRef(fontRef) // caller has already called CFRetain for us |
433 , fFontStyle(stylebits2fontstyle(style)) | 433 , fFontStyle(stylebits2fontstyle(style)) |
| 434 , fIsLocalStream(isLocalStream) |
434 { | 435 { |
435 SkASSERT(fontRef); | 436 SkASSERT(fontRef); |
436 } | 437 } |
437 | 438 |
438 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, | 439 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, |
439 CTFontRef fontRef, const char name[]) | 440 CTFontRef fontRef, const char name[], bool isLocalStream) |
440 : SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch) | 441 : SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch) |
441 , fName(name) | 442 , fName(name) |
442 , fFontRef(fontRef) // caller has already called CFRetain for us | 443 , fFontRef(fontRef) // caller has already called CFRetain for us |
443 , fFontStyle(fs) | 444 , fFontStyle(fs) |
| 445 , fIsLocalStream(isLocalStream) |
444 { | 446 { |
445 SkASSERT(fontRef); | 447 SkASSERT(fontRef); |
446 } | 448 } |
447 | 449 |
448 SkString fName; | 450 SkString fName; |
449 AutoCFRelease<CTFontRef> fFontRef; | 451 AutoCFRelease<CTFontRef> fFontRef; |
450 SkFontStyle fFontStyle; | 452 SkFontStyle fFontStyle; |
451 | 453 |
452 protected: | 454 protected: |
453 friend class SkFontHost; // to access our protected members for deprecate
d methods | 455 friend class SkFontHost; // to access our protected members for deprecate
d methods |
454 | 456 |
455 virtual int onGetUPEM() const SK_OVERRIDE; | 457 virtual int onGetUPEM() const SK_OVERRIDE; |
456 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 458 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
457 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; | 459 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; |
458 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 460 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
459 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 461 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
460 size_t length, void* data) const SK_OVERRIDE; | 462 size_t length, void* data) const SK_OVERRIDE; |
461 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 463 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
462 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 464 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
463 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 465 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
464 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 466 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
465 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 467 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
466 const uint32_t*, uint32_t) const SK_OVERRIDE; | 468 const uint32_t*, uint32_t) const SK_OVERRIDE; |
467 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 469 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
468 int glyphCount) const SK_OVERRIDE; | 470 int glyphCount) const SK_OVERRIDE; |
469 virtual int onCountGlyphs() const SK_OVERRIDE; | 471 virtual int onCountGlyphs() const SK_OVERRIDE; |
470 | 472 |
471 private: | 473 private: |
| 474 bool fIsLocalStream; |
472 | 475 |
473 typedef SkTypeface INHERITED; | 476 typedef SkTypeface INHERITED; |
474 }; | 477 }; |
475 | 478 |
476 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { | 479 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isL
ocalStream) { |
477 SkASSERT(fontRef); | 480 SkASSERT(fontRef); |
478 bool isFixedPitch; | 481 bool isFixedPitch; |
479 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); | 482 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); |
480 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); | 483 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
481 | 484 |
482 return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name); | 485 return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name, isLoca
lStream); |
483 } | 486 } |
484 | 487 |
485 static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theSty
le) { | 488 static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theSty
le) { |
486 CTFontRef ctFont = NULL; | 489 CTFontRef ctFont = NULL; |
487 | 490 |
488 CTFontSymbolicTraits ctFontTraits = 0; | 491 CTFontSymbolicTraits ctFontTraits = 0; |
489 if (theStyle & SkTypeface::kBold) { | 492 if (theStyle & SkTypeface::kBold) { |
490 ctFontTraits |= kCTFontBoldTrait; | 493 ctFontTraits |= kCTFontBoldTrait; |
491 } | 494 } |
492 if (theStyle & SkTypeface::kItalic) { | 495 if (theStyle & SkTypeface::kItalic) { |
(...skipping 24 matching lines...) Expand all Loading... |
517 CFDictionaryAddValue(cfAttributes, kCTFontTraitsAttribute, cfTraits); | 520 CFDictionaryAddValue(cfAttributes, kCTFontTraitsAttribute, cfTraits); |
518 | 521 |
519 AutoCFRelease<CTFontDescriptorRef> ctFontDesc( | 522 AutoCFRelease<CTFontDescriptorRef> ctFontDesc( |
520 CTFontDescriptorCreateWithAttributes(cfAttributes)); | 523 CTFontDescriptorCreateWithAttributes(cfAttributes)); |
521 | 524 |
522 if (ctFontDesc != NULL) { | 525 if (ctFontDesc != NULL) { |
523 ctFont = CTFontCreateWithFontDescriptor(ctFontDesc, 0, NULL); | 526 ctFont = CTFontCreateWithFontDescriptor(ctFontDesc, 0, NULL); |
524 } | 527 } |
525 } | 528 } |
526 | 529 |
527 return ctFont ? NewFromFontRef(ctFont, familyName) : NULL; | 530 return ctFont ? NewFromFontRef(ctFont, familyName, false) : NULL; |
528 } | 531 } |
529 | 532 |
530 static SkTypeface* GetDefaultFace() { | 533 static SkTypeface* GetDefaultFace() { |
531 SK_DECLARE_STATIC_MUTEX(gMutex); | 534 SK_DECLARE_STATIC_MUTEX(gMutex); |
532 SkAutoMutexAcquire ma(gMutex); | 535 SkAutoMutexAcquire ma(gMutex); |
533 | 536 |
534 static SkTypeface* gDefaultFace; | 537 static SkTypeface* gDefaultFace; |
535 | 538 |
536 if (NULL == gDefaultFace) { | 539 if (NULL == gDefaultFace) { |
537 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkTypeface::kNormal); | 540 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkTypeface::kNormal); |
(...skipping 12 matching lines...) Expand all Loading... |
550 | 553 |
551 /* This function is visible on the outside. It first searches the cache, and if | 554 /* This function is visible on the outside. It first searches the cache, and if |
552 * not found, returns a new entry (after adding it to the cache). | 555 * not found, returns a new entry (after adding it to the cache). |
553 */ | 556 */ |
554 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { | 557 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { |
555 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); | 558 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
556 SkTypeface* face = SkTypefaceCache::FindByID(fontID); | 559 SkTypeface* face = SkTypefaceCache::FindByID(fontID); |
557 if (face) { | 560 if (face) { |
558 face->ref(); | 561 face->ref(); |
559 } else { | 562 } else { |
560 face = NewFromFontRef(fontRef, NULL); | 563 face = NewFromFontRef(fontRef, NULL, false); |
561 SkTypefaceCache::Add(face, face->style()); | 564 SkTypefaceCache::Add(face, face->style()); |
562 // NewFromFontRef doesn't retain the parameter, but the typeface it | 565 // NewFromFontRef doesn't retain the parameter, but the typeface it |
563 // creates does release it in its destructor, so we balance that with | 566 // creates does release it in its destructor, so we balance that with |
564 // a retain call here. | 567 // a retain call here. |
565 CFRetain(fontRef); | 568 CFRetain(fontRef); |
566 } | 569 } |
567 SkASSERT(face->getRefCnt() > 1); | 570 SkASSERT(face->getRefCnt() > 1); |
568 return face; | 571 return face; |
569 } | 572 } |
570 | 573 |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 /////////////////////////////////////////////////////////////////////////////// | 1434 /////////////////////////////////////////////////////////////////////////////// |
1432 | 1435 |
1433 // Returns NULL on failure | 1436 // Returns NULL on failure |
1434 // Call must still manage its ownership of provider | 1437 // Call must still manage its ownership of provider |
1435 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { | 1438 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
1436 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 1439 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
1437 if (NULL == cg) { | 1440 if (NULL == cg) { |
1438 return NULL; | 1441 return NULL; |
1439 } | 1442 } |
1440 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); | 1443 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); |
1441 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; | 1444 return ct ? NewFromFontRef(ct, NULL, true) : NULL; |
1442 } | 1445 } |
1443 | 1446 |
1444 // Web fonts added to the the CTFont registry do not return their character set. | 1447 // Web fonts added to the the CTFont registry do not return their character set. |
1445 // Iterate through the font in this case. The existing caller caches the result, | 1448 // Iterate through the font in this case. The existing caller caches the result, |
1446 // so the performance impact isn't too bad. | 1449 // so the performance impact isn't too bad. |
1447 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, | 1450 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, |
1448 SkTDArray<SkUnichar>* glyphToUnicode)
{ | 1451 SkTDArray<SkUnichar>* glyphToUnicode)
{ |
1449 glyphToUnicode->setCount(SkToInt(glyphCount)); | 1452 glyphToUnicode->setCount(SkToInt(glyphCount)); |
1450 SkUnichar* out = glyphToUnicode->begin(); | 1453 SkUnichar* out = glyphToUnicode->begin(); |
1451 sk_bzero(out, glyphCount * sizeof(SkUnichar)); | 1454 sk_bzero(out, glyphCount * sizeof(SkUnichar)); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 return str->c_str(); | 1904 return str->c_str(); |
1902 } | 1905 } |
1903 | 1906 |
1904 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, | 1907 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, |
1905 bool* isLocalStream) const { | 1908 bool* isLocalStream) const { |
1906 SkString tmpStr; | 1909 SkString tmpStr; |
1907 | 1910 |
1908 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); | 1911 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); |
1909 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); | 1912 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); |
1910 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); | 1913 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); |
1911 // TODO: need to add support for local-streams (here and openStream) | 1914 *isLocalStream = fIsLocalStream; |
1912 *isLocalStream = false; | |
1913 } | 1915 } |
1914 | 1916 |
1915 int SkTypeface_Mac::onCharsToGlyphs(const void* chars, Encoding encoding, | 1917 int SkTypeface_Mac::onCharsToGlyphs(const void* chars, Encoding encoding, |
1916 uint16_t glyphs[], int glyphCount) const | 1918 uint16_t glyphs[], int glyphCount) const |
1917 { | 1919 { |
1918 // Undocumented behavior of CTFontGetGlyphsForCharacters with non-bmp code p
oints: | 1920 // Undocumented behavior of CTFontGetGlyphsForCharacters with non-bmp code p
oints: |
1919 // When a surrogate pair is detected, the glyph index used is the index of t
he high surrogate. | 1921 // When a surrogate pair is detected, the glyph index used is the index of t
he high surrogate. |
1920 // It is documented that if a mapping is unavailable, the glyph will be set
to 0. | 1922 // It is documented that if a mapping is unavailable, the glyph will be set
to 0. |
1921 | 1923 |
1922 SkAutoSTMalloc<1024, UniChar> charStorage; | 1924 SkAutoSTMalloc<1024, UniChar> charStorage; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 } | 2123 } |
2122 | 2124 |
2123 SkString str; | 2125 SkString str; |
2124 CFStringToSkString(cfFamilyName, &str); | 2126 CFStringToSkString(cfFamilyName, &str); |
2125 | 2127 |
2126 bool isFixedPitch; | 2128 bool isFixedPitch; |
2127 (void)computeStyleBits(ctFont, &isFixedPitch); | 2129 (void)computeStyleBits(ctFont, &isFixedPitch); |
2128 SkFontID fontID = CTFontRef_to_SkFontID(ctFont); | 2130 SkFontID fontID = CTFontRef_to_SkFontID(ctFont); |
2129 | 2131 |
2130 face = SkNEW_ARGS(SkTypeface_Mac, (rec.fFontStyle, fontID, isFixedPitch, | 2132 face = SkNEW_ARGS(SkTypeface_Mac, (rec.fFontStyle, fontID, isFixedPitch, |
2131 ctFont, str.c_str())); | 2133 ctFont, str.c_str(), false)); |
2132 SkTypefaceCache::Add(face, face->style()); | 2134 SkTypefaceCache::Add(face, face->style()); |
2133 return face; | 2135 return face; |
2134 } | 2136 } |
2135 | 2137 |
2136 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2138 class SkFontStyleSet_Mac : public SkFontStyleSet { |
2137 public: | 2139 public: |
2138 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) | 2140 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) |
2139 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL)) | 2141 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL)) |
2140 , fFamilyName(familyName) | 2142 , fFamilyName(familyName) |
2141 , fCount(0) { | 2143 , fCount(0) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); | 2308 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); |
2307 } | 2309 } |
2308 }; | 2310 }; |
2309 | 2311 |
2310 /////////////////////////////////////////////////////////////////////////////// | 2312 /////////////////////////////////////////////////////////////////////////////// |
2311 | 2313 |
2312 SkFontMgr* SkFontMgr::Factory() { | 2314 SkFontMgr* SkFontMgr::Factory() { |
2313 return SkNEW(SkFontMgr_Mac); | 2315 return SkNEW(SkFontMgr_Mac); |
2314 } | 2316 } |
2315 #endif | 2317 #endif |
OLD | NEW |