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

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

Issue 12807004: move impl of AdvancedTypefaceMetrics into typeface (3) (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 protected: 411 protected:
412 friend class SkFontHost; // to access our protected members for deprecate d methods 412 friend class SkFontHost; // to access our protected members for deprecate d methods
413 413
414 virtual int onGetUPEM() const SK_OVERRIDE; 414 virtual int onGetUPEM() const SK_OVERRIDE;
415 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; 415 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
416 virtual size_t onGetTableData(SkFontTableTag, size_t offset, 416 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
417 size_t length, void* data) const SK_OVERRIDE; 417 size_t length, void* data) const SK_OVERRIDE;
418 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; 418 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE;
419 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 419 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE;
420 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE; 420 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE;
421 421 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
422 SkAdvancedTypefaceMetrics::PerGlyphInfo,
423 const uint32_t*, uint32_t) const SK_OVERRIDE;
424
422 private: 425 private:
423 typedef SkTypeface INHERITED; 426 typedef SkTypeface INHERITED;
424 }; 427 };
425 428
426 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) { 429 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[]) {
427 SkASSERT(fontRef); 430 SkASSERT(fontRef);
428 bool isMonospace; 431 bool isMonospace;
429 SkTypeface::Style style = computeStyleBits(fontRef, &isMonospace); 432 SkTypeface::Style style = computeStyleBits(fontRef, &isMonospace);
430 SkFontID fontID = CTFontRef_to_SkFontID(fontRef); 433 SkFontID fontID = CTFontRef_to_SkFontID(fontRef);
431 434
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 typedef SkScalerContext INHERITED; 653 typedef SkScalerContext INHERITED;
651 }; 654 };
652 655
653 SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface, 656 SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
654 const SkDescriptor* desc) 657 const SkDescriptor* desc)
655 : INHERITED(typeface, desc) 658 : INHERITED(typeface, desc)
656 , fFBoundingBoxes(NULL) 659 , fFBoundingBoxes(NULL)
657 , fFBoundingBoxesGlyphOffset(0) 660 , fFBoundingBoxesGlyphOffset(0)
658 , fGeneratedFBoundingBoxes(false) 661 , fGeneratedFBoundingBoxes(false)
659 { 662 {
660 CTFontRef ctFont = GetFontRefFromFontID(fRec.fFontID); 663 CTFontRef ctFont = typeface->fFontRef.get();
661 CFIndex numGlyphs = CTFontGetGlyphCount(ctFont); 664 CFIndex numGlyphs = CTFontGetGlyphCount(ctFont);
662 665
663 // Get the state we need 666 // Get the state we need
664 fRec.getSingleMatrix(&fMatrix); 667 fRec.getSingleMatrix(&fMatrix);
665 fUnitMatrix = fMatrix; 668 fUnitMatrix = fMatrix;
666 669
667 // extract the font size out of the matrix, but leave the skewing for italic 670 // extract the font size out of the matrix, but leave the skewing for italic
668 SkScalar reciprocal = SkScalarInvert(fRec.fTextSize); 671 SkScalar reciprocal = SkScalarInvert(fRec.fTextSize);
669 fUnitMatrix.preScale(reciprocal, reciprocal); 672 fUnitMatrix.preScale(reciprocal, reciprocal);
670 673
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 // Reserve enough room for the worst-case string, 1468 // Reserve enough room for the worst-case string,
1466 // plus 1 byte for the trailing null. 1469 // plus 1 byte for the trailing null.
1467 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src), 1470 CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(src),
1468 kCFStringEncodingUTF8) + 1; 1471 kCFStringEncodingUTF8) + 1;
1469 dst->resize(length); 1472 dst->resize(length);
1470 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8); 1473 CFStringGetCString(src, dst->writable_str(), length, kCFStringEncodingUTF8);
1471 // Resize to the actual UTF-8 length used, stripping the null character. 1474 // Resize to the actual UTF-8 length used, stripping the null character.
1472 dst->resize(strlen(dst->c_str())); 1475 dst->resize(strlen(dst->c_str()));
1473 } 1476 }
1474 1477
1475 // static 1478 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
1476 SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics(
1477 uint32_t fontID,
1478 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 1479 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
1479 const uint32_t* glyphIDs, 1480 const uint32_t* glyphIDs,
1480 uint32_t glyphIDsCount) { 1481 uint32_t glyphIDsCount) const {
1481 CTFontRef originalCTFont = GetFontRefFromFontID(fontID); 1482
1483 CTFontRef originalCTFont = fFontRef.get();
1482 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( 1484 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
1483 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL)); 1485 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), NULL, NULL));
1484 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; 1486 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
1485 1487
1486 { 1488 {
1487 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); 1489 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont));
1488 CFStringToSkString(fontName, &info->fFontName); 1490 CFStringToSkString(fontName, &info->fFontName);
1489 } 1491 }
1490 1492
1491 info->fMultiMaster = false; 1493 info->fMultiMaster = false;
1492 CFIndex glyphCount = CTFontGetGlyphCount(ctFont); 1494 CFIndex glyphCount = CTFontGetGlyphCount(ctFont);
1493 info->fLastGlyphID = SkToU16(glyphCount - 1); 1495 info->fLastGlyphID = SkToU16(glyphCount - 1);
1494 info->fEmSize = CTFontGetUnitsPerEm(ctFont); 1496 info->fEmSize = CTFontGetUnitsPerEm(ctFont);
1495 1497
1496 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { 1498 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
1497 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode); 1499 populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode);
1498 } 1500 }
1499 1501
1500 info->fStyle = 0; 1502 info->fStyle = 0;
1501 1503
1502 // If it's not a truetype font, mark it as 'other'. Assume that TrueType 1504 // If it's not a truetype font, mark it as 'other'. Assume that TrueType
1503 // fonts always have both glyf and loca tables. At the least, this is what 1505 // fonts always have both glyf and loca tables. At the least, this is what
1504 // sfntly needs to subset the font. CTFontCopyAttribute() does not always 1506 // sfntly needs to subset the font. CTFontCopyAttribute() does not always
1505 // succeed in determining this directly. 1507 // succeed in determining this directly.
1506 if (!GetTableSize(fontID, 'glyf') || !GetTableSize(fontID, 'loca')) { 1508 if (!this->getTableSize('glyf') || !this->getTableSize('loca')) {
1507 info->fType = SkAdvancedTypefaceMetrics::kOther_Font; 1509 info->fType = SkAdvancedTypefaceMetrics::kOther_Font;
1508 info->fItalicAngle = 0; 1510 info->fItalicAngle = 0;
1509 info->fAscent = 0; 1511 info->fAscent = 0;
1510 info->fDescent = 0; 1512 info->fDescent = 0;
1511 info->fStemV = 0; 1513 info->fStemV = 0;
1512 info->fCapHeight = 0; 1514 info->fCapHeight = 0;
1513 info->fBBox = SkIRect::MakeEmpty(); 1515 info->fBBox = SkIRect::MakeEmpty();
1514 return info; 1516 return info;
1515 } 1517 }
1516 1518
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 } 1881 }
1880 1882
1881 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc) const { 1883 void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc) const {
1882 this->INHERITED::onGetFontDescriptor(desc); 1884 this->INHERITED::onGetFontDescriptor(desc);
1883 SkString tmpStr; 1885 SkString tmpStr;
1884 1886
1885 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); 1887 desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr));
1886 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); 1888 desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr));
1887 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr) ); 1889 desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr) );
1888 } 1890 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698