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 <vector> | 9 #include <vector> |
10 #ifdef SK_BUILD_FOR_MAC | 10 #ifdef SK_BUILD_FOR_MAC |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 size_t length, void* data) const SK_OVERRIDE; | 458 size_t length, void* data) const SK_OVERRIDE; |
459 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 459 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
460 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 460 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
461 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 461 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
462 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 462 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
463 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 463 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
464 const uint32_t*, uint32_t) const SK_OVERRIDE; | 464 const uint32_t*, uint32_t) const SK_OVERRIDE; |
465 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 465 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
466 int glyphCount) const SK_OVERRIDE; | 466 int glyphCount) const SK_OVERRIDE; |
467 virtual int onCountGlyphs() const SK_OVERRIDE; | 467 virtual int onCountGlyphs() const SK_OVERRIDE; |
| 468 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; |
468 | 469 |
469 private: | 470 private: |
470 | 471 |
471 typedef SkTypeface INHERITED; | 472 typedef SkTypeface INHERITED; |
472 }; | 473 }; |
473 | 474 |
474 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { | 475 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { |
475 SkASSERT(fontRef); | 476 SkASSERT(fontRef); |
476 bool isFixedPitch; | 477 bool isFixedPitch; |
477 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); | 478 SkTypeface::Style style = computeStyleBits(fontRef, &isFixedPitch); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 }; | 591 }; |
591 | 592 |
592 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { | 593 for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) { |
593 if (strcmp(name, gPairs[i].fFrom) == 0) { | 594 if (strcmp(name, gPairs[i].fFrom) == 0) { |
594 return gPairs[i].fTo; | 595 return gPairs[i].fTo; |
595 } | 596 } |
596 } | 597 } |
597 return name; // no change | 598 return name; // no change |
598 } | 599 } |
599 | 600 |
600 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, | 601 static SkTypeface* create_typeface(const SkTypeface* familyFace, |
601 const char familyName[], | 602 const char familyName[], |
602 SkTypeface::Style style) { | 603 SkTypeface::Style style) { |
603 if (familyName) { | 604 if (familyName) { |
604 familyName = map_css_names(familyName); | 605 familyName = map_css_names(familyName); |
605 } | 606 } |
606 | 607 |
607 // Clone an existing typeface | 608 // Clone an existing typeface |
608 // TODO: only clone if style matches the familyFace's style... | 609 // TODO: only clone if style matches the familyFace's style... |
609 if (familyName == NULL && familyFace != NULL) { | 610 if (familyName == NULL && familyFace != NULL) { |
610 familyFace->ref(); | 611 familyFace->ref(); |
611 return const_cast<SkTypeface*>(familyFace); | 612 return const_cast<SkTypeface*>(familyFace); |
612 } | 613 } |
613 | 614 |
614 if (!familyName || !*familyName) { | 615 if (!familyName || !*familyName) { |
615 familyName = FONT_DEFAULT_NAME; | 616 familyName = FONT_DEFAULT_NAME; |
616 } | 617 } |
617 | 618 |
618 NameStyleRec rec = { familyName, style }; | 619 NameStyleRec rec = { familyName, style }; |
619 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(FindByNameStyle, &rec); | 620 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(FindByNameStyle, &rec); |
620 | 621 |
621 if (NULL == face) { | 622 if (NULL == face) { |
622 face = NewFromName(familyName, style); | 623 face = NewFromName(familyName, style); |
623 if (face) { | 624 if (face) { |
624 SkTypefaceCache::Add(face, style); | 625 SkTypefaceCache::Add(face, style); |
625 } else { | 626 } else { |
626 face = GetDefaultFace(); | 627 face = GetDefaultFace(); |
627 face->ref(); | 628 face->ref(); |
628 } | 629 } |
629 } | 630 } |
630 return face; | 631 return face; |
631 } | 632 } |
632 | 633 |
| 634 SkTypeface* SkTypeface_Mac::onRefMatchingStyle(Style styleBits) const { |
| 635 return create_typeface(this, NULL, styleBits); |
| 636 } |
| 637 |
633 /////////////////////////////////////////////////////////////////////////////// | 638 /////////////////////////////////////////////////////////////////////////////// |
634 | 639 |
635 /** GlyphRect is in FUnits (em space, y up). */ | 640 /** GlyphRect is in FUnits (em space, y up). */ |
636 struct GlyphRect { | 641 struct GlyphRect { |
637 int16_t fMinX; | 642 int16_t fMinX; |
638 int16_t fMinY; | 643 int16_t fMinY; |
639 int16_t fMaxX; | 644 int16_t fMaxX; |
640 int16_t fMaxY; | 645 int16_t fMaxY; |
641 }; | 646 }; |
642 | 647 |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 // Call must still manage its ownership of provider | 1435 // Call must still manage its ownership of provider |
1431 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { | 1436 static SkTypeface* create_from_dataProvider(CGDataProviderRef provider) { |
1432 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); | 1437 AutoCFRelease<CGFontRef> cg(CGFontCreateWithDataProvider(provider)); |
1433 if (NULL == cg) { | 1438 if (NULL == cg) { |
1434 return NULL; | 1439 return NULL; |
1435 } | 1440 } |
1436 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); | 1441 CTFontRef ct = CTFontCreateWithGraphicsFont(cg, 0, NULL, NULL); |
1437 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; | 1442 return cg ? SkCreateTypefaceFromCTFont(ct) : NULL; |
1438 } | 1443 } |
1439 | 1444 |
1440 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | |
1441 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(str
eam)); | |
1442 if (NULL == provider) { | |
1443 return NULL; | |
1444 } | |
1445 return create_from_dataProvider(provider); | |
1446 } | |
1447 | |
1448 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | |
1449 AutoCFRelease<CGDataProviderRef> provider(CGDataProviderCreateWithFilename(p
ath)); | |
1450 if (NULL == provider) { | |
1451 return NULL; | |
1452 } | |
1453 return create_from_dataProvider(provider); | |
1454 } | |
1455 | |
1456 // Web fonts added to the the CTFont registry do not return their character set. | 1445 // Web fonts added to the the CTFont registry do not return their character set. |
1457 // Iterate through the font in this case. The existing caller caches the result, | 1446 // Iterate through the font in this case. The existing caller caches the result, |
1458 // so the performance impact isn't too bad. | 1447 // so the performance impact isn't too bad. |
1459 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, | 1448 static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, |
1460 SkTDArray<SkUnichar>* glyphToUnicode)
{ | 1449 SkTDArray<SkUnichar>* glyphToUnicode)
{ |
1461 glyphToUnicode->setCount(glyphCount); | 1450 glyphToUnicode->setCount(glyphCount); |
1462 SkUnichar* out = glyphToUnicode->begin(); | 1451 SkUnichar* out = glyphToUnicode->begin(); |
1463 sk_bzero(out, glyphCount * sizeof(SkUnichar)); | 1452 sk_bzero(out, glyphCount * sizeof(SkUnichar)); |
1464 UniChar unichar = 0; | 1453 UniChar unichar = 0; |
1465 while (glyphCount > 0) { | 1454 while (glyphCount > 0) { |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 } | 2240 } |
2252 | 2241 |
2253 virtual SkTypeface* onCreateFromFile(const char path[], | 2242 virtual SkTypeface* onCreateFromFile(const char path[], |
2254 int ttcIndex) SK_OVERRIDE { | 2243 int ttcIndex) SK_OVERRIDE { |
2255 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); | 2244 AutoCFRelease<CGDataProviderRef> pr(CGDataProviderCreateWithFilename(pat
h)); |
2256 if (NULL == pr) { | 2245 if (NULL == pr) { |
2257 return NULL; | 2246 return NULL; |
2258 } | 2247 } |
2259 return create_from_dataProvider(pr); | 2248 return create_from_dataProvider(pr); |
2260 } | 2249 } |
| 2250 |
| 2251 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 2252 unsigned styleBits) SK_OVERRIDE { |
| 2253 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); |
| 2254 } |
2261 }; | 2255 }; |
2262 | 2256 |
| 2257 /////////////////////////////////////////////////////////////////////////////// |
| 2258 |
| 2259 #ifndef SK_FONTHOST_USES_FONTMGR |
| 2260 |
| 2261 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
| 2262 const char familyName[], |
| 2263 SkTypeface::Style style) { |
| 2264 return create_typeface(familyFace, familyName, style); |
| 2265 } |
| 2266 |
| 2267 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
| 2268 AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(str
eam)); |
| 2269 if (NULL == provider) { |
| 2270 return NULL; |
| 2271 } |
| 2272 return create_from_dataProvider(provider); |
| 2273 } |
| 2274 |
| 2275 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
| 2276 AutoCFRelease<CGDataProviderRef> provider(CGDataProviderCreateWithFilename(p
ath)); |
| 2277 if (NULL == provider) { |
| 2278 return NULL; |
| 2279 } |
| 2280 return create_from_dataProvider(provider); |
| 2281 } |
| 2282 |
| 2283 #endif |
| 2284 |
2263 SkFontMgr* SkFontMgr::Factory() { | 2285 SkFontMgr* SkFontMgr::Factory() { |
2264 return SkNEW(SkFontMgr_Mac); | 2286 return SkNEW(SkFontMgr_Mac); |
2265 } | 2287 } |
2266 #endif | 2288 #endif |
OLD | NEW |