Chromium Code Reviews| Index: src/ports/SkFontHost_mac.cpp |
| diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp |
| index 7d90d84695f386c6ad40d55f33317e9c5bacf09f..6530a957923c43ccfe9892c520bae8e93075182d 100644 |
| --- a/src/ports/SkFontHost_mac.cpp |
| +++ b/src/ports/SkFontHost_mac.cpp |
| @@ -740,30 +740,59 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface, |
| fTransform = MatrixToCGAffineTransform(skTransform); |
| fInvTransform = CGAffineTransformInvert(fTransform); |
| - AutoCFRelease<CTFontDescriptorRef> ctFontDesc; |
| - if (fVertical) { |
| - // Setting the vertical orientation here is required for vertical metrics on some versions. |
| - AutoCFRelease<CFMutableDictionaryRef> cfAttributes(CFDictionaryCreateMutable( |
| - kCFAllocatorDefault, 0, |
| - &kCFTypeDictionaryKeyCallBacks, |
| - &kCFTypeDictionaryValueCallBacks)); |
| - if (cfAttributes) { |
| - CTFontOrientation ctOrientation = kCTFontVerticalOrientation; |
| - AutoCFRelease<CFNumberRef> cfVertical(CFNumberCreate( |
| - kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation)); |
| - CFDictionaryAddValue(cfAttributes, kCTFontOrientationAttribute, cfVertical); |
| - ctFontDesc.reset(CTFontDescriptorCreateWithAttributes(cfAttributes)); |
| - } |
| + // CTFontCreateCopyWithAttributes or CTFontCreateCopyWithSymbolicTraits cannot be used on 10.10 |
| + // as they appear to be buggy with respect to the default font. It is not possible to use |
| + // descriptors with CTFontCreateWithFontDescriptor, since that does not work with non-system |
| + // fonts. As a result, create the new fonts from the underlying CGFont. |
| + |
| + AutoCFRelease<CTFontDescriptorRef> baseDescriptor; |
| + AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(ctFont, &baseDescriptor)); |
| + |
| + // Make a mutable copy of baseDescriptor attributes. |
| + AutoCFRelease<CFMutableDictionaryRef> newAttributes; |
| + if (nullptr == baseDescriptor) { |
| + newAttributes.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| + } else { |
| + AutoCFRelease<CFDictionaryRef> baseAttributes( |
| + CTFontDescriptorCopyAttributes(baseDescriptor)); |
| + newAttributes.reset(CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, baseAttributes)); |
| } |
| // The transform contains everything except the requested text size. |
| // Some properties, like 'trak', are based on the text size (before applying the matrix). |
| CGFloat textSize = ScalarToCG(scale.y()); |
| + AutoCFRelease<CFNumberRef> cfTextSize( |
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &textSize)); |
| + CFDictionarySetValue(newAttributes, kCTFontSizeAttribute, cfTextSize); |
| + |
| + // First create the unrotated font at the right size. |
| + CFDictionaryRemoveValue(newAttributes, kCTFontMatrixAttribute); |
| + |
| + AutoCFRelease<CTFontDescriptorRef> unrotatedFontDescriptor( |
| + CTFontDescriptorCreateWithAttributes(newAttributes)); |
| + fCTUnrotatedFont.reset(CTFontCreateWithGraphicsFont(baseCGFont, textSize, nullptr, |
|
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
|
| + unrotatedFontDescriptor)); |
| + |
| + // Now create the fully transformed font. |
| + if (fVertical) { |
| + CTFontOrientation ctOrientation = kCTFontVerticalOrientation; |
| + AutoCFRelease<CFNumberRef> cfVertical( |
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation)); |
| + CFDictionarySetValue(newAttributes, kCTFontOrientationAttribute, cfVertical); |
| + } |
| + |
| + AutoCFRelease<CFDataRef> cfMatrixData(CFDataCreate( |
| + kCFAllocatorDefault, reinterpret_cast<const UInt8*>(&fTransform), sizeof(fTransform))); |
| + CFDictionaryAddValue(newAttributes, kCTFontMatrixAttribute, cfMatrixData); |
| + |
| + AutoCFRelease<CTFontDescriptorRef> newFontDescriptor( |
| + CTFontDescriptorCreateWithAttributes(newAttributes)); |
| + fCTFont.reset(CTFontCreateWithGraphicsFont(baseCGFont, textSize, &fTransform, |
| + newFontDescriptor)); |
| - fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc)); |
| fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); |
| - fCTUnrotatedFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, |
| - &CGAffineTransformIdentity, nullptr)); |
| // The fUnitMatrix includes the text size (and em) as it is used to scale the raw font data. |
| SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFont))); |