Chromium Code Reviews| 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 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1513 | 1513 |
| 1514 static bool getWidthAdvance(CTFontRef ctFont, int gId, int16_t* data) { | 1514 static bool getWidthAdvance(CTFontRef ctFont, int gId, int16_t* data) { |
| 1515 CGSize advance; | 1515 CGSize advance; |
| 1516 advance.width = 0; | 1516 advance.width = 0; |
| 1517 CGGlyph glyph = gId; | 1517 CGGlyph glyph = gId; |
| 1518 CTFontGetAdvancesForGlyphs(ctFont, kCTFontHorizontalOrientation, &glyph, &ad vance, 1); | 1518 CTFontGetAdvancesForGlyphs(ctFont, kCTFontHorizontalOrientation, &glyph, &ad vance, 1); |
| 1519 *data = sk_float_round2int(advance.width); | 1519 *data = sk_float_round2int(advance.width); |
| 1520 return true; | 1520 return true; |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 // we might move this into our CGUtils... | 1523 /** Assumes src and dst are not NULL. */ |
| 1524 static void CFStringToSkString(CFStringRef src, SkString* dst) { | 1524 static void CFStringToSkString(CFStringRef src, SkString* dst) { |
| 1525 // Reserve enough room for the worst-case string, | 1525 // Reserve enough room for the worst-case string, |
| 1526 // plus 1 byte for the trailing null. | 1526 // plus 1 byte for the trailing null. |
| 1527 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), | 1527 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), |
| 1528 kCFStringEncodingUTF8) + 1; | 1528 kCFStringEncodingUTF8) + 1; |
| 1529 dst->resize(length); | 1529 dst->resize(length); |
| 1530 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); | 1530 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); |
| 1531 // Resize to the actual UTF-8 length used, stripping the null character. | 1531 // Resize to the actual UTF-8 length used, stripping the null character. |
| 1532 dst->resize(strlen(dst->c_str())); | 1532 dst->resize(strlen(dst->c_str())); |
| 1533 } | 1533 } |
| 1534 | 1534 |
| 1535 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( | 1535 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( |
| 1536 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, | 1536 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, |
| 1537 const uint32_t* glyphIDs, | 1537 const uint32_t* glyphIDs, |
| 1538 uint32_t glyphIDsCount) const { | 1538 uint32_t glyphIDsCount) const { |
| 1539 | 1539 |
| 1540 CTFontRef originalCTFont = fFontRef.get(); | 1540 CTFontRef originalCTFont = fFontRef.get(); |
| 1541 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( | 1541 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( |
| 1542 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); | 1542 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); |
| 1543 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; | 1543 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; |
| 1544 | 1544 |
| 1545 { | 1545 { |
| 1546 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); | 1546 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); |
| 1547 CFStringToSkString(fontName, &info->fFontName); | 1547 if (fontName.get()) { |
| 1548 CFStringToSkString(fontName, &info->fFontName); | |
| 1549 } | |
| 1548 } | 1550 } |
| 1549 | 1551 |
| 1550 CFIndex glyphCount = CTFontGetGlyphCount(ctFont); | 1552 CFIndex glyphCount = CTFontGetGlyphCount(ctFont); |
| 1551 info->fLastGlyphID = SkToU16(glyphCount - 1); | 1553 info->fLastGlyphID = SkToU16(glyphCount - 1); |
| 1552 info->fEmSize = CTFontGetUnitsPerEm(ctFont); | 1554 info->fEmSize = CTFontGetUnitsPerEm(ctFont); |
| 1553 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; | 1555 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; |
| 1554 info->fStyle = 0; | 1556 info->fStyle = 0; |
| 1555 | 1557 |
| 1556 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { | 1558 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { |
| 1557 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode); | 1559 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 #ifndef SK_GAMMA_APPLY_TO_A8 | 1893 #ifndef SK_GAMMA_APPLY_TO_A8 |
| 1892 rec->ignorePreBlend(); | 1894 rec->ignorePreBlend(); |
| 1893 #endif | 1895 #endif |
| 1894 } else { | 1896 } else { |
| 1895 //CoreGraphics dialates smoothed text as needed. | 1897 //CoreGraphics dialates smoothed text as needed. |
| 1896 rec->setContrast(0); | 1898 rec->setContrast(0); |
| 1897 } | 1899 } |
| 1898 } | 1900 } |
| 1899 | 1901 |
| 1900 // we take ownership of the ref | 1902 // we take ownership of the ref |
| 1901 static const char* get_str(CFStringRef ref, SkString* str) { | 1903 static const char* get_str(CFStringRef ref, SkString* str) { |
|
reed1
2014/07/01 18:46:23
does our caller (in this file) know to look for NU
| |
| 1904 if (NULL == ref) { | |
| 1905 return NULL; | |
| 1906 } | |
| 1902 CFStringToSkString(ref, str); | 1907 CFStringToSkString(ref, str); |
| 1903 CFSafeRelease(ref); | 1908 CFSafeRelease(ref); |
| 1904 return str->c_str(); | 1909 return str->c_str(); |
| 1905 } | 1910 } |
| 1906 | 1911 |
| 1907 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, | 1912 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, |
| 1908 bool* isLocalStream) const { | 1913 bool* isLocalStream) const { |
| 1909 SkString tmpStr; | 1914 SkString tmpStr; |
| 1910 | 1915 |
| 1911 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); | 1916 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2308 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); | 2313 return create_typeface(NULL, familyName, (SkTypeface::Style)styleBits); |
| 2309 } | 2314 } |
| 2310 }; | 2315 }; |
| 2311 | 2316 |
| 2312 /////////////////////////////////////////////////////////////////////////////// | 2317 /////////////////////////////////////////////////////////////////////////////// |
| 2313 | 2318 |
| 2314 SkFontMgr* SkFontMgr::Factory() { | 2319 SkFontMgr* SkFontMgr::Factory() { |
| 2315 return SkNEW(SkFontMgr_Mac); | 2320 return SkNEW(SkFontMgr_Mac); |
| 2316 } | 2321 } |
| 2317 #endif | 2322 #endif |
| OLD | NEW |