| 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 "SkTypes.h" // Keep this before any #ifdef ... | 9 #include "SkTypes.h" // Keep this before any #ifdef ... |
| 10 | 10 |
| 11 #ifdef SK_BUILD_FOR_MAC | 11 #ifdef SK_BUILD_FOR_MAC |
| 12 #import <ApplicationServices/ApplicationServices.h> | 12 #import <ApplicationServices/ApplicationServices.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #ifdef SK_BUILD_FOR_IOS | 15 #ifdef SK_BUILD_FOR_IOS |
| 16 #include <CoreText/CoreText.h> | 16 #include <CoreText/CoreText.h> |
| 17 #include <CoreText/CTFontManager.h> | 17 #include <CoreText/CTFontManager.h> |
| 18 #include <CoreGraphics/CoreGraphics.h> | 18 #include <CoreGraphics/CoreGraphics.h> |
| 19 #include <CoreFoundation/CoreFoundation.h> | 19 #include <CoreFoundation/CoreFoundation.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #include "SkAdvancedTypefaceMetrics.h" |
| 22 #include "SkCGUtils.h" | 23 #include "SkCGUtils.h" |
| 23 #include "SkColorPriv.h" | 24 #include "SkColorPriv.h" |
| 24 #include "SkDescriptor.h" | 25 #include "SkDescriptor.h" |
| 25 #include "SkEndian.h" | 26 #include "SkEndian.h" |
| 26 #include "SkFontDescriptor.h" | 27 #include "SkFontDescriptor.h" |
| 27 #include "SkFloatingPoint.h" | 28 #include "SkFloatingPoint.h" |
| 28 #include "SkGlyph.h" | 29 #include "SkGlyph.h" |
| 29 #include "SkLazyFnPtr.h" | 30 #include "SkLazyFnPtr.h" |
| 30 #include "SkMaskGamma.h" | 31 #include "SkMaskGamma.h" |
| 31 #include "SkSFNTHeader.h" | 32 #include "SkSFNTHeader.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 SkStreamAsset* onOpenStream(int* ttcIndex) const override; | 447 SkStreamAsset* onOpenStream(int* ttcIndex) const override; |
| 447 void onGetFamilyName(SkString* familyName) const override; | 448 void onGetFamilyName(SkString* familyName) const override; |
| 448 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; | 449 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
| 449 int onGetTableTags(SkFontTableTag tags[]) const override; | 450 int onGetTableTags(SkFontTableTag tags[]) const override; |
| 450 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 451 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
| 451 size_t length, void* data) const override; | 452 size_t length, void* data) const override; |
| 452 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; | 453 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override; |
| 453 void onFilterRec(SkScalerContextRec*) const override; | 454 void onFilterRec(SkScalerContextRec*) const override; |
| 454 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; | 455 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; |
| 455 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 456 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 456 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 457 PerGlyphInfo, |
| 457 const uint32_t*, uint32_t) const override; | 458 const uint32_t*, uint32_t) const override; |
| 458 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], | 459 virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], |
| 459 int glyphCount) const override; | 460 int glyphCount) const override; |
| 460 int onCountGlyphs() const override; | 461 int onCountGlyphs() const override; |
| 461 | 462 |
| 462 private: | 463 private: |
| 463 bool fIsLocalStream; | 464 bool fIsLocalStream; |
| 464 | 465 |
| 465 typedef SkTypeface INHERITED; | 466 typedef SkTypeface INHERITED; |
| 466 }; | 467 }; |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 // plus 1 byte for the trailing null. | 1537 // plus 1 byte for the trailing null. |
| 1537 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), | 1538 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), |
| 1538 kCFStringEncodingUTF8) +
1; | 1539 kCFStringEncodingUTF8) +
1; |
| 1539 dst->resize(length); | 1540 dst->resize(length); |
| 1540 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); | 1541 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); |
| 1541 // Resize to the actual UTF-8 length used, stripping the null character. | 1542 // Resize to the actual UTF-8 length used, stripping the null character. |
| 1542 dst->resize(strlen(dst->c_str())); | 1543 dst->resize(strlen(dst->c_str())); |
| 1543 } | 1544 } |
| 1544 | 1545 |
| 1545 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( | 1546 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( |
| 1546 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, | 1547 PerGlyphInfo perGlyphInfo, |
| 1547 const uint32_t* glyphIDs, | 1548 const uint32_t* glyphIDs, |
| 1548 uint32_t glyphIDsCount) const { | 1549 uint32_t glyphIDsCount) const { |
| 1549 | 1550 |
| 1550 CTFontRef originalCTFont = fFontRef.get(); | 1551 CTFontRef originalCTFont = fFontRef.get(); |
| 1551 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( | 1552 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( |
| 1552 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); | 1553 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); |
| 1553 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; | 1554 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; |
| 1554 | 1555 |
| 1555 { | 1556 { |
| 1556 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); | 1557 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); |
| 1557 if (fontName.get()) { | 1558 if (fontName.get()) { |
| 1558 CFStringToSkString(fontName, &info->fFontName); | 1559 CFStringToSkString(fontName, &info->fFontName); |
| 1559 } | 1560 } |
| 1560 } | 1561 } |
| 1561 | 1562 |
| 1562 CFIndex glyphCount = CTFontGetGlyphCount(ctFont); | 1563 CFIndex glyphCount = CTFontGetGlyphCount(ctFont); |
| 1563 info->fLastGlyphID = SkToU16(glyphCount - 1); | 1564 info->fLastGlyphID = SkToU16(glyphCount - 1); |
| 1564 info->fEmSize = CTFontGetUnitsPerEm(ctFont); | 1565 info->fEmSize = CTFontGetUnitsPerEm(ctFont); |
| 1565 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; | 1566 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag; |
| 1566 info->fStyle = 0; | 1567 info->fStyle = 0; |
| 1567 | 1568 |
| 1568 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { | 1569 if (perGlyphInfo & kToUnicode_PerGlyphInfo) { |
| 1569 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode); | 1570 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode); |
| 1570 } | 1571 } |
| 1571 | 1572 |
| 1572 // If it's not a truetype font, mark it as 'other'. Assume that TrueType | 1573 // If it's not a truetype font, mark it as 'other'. Assume that TrueType |
| 1573 // fonts always have both glyf and loca tables. At the least, this is what | 1574 // fonts always have both glyf and loca tables. At the least, this is what |
| 1574 // sfntly needs to subset the font. CTFontCopyAttribute() does not always | 1575 // sfntly needs to subset the font. CTFontCopyAttribute() does not always |
| 1575 // succeed in determining this directly. | 1576 // succeed in determining this directly. |
| 1576 if (!this->getTableSize('glyf') || !this->getTableSize('loca')) { | 1577 if (!this->getTableSize('glyf') || !this->getTableSize('loca')) { |
| 1577 info->fType = SkAdvancedTypefaceMetrics::kOther_Font; | 1578 info->fType = SkAdvancedTypefaceMetrics::kOther_Font; |
| 1578 info->fItalicAngle = 0; | 1579 info->fItalicAngle = 0; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1625 glyphs, boundingRects, count); | 1626 glyphs, boundingRects, count); |
| 1626 for (size_t i = 0; i < count; i++) { | 1627 for (size_t i = 0; i < count; i++) { |
| 1627 int16_t width = (int16_t) boundingRects[i].size.width; | 1628 int16_t width = (int16_t) boundingRects[i].size.width; |
| 1628 if (width > 0 && width < min_width) { | 1629 if (width > 0 && width < min_width) { |
| 1629 min_width = width; | 1630 min_width = width; |
| 1630 info->fStemV = min_width; | 1631 info->fStemV = min_width; |
| 1631 } | 1632 } |
| 1632 } | 1633 } |
| 1633 } | 1634 } |
| 1634 | 1635 |
| 1635 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { | 1636 if (perGlyphInfo & kHAdvance_PerGlyphInfo) { |
| 1636 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { | 1637 if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { |
| 1637 skia_advanced_typeface_metrics_utils::appendRange(&info->fGlyphWidth
s, 0); | 1638 skia_advanced_typeface_metrics_utils::appendRange(&info->fGlyphWidth
s, 0); |
| 1638 info->fGlyphWidths->fAdvance.append(1, &min_width); | 1639 info->fGlyphWidths->fAdvance.append(1, &min_width); |
| 1639 skia_advanced_typeface_metrics_utils::finishRange(info->fGlyphWidths
.get(), 0, | 1640 skia_advanced_typeface_metrics_utils::finishRange(info->fGlyphWidths
.get(), 0, |
| 1640 SkAdvancedTypefaceMetrics::WidthRange::kDefault); | 1641 SkAdvancedTypefaceMetrics::WidthRange::kDefault); |
| 1641 } else { | 1642 } else { |
| 1642 info->fGlyphWidths.reset( | 1643 info->fGlyphWidths.reset( |
| 1643 skia_advanced_typeface_metrics_utils::getAdvanceData(ctFont.get(
), | 1644 skia_advanced_typeface_metrics_utils::getAdvanceData(ctFont.get(
), |
| 1644 SkToInt(glyphCount), | 1645 SkToInt(glyphCount), |
| 1645 glyphIDs, | 1646 glyphIDs, |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 } | 2281 } |
| 2281 return face; | 2282 return face; |
| 2282 } | 2283 } |
| 2283 }; | 2284 }; |
| 2284 | 2285 |
| 2285 /////////////////////////////////////////////////////////////////////////////// | 2286 /////////////////////////////////////////////////////////////////////////////// |
| 2286 | 2287 |
| 2287 SkFontMgr* SkFontMgr::Factory() { | 2288 SkFontMgr* SkFontMgr::Factory() { |
| 2288 return SkNEW(SkFontMgr_Mac); | 2289 return SkNEW(SkFontMgr_Mac); |
| 2289 } | 2290 } |
| OLD | NEW |