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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 431 } |
432 if (fs.isItalic()) { | 432 if (fs.isItalic()) { |
433 style |= SkTypeface::kItalic; | 433 style |= SkTypeface::kItalic; |
434 } | 434 } |
435 return (SkTypeface::Style)style; | 435 return (SkTypeface::Style)style; |
436 } | 436 } |
437 | 437 |
438 class SkTypeface_Mac : public SkTypeface { | 438 class SkTypeface_Mac : public SkTypeface { |
439 public: | 439 public: |
440 SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch, | 440 SkTypeface_Mac(SkTypeface::Style style, SkFontID fontID, bool isFixedPitch, |
441 CTFontRef fontRef, const char name[]) | 441 CTFontRef fontRef, const char name[], bool serializeData) |
442 : SkTypeface(style, fontID, isFixedPitch) | 442 : SkTypeface(style, fontID, isFixedPitch) |
443 , fName(name) | 443 , fName(name) |
444 , fFontRef(fontRef) // caller has already called CFRetain for us | 444 , fFontRef(fontRef) // caller has already called CFRetain for us |
445 , fFontStyle(stylebits2fontstyle(style)) | 445 , fFontStyle(stylebits2fontstyle(style)) |
| 446 , fSerializeData(serializeData) |
446 { | 447 { |
447 SkASSERT(fontRef); | 448 SkASSERT(fontRef); |
448 } | 449 } |
449 | 450 |
450 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, | 451 SkTypeface_Mac(const SkFontStyle& fs, SkFontID fontID, bool isFixedPitch, |
451 CTFontRef fontRef, const char name[]) | 452 CTFontRef fontRef, const char name[], bool serializeData) |
452 : SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch) | 453 : SkTypeface(fontstyle2stylebits(fs), fontID, isFixedPitch) |
453 , fName(name) | 454 , fName(name) |
454 , fFontRef(fontRef) // caller has already called CFRetain for us | 455 , fFontRef(fontRef) // caller has already called CFRetain for us |
455 , fFontStyle(fs) | 456 , fFontStyle(fs) |
| 457 , fSerializeData(serializeData) |
456 { | 458 { |
457 SkASSERT(fontRef); | 459 SkASSERT(fontRef); |
458 } | 460 } |
459 | 461 |
460 SkString fName; | 462 SkString fName; |
461 AutoCFRelease<CTFontRef> fFontRef; | 463 AutoCFRelease<CTFontRef> fFontRef; |
462 SkFontStyle fFontStyle; | 464 SkFontStyle fFontStyle; |
| 465 bool fSerializeData; |
463 | 466 |
464 protected: | 467 protected: |
465 friend class SkFontHost; // to access our protected members for deprecate
d methods | 468 friend class SkFontHost; // to access our protected members for deprecate
d methods |
466 | 469 |
467 virtual int onGetUPEM() const SK_OVERRIDE; | 470 virtual int onGetUPEM() const SK_OVERRIDE; |
468 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 471 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
469 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 472 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
470 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 473 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
471 size_t length, void* data) const SK_OVERRIDE; | 474 size_t length, void* data) const SK_OVERRIDE; |
472 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 475 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
473 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 476 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
474 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 477 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
475 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 478 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
476 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 479 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
477 const uint32_t*, uint32_t) const SK_OVERRIDE; | 480 const uint32_t*, uint32_t) const SK_OVERRIDE; |
478 | 481 |
479 private: | 482 private: |
480 | 483 |
481 typedef SkTypeface INHERITED; | 484 typedef SkTypeface INHERITED; |
482 }; | 485 }; |
483 | 486 |
484 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { | 487 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool ser
ializeData) { |
485 SkASSERT(fontRef); | 488 SkASSERT(fontRef); |
486 bool isFixedPitch; | 489 bool isFixedPitch; |
487 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); | 490 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); |
488 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); | 491 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
489 | 492 |
490 return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name); | 493 return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name, serial
izeData); |
491 } | 494 } |
492 | 495 |
493 static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theSty
le) { | 496 static SkTypeface* NewFromName(const char familyName[], SkTypeface::Style theSty
le) { |
494 CTFontRef ctFont = NULL; | 497 CTFontRef ctFont = NULL; |
495 | 498 |
496 CTFontSymbolicTraits ctFontTraits = 0; | 499 CTFontSymbolicTraits ctFontTraits = 0; |
497 if (theStyle & SkTypeface::kBold) { | 500 if (theStyle & SkTypeface::kBold) { |
498 ctFontTraits |= kCTFontBoldTrait; | 501 ctFontTraits |= kCTFontBoldTrait; |
499 } | 502 } |
500 if (theStyle & SkTypeface::kItalic) { | 503 if (theStyle & SkTypeface::kItalic) { |
(...skipping 30 matching lines...) Expand all Loading... |
531 if (isLeopard()) { | 534 if (isLeopard()) { |
532 // CTFontCreateWithFontDescriptor on Leopard ignores the name | 535 // CTFontCreateWithFontDescriptor on Leopard ignores the name |
533 AutoCFRelease<CTFontRef> ctNamed(CTFontCreateWithName(cfFontName
, 1, NULL)); | 536 AutoCFRelease<CTFontRef> ctNamed(CTFontCreateWithName(cfFontName
, 1, NULL)); |
534 ctFont = CTFontCreateCopyWithAttributes(ctNamed, 1, NULL, ctFont
Desc); | 537 ctFont = CTFontCreateCopyWithAttributes(ctNamed, 1, NULL, ctFont
Desc); |
535 } else { | 538 } else { |
536 ctFont = CTFontCreateWithFontDescriptor(ctFontDesc, 0, NULL); | 539 ctFont = CTFontCreateWithFontDescriptor(ctFontDesc, 0, NULL); |
537 } | 540 } |
538 } | 541 } |
539 } | 542 } |
540 | 543 |
541 return ctFont ? NewFromFontRef(ctFont, familyName) : NULL; | 544 return ctFont ? NewFromFontRef(ctFont, familyName, false) : NULL; |
542 } | 545 } |
543 | 546 |
544 static SkTypeface* GetDefaultFace() { | 547 static SkTypeface* GetDefaultFace() { |
545 SK_DECLARE_STATIC_MUTEX(gMutex); | 548 SK_DECLARE_STATIC_MUTEX(gMutex); |
546 SkAutoMutexAcquire ma(gMutex); | 549 SkAutoMutexAcquire ma(gMutex); |
547 | 550 |
548 static SkTypeface* gDefaultFace; | 551 static SkTypeface* gDefaultFace; |
549 | 552 |
550 if (NULL == gDefaultFace) { | 553 if (NULL == gDefaultFace) { |
551 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkTypeface::kNormal); | 554 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkTypeface::kNormal); |
552 SkTypefaceCache::Add(gDefaultFace, SkTypeface::kNormal); | 555 SkTypefaceCache::Add(gDefaultFace, SkTypeface::kNormal); |
553 } | 556 } |
554 return gDefaultFace; | 557 return gDefaultFace; |
555 } | 558 } |
556 | 559 |
557 /////////////////////////////////////////////////////////////////////////////// | 560 /////////////////////////////////////////////////////////////////////////////// |
558 | 561 |
559 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); | 562 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); |
560 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { | 563 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { |
561 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; | 564 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; |
562 return macface ? macface->fFontRef.get() : NULL; | 565 return macface ? macface->fFontRef.get() : NULL; |
563 } | 566 } |
564 | 567 |
565 /* 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 |
566 * 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). |
567 */ | 570 */ |
568 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) { | 571 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, bool serializeData) { |
569 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); | 572 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); |
570 SkTypeface* face = SkTypefaceCache::FindByID(fontID); | 573 SkTypeface* face = SkTypefaceCache::FindByID(fontID); |
571 if (face) { | 574 if (face) { |
572 face->ref(); | 575 face->ref(); |
573 } else { | 576 } else { |
574 face = NewFromFontRef(fontRef, NULL); | 577 face = NewFromFontRef(fontRef, NULL, serializeData); |
575 SkTypefaceCache::Add(face, face->style()); | 578 SkTypefaceCache::Add(face, face->style()); |
576 // NewFromFontRef doesn't retain the parameter, but the typeface it | 579 // NewFromFontRef doesn't retain the parameter, but the typeface it |
577 // creates does release it in its destructor, so we balance that with | 580 // creates does release it in its destructor, so we balance that with |
578 // a retain call here. | 581 // a retain call here. |
579 CFRetain(fontRef); | 582 CFRetain(fontRef); |
580 } | 583 } |
581 SkASSERT(face->getRefCnt() > 1); | 584 SkASSERT(face->getRefCnt() > 1); |
582 return face; | 585 return face; |
583 } | 586 } |
584 | 587 |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 /////////////////////////////////////////////////////////////////////////////// | 1413 /////////////////////////////////////////////////////////////////////////////// |
1411 | 1414 |
1412 // Returns NULL on failure | 1415 // Returns NULL on failure |
1413 // Call must still manage its ownership of provider | 1416 // Call must still manage its ownership of provider |
1414 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { | 1417 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
1415 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 1418 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
1416 if (NULL == cg) { | 1419 if (NULL == cg) { |
1417 return NULL; | 1420 return NULL; |
1418 } | 1421 } |
1419 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); | 1422 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); |
1420 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; | 1423 return cg ? SkCreateTypefaceFromCTFont(ct, true) : NULL; |
1421 } | 1424 } |
1422 | 1425 |
1423 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 1426 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
1424 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(str
eam)); | 1427 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(str
eam)); |
1425 if (NULL == provider) { | 1428 if (NULL == provider) { |
1426 return NULL; | 1429 return NULL; |
1427 } | 1430 } |
1428 return create_from_dataProvider(provider); | 1431 return create_from_dataProvider(provider); |
1429 } | 1432 } |
1430 | 1433 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 return str->c_str(); | 1866 return str->c_str(); |
1864 } | 1867 } |
1865 | 1868 |
1866 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, | 1869 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, |
1867 bool* isLocalStream) const { | 1870 bool* isLocalStream) const { |
1868 SkString tmpStr; | 1871 SkString tmpStr; |
1869 | 1872 |
1870 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); | 1873 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); |
1871 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); | 1874 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); |
1872 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); | 1875 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)
); |
1873 // TODO: need to add support for local-streams (here and openStream) | 1876 *isLocalStream = fSerializeData; |
1874 *isLocalStream = false; | |
1875 } | 1877 } |
1876 | 1878 |
1877 /////////////////////////////////////////////////////////////////////////////// | 1879 /////////////////////////////////////////////////////////////////////////////// |
1878 /////////////////////////////////////////////////////////////////////////////// | 1880 /////////////////////////////////////////////////////////////////////////////// |
1879 #if 1 | 1881 #if 1 |
1880 | 1882 |
1881 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString*
value) { | 1883 static bool find_desc_str(CTFontDescriptorRef desc, CFStringRef name, SkString*
value) { |
1882 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de
sc, name)); | 1884 AutoCFRelease<CFStringRef> ref((CFStringRef)CTFontDescriptorCopyAttribute(de
sc, name)); |
1883 if (NULL == ref.get()) { | 1885 if (NULL == ref.get()) { |
1884 return false; | 1886 return false; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 } | 1988 } |
1987 | 1989 |
1988 SkString str; | 1990 SkString str; |
1989 CFStringToSkString(cfFamilyName, &str); | 1991 CFStringToSkString(cfFamilyName, &str); |
1990 | 1992 |
1991 bool isFixedPitch; | 1993 bool isFixedPitch; |
1992 (void)computeStyleBits(ctFont, &isFixedPitch); | 1994 (void)computeStyleBits(ctFont, &isFixedPitch); |
1993 SkFontID fontID = CTFontRef_to_SkFontID(ctFont); | 1995 SkFontID fontID = CTFontRef_to_SkFontID(ctFont); |
1994 | 1996 |
1995 face = SkNEW_ARGS(SkTypeface_Mac, (rec.fFontStyle, fontID, isFixedPitch, | 1997 face = SkNEW_ARGS(SkTypeface_Mac, (rec.fFontStyle, fontID, isFixedPitch, |
1996 ctFont, str.c_str())); | 1998 ctFont, str.c_str(), false)); |
1997 SkTypefaceCache::Add(face, face->style()); | 1999 SkTypefaceCache::Add(face, face->style()); |
1998 return face; | 2000 return face; |
1999 } | 2001 } |
2000 | 2002 |
2001 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2003 class SkFontStyleSet_Mac : public SkFontStyleSet { |
2002 public: | 2004 public: |
2003 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) | 2005 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) |
2004 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL)) | 2006 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, NULL)) |
2005 , fFamilyName(familyName) | 2007 , fFamilyName(familyName) |
2006 , fCount(0) { | 2008 , fCount(0) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2172 return NULL; | 2174 return NULL; |
2173 } | 2175 } |
2174 return create_from_dataProvider(pr); | 2176 return create_from_dataProvider(pr); |
2175 } | 2177 } |
2176 }; | 2178 }; |
2177 | 2179 |
2178 SkFontMgr* SkFontMgr::Factory() { | 2180 SkFontMgr* SkFontMgr::Factory() { |
2179 return SkNEW(SkFontMgr_Mac); | 2181 return SkNEW(SkFontMgr_Mac); |
2180 } | 2182 } |
2181 #endif | 2183 #endif |
OLD | NEW |