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 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 10 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 explicit AutoCFRelease(CFRef cfRef = nullptr) : fCFRef(cfRef) { } | 98 explicit AutoCFRelease(CFRef cfRef = nullptr) : fCFRef(cfRef) { } |
99 ~AutoCFRelease() { CFSafeRelease(fCFRef); } | 99 ~AutoCFRelease() { CFSafeRelease(fCFRef); } |
100 | 100 |
101 void reset(CFRef that = nullptr) { | 101 void reset(CFRef that = nullptr) { |
102 if (that != fCFRef) { | 102 if (that != fCFRef) { |
103 CFSafeRelease(fCFRef); | 103 CFSafeRelease(fCFRef); |
104 fCFRef = that; | 104 fCFRef = that; |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 CFRef detach() { | 108 CFRef release() { |
109 CFRef self = fCFRef; | 109 CFRef self = fCFRef; |
110 fCFRef = nullptr; | 110 fCFRef = nullptr; |
111 return self; | 111 return self; |
112 } | 112 } |
113 | 113 |
114 operator CFRef() const { return fCFRef; } | 114 operator CFRef() const { return fCFRef; } |
115 CFRef get() const { return fCFRef; } | 115 CFRef get() const { return fCFRef; } |
116 | 116 |
117 CFRef* operator&() { SkASSERT(fCFRef == nullptr); return &fCFRef; } | 117 CFRef* operator&() { SkASSERT(fCFRef == nullptr); return &fCFRef; } |
118 private: | 118 private: |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 return nullptr; | 543 return nullptr; |
544 } | 544 } |
545 | 545 |
546 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0
, nullptr)); | 546 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0
, nullptr)); |
547 if (!ctFont) { | 547 if (!ctFont) { |
548 return nullptr; | 548 return nullptr; |
549 } | 549 } |
550 | 550 |
551 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | 551 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); |
552 if (!face) { | 552 if (!face) { |
553 face = NewFromFontRef(ctFont.detach(), nullptr, nullptr, false); | 553 face = NewFromFontRef(ctFont.release(), nullptr, nullptr, false); |
554 SkTypefaceCache::Add(face, face->fontStyle()); | 554 SkTypefaceCache::Add(face, face->fontStyle()); |
555 } | 555 } |
556 return face; | 556 return face; |
557 } | 557 } |
558 | 558 |
559 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); | 559 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); |
560 static SkTypeface* GetDefaultFace() { | 560 static SkTypeface* GetDefaultFace() { |
561 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); | 561 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); |
562 | 562 |
563 static SkTypeface* gDefaultFace; | 563 static SkTypeface* gDefaultFace; |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 | 1860 |
1861 return true; | 1861 return true; |
1862 } | 1862 } |
1863 SkFontData* SkTypeface_Mac::onCreateFontData() const { | 1863 SkFontData* SkTypeface_Mac::onCreateFontData() const { |
1864 int index; | 1864 int index; |
1865 SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index)); | 1865 SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index)); |
1866 | 1866 |
1867 CFIndex cgAxisCount; | 1867 CFIndex cgAxisCount; |
1868 SkAutoSTMalloc<4, SkFixed> axisValues; | 1868 SkAutoSTMalloc<4, SkFixed> axisValues; |
1869 if (get_variations(fFontRef, &cgAxisCount, &axisValues)) { | 1869 if (get_variations(fFontRef, &cgAxisCount, &axisValues)) { |
1870 return new SkFontData(stream.detach(), index, axisValues.get(), cgAxisCo
unt); | 1870 return new SkFontData(stream.release(), index, axisValues.get(), cgAxisC
ount); |
1871 } | 1871 } |
1872 return new SkFontData(stream.detach(), index, nullptr, 0); | 1872 return new SkFontData(stream.release(), index, nullptr, 0); |
1873 } | 1873 } |
1874 | 1874 |
1875 /////////////////////////////////////////////////////////////////////////////// | 1875 /////////////////////////////////////////////////////////////////////////////// |
1876 /////////////////////////////////////////////////////////////////////////////// | 1876 /////////////////////////////////////////////////////////////////////////////// |
1877 | 1877 |
1878 int SkTypeface_Mac::onGetUPEM() const { | 1878 int SkTypeface_Mac::onGetUPEM() const { |
1879 AutoCFRelease<CGFontRef> cgFont(CTFontCopyGraphicsFont(fFontRef, nullptr)); | 1879 AutoCFRelease<CGFontRef> cgFont(CTFontCopyGraphicsFont(fFontRef, nullptr)); |
1880 return CGFontGetUnitsPerEm(cgFont); | 1880 return CGFontGetUnitsPerEm(cgFont); |
1881 } | 1881 } |
1882 | 1882 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 } | 2192 } |
2193 | 2193 |
2194 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); | 2194 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); |
2195 if (!ctFont) { | 2195 if (!ctFont) { |
2196 return nullptr; | 2196 return nullptr; |
2197 } | 2197 } |
2198 | 2198 |
2199 bool isFixedPitch; | 2199 bool isFixedPitch; |
2200 (void)computeStyleBits(ctFont, &isFixedPitch); | 2200 (void)computeStyleBits(ctFont, &isFixedPitch); |
2201 | 2201 |
2202 face = new SkTypeface_Mac(ctFont.detach(), nullptr, cacheRequest.fStyle, isF
ixedPitch, | 2202 face = new SkTypeface_Mac(ctFont.release(), nullptr, cacheRequest.fStyle, is
FixedPitch, |
2203 skFamilyName.c_str(), false); | 2203 skFamilyName.c_str(), false); |
2204 SkTypefaceCache::Add(face, face->fontStyle()); | 2204 SkTypefaceCache::Add(face, face->fontStyle()); |
2205 return face; | 2205 return face; |
2206 } | 2206 } |
2207 | 2207 |
2208 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2208 class SkFontStyleSet_Mac : public SkFontStyleSet { |
2209 public: | 2209 public: |
2210 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) | 2210 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) |
2211 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) | 2211 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) |
2212 , fFamilyName(familyName) | 2212 , fFamilyName(familyName) |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2490 } | 2490 } |
2491 | 2491 |
2492 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, params)); | 2492 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, params)); |
2493 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2493 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
2494 // created from a data provider does not appear to have any ownership of
the underlying | 2494 // created from a data provider does not appear to have any ownership of
the underlying |
2495 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. | 2495 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. |
2496 AutoCFRelease<CGFontRef> cgVariant; | 2496 AutoCFRelease<CGFontRef> cgVariant; |
2497 if (cgVariations) { | 2497 if (cgVariations) { |
2498 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2498 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
2499 } else { | 2499 } else { |
2500 cgVariant.reset(cg.detach()); | 2500 cgVariant.reset(cg.release()); |
2501 } | 2501 } |
2502 | 2502 |
2503 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); | 2503 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); |
2504 if (!ct) { | 2504 if (!ct) { |
2505 return nullptr; | 2505 return nullptr; |
2506 } | 2506 } |
2507 return NewFromFontRef(ct, cg.detach(), nullptr, true); | 2507 return NewFromFontRef(ct, cg.release(), nullptr, true); |
2508 } | 2508 } |
2509 | 2509 |
2510 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { | 2510 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { |
2511 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); | 2511 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); |
2512 if (!cgAxes) { | 2512 if (!cgAxes) { |
2513 return nullptr; | 2513 return nullptr; |
2514 } | 2514 } |
2515 | 2515 |
2516 CFIndex axisCount = CFArrayGetCount(cgAxes); | 2516 CFIndex axisCount = CFArrayGetCount(cgAxes); |
2517 if (0 == axisCount || axisCount != fontData->getAxisCount()) { | 2517 if (0 == axisCount || axisCount != fontData->getAxisCount()) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2573 } | 2573 } |
2574 | 2574 |
2575 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData)); | 2575 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData)); |
2576 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2576 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
2577 // created from a data provider does not appear to have any ownership of
the underlying | 2577 // created from a data provider does not appear to have any ownership of
the underlying |
2578 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. | 2578 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. |
2579 AutoCFRelease<CGFontRef> cgVariant; | 2579 AutoCFRelease<CGFontRef> cgVariant; |
2580 if (cgVariations) { | 2580 if (cgVariations) { |
2581 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2581 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
2582 } else { | 2582 } else { |
2583 cgVariant.reset(cg.detach()); | 2583 cgVariant.reset(cg.release()); |
2584 } | 2584 } |
2585 | 2585 |
2586 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); | 2586 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); |
2587 if (!ct) { | 2587 if (!ct) { |
2588 return nullptr; | 2588 return nullptr; |
2589 } | 2589 } |
2590 return NewFromFontRef(ct, cg.detach(), nullptr, true); | 2590 return NewFromFontRef(ct, cg.release(), nullptr, true); |
2591 } | 2591 } |
2592 | 2592 |
2593 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 2593 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
2594 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); | 2594 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); |
2595 if (nullptr == pr) { | 2595 if (nullptr == pr) { |
2596 return nullptr; | 2596 return nullptr; |
2597 } | 2597 } |
2598 return create_from_dataProvider(pr); | 2598 return create_from_dataProvider(pr); |
2599 } | 2599 } |
2600 | 2600 |
(...skipping 23 matching lines...) Expand all Loading... |
2624 } | 2624 } |
2625 return face; | 2625 return face; |
2626 } | 2626 } |
2627 }; | 2627 }; |
2628 | 2628 |
2629 /////////////////////////////////////////////////////////////////////////////// | 2629 /////////////////////////////////////////////////////////////////////////////// |
2630 | 2630 |
2631 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2631 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2632 | 2632 |
2633 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2633 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |