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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) { | 413 if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) { |
414 slant = 0; | 414 slant = 0; |
415 } | 415 } |
416 | 416 |
417 return SkFontStyle(unit_weight_to_fontstyle(weight), | 417 return SkFontStyle(unit_weight_to_fontstyle(weight), |
418 unit_width_to_fontstyle(width), | 418 unit_width_to_fontstyle(width), |
419 slant ? SkFontStyle::kItalic_Slant | 419 slant ? SkFontStyle::kItalic_Slant |
420 : SkFontStyle::kUpright_Slant); | 420 : SkFontStyle::kUpright_Slant); |
421 } | 421 } |
422 | 422 |
423 static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isFixedPitch) { | |
424 unsigned style = SkTypeface::kNormal; | |
425 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font); | |
426 | |
427 if (traits & kCTFontBoldTrait) { | |
428 style |= SkTypeface::kBold; | |
429 } | |
430 if (traits & kCTFontItalicTrait) { | |
431 style |= SkTypeface::kItalic; | |
432 } | |
433 if (isFixedPitch) { | |
434 *isFixedPitch = (traits & kCTFontMonoSpaceTrait) != 0; | |
435 } | |
436 return (SkTypeface::Style)style; | |
437 } | |
438 | |
439 #define WEIGHT_THRESHOLD ((SkFontStyle::kNormal_Weight + SkFontStyle::kBold_W
eight)/2) | 423 #define WEIGHT_THRESHOLD ((SkFontStyle::kNormal_Weight + SkFontStyle::kBold_W
eight)/2) |
440 | 424 |
441 // kCTFontColorGlyphsTrait was added in the Mac 10.7 and iPhone 4.3 SDKs. | 425 // kCTFontColorGlyphsTrait was added in the Mac 10.7 and iPhone 4.3 SDKs. |
442 // Being an enum value it is not guarded by version macros, but old SDKs must st
ill be supported. | 426 // Being an enum value it is not guarded by version macros, but old SDKs must st
ill be supported. |
443 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) | 427 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) |
444 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; | 428 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; |
445 #else | 429 #else |
446 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); | 430 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); |
447 #endif | 431 #endif |
448 | 432 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 470 |
487 private: | 471 private: |
488 bool fIsLocalStream; | 472 bool fIsLocalStream; |
489 | 473 |
490 typedef SkTypeface INHERITED; | 474 typedef SkTypeface INHERITED; |
491 }; | 475 }; |
492 | 476 |
493 /** Creates a typeface without searching the cache. Takes ownership of the CTFon
tRef. */ | 477 /** Creates a typeface without searching the cache. Takes ownership of the CTFon
tRef. */ |
494 static SkTypeface* NewFromFontRef(CTFontRef fontRef, CFTypeRef resourceRef, bool
isLocalStream) { | 478 static SkTypeface* NewFromFontRef(CTFontRef fontRef, CFTypeRef resourceRef, bool
isLocalStream) { |
495 SkASSERT(fontRef); | 479 SkASSERT(fontRef); |
496 bool isFixedPitch; | |
497 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); | |
498 | 480 |
| 481 AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef)); |
| 482 SkFontStyle style = fontstyle_from_descriptor(desc); |
| 483 |
| 484 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(fontRef); |
| 485 bool isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait); |
499 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal
Stream); | 486 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal
Stream); |
500 } | 487 } |
501 | 488 |
502 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont
ext) { | 489 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont
ext) { |
503 CTFontRef self = (CTFontRef)context; | 490 CTFontRef self = (CTFontRef)context; |
504 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; | 491 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; |
505 | 492 |
506 return CFEqual(self, other); | 493 return CFEqual(self, other); |
507 } | 494 } |
508 | 495 |
(...skipping 2056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 } | 2552 } |
2566 | 2553 |
2567 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 2554 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
2568 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); | 2555 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); |
2569 if (nullptr == pr) { | 2556 if (nullptr == pr) { |
2570 return nullptr; | 2557 return nullptr; |
2571 } | 2558 } |
2572 return create_from_dataProvider(pr); | 2559 return create_from_dataProvider(pr); |
2573 } | 2560 } |
2574 | 2561 |
2575 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 2562 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE |
2576 unsigned styleBits) const overrid
e { | 2563 SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBi
ts) const override { |
2577 | 2564 SkFontStyle style = SkFontStyle::FromOldStyle(styleBits); |
2578 SkFontStyle style = SkFontStyle((SkTypeface::Style)styleBits); | 2565 #else |
| 2566 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl
e) const override { |
| 2567 #endif |
2579 if (familyName) { | 2568 if (familyName) { |
2580 familyName = map_css_names(familyName); | 2569 familyName = map_css_names(familyName); |
2581 } | 2570 } |
2582 | 2571 |
2583 if (!familyName || !*familyName) { | 2572 if (!familyName || !*familyName) { |
2584 familyName = FONT_DEFAULT_NAME; | 2573 familyName = FONT_DEFAULT_NAME; |
2585 } | 2574 } |
2586 | 2575 |
2587 SkTypeface* face = NewFromName(familyName, style); | 2576 SkTypeface* face = NewFromName(familyName, style); |
2588 if (face) { | 2577 if (face) { |
2589 return face; | 2578 return face; |
2590 } | 2579 } |
2591 | 2580 |
2592 return SkSafeRef(GetDefaultFace()); | 2581 return SkSafeRef(GetDefaultFace()); |
2593 } | 2582 } |
2594 }; | 2583 }; |
2595 | 2584 |
2596 /////////////////////////////////////////////////////////////////////////////// | 2585 /////////////////////////////////////////////////////////////////////////////// |
2597 | 2586 |
2598 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2587 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2599 | 2588 |
2600 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2589 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |