| OLD | NEW |
| 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 "SkTypes.h" // Keep this before any #ifdef ... | 8 #include "SkTypes.h" // Keep this before any #ifdef ... |
| 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 10 | 10 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 SkASSERT(fontRef); | 479 SkASSERT(fontRef); |
| 480 | 480 |
| 481 AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef)); | 481 AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef)); |
| 482 SkFontStyle style = fontstyle_from_descriptor(desc); | 482 SkFontStyle style = fontstyle_from_descriptor(desc); |
| 483 | 483 |
| 484 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(fontRef); | 484 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(fontRef); |
| 485 bool isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait); | 485 bool isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait); |
| 486 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal
Stream); | 486 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal
Stream); |
| 487 } | 487 } |
| 488 | 488 |
| 489 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont
ext) { | 489 static bool find_by_CTFontRef(SkTypeface* cached, void* context) { |
| 490 CTFontRef self = (CTFontRef)context; | 490 CTFontRef self = (CTFontRef)context; |
| 491 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; | 491 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; |
| 492 | 492 |
| 493 return CFEqual(self, other); | 493 return CFEqual(self, other); |
| 494 } | 494 } |
| 495 | 495 |
| 496 /** Creates a typeface from a name, searching the cache. */ | 496 /** Creates a typeface from a name, searching the cache. */ |
| 497 static SkTypeface* NewFromName(const char familyName[], const SkFontStyle& theSt
yle) { | 497 static SkTypeface* NewFromName(const char familyName[], const SkFontStyle& theSt
yle) { |
| 498 CTFontSymbolicTraits ctFontTraits = 0; | 498 CTFontSymbolicTraits ctFontTraits = 0; |
| 499 if (theStyle.weight() >= SkFontStyle::kBold_Weight) { | 499 if (theStyle.weight() >= SkFontStyle::kBold_Weight) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0
, nullptr)); | 539 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0
, nullptr)); |
| 540 if (!ctFont) { | 540 if (!ctFont) { |
| 541 return nullptr; | 541 return nullptr; |
| 542 } | 542 } |
| 543 | 543 |
| 544 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | 544 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); |
| 545 if (face) { | 545 if (face) { |
| 546 return face; | 546 return face; |
| 547 } | 547 } |
| 548 face = NewFromFontRef(ctFont.release(), nullptr, false); | 548 face = NewFromFontRef(ctFont.release(), nullptr, false); |
| 549 SkTypefaceCache::Add(face, face->fontStyle()); | 549 SkTypefaceCache::Add(face); |
| 550 return face; | 550 return face; |
| 551 } | 551 } |
| 552 | 552 |
| 553 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); | 553 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); |
| 554 static SkTypeface* GetDefaultFace() { | 554 static SkTypeface* GetDefaultFace() { |
| 555 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); | 555 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); |
| 556 | 556 |
| 557 static SkTypeface* gDefaultFace; | 557 static SkTypeface* gDefaultFace; |
| 558 | 558 |
| 559 if (nullptr == gDefaultFace) { | 559 if (nullptr == gDefaultFace) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 576 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef)
{ | 576 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef)
{ |
| 577 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)fontRef); | 577 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)fontRef); |
| 578 if (face) { | 578 if (face) { |
| 579 return face; | 579 return face; |
| 580 } | 580 } |
| 581 CFRetain(fontRef); | 581 CFRetain(fontRef); |
| 582 if (resourceRef) { | 582 if (resourceRef) { |
| 583 CFRetain(resourceRef); | 583 CFRetain(resourceRef); |
| 584 } | 584 } |
| 585 face = NewFromFontRef(fontRef, resourceRef, false); | 585 face = NewFromFontRef(fontRef, resourceRef, false); |
| 586 SkTypefaceCache::Add(face, face->fontStyle()); | 586 SkTypefaceCache::Add(face); |
| 587 return face; | 587 return face; |
| 588 } | 588 } |
| 589 | 589 |
| 590 static const char* map_css_names(const char* name) { | 590 static const char* map_css_names(const char* name) { |
| 591 static const struct { | 591 static const struct { |
| 592 const char* fFrom; // name the caller specified | 592 const char* fFrom; // name the caller specified |
| 593 const char* fTo; // "canonical" name we map to | 593 const char* fTo; // "canonical" name we map to |
| 594 } gPairs[] = { | 594 } gPairs[] = { |
| 595 { "sans-serif", "Helvetica" }, | 595 { "sans-serif", "Helvetica" }, |
| 596 { "serif", "Times" }, | 596 { "serif", "Times" }, |
| (...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 if (!ctFont) { | 2159 if (!ctFont) { |
| 2160 return nullptr; | 2160 return nullptr; |
| 2161 } | 2161 } |
| 2162 | 2162 |
| 2163 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | 2163 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); |
| 2164 if (face) { | 2164 if (face) { |
| 2165 return face; | 2165 return face; |
| 2166 } | 2166 } |
| 2167 | 2167 |
| 2168 face = NewFromFontRef(ctFont.release(), nullptr, false); | 2168 face = NewFromFontRef(ctFont.release(), nullptr, false); |
| 2169 SkTypefaceCache::Add(face, face->fontStyle()); | 2169 SkTypefaceCache::Add(face); |
| 2170 return face; | 2170 return face; |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2173 class SkFontStyleSet_Mac : public SkFontStyleSet { |
| 2174 public: | 2174 public: |
| 2175 SkFontStyleSet_Mac(CTFontDescriptorRef desc) | 2175 SkFontStyleSet_Mac(CTFontDescriptorRef desc) |
| 2176 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) | 2176 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) |
| 2177 , fCount(0) { | 2177 , fCount(0) { |
| 2178 if (nullptr == fArray) { | 2178 if (nullptr == fArray) { |
| 2179 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); | 2179 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 | 2575 |
| 2576 return SkSafeRef(GetDefaultFace()); | 2576 return SkSafeRef(GetDefaultFace()); |
| 2577 } | 2577 } |
| 2578 }; | 2578 }; |
| 2579 | 2579 |
| 2580 /////////////////////////////////////////////////////////////////////////////// | 2580 /////////////////////////////////////////////////////////////////////////////// |
| 2581 | 2581 |
| 2582 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2582 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
| 2583 | 2583 |
| 2584 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2584 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| OLD | NEW |