Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: src/ports/SkFontHost_mac.cpp

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

Powered by Google App Engine
This is Rietveld 408576698