Chromium Code Reviews| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) | 443 #if defined(__MAC_10_7) || defined(__IPHONE_4_3) |
| 444 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; | 444 static const uint32_t SkCTFontColorGlyphsTrait = kCTFontColorGlyphsTrait; |
| 445 #else | 445 #else |
| 446 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); | 446 static const uint32_t SkCTFontColorGlyphsTrait = (1 << 13); |
| 447 #endif | 447 #endif |
| 448 | 448 |
| 449 class SkTypeface_Mac : public SkTypeface { | 449 class SkTypeface_Mac : public SkTypeface { |
| 450 public: | 450 public: |
| 451 SkTypeface_Mac(CTFontRef fontRef, CFTypeRef resourceRef, | 451 SkTypeface_Mac(CTFontRef fontRef, CFTypeRef resourceRef, |
| 452 const SkFontStyle& fs, bool isFixedPitch, | 452 const SkFontStyle& fs, bool isFixedPitch, |
| 453 const char requestedName[], bool isLocalStream) | 453 bool isLocalStream) |
| 454 : SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch) | 454 : SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch) |
| 455 , fRequestedName(requestedName) | |
| 456 , fFontRef(fontRef) // caller has already called CFRetain for us | 455 , fFontRef(fontRef) // caller has already called CFRetain for us |
| 457 , fOriginatingCFTypeRef(resourceRef) // caller has already called CFReta in for us | 456 , fOriginatingCFTypeRef(resourceRef) // caller has already called CFReta in for us |
| 458 , fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontC olorGlyphsTrait)) | 457 , fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontC olorGlyphsTrait)) |
| 459 , fIsLocalStream(isLocalStream) | 458 , fIsLocalStream(isLocalStream) |
| 460 { | 459 { |
| 461 SkASSERT(fontRef); | 460 SkASSERT(fontRef); |
| 462 } | 461 } |
| 463 | 462 |
| 464 SkString fRequestedName; | |
| 465 AutoCFRelease<CTFontRef> fFontRef; | 463 AutoCFRelease<CTFontRef> fFontRef; |
| 466 AutoCFRelease<CFTypeRef> fOriginatingCFTypeRef; | 464 AutoCFRelease<CFTypeRef> fOriginatingCFTypeRef; |
| 467 const bool fHasColorGlyphs; | 465 const bool fHasColorGlyphs; |
| 468 | 466 |
| 469 protected: | 467 protected: |
| 470 int onGetUPEM() const override; | 468 int onGetUPEM() const override; |
| 471 SkStreamAsset* onOpenStream(int* ttcIndex) const override; | 469 SkStreamAsset* onOpenStream(int* ttcIndex) const override; |
| 472 SkFontData* onCreateFontData() const override; | 470 SkFontData* onCreateFontData() const override; |
| 473 void onGetFamilyName(SkString* familyName) const override; | 471 void onGetFamilyName(SkString* familyName) const override; |
| 474 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; | 472 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 485 int glyphCount) const override; | 483 int glyphCount) const override; |
| 486 int onCountGlyphs() const override; | 484 int onCountGlyphs() const override; |
| 487 | 485 |
| 488 private: | 486 private: |
| 489 bool fIsLocalStream; | 487 bool fIsLocalStream; |
| 490 | 488 |
| 491 typedef SkTypeface INHERITED; | 489 typedef SkTypeface INHERITED; |
| 492 }; | 490 }; |
| 493 | 491 |
| 494 /** Creates a typeface without searching the cache. Takes ownership of the CTFon tRef. */ | 492 /** Creates a typeface without searching the cache. Takes ownership of the CTFon tRef. */ |
| 495 static SkTypeface* NewFromFontRef(CTFontRef fontRef, CFTypeRef resourceRef, | 493 static SkTypeface* NewFromFontRef(CTFontRef fontRef, CFTypeRef resourceRef, bool isLocalStream) { |
| 496 const char name[], bool isLocalStream) | |
| 497 { | |
| 498 SkASSERT(fontRef); | 494 SkASSERT(fontRef); |
| 499 bool isFixedPitch; | 495 bool isFixedPitch; |
| 500 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); | 496 SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch)); |
| 501 | 497 |
| 502 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, name, i sLocalStream); | 498 return new SkTypeface_Mac(fontRef, resourceRef, style, isFixedPitch, isLocal Stream); |
| 503 } | 499 } |
| 504 | 500 |
| 505 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont ext) { | 501 static bool find_by_CTFontRef(SkTypeface* cached, const SkFontStyle&, void* cont ext) { |
| 506 CTFontRef self = (CTFontRef)context; | 502 CTFontRef self = (CTFontRef)context; |
| 507 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; | 503 CTFontRef other = ((SkTypeface_Mac*)cached)->fFontRef; |
| 508 | 504 |
| 509 return CFEqual(self, other); | 505 return CFEqual(self, other); |
| 510 } | 506 } |
| 511 | 507 |
| 512 /** Creates a typeface from a name, searching the cache. */ | 508 /** Creates a typeface from a name, searching the cache. */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 if (!ctFontDesc) { | 547 if (!ctFontDesc) { |
| 552 return nullptr; | 548 return nullptr; |
| 553 } | 549 } |
| 554 | 550 |
| 555 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0 , nullptr)); | 551 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(ctFontDesc, 0 , nullptr)); |
| 556 if (!ctFont) { | 552 if (!ctFont) { |
| 557 return nullptr; | 553 return nullptr; |
| 558 } | 554 } |
| 559 | 555 |
| 560 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)ctFont.get()); | 556 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)ctFont.get()); |
| 561 if (!face) { | 557 if (face) { |
| 562 face = NewFromFontRef(ctFont.release(), nullptr, nullptr, false); | 558 return face; |
|
mtklein
2016/04/08 00:59:49
this'd be easier to review if you keep the demorga
| |
| 563 SkTypefaceCache::Add(face, face->fontStyle()); | |
| 564 } | 559 } |
| 560 face = NewFromFontRef(ctFont.release(), nullptr, false); | |
| 561 SkTypefaceCache::Add(face, face->fontStyle()); | |
| 565 return face; | 562 return face; |
| 566 } | 563 } |
| 567 | 564 |
| 568 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); | 565 SK_DECLARE_STATIC_MUTEX(gGetDefaultFaceMutex); |
| 569 static SkTypeface* GetDefaultFace() { | 566 static SkTypeface* GetDefaultFace() { |
| 570 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); | 567 SkAutoMutexAcquire ma(gGetDefaultFaceMutex); |
| 571 | 568 |
| 572 static SkTypeface* gDefaultFace; | 569 static SkTypeface* gDefaultFace; |
| 573 | 570 |
| 574 if (nullptr == gDefaultFace) { | 571 if (nullptr == gDefaultFace) { |
| 575 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkFontStyle()); | 572 gDefaultFace = NewFromName(FONT_DEFAULT_NAME, SkFontStyle()); |
| 576 SkTypefaceCache::Add(gDefaultFace, SkFontStyle()); | |
| 577 } | 573 } |
| 578 return gDefaultFace; | 574 return gDefaultFace; |
| 579 } | 575 } |
| 580 | 576 |
| 581 /////////////////////////////////////////////////////////////////////////////// | 577 /////////////////////////////////////////////////////////////////////////////// |
| 582 | 578 |
| 583 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); | 579 extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); |
| 584 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { | 580 CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { |
| 585 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; | 581 const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; |
| 586 return macface ? macface->fFontRef.get() : nullptr; | 582 return macface ? macface->fFontRef.get() : nullptr; |
| 587 } | 583 } |
| 588 | 584 |
| 589 /* This function is visible on the outside. It first searches the cache, and if | 585 /* This function is visible on the outside. It first searches the cache, and if |
| 590 * not found, returns a new entry (after adding it to the cache). | 586 * not found, returns a new entry (after adding it to the cache). |
| 591 */ | 587 */ |
| 592 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef) { | 588 SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef, CFTypeRef resourceRef) { |
| 593 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)fontRef); | 589 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)fontRef); |
| 594 if (!face) { | 590 if (face) { |
| 595 CFRetain(fontRef); | 591 return face; |
| 596 if (resourceRef) { | |
| 597 CFRetain(resourceRef); | |
| 598 } | |
| 599 face = NewFromFontRef(fontRef, resourceRef, nullptr, false); | |
| 600 SkTypefaceCache::Add(face, face->fontStyle()); | |
| 601 } | 592 } |
| 593 CFRetain(fontRef); | |
| 594 if (resourceRef) { | |
| 595 CFRetain(resourceRef); | |
| 596 } | |
| 597 face = NewFromFontRef(fontRef, resourceRef, false); | |
| 598 SkTypefaceCache::Add(face, face->fontStyle()); | |
| 602 return face; | 599 return face; |
| 603 } | 600 } |
| 604 | 601 |
| 605 struct NameStyle { | |
| 606 const char* fName; | |
| 607 SkFontStyle fStyle; | |
| 608 }; | |
| 609 | |
| 610 static bool find_by_NameStyle(SkTypeface* cachedFace, const SkFontStyle& cachedS tyle, void* ctx) { | |
| 611 const SkTypeface_Mac* cachedMacFace = static_cast<SkTypeface_Mac*>(cachedFac e); | |
| 612 const NameStyle* requested = static_cast<const NameStyle*>(ctx); | |
| 613 | |
| 614 return cachedStyle == requested->fStyle | |
| 615 && cachedMacFace->fRequestedName.equals(requested->fName); | |
| 616 } | |
| 617 | |
| 618 static const char* map_css_names(const char* name) { | 602 static const char* map_css_names(const char* name) { |
| 619 static const struct { | 603 static const struct { |
| 620 const char* fFrom; // name the caller specified | 604 const char* fFrom; // name the caller specified |
| 621 const char* fTo; // "canonical" name we map to | 605 const char* fTo; // "canonical" name we map to |
| 622 } gPairs[] = { | 606 } gPairs[] = { |
| 623 { "sans-serif", "Helvetica" }, | 607 { "sans-serif", "Helvetica" }, |
| 624 { "serif", "Times" }, | 608 { "serif", "Times" }, |
| 625 { "monospace", "Courier" } | 609 { "monospace", "Courier" } |
| 626 }; | 610 }; |
| 627 | 611 |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1462 /////////////////////////////////////////////////////////////////////////////// | 1446 /////////////////////////////////////////////////////////////////////////////// |
| 1463 | 1447 |
| 1464 // Returns nullptr on failure | 1448 // Returns nullptr on failure |
| 1465 // Call must still manage its ownership of provider | 1449 // Call must still manage its ownership of provider |
| 1466 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { | 1450 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
| 1467 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 1451 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
| 1468 if (nullptr == cg) { | 1452 if (nullptr == cg) { |
| 1469 return nullptr; | 1453 return nullptr; |
| 1470 } | 1454 } |
| 1471 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, nullptr, nullptr); | 1455 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, nullptr, nullptr); |
| 1472 return ct ? NewFromFontRef(ct, nullptr, nullptr, true) : nullptr; | 1456 return ct ? NewFromFontRef(ct, nullptr, true) : nullptr; |
| 1473 } | 1457 } |
| 1474 | 1458 |
| 1475 // Web fonts added to the the CTFont registry do not return their character set. | 1459 // Web fonts added to the the CTFont registry do not return their character set. |
| 1476 // Iterate through the font in this case. The existing caller caches the result, | 1460 // Iterate through the font in this case. The existing caller caches the result, |
| 1477 // so the performance impact isn't too bad. | 1461 // so the performance impact isn't too bad. |
| 1478 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, | 1462 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, |
| 1479 SkTDArray<SkUnichar>* glyphToUnicode) { | 1463 SkTDArray<SkUnichar>* glyphToUnicode) { |
| 1480 glyphToUnicode->setCount(SkToInt(glyphCount)); | 1464 glyphToUnicode->setCount(SkToInt(glyphCount)); |
| 1481 SkUnichar* out = glyphToUnicode->begin(); | 1465 SkUnichar* out = glyphToUnicode->begin(); |
| 1482 sk_bzero(out, glyphCount * sizeof(SkUnichar)); | 1466 sk_bzero(out, glyphCount * sizeof(SkUnichar)); |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2172 return value * value; | 2156 return value * value; |
| 2173 } | 2157 } |
| 2174 | 2158 |
| 2175 // We normalize each axis (weight, width, italic) to be base-900 | 2159 // We normalize each axis (weight, width, italic) to be base-900 |
| 2176 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { | 2160 static int compute_metric(const SkFontStyle& a, const SkFontStyle& b) { |
| 2177 return sqr(a.weight() - b.weight()) + | 2161 return sqr(a.weight() - b.weight()) + |
| 2178 sqr((a.width() - b.width()) * 100) + | 2162 sqr((a.width() - b.width()) * 100) + |
| 2179 sqr((a.isItalic() != b.isItalic()) * 900); | 2163 sqr((a.isItalic() != b.isItalic()) * 900); |
| 2180 } | 2164 } |
| 2181 | 2165 |
| 2182 static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef desc) { | 2166 static SkTypeface* createFromDesc(CTFontDescriptorRef desc) { |
| 2183 NameStyle cacheRequest; | |
| 2184 SkString skFamilyName; | |
| 2185 CFStringToSkString(cfFamilyName, &skFamilyName); | |
| 2186 cacheRequest.fName = skFamilyName.c_str(); | |
| 2187 cacheRequest.fStyle = fontstyle_from_descriptor(desc); | |
| 2188 | |
| 2189 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cac heRequest); | |
| 2190 if (face) { | |
| 2191 return face; | |
| 2192 } | |
| 2193 | |
| 2194 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null ptr)); | 2167 AutoCFRelease<CTFontRef> ctFont(CTFontCreateWithFontDescriptor(desc, 0, null ptr)); |
| 2195 if (!ctFont) { | 2168 if (!ctFont) { |
| 2196 return nullptr; | 2169 return nullptr; |
| 2197 } | 2170 } |
| 2198 | 2171 |
| 2199 bool isFixedPitch; | 2172 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_CTFontRef, (voi d*)ctFont.get()); |
| 2200 (void)computeStyleBits(ctFont, &isFixedPitch); | 2173 if (face) { |
| 2174 return face; | |
| 2175 } | |
| 2201 | 2176 |
| 2202 face = new SkTypeface_Mac(ctFont.release(), nullptr, cacheRequest.fStyle, is FixedPitch, | 2177 face = NewFromFontRef(ctFont.release(), nullptr, false); |
| 2203 skFamilyName.c_str(), false); | |
| 2204 SkTypefaceCache::Add(face, face->fontStyle()); | 2178 SkTypefaceCache::Add(face, face->fontStyle()); |
| 2205 return face; | 2179 return face; |
| 2206 } | 2180 } |
| 2207 | 2181 |
| 2208 class SkFontStyleSet_Mac : public SkFontStyleSet { | 2182 class SkFontStyleSet_Mac : public SkFontStyleSet { |
| 2209 public: | 2183 public: |
| 2210 SkFontStyleSet_Mac(CFStringRef familyName, CTFontDescriptorRef desc) | 2184 SkFontStyleSet_Mac(CTFontDescriptorRef desc) |
| 2211 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) | 2185 : fArray(CTFontDescriptorCreateMatchingFontDescriptors(desc, nullptr)) |
| 2212 , fFamilyName(familyName) | |
| 2213 , fCount(0) { | 2186 , fCount(0) { |
| 2214 CFRetain(familyName); | |
| 2215 if (nullptr == fArray) { | 2187 if (nullptr == fArray) { |
| 2216 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); | 2188 fArray = CFArrayCreate(nullptr, nullptr, 0, nullptr); |
| 2217 } | 2189 } |
| 2218 fCount = SkToInt(CFArrayGetCount(fArray)); | 2190 fCount = SkToInt(CFArrayGetCount(fArray)); |
| 2219 } | 2191 } |
| 2220 | 2192 |
| 2221 virtual ~SkFontStyleSet_Mac() { | 2193 virtual ~SkFontStyleSet_Mac() { |
| 2222 CFRelease(fArray); | 2194 CFRelease(fArray); |
| 2223 CFRelease(fFamilyName); | |
| 2224 } | 2195 } |
| 2225 | 2196 |
| 2226 int count() override { | 2197 int count() override { |
| 2227 return fCount; | 2198 return fCount; |
| 2228 } | 2199 } |
| 2229 | 2200 |
| 2230 void getStyle(int index, SkFontStyle* style, SkString* name) override { | 2201 void getStyle(int index, SkFontStyle* style, SkString* name) override { |
| 2231 SkASSERT((unsigned)index < (unsigned)fCount); | 2202 SkASSERT((unsigned)index < (unsigned)fCount); |
| 2232 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f Array, index); | 2203 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f Array, index); |
| 2233 if (style) { | 2204 if (style) { |
| 2234 *style = fontstyle_from_descriptor(desc); | 2205 *style = fontstyle_from_descriptor(desc); |
| 2235 } | 2206 } |
| 2236 if (name) { | 2207 if (name) { |
| 2237 if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) { | 2208 if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) { |
| 2238 name->reset(); | 2209 name->reset(); |
| 2239 } | 2210 } |
| 2240 } | 2211 } |
| 2241 } | 2212 } |
| 2242 | 2213 |
| 2243 SkTypeface* createTypeface(int index) override { | 2214 SkTypeface* createTypeface(int index) override { |
| 2244 SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray)); | 2215 SkASSERT((unsigned)index < (unsigned)CFArrayGetCount(fArray)); |
| 2245 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f Array, index); | 2216 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(f Array, index); |
| 2246 | 2217 |
| 2247 return createFromDesc(fFamilyName, desc); | 2218 return createFromDesc(desc); |
| 2248 } | 2219 } |
| 2249 | 2220 |
| 2250 SkTypeface* matchStyle(const SkFontStyle& pattern) override { | 2221 SkTypeface* matchStyle(const SkFontStyle& pattern) override { |
| 2251 if (0 == fCount) { | 2222 if (0 == fCount) { |
| 2252 return nullptr; | 2223 return nullptr; |
| 2253 } | 2224 } |
| 2254 return createFromDesc(fFamilyName, findMatchingDesc(pattern)); | 2225 return createFromDesc(findMatchingDesc(pattern)); |
| 2255 } | 2226 } |
| 2256 | 2227 |
| 2257 private: | 2228 private: |
| 2258 CFArrayRef fArray; | 2229 CFArrayRef fArray; |
| 2259 CFStringRef fFamilyName; | |
| 2260 int fCount; | 2230 int fCount; |
| 2261 | 2231 |
| 2262 CTFontDescriptorRef findMatchingDesc(const SkFontStyle& pattern) const { | 2232 CTFontDescriptorRef findMatchingDesc(const SkFontStyle& pattern) const { |
| 2263 int bestMetric = SK_MaxS32; | 2233 int bestMetric = SK_MaxS32; |
| 2264 CTFontDescriptorRef bestDesc = nullptr; | 2234 CTFontDescriptorRef bestDesc = nullptr; |
| 2265 | 2235 |
| 2266 for (int i = 0; i < fCount; ++i) { | 2236 for (int i = 0; i < fCount; ++i) { |
| 2267 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtInd ex(fArray, i); | 2237 CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtInd ex(fArray, i); |
| 2268 int metric = compute_metric(pattern, fontstyle_from_descriptor(desc) ); | 2238 int metric = compute_metric(pattern, fontstyle_from_descriptor(desc) ); |
| 2269 if (0 == metric) { | 2239 if (0 == metric) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2291 static SkFontStyleSet* CreateSet(CFStringRef cfFamilyName) { | 2261 static SkFontStyleSet* CreateSet(CFStringRef cfFamilyName) { |
| 2292 AutoCFRelease<CFMutableDictionaryRef> cfAttr( | 2262 AutoCFRelease<CFMutableDictionaryRef> cfAttr( |
| 2293 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | 2263 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 2294 &kCFTypeDictionaryKeyCallBacks, | 2264 &kCFTypeDictionaryKeyCallBacks, |
| 2295 &kCFTypeDictionaryValueCallBacks)); | 2265 &kCFTypeDictionaryValueCallBacks)); |
| 2296 | 2266 |
| 2297 CFDictionaryAddValue(cfAttr, kCTFontFamilyNameAttribute, cfFamilyName); | 2267 CFDictionaryAddValue(cfAttr, kCTFontFamilyNameAttribute, cfFamilyName); |
| 2298 | 2268 |
| 2299 AutoCFRelease<CTFontDescriptorRef> desc( | 2269 AutoCFRelease<CTFontDescriptorRef> desc( |
| 2300 CTFontDescriptorCreateWithAttributes(cfAttr)); | 2270 CTFontDescriptorCreateWithAttributes(cfAttr)); |
| 2301 return new SkFontStyleSet_Mac(cfFamilyName, desc); | 2271 return new SkFontStyleSet_Mac(desc); |
| 2302 } | 2272 } |
| 2303 | 2273 |
| 2304 public: | 2274 public: |
| 2305 SkFontMgr_Mac() | 2275 SkFontMgr_Mac() |
| 2306 : fNames(SkCTFontManagerCopyAvailableFontFamilyNames()) | 2276 : fNames(SkCTFontManagerCopyAvailableFontFamilyNames()) |
| 2307 , fCount(fNames ? SkToInt(CFArrayGetCount(fNames)) : 0) {} | 2277 , fCount(fNames ? SkToInt(CFArrayGetCount(fNames)) : 0) {} |
| 2308 | 2278 |
| 2309 virtual ~SkFontMgr_Mac() { | 2279 virtual ~SkFontMgr_Mac() { |
| 2310 CFSafeRelease(fNames); | 2280 CFSafeRelease(fNames); |
| 2311 } | 2281 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2497 if (cgVariations) { | 2467 if (cgVariations) { |
| 2498 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2468 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
| 2499 } else { | 2469 } else { |
| 2500 cgVariant.reset(cg.release()); | 2470 cgVariant.reset(cg.release()); |
| 2501 } | 2471 } |
| 2502 | 2472 |
| 2503 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp tr); | 2473 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp tr); |
| 2504 if (!ct) { | 2474 if (!ct) { |
| 2505 return nullptr; | 2475 return nullptr; |
| 2506 } | 2476 } |
| 2507 return NewFromFontRef(ct, cg.release(), nullptr, true); | 2477 return NewFromFontRef(ct, cg.release(), true); |
| 2508 } | 2478 } |
| 2509 | 2479 |
| 2510 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { | 2480 static CFDictionaryRef get_axes(CGFontRef cg, SkFontData* fontData) { |
| 2511 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); | 2481 AutoCFRelease<CFArrayRef> cgAxes(CGFontCopyVariationAxes(cg)); |
| 2512 if (!cgAxes) { | 2482 if (!cgAxes) { |
| 2513 return nullptr; | 2483 return nullptr; |
| 2514 } | 2484 } |
| 2515 | 2485 |
| 2516 CFIndex axisCount = CFArrayGetCount(cgAxes); | 2486 CFIndex axisCount = CFArrayGetCount(cgAxes); |
| 2517 if (0 == axisCount || axisCount != fontData->getAxisCount()) { | 2487 if (0 == axisCount || axisCount != fontData->getAxisCount()) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2580 if (cgVariations) { | 2550 if (cgVariations) { |
| 2581 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); | 2551 cgVariant.reset(CGFontCreateCopyWithVariations(cg, cgVariations)); |
| 2582 } else { | 2552 } else { |
| 2583 cgVariant.reset(cg.release()); | 2553 cgVariant.reset(cg.release()); |
| 2584 } | 2554 } |
| 2585 | 2555 |
| 2586 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp tr); | 2556 CTFontRef ct = CTFontCreateWithGraphicsFont(cgVariant, 0, nullptr, nullp tr); |
| 2587 if (!ct) { | 2557 if (!ct) { |
| 2588 return nullptr; | 2558 return nullptr; |
| 2589 } | 2559 } |
| 2590 return NewFromFontRef(ct, cg.release(), nullptr, true); | 2560 return NewFromFontRef(ct, cg.release(), true); |
| 2591 } | 2561 } |
| 2592 | 2562 |
| 2593 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { | 2563 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { |
| 2594 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat h)); | 2564 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat h)); |
| 2595 if (nullptr == pr) { | 2565 if (nullptr == pr) { |
| 2596 return nullptr; | 2566 return nullptr; |
| 2597 } | 2567 } |
| 2598 return create_from_dataProvider(pr); | 2568 return create_from_dataProvider(pr); |
| 2599 } | 2569 } |
| 2600 | 2570 |
| 2601 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 2571 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 2602 unsigned styleBits) const overrid e { | 2572 unsigned styleBits) const overrid e { |
| 2603 | 2573 |
| 2604 SkFontStyle style = SkFontStyle((SkTypeface::Style)styleBits); | 2574 SkFontStyle style = SkFontStyle((SkTypeface::Style)styleBits); |
| 2605 if (familyName) { | 2575 if (familyName) { |
| 2606 familyName = map_css_names(familyName); | 2576 familyName = map_css_names(familyName); |
| 2607 } | 2577 } |
| 2608 | 2578 |
| 2609 if (!familyName || !*familyName) { | 2579 if (!familyName || !*familyName) { |
| 2610 familyName = FONT_DEFAULT_NAME; | 2580 familyName = FONT_DEFAULT_NAME; |
| 2611 } | 2581 } |
| 2612 | 2582 |
| 2613 NameStyle cacheRequest = { familyName, style }; | 2583 SkTypeface* face = NewFromName(familyName, style); |
| 2614 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cacheRequest); | 2584 if (face) { |
| 2585 return face; | |
| 2586 } | |
| 2615 | 2587 |
| 2616 if (nullptr == face) { | 2588 return SkSafeRef(GetDefaultFace()); |
| 2617 face = NewFromName(familyName, style); | |
| 2618 if (face) { | |
| 2619 SkTypefaceCache::Add(face, style); | |
| 2620 } else { | |
| 2621 face = GetDefaultFace(); | |
| 2622 face->ref(); | |
| 2623 } | |
| 2624 } | |
| 2625 return face; | |
| 2626 } | 2589 } |
| 2627 }; | 2590 }; |
| 2628 | 2591 |
| 2629 /////////////////////////////////////////////////////////////////////////////// | 2592 /////////////////////////////////////////////////////////////////////////////// |
| 2630 | 2593 |
| 2631 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2594 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
| 2632 | 2595 |
| 2633 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2596 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| OLD | NEW |