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

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

Issue 1955053002: SkAdvancedTypefaceMetrics: getAdvanceData uses std::function (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typedef Created 4 years, 7 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.cpp ('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 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 for (int j = 0; j < 8; j++) { 1505 for (int j = 0; j < 8; j++) {
1506 CGGlyph glyph; 1506 CGGlyph glyph;
1507 UniChar unichar = static_cast<UniChar>((i << 3) + j); 1507 UniChar unichar = static_cast<UniChar>((i << 3) + j);
1508 if (mask & (1 << j) && CTFontGetGlyphsForCharacters(ctFont, &unichar , &glyph, 1)) { 1508 if (mask & (1 << j) && CTFontGetGlyphsForCharacters(ctFont, &unichar , &glyph, 1)) {
1509 out[glyph] = unichar; 1509 out[glyph] = unichar;
1510 } 1510 }
1511 } 1511 }
1512 } 1512 }
1513 } 1513 }
1514 1514
1515 static bool getWidthAdvance(CTFontRef ctFont, int gId, int16_t* data) {
1516 CGSize advance;
1517 advance.width = 0;
1518 CGGlyph glyph = gId;
1519 CTFontGetAdvancesForGlyphs(ctFont, kCTFontHorizontalOrientation, &glyph, &ad vance, 1);
1520 *data = sk_float_round2int(advance.width);
1521 return true;
1522 }
1523
1524 /** Assumes src and dst are not nullptr. */ 1515 /** Assumes src and dst are not nullptr. */
1525 static void CFStringToSkString(CFStringRef src, SkString* dst) { 1516 static void CFStringToSkString(CFStringRef src, SkString* dst) {
1526 // Reserve enough room for the worst-case string, 1517 // Reserve enough room for the worst-case string,
1527 // plus 1 byte for the trailing null. 1518 // plus 1 byte for the trailing null.
1528 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), 1519 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src),
1529 kCFStringEncodingUTF8) + 1; 1520 kCFStringEncodingUTF8) + 1;
1530 dst->resize(length); 1521 dst->resize(length);
1531 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); 1522 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8);
1532 // Resize to the actual UTF-8 length used, stripping the null character. 1523 // Resize to the actual UTF-8 length used, stripping the null character.
1533 dst->resize(strlen(dst->c_str())); 1524 dst->resize(strlen(dst->c_str()));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 } 1609 }
1619 1610
1620 if (perGlyphInfo & kHAdvance_PerGlyphInfo) { 1611 if (perGlyphInfo & kHAdvance_PerGlyphInfo) {
1621 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { 1612 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) {
1622 SkAdvancedTypefaceMetrics::WidthRange range(0); 1613 SkAdvancedTypefaceMetrics::WidthRange range(0);
1623 range.fAdvance.append(1, &min_width); 1614 range.fAdvance.append(1, &min_width);
1624 SkAdvancedTypefaceMetrics::FinishRange( 1615 SkAdvancedTypefaceMetrics::FinishRange(
1625 &range, 0, SkAdvancedTypefaceMetrics::WidthRange::kDefault); 1616 &range, 0, SkAdvancedTypefaceMetrics::WidthRange::kDefault);
1626 info->fGlyphWidths.emplace_back(std::move(range)); 1617 info->fGlyphWidths.emplace_back(std::move(range));
1627 } else { 1618 } else {
1628 info->setGlyphWidths(ctFont.get(), SkToInt(glyphCount), glyphIDs, 1619 CTFontRef borrowedCTFont = ctFont.get();
1629 glyphIDsCount, &getWidthAdvance); 1620 info->setGlyphWidths(
1621 SkToInt(glyphCount), glyphIDs, glyphIDsCount,
1622 SkAdvancedTypefaceMetrics::GetAdvance(
1623 [borrowedCTFont](int gId, int16_t* data) {
1624 CGSize advance;
1625 advance.width = 0;
1626 CGGlyph glyph = gId;
1627 CTFontGetAdvancesForGlyphs(
1628 borrowedCTFont, kCTFontHorizontalOrientation ,
1629 &glyph, &advance, 1);
1630 *data = sk_float_round2int(advance.width);
1631 return true;
1632 }));
1630 } 1633 }
1631 } 1634 }
1632 return info; 1635 return info;
1633 } 1636 }
1634 1637
1635 /////////////////////////////////////////////////////////////////////////////// 1638 ///////////////////////////////////////////////////////////////////////////////
1636 1639
1637 static SK_SFNT_ULONG get_font_type_tag(const SkTypeface_Mac* typeface) { 1640 static SK_SFNT_ULONG get_font_type_tag(const SkTypeface_Mac* typeface) {
1638 CTFontRef ctFont = typeface->fFontRef.get(); 1641 CTFontRef ctFont = typeface->fFontRef.get();
1639 AutoCFRelease<CFNumberRef> fontFormatRef( 1642 AutoCFRelease<CFNumberRef> fontFormatRef(
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 2575
2573 return SkSafeRef(GetDefaultFace()); 2576 return SkSafeRef(GetDefaultFace());
2574 } 2577 }
2575 }; 2578 };
2576 2579
2577 /////////////////////////////////////////////////////////////////////////////// 2580 ///////////////////////////////////////////////////////////////////////////////
2578 2581
2579 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } 2582 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; }
2580 2583
2581 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) 2584 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_FreeType.cpp ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698