| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 527 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
| 528 int glyphCount) const override; | 528 int glyphCount) const override; |
| 529 int onCountGlyphs() const override; | 529 int onCountGlyphs() const override; |
| 530 | 530 |
| 531 private: | 531 private: |
| 532 bool fIsLocalStream; | 532 bool fIsLocalStream; |
| 533 | 533 |
| 534 typedef SkTypeface INHERITED; | 534 typedef SkTypeface INHERITED; |
| 535 }; | 535 }; |
| 536 | 536 |
| 537 /** Creates a typeface without searching the cache. Takes ownership of the CTFon
tRef. */ | |
| 538 static SkTypeface* NewFromFontRef(CTFontRef fontRef, CFTypeRef resourceRef, bool
isLocalStream) { | |
| 539 SkASSERT(fontRef); | |
| 540 | |
| 541 AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef)); | |
| 542 SkFontStyle style = fontstyle_from_descriptor(desc); | |
| 543 | |
| 544 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(fontRef); | |
| 545 bool isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait); | |
| 546 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal
Stream); | |
| 547 } | |
| 548 | |
| 549 static bool find_by_CTFontRef(SkTypeface* cached, void* context) { | 537 static bool find_by_CTFontRef(SkTypeface* cached, void* context) { |
| 550 CTFontRef self = (CTFontRef)context; | 538 CTFontRef self = (CTFontRef)context; |
| 551 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; | 539 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; |
| 552 | 540 |
| 553 return CFEqual(self, other); | 541 return CFEqual(self, other); |
| 554 } | 542 } |
| 555 | 543 |
| 556 /** Creates a typeface from a name, searching the cache. */ | 544 /** Creates a typeface, searching the cache if isLocalStream is false. |
| 557 static SkTypeface* NewFromName(const char familyName[], const SkFontStyle& theSt
yle) { | 545 * Takes ownership of the CTFontRef and CFTypeRef. |
| 546 */ |
| 547 static SkTypeface* create_from_CTFontRef(CTFontRef f, CFTypeRef r, bool isLocalS
tream) { |
| 548 SkASSERT(f); |
| 549 AutoCFRelease<CTFontRef> font(f); |
| 550 AutoCFRelease<CFTypeRef> resource(r); |
| 551 |
| 552 if (!isLocalStream) { |
| 553 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef,
(void*)font.get()); |
| 554 if (face) { |
| 555 return face; |
| 556 } |
| 557 } |
| 558 |
| 559 AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(font)); |
| 560 SkFontStyle style = fontstyle_from_descriptor(desc); |
| 561 CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font); |
| 562 bool isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait); |
| 563 |
| 564 SkTypeface* face = new SkTypeface_Mac(font.release(), resource.release(), |
| 565 style, isFixedPitch, isLocalStream); |
| 566 if (!isLocalStream) { |
| 567 SkTypefaceCache::Add(face); |
| 568 } |
| 569 return face; |
| 570 } |
| 571 |
| 572 /** Creates a typeface from a descriptor, searching the cache. */ |
| 573 static SkTypeface* create_from_desc(CTFontDescriptorRef desc) { |
| 574 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); |
| 575 if (!ctFont) { |
| 576 return nullptr; |
| 577 } |
| 578 |
| 579 return create_from_CTFontRef(ctFont.release(), nullptr, false); |
| 580 } |
| 581 |
| 582 static CTFontDescriptorRef create_descriptor(const char familyName[], const SkFo
ntStyle& style) { |
| 558 CTFontSymbolicTraits ctFontTraits = 0; | 583 CTFontSymbolicTraits ctFontTraits = 0; |
| 559 if (theStyle.weight() >= SkFontStyle::kBold_Weight) { | 584 if (style.weight() >= SkFontStyle::kBold_Weight) { |
| 560 ctFontTraits |= kCTFontBoldTrait; | 585 ctFontTraits |= kCTFontBoldTrait; |
| 561 } | 586 } |
| 562 if (theStyle.slant() != SkFontStyle::kUpright_Slant) { | 587 if (style.slant() != SkFontStyle::kUpright_Slant) { |
| 563 ctFontTraits |= kCTFontItalicTrait; | 588 ctFontTraits |= kCTFontItalicTrait; |
| 564 } | 589 } |
| 565 | 590 |
| 566 //TODO: add weight width slant | 591 //TODO: add weight width slant |
| 567 | 592 |
| 568 // Create the font info | 593 // Create the font info |
| 569 AutoCFRelease<CFStringRef> cfFontName(make_CFString(familyName)); | 594 AutoCFRelease<CFStringRef> cfFontName(make_CFString(familyName)); |
| 570 | 595 |
| 571 AutoCFRelease<CFNumberRef> cfFontTraits( | 596 AutoCFRelease<CFNumberRef> cfFontTraits( |
| 572 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctFontTrai
ts)); | 597 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctFontTrai
ts)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 583 | 608 |
| 584 if (!cfFontName || !cfFontTraits || !cfAttributes || !cfTraits) { | 609 if (!cfFontName || !cfFontTraits || !cfAttributes || !cfTraits) { |
| 585 return nullptr; | 610 return nullptr; |
| 586 } | 611 } |
| 587 | 612 |
| 588 CFDictionaryAddValue(cfTraits, kCTFontSymbolicTrait, cfFontTraits); | 613 CFDictionaryAddValue(cfTraits, kCTFontSymbolicTrait, cfFontTraits); |
| 589 | 614 |
| 590 CFDictionaryAddValue(cfAttributes, kCTFontFamilyNameAttribute, cfFontName); | 615 CFDictionaryAddValue(cfAttributes, kCTFontFamilyNameAttribute, cfFontName); |
| 591 CFDictionaryAddValue(cfAttributes, kCTFontTraitsAttribute, cfTraits); | 616 CFDictionaryAddValue(cfAttributes, kCTFontTraitsAttribute, cfTraits); |
| 592 | 617 |
| 593 AutoCFRelease<CTFontDescriptorRef> ctFontDesc( | 618 return CTFontDescriptorCreateWithAttributes(cfAttributes); |
| 594 CTFontDescriptorCreateWithAttributes(cfAttributes)); | 619 } |
| 595 if (!ctFontDesc) { | 620 |
| 621 /** Creates a typeface from a name, searching the cache. */ |
| 622 static SkTypeface* create_from_name(const char familyName[], const SkFontStyle&
style) { |
| 623 AutoCFRelease<CTFontDescriptorRef> desc(create_descriptor(familyName, style)
); |
| 624 if (!desc) { |
| 596 return nullptr; | 625 return nullptr; |
| 597 } | 626 } |
| 598 | 627 return create_from_desc(desc); |
| 599 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0
, nullptr)); | |
| 600 if (!ctFont) { | |
| 601 return nullptr; | |
| 602 } | |
| 603 | |
| 604 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | |
| 605 if (face) { | |
| 606 return face; | |
| 607 } | |
| 608 face = NewFromFontRef(ctFont.release(), nullptr, false); | |
| 609 SkTypefaceCache::Add(face); | |
| 610 return face; | |
| 611 } | 628 } |
| 612 | 629 |
| 613 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); | 630 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); |
| 614 static SkTypeface* GetDefaultFace() { | 631 static SkTypeface* GetDefaultFace() { |
| 615 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); | 632 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); |
| 616 | 633 |
| 617 static SkTypeface* gDefaultFace; | 634 static SkTypeface* gDefaultFace; |
| 618 | 635 |
| 619 if (nullptr == gDefaultFace) { | 636 if (nullptr == gDefaultFace) { |
| 620 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkFontStyle()); | 637 gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle()); |
| 621 } | 638 } |
| 622 return gDefaultFace; | 639 return gDefaultFace; |
| 623 } | 640 } |
| 624 | 641 |
| 625 /////////////////////////////////////////////////////////////////////////////// | 642 /////////////////////////////////////////////////////////////////////////////// |
| 626 | 643 |
| 627 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); | 644 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); |
| 628 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { | 645 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { |
| 629 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; | 646 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; |
| 630 return macface ? macface->fFontRef.get() : nullptr; | 647 return macface ? macface->fFontRef.get() : nullptr; |
| 631 } | 648 } |
| 632 | 649 |
| 633 /* This function is visible on the outside. It first searches the cache, and if | 650 /* This function is visible on the outside. It first searches the cache, and if |
| 634 * not found, returns a new entry (after adding it to the cache). | 651 * not found, returns a new entry (after adding it to the cache). |
| 635 */ | 652 */ |
| 636 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef)
{ | 653 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef)
{ |
| 637 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)fontRef); | |
| 638 if (face) { | |
| 639 return face; | |
| 640 } | |
| 641 CFRetain(fontRef); | 654 CFRetain(fontRef); |
| 642 if (resourceRef) { | 655 if (resourceRef) { |
| 643 CFRetain(resourceRef); | 656 CFRetain(resourceRef); |
| 644 } | 657 } |
| 645 face = NewFromFontRef(fontRef, resourceRef, false); | 658 return create_from_CTFontRef(fontRef, resourceRef, false); |
| 646 SkTypefaceCache::Add(face); | |
| 647 return face; | |
| 648 } | 659 } |
| 649 | 660 |
| 650 static const char* map_css_names(const char* name) { | 661 static const char* map_css_names(const char* name) { |
| 651 static const struct { | 662 static const struct { |
| 652 const char* fFrom; // name the caller specified | 663 const char* fFrom; // name the caller specified |
| 653 const char* fTo; // "canonical" name we map to | 664 const char* fTo; // "canonical" name we map to |
| 654 } gPairs[] = { | 665 } gPairs[] = { |
| 655 { "sans-serif", "Helvetica" }, | 666 { "sans-serif", "Helvetica" }, |
| 656 { "serif", "Times" }, | 667 { "serif", "Times" }, |
| 657 { "monospace", "Courier" } | 668 { "monospace", "Courier" } |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 /////////////////////////////////////////////////////////////////////////////// | 1506 /////////////////////////////////////////////////////////////////////////////// |
| 1496 | 1507 |
| 1497 // Returns nullptr on failure | 1508 // Returns nullptr on failure |
| 1498 // Call must still manage its ownership of provider | 1509 // Call must still manage its ownership of provider |
| 1499 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { | 1510 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
| 1500 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 1511 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
| 1501 if (nullptr == cg) { | 1512 if (nullptr == cg) { |
| 1502 return nullptr; | 1513 return nullptr; |
| 1503 } | 1514 } |
| 1504 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, nullptr, nullptr); | 1515 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, nullptr, nullptr); |
| 1505 return ct ? NewFromFontRef(ct, nullptr, true) : nullptr; | 1516 return ct ? create_from_CTFontRef(ct, nullptr, true) : nullptr; |
| 1506 } | 1517 } |
| 1507 | 1518 |
| 1508 // Web fonts added to the the CTFont registry do not return their character set. | 1519 // Web fonts added to the the CTFont registry do not return their character set. |
| 1509 // Iterate through the font in this case. The existing caller caches the result, | 1520 // Iterate through the font in this case. The existing caller caches the result, |
| 1510 // so the performance impact isn't too bad. | 1521 // so the performance impact isn't too bad. |
| 1511 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, | 1522 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, |
| 1512 SkTDArray<SkUnichar>* glyphToUnicode)
{ | 1523 SkTDArray<SkUnichar>* glyphToUnicode)
{ |
| 1513 glyphToUnicode->setCount(SkToInt(glyphCount)); | 1524 glyphToUnicode->setCount(SkToInt(glyphCount)); |
| 1514 SkUnichar* out = glyphToUnicode->begin(); | 1525 SkUnichar* out = glyphToUnicode->begin(); |
| 1515 sk_bzero(out, glyphCount * sizeof(SkUnichar)); | 1526 sk_bzero(out, glyphCount * sizeof(SkUnichar)); |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 return value * value; | 2194 return value * value; |
| 2184 } | 2195 } |
| 2185 | 2196 |
| 2186 // We normalize each axis (weight, width, italic) to be base-900 | 2197 // We normalize each axis (weight, width, italic) to be base-900 |
| 2187 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { | 2198 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { |
| 2188 return sqr(a.weight() - b.weight()) + | 2199 return sqr(a.weight() - b.weight()) + |
| 2189 sqr((a.width() - b.width()) * 100) + | 2200 sqr((a.width() - b.width()) * 100) + |
| 2190 sqr((a.slant() != b.slant()) * 900); | 2201 sqr((a.slant() != b.slant()) * 900); |
| 2191 } | 2202 } |
| 2192 | 2203 |
| 2193 static SkTypeface* createFromDesc(CTFontDescriptorRef desc) { | |
| 2194 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null
ptr)); | |
| 2195 if (!ctFont) { | |
| 2196 return nullptr; | |
| 2197 } | |
| 2198 | |
| 2199 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi
d*)ctFont.get()); | |
| 2200 if (face) { | |
| 2201 return face; | |
| 2202 } | |
| 2203 | |
| 2204 face = NewFromFontRef(ctFont.release(), nullptr, false); | |
| 2205 SkTypefaceCache::Add(face); | |
| 2206 return face; | |
| 2207 } | |
| 2208 | |
| 2209 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2204 class SkFontStyleSet_Mac : public SkFontStyleSet { |
| 2210 public: | 2205 public: |
| 2211 SkFontStyleSet_Mac(CTFontDescriptorRef desc) | 2206 SkFontStyleSet_Mac(CTFontDescriptorRef desc) |
| 2212 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) | 2207 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) |
| 2213 , fCount(0) { | 2208 , fCount(0) { |
| 2214 if (nullptr == fArray) { | 2209 if (nullptr == fArray) { |
| 2215 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); | 2210 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); |
| 2216 } | 2211 } |
| 2217 fCount = SkToInt(CFArrayGetCount(fArray)); | 2212 fCount = SkToInt(CFArrayGetCount(fArray)); |
| 2218 } | 2213 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2235 if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) { | 2230 if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) { |
| 2236 name->reset(); | 2231 name->reset(); |
| 2237 } | 2232 } |
| 2238 } | 2233 } |
| 2239 } | 2234 } |
| 2240 | 2235 |
| 2241 SkTypeface* createTypeface(int index) override { | 2236 SkTypeface* createTypeface(int index) override { |
| 2242 SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray)); | 2237 SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray)); |
| 2243 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f
Array, index); | 2238 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f
Array, index); |
| 2244 | 2239 |
| 2245 return createFromDesc(desc); | 2240 return create_from_desc(desc); |
| 2246 } | 2241 } |
| 2247 | 2242 |
| 2248 SkTypeface* matchStyle(const SkFontStyle& pattern) override { | 2243 SkTypeface* matchStyle(const SkFontStyle& pattern) override { |
| 2249 if (0 == fCount) { | 2244 if (0 == fCount) { |
| 2250 return nullptr; | 2245 return nullptr; |
| 2251 } | 2246 } |
| 2252 return createFromDesc(findMatchingDesc(pattern)); | 2247 return create_from_desc(findMatchingDesc(pattern)); |
| 2253 } | 2248 } |
| 2254 | 2249 |
| 2255 private: | 2250 private: |
| 2256 CFArrayRef fArray; | 2251 CFArrayRef fArray; |
| 2257 int fCount; | 2252 int fCount; |
| 2258 | 2253 |
| 2259 CTFontDescriptorRef findMatchingDesc(const SkFontStyle& pattern) const { | 2254 CTFontDescriptorRef findMatchingDesc(const SkFontStyle& pattern) const { |
| 2260 int bestMetric = SK_MaxS32; | 2255 int bestMetric = SK_MaxS32; |
| 2261 CTFontDescriptorRef bestDesc = nullptr; | 2256 CTFontDescriptorRef bestDesc = nullptr; |
| 2262 | 2257 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2331 AutoCFRelease<CFStringRef> cfName(make_CFString(familyName)); | 2326 AutoCFRelease<CFStringRef> cfName(make_CFString(familyName)); |
| 2332 return CreateSet(cfName); | 2327 return CreateSet(cfName); |
| 2333 } | 2328 } |
| 2334 | 2329 |
| 2335 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 2330 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
| 2336 const SkFontStyle& fontStyle) const o
verride { | 2331 const SkFontStyle& fontStyle) const o
verride { |
| 2337 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); | 2332 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); |
| 2338 return sset->matchStyle(fontStyle); | 2333 return sset->matchStyle(fontStyle); |
| 2339 } | 2334 } |
| 2340 | 2335 |
| 2341 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
st SkFontStyle&, | 2336 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], |
| 2337 const SkFontStyle& style, |
| 2342 const char* bcp47[], int bcp
47Count, | 2338 const char* bcp47[], int bcp
47Count, |
| 2343 SkUnichar character) const o
verride { | 2339 SkUnichar character) const o
verride { |
| 2344 return nullptr; | 2340 AutoCFRelease<CTFontDescriptorRef> desc(create_descriptor(familyName, st
yle)); |
| 2341 AutoCFRelease<CTFontRef> currentFont(CTFontCreateWithFontDescriptor(desc
, 0, nullptr)); |
| 2342 |
| 2343 // kCFStringEncodingUTF32 is BE unless there is a BOM. |
| 2344 // Since there is no machine endian option, explicitly state machine end
ian. |
| 2345 #ifdef SK_CPU_LENDIAN |
| 2346 constexpr CFStringEncoding encoding = kCFStringEncodingUTF32LE; |
| 2347 #else |
| 2348 constexpr CFStringEncoding encoding = kCFStringEncodingUTF32BE; |
| 2349 #endif |
| 2350 AutoCFRelease<CFStringRef> string(CFStringCreateWithBytes( |
| 2351 kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(&character)
, sizeof(character), |
| 2352 encoding, false)); |
| 2353 CFRange range = CFRangeMake(0, CFStringGetLength(string)); // in UniCha
r units. |
| 2354 AutoCFRelease<CTFontRef> fallbackFont(CTFontCreateForString(currentFont,
string, range)); |
| 2355 return create_from_CTFontRef(fallbackFont.release(), nullptr, false); |
| 2345 } | 2356 } |
| 2346 | 2357 |
| 2347 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 2358 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |
| 2348 const SkFontStyle&) const override { | 2359 const SkFontStyle&) const override { |
| 2349 return nullptr; | 2360 return nullptr; |
| 2350 } | 2361 } |
| 2351 | 2362 |
| 2352 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 2363 SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { |
| 2353 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(data)); | 2364 AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(data)); |
| 2354 if (nullptr == pr) { | 2365 if (nullptr == pr) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2501 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
| 2491 // created from a data provider does not appear to have any ownership of
the underlying | 2502 // created from a data provider does not appear to have any ownership of
the underlying |
| 2492 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. | 2503 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. |
| 2493 AutoCFRelease<CGFontRef> cgVariant; | 2504 AutoCFRelease<CGFontRef> cgVariant; |
| 2494 if (cgVariations) { | 2505 if (cgVariations) { |
| 2495 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2506 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
| 2496 } else { | 2507 } else { |
| 2497 cgVariant.reset(cg.release()); | 2508 cgVariant.reset(cg.release()); |
| 2498 } | 2509 } |
| 2499 | 2510 |
| 2500 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); | 2511 AutoCFRelease<CTFontRef> ct(CTFontCreateWithGraphicsFont(cgVariant, 0, n
ullptr, nullptr)); |
| 2501 if (!ct) { | 2512 if (!ct) { |
| 2502 return nullptr; | 2513 return nullptr; |
| 2503 } | 2514 } |
| 2504 return NewFromFontRef(ct, cg.release(), true); | 2515 return create_from_CTFontRef(ct.release(), cg.release(), true); |
| 2505 } | 2516 } |
| 2506 | 2517 |
| 2507 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { | 2518 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { |
| 2508 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); | 2519 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); |
| 2509 if (!cgAxes) { | 2520 if (!cgAxes) { |
| 2510 return nullptr; | 2521 return nullptr; |
| 2511 } | 2522 } |
| 2512 | 2523 |
| 2513 CFIndex axisCount = CFArrayGetCount(cgAxes); | 2524 CFIndex axisCount = CFArrayGetCount(cgAxes); |
| 2514 if (0 == axisCount || axisCount != fontData->getAxisCount()) { | 2525 if (0 == axisCount || axisCount != fontData->getAxisCount()) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2573 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was | 2584 // The CGFontRef returned by CGFontCreateCopyWithVariations when the pas
sed CGFontRef was |
| 2574 // created from a data provider does not appear to have any ownership of
the underlying | 2585 // created from a data provider does not appear to have any ownership of
the underlying |
| 2575 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. | 2586 // data. The original CGFontRef must be kept alive until the copy will n
o longer be used. |
| 2576 AutoCFRelease<CGFontRef> cgVariant; | 2587 AutoCFRelease<CGFontRef> cgVariant; |
| 2577 if (cgVariations) { | 2588 if (cgVariations) { |
| 2578 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2589 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
| 2579 } else { | 2590 } else { |
| 2580 cgVariant.reset(cg.release()); | 2591 cgVariant.reset(cg.release()); |
| 2581 } | 2592 } |
| 2582 | 2593 |
| 2583 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp
tr); | 2594 AutoCFRelease<CTFontRef> ct(CTFontCreateWithGraphicsFont(cgVariant, 0, n
ullptr, nullptr)); |
| 2584 if (!ct) { | 2595 if (!ct) { |
| 2585 return nullptr; | 2596 return nullptr; |
| 2586 } | 2597 } |
| 2587 return NewFromFontRef(ct, cg.release(), true); | 2598 return create_from_CTFontRef(ct.release(), cg.release(), true); |
| 2588 } | 2599 } |
| 2589 | 2600 |
| 2590 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 2601 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
| 2591 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); | 2602 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); |
| 2592 if (nullptr == pr) { | 2603 if (nullptr == pr) { |
| 2593 return nullptr; | 2604 return nullptr; |
| 2594 } | 2605 } |
| 2595 return create_from_dataProvider(pr); | 2606 return create_from_dataProvider(pr); |
| 2596 } | 2607 } |
| 2597 | 2608 |
| 2598 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl
e) const override { | 2609 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl
e) const override { |
| 2599 if (familyName) { | 2610 if (familyName) { |
| 2600 familyName = map_css_names(familyName); | 2611 familyName = map_css_names(familyName); |
| 2601 } | 2612 } |
| 2602 | 2613 |
| 2603 if (!familyName || !*familyName) { | 2614 if (!familyName || !*familyName) { |
| 2604 familyName = FONT_DEFAULT_NAME; | 2615 familyName = FONT_DEFAULT_NAME; |
| 2605 } | 2616 } |
| 2606 | 2617 |
| 2607 SkTypeface* face = NewFromName(familyName, style); | 2618 SkTypeface* face = create_from_name(familyName, style); |
| 2608 if (face) { | 2619 if (face) { |
| 2609 return face; | 2620 return face; |
| 2610 } | 2621 } |
| 2611 | 2622 |
| 2612 return SkSafeRef(GetDefaultFace()); | 2623 return SkSafeRef(GetDefaultFace()); |
| 2613 } | 2624 } |
| 2614 }; | 2625 }; |
| 2615 | 2626 |
| 2616 /////////////////////////////////////////////////////////////////////////////// | 2627 /////////////////////////////////////////////////////////////////////////////// |
| 2617 | 2628 |
| 2618 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2629 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
| 2619 | 2630 |
| 2620 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2631 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| OLD | NEW |