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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)));
« 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