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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #include "SkAdvancedTypefaceMetrics.h" | 22 #include "SkAdvancedTypefaceMetrics.h" |
23 #include "SkCGUtils.h" | 23 #include "SkCGUtils.h" |
24 #include "SkColorPriv.h" | 24 #include "SkColorPriv.h" |
25 #include "SkDescriptor.h" | 25 #include "SkDescriptor.h" |
26 #include "SkEndian.h" | 26 #include "SkEndian.h" |
27 #include "SkFloatingPoint.h" | 27 #include "SkFloatingPoint.h" |
28 #include "SkFontDescriptor.h" | 28 #include "SkFontDescriptor.h" |
29 #include "SkFontMgr.h" | 29 #include "SkFontMgr.h" |
30 #include "SkGlyph.h" | 30 #include "SkGlyph.h" |
31 #include "SkMakeUnique.h" | |
32 #include "SkMaskGamma.h" | 31 #include "SkMaskGamma.h" |
33 #include "SkMathPriv.h" | 32 #include "SkMathPriv.h" |
34 #include "SkMutex.h" | 33 #include "SkMutex.h" |
35 #include "SkOTTable_glyf.h" | 34 #include "SkOTTable_glyf.h" |
36 #include "SkOTTable_head.h" | 35 #include "SkOTTable_head.h" |
37 #include "SkOTTable_hhea.h" | 36 #include "SkOTTable_hhea.h" |
38 #include "SkOTTable_loca.h" | 37 #include "SkOTTable_loca.h" |
39 #include "SkOTUtils.h" | 38 #include "SkOTUtils.h" |
40 #include "SkOnce.h" | 39 #include "SkOnce.h" |
41 #include "SkPaint.h" | 40 #include "SkPaint.h" |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 SkASSERT(fontRef); | 504 SkASSERT(fontRef); |
506 } | 505 } |
507 | 506 |
508 AutoCFRelease<CTFontRef> fFontRef; | 507 AutoCFRelease<CTFontRef> fFontRef; |
509 AutoCFRelease<CFTypeRef> fOriginatingCFTypeRef; | 508 AutoCFRelease<CFTypeRef> fOriginatingCFTypeRef; |
510 const bool fHasColorGlyphs; | 509 const bool fHasColorGlyphs; |
511 | 510 |
512 protected: | 511 protected: |
513 int onGetUPEM() const override; | 512 int onGetUPEM() const override; |
514 SkStreamAsset* onOpenStream(int* ttcIndex) const override; | 513 SkStreamAsset* onOpenStream(int* ttcIndex) const override; |
515 std::unique_ptr<SkFontData> onMakeFontData() const override; | 514 SkFontData* onCreateFontData() const override; |
516 void onGetFamilyName(SkString* familyName) const override; | 515 void onGetFamilyName(SkString* familyName) const override; |
517 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; | 516 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
518 int onGetTableTags(SkFontTableTag tags[]) const override; | 517 int onGetTableTags(SkFontTableTag tags[]) const override; |
519 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 518 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
520 size_t length, void* data) const override; | 519 size_t length, void* data) const override; |
521 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, | 520 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, |
522 const SkDescriptor*) const override; | 521 const SkDescriptor*) const override; |
523 void onFilterRec(SkScalerContextRec*) const override; | 522 void onFilterRec(SkScalerContextRec*) const override; |
524 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; | 523 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; |
525 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 524 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 } | 1878 } |
1880 (*axisValues)[(int)i] = SkDoubleToFixed(axisDefaultValueDouble); | 1879 (*axisValues)[(int)i] = SkDoubleToFixed(axisDefaultValueDouble); |
1881 } | 1880 } |
1882 | 1881 |
1883 // Override the default values with the given font's stated axis values. | 1882 // Override the default values with the given font's stated axis values. |
1884 NonDefaultAxesContext c = { axisValues->get(), cgAxes.get() }; | 1883 NonDefaultAxesContext c = { axisValues->get(), cgAxes.get() }; |
1885 CFDictionaryApplyFunction(cgVariations, set_non_default_axes, &c); | 1884 CFDictionaryApplyFunction(cgVariations, set_non_default_axes, &c); |
1886 | 1885 |
1887 return true; | 1886 return true; |
1888 } | 1887 } |
1889 std::unique_ptr<SkFontData> SkTypeface_Mac::onMakeFontData() const { | 1888 SkFontData* SkTypeface_Mac::onCreateFontData() const { |
1890 int index; | 1889 int index; |
1891 std::unique_ptr<SkStreamAsset> stream(this->onOpenStream(&index)); | 1890 SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index)); |
1892 | 1891 |
1893 CFIndex cgAxisCount; | 1892 CFIndex cgAxisCount; |
1894 SkAutoSTMalloc<4, SkFixed> axisValues; | 1893 SkAutoSTMalloc<4, SkFixed> axisValues; |
1895 if (get_variations(fFontRef, &cgAxisCount, &axisValues)) { | 1894 if (get_variations(fFontRef, &cgAxisCount, &axisValues)) { |
1896 return skstd::make_unique<SkFontData>(std::move(stream), index, | 1895 return new SkFontData(stream.release(), index, axisValues.get(), cgAxisC
ount); |
1897 axisValues.get(), cgAxisCount); | |
1898 } | 1896 } |
1899 return skstd::make_unique<SkFontData>(std::move(stream), index, nullptr, 0); | 1897 return new SkFontData(stream.release(), index, nullptr, 0); |
1900 } | 1898 } |
1901 | 1899 |
1902 /////////////////////////////////////////////////////////////////////////////// | 1900 /////////////////////////////////////////////////////////////////////////////// |
1903 /////////////////////////////////////////////////////////////////////////////// | 1901 /////////////////////////////////////////////////////////////////////////////// |
1904 | 1902 |
1905 int SkTypeface_Mac::onGetUPEM() const { | 1903 int SkTypeface_Mac::onGetUPEM() const { |
1906 AutoCFRelease<CGFontRef> cgFont(CTFontCopyGraphicsFont(fFontRef, nullptr)); | 1904 AutoCFRelease<CGFontRef> cgFont(CTFontCopyGraphicsFont(fFontRef, nullptr)); |
1907 return CGFontGetUnitsPerEm(cgFont); | 1905 return CGFontGetUnitsPerEm(cgFont); |
1908 } | 1906 } |
1909 | 1907 |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 AutoCFRelease<CTFontRef> fallbackFont(CTFontCreateForString(currentFont,
string, range)); | 2360 AutoCFRelease<CTFontRef> fallbackFont(CTFontCreateForString(currentFont,
string, range)); |
2363 return create_from_CTFontRef(fallbackFont.release(), nullptr, false); | 2361 return create_from_CTFontRef(fallbackFont.release(), nullptr, false); |
2364 } | 2362 } |
2365 | 2363 |
2366 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 2364 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |
2367 const SkFontStyle&) const override { | 2365 const SkFontStyle&) const override { |
2368 return nullptr; | 2366 return nullptr; |
2369 } | 2367 } |
2370 | 2368 |
2371 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 2369 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
2372 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_
sp(data))); | 2370 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(data)); |
2373 if (nullptr == pr) { | 2371 if (nullptr == pr) { |
2374 return nullptr; | 2372 return nullptr; |
2375 } | 2373 } |
2376 return create_from_dataProvider(pr); | 2374 return create_from_dataProvider(pr); |
2377 } | 2375 } |
2378 | 2376 |
2379 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 2377 SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const ov
erride { |
2380 std::unique_ptr<SkStreamAsset> stream(bareStream); | 2378 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(strea
m)); |
2381 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::
move(stream))); | |
2382 if (nullptr == pr) { | 2379 if (nullptr == pr) { |
2383 return nullptr; | 2380 return nullptr; |
2384 } | 2381 } |
2385 return create_from_dataProvider(pr); | 2382 return create_from_dataProvider(pr); |
2386 } | 2383 } |
2387 | 2384 |
2388 static CFNumberRef get_tag_for_name(CFStringRef name, CFArrayRef ctAxes) { | 2385 static CFNumberRef get_tag_for_name(CFStringRef name, CFArrayRef ctAxes) { |
2389 CFIndex ctAxisCount = CFArrayGetCount(ctAxes); | 2386 CFIndex ctAxisCount = CFArrayGetCount(ctAxes); |
2390 for (int i = 0; i < ctAxisCount; ++i) { | 2387 for (int i = 0; i < ctAxisCount; ++i) { |
2391 CFTypeRef ctAxisInfo = CFArrayGetValueAtIndex(ctAxes, i); | 2388 CFTypeRef ctAxisInfo = CFArrayGetValueAtIndex(ctAxes, i); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2489 break; | 2486 break; |
2490 } | 2487 } |
2491 } | 2488 } |
2492 CFNumberRef valueNumber = CFNumberCreate(kCFAllocatorDefault, kCFNum
berDoubleType, | 2489 CFNumberRef valueNumber = CFNumberCreate(kCFAllocatorDefault, kCFNum
berDoubleType, |
2493 &value); | 2490 &value); |
2494 CFDictionaryAddValue(dict, axisName, valueNumber); | 2491 CFDictionaryAddValue(dict, axisName, valueNumber); |
2495 CFRelease(valueNumber); | 2492 CFRelease(valueNumber); |
2496 } | 2493 } |
2497 return dict; | 2494 return dict; |
2498 } | 2495 } |
2499 SkTypeface* onCreateFromStream(SkStreamAsset* bs, const FontParameters& para
ms) const override { | 2496 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param
s) const override { |
2500 std::unique_ptr<SkStreamAsset> s(bs); | 2497 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream
(s)); |
2501 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream
(std::move(s))); | |
2502 if (nullptr == provider) { | 2498 if (nullptr == provider) { |
2503 return nullptr; | 2499 return nullptr; |
2504 } | 2500 } |
2505 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 2501 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
2506 if (nullptr == cg) { | 2502 if (nullptr == cg) { |
2507 return nullptr; | 2503 return nullptr; |
2508 } | 2504 } |
2509 | 2505 |
2510 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, params)); | 2506 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, params)); |
2511 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2507 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 } | 2567 } |
2572 double value = SkTPin(SkFixedToDouble(fontData->getAxis()[i]), minDo
uble, maxDouble); | 2568 double value = SkTPin(SkFixedToDouble(fontData->getAxis()[i]), minDo
uble, maxDouble); |
2573 CFNumberRef valueNumber = CFNumberCreate(kCFAllocatorDefault, kCFNum
berDoubleType, | 2569 CFNumberRef valueNumber = CFNumberCreate(kCFAllocatorDefault, kCFNum
berDoubleType, |
2574 &value); | 2570 &value); |
2575 | 2571 |
2576 CFDictionaryAddValue(dict, axisName, valueNumber); | 2572 CFDictionaryAddValue(dict, axisName, valueNumber); |
2577 CFRelease(valueNumber); | 2573 CFRelease(valueNumber); |
2578 } | 2574 } |
2579 return dict; | 2575 return dict; |
2580 } | 2576 } |
2581 SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const
override { | 2577 SkTypeface* onCreateFromFontData(SkFontData* data) const override { |
2582 AutoCFRelease<CGDataProviderRef> provider( | 2578 SkAutoTDelete<SkFontData> fontData(data); |
2583 SkCreateDataProviderFromStream(fontData->detachStream())); | 2579 SkStreamAsset* stream = fontData->detachStream(); |
| 2580 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream
(stream)); |
2584 if (nullptr == provider) { | 2581 if (nullptr == provider) { |
2585 return nullptr; | 2582 return nullptr; |
2586 } | 2583 } |
2587 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 2584 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
2588 if (nullptr == cg) { | 2585 if (nullptr == cg) { |
2589 return nullptr; | 2586 return nullptr; |
2590 } | 2587 } |
2591 | 2588 |
2592 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData.get())
); | 2589 AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData)); |
2593 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2590 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
2594 // created from a data provider does not appear to have any ownership of
the underlying | 2591 // created from a data provider does not appear to have any ownership of
the underlying |
2595 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. | 2592 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. |
2596 AutoCFRelease<CGFontRef> cgVariant; | 2593 AutoCFRelease<CGFontRef> cgVariant; |
2597 if (cgVariations) { | 2594 if (cgVariations) { |
2598 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2595 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
2599 } else { | 2596 } else { |
2600 cgVariant.reset(cg.release()); | 2597 cgVariant.reset(cg.release()); |
2601 } | 2598 } |
2602 | 2599 |
(...skipping 28 matching lines...) Expand all Loading... |
2631 | 2628 |
2632 return SkSafeRef(GetDefaultFace()); | 2629 return SkSafeRef(GetDefaultFace()); |
2633 } | 2630 } |
2634 }; | 2631 }; |
2635 | 2632 |
2636 /////////////////////////////////////////////////////////////////////////////// | 2633 /////////////////////////////////////////////////////////////////////////////// |
2637 | 2634 |
2638 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2635 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2639 | 2636 |
2640 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2637 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |