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

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

Issue 1344213004: Avoid CTFontCreateCopyWithAttributes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Doesn't break webfonts. Created 5 years, 3 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 | « no previous file | no next file » | 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 /* 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
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 733
734 // CT on (at least) 10.9 will size color glyphs down from the requested size , but not up. 734 // CT on (at least) 10.9 will size color glyphs down from the requested size , but not up.
735 // As a result, it is necessary to know the actual device size and request t hat. 735 // As a result, it is necessary to know the actual device size and request t hat.
736 SkVector scale; 736 SkVector scale;
737 SkMatrix skTransform; 737 SkMatrix skTransform;
738 fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, & skTransform, 738 fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, & skTransform,
739 nullptr, nullptr, &fFUnitMatrix); 739 nullptr, nullptr, &fFUnitMatrix);
740 fTransform = MatrixToCGAffineTransform(skTransform); 740 fTransform = MatrixToCGAffineTransform(skTransform);
741 fInvTransform = CGAffineTransformInvert(fTransform); 741 fInvTransform = CGAffineTransformInvert(fTransform);
742 742
743 AutoCFRelease<CTFontDescriptorRef> ctFontDesc; 743 // CTFontCreateCopyWithAttributes or CTFontCreateCopyWithSymbolicTraits cann ot be used on 10.10
744 if (fVertical) { 744 // as they appear to be buggy with respect to the default font. It is not po ssible to use
745 // Setting the vertical orientation here is required for vertical metric s on some versions. 745 // descriptors with CTFontCreateWithFontDescriptor, since that does not work with non-system
746 AutoCFRelease<CFMutableDictionaryRef> cfAttributes(CFDictionaryCreateMut able( 746 // fonts. As a result, create the new fonts from the underlying CGFont.
747 kCFAllocatorDefault, 0, 747
748 &kCFTypeDictionaryKeyCallBacks, 748 AutoCFRelease<CTFontDescriptorRef> baseDescriptor;
749 &kCFTypeDictionaryValueCallBacks)); 749 AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(ctFont, &baseDesc riptor));
750 if (cfAttributes) { 750
751 CTFontOrientation ctOrientation = kCTFontVerticalOrientation; 751 // Make a mutable copy of baseDescriptor attributes.
752 AutoCFRelease<CFNumberRef> cfVertical(CFNumberCreate( 752 AutoCFRelease<CFMutableDictionaryRef> newAttributes;
753 kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation)); 753 if (nullptr == baseDescriptor) {
754 CFDictionaryAddValue(cfAttributes, kCTFontOrientationAttribute, cfVe rtical); 754 newAttributes.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
755 ctFontDesc.reset(CTFontDescriptorCreateWithAttributes(cfAttributes)) ; 755 &kCFTypeDictionaryKeyCallB acks,
756 } 756 &kCFTypeDictionaryValueCal lBacks));
757 } else {
758 AutoCFRelease<CFDictionaryRef> baseAttributes(
759 CTFontDescriptorCopyAttributes(baseDescriptor));
760 newAttributes.reset(CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0 , baseAttributes));
757 } 761 }
758 762
759 // The transform contains everything except the requested text size. 763 // The transform contains everything except the requested text size.
760 // Some properties, like 'trak', are based on the text size (before applying the matrix). 764 // Some properties, like 'trak', are based on the text size (before applying the matrix).
761 CGFloat textSize = ScalarToCG(scale.y()); 765 CGFloat textSize = ScalarToCG(scale.y());
766 AutoCFRelease<CFNumberRef> cfTextSize(
767 CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &textSize));
768 CFDictionarySetValue(newAttributes, kCTFontSizeAttribute, cfTextSize);
762 769
763 fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc)); 770 // First create the unrotated font at the right size.
771 CFDictionaryRemoveValue(newAttributes, kCTFontMatrixAttribute);
772
773 AutoCFRelease<CTFontDescriptorRef> unrotatedFontDescriptor(
774 CTFontDescriptorCreateWithAttributes(newAttributes));
775 fCTUnrotatedFont.reset(CTFontCreateWithGraphicsFont(baseCGFont, textSize, nu llptr,
erikchen 2015/09/16 20:50:28 nit: The textSize parameter here looks redundant w
bungeman-skia 2015/09/17 16:26:06 It does, doesn't it. On the other hand, under the
776 unrotatedFontDescriptor) );
777
778 // Now create the fully transformed font.
779 if (fVertical) {
780 CTFontOrientation ctOrientation = kCTFontVerticalOrientation;
781 AutoCFRelease<CFNumberRef> cfVertical(
782 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientat ion));
783 CFDictionarySetValue(newAttributes, kCTFontOrientationAttribute, cfVerti cal);
784 }
785
786 AutoCFRelease<CFDataRef> cfMatrixData(CFDataCreate(
787 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&fTransform), sizeof (fTransform)));
788 CFDictionaryAddValue(newAttributes, kCTFontMatrixAttribute, cfMatrixData);
789
790 AutoCFRelease<CTFontDescriptorRef> newFontDescriptor(
791 CTFontDescriptorCreateWithAttributes(newAttributes));
792 fCTFont.reset(CTFontCreateWithGraphicsFont(baseCGFont, textSize, &fTransform ,
793 newFontDescriptor));
794
764 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); 795 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr));
765 fCTUnrotatedFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize,
766 &CGAffineTransformIden tity, nullptr));
767 796
768 // The fUnitMatrix includes the text size (and em) as it is used to scale th e raw font data. 797 // The fUnitMatrix includes the text size (and em) as it is used to scale th e raw font data.
769 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo nt))); 798 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo nt)));
770 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); 799 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit);
771 } 800 }
772 801
773 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in 10.7. */ 802 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in 10.7. */
774 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP oint points[], 803 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP oint points[],
775 size_t count, CGContextRef cg) { 804 size_t count, CGContextRef cg) {
776 CGContextShowGlyphsAtPositions(cg, glyphs, points, count); 805 CGContextShowGlyphsAtPositions(cg, glyphs, points, count);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 break; 1387 break;
1359 case kY_SkAxisAlignment: 1388 case kY_SkAxisAlignment:
1360 scaleX = SK_Scalar1; // want hinting in the X direction 1389 scaleX = SK_Scalar1; // want hinting in the X direction
1361 break; 1390 break;
1362 default: 1391 default:
1363 break; 1392 break;
1364 } 1393 }
1365 1394
1366 CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY); 1395 CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY);
1367 // need to release font when we're done 1396 // need to release font when we're done
1368 font = CTFontCreateCopyWithAttributes(fCTFont, 1, &xform, nullptr); 1397 font = CTFontCreateCopyWithAttributes(fCTFont, 1, &xform, nullptr);
bungeman-skia 2015/09/17 16:26:06 Will need to fix this use.
1369 } 1398 }
1370 1399
1371 CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID(); 1400 CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID();
1372 AutoCFRelease<CGPathRef> cgPath(CTFontCreatePathForGlyph(font, cgGlyph, null ptr)); 1401 AutoCFRelease<CGPathRef> cgPath(CTFontCreatePathForGlyph(font, cgGlyph, null ptr));
1373 1402
1374 path->reset(); 1403 path->reset();
1375 if (cgPath != nullptr) { 1404 if (cgPath != nullptr) {
1376 CGPathApply(cgPath, path, SkScalerContext_Mac::CTPathElement); 1405 CGPathApply(cgPath, path, SkScalerContext_Mac::CTPathElement);
1377 } 1406 }
1378 1407
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 } 1583 }
1555 1584
1556 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( 1585 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
1557 PerGlyphInfo perGlyphInfo, 1586 PerGlyphInfo perGlyphInfo,
1558 const uint32_t* glyphIDs, 1587 const uint32_t* glyphIDs,
1559 uint32_t glyphIDsCount) const { 1588 uint32_t glyphIDsCount) const {
1560 1589
1561 AUTO_CG_LOCK(); 1590 AUTO_CG_LOCK();
1562 1591
1563 CTFontRef originalCTFont = fFontRef.get(); 1592 CTFontRef originalCTFont = fFontRef.get();
1564 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes( 1593 AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
bungeman-skia 2015/09/17 16:26:06 And this use.
1565 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, nullpt r)); 1594 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, nullpt r));
1566 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; 1595 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
1567 1596
1568 { 1597 {
1569 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); 1598 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont));
1570 if (fontName.get()) { 1599 if (fontName.get()) {
1571 CFStringToSkString(fontName, &info->fFontName); 1600 CFStringToSkString(fontName, &info->fFontName);
1572 } 1601 }
1573 } 1602 }
1574 1603
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 face->ref(); 2503 face->ref();
2475 } 2504 }
2476 } 2505 }
2477 return face; 2506 return face;
2478 } 2507 }
2479 }; 2508 };
2480 2509
2481 /////////////////////////////////////////////////////////////////////////////// 2510 ///////////////////////////////////////////////////////////////////////////////
2482 2511
2483 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } 2512 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698