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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 1362053003: Avoid last param to CTFontCreateWithGraphicsFont. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 c10d830715a7864a60b03ac07fa059f4644bb11d..8db318b3ff5238798e91740f8bd616aeba2f59a7 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -715,62 +715,24 @@ private:
};
// 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 strike specific CTFonts from the underlying CGFont.
+// and later, as they will return different underlying fonts depending on the size requested.
+// It is not possible to use descriptors with CTFontCreateWithFontDescriptor, since that does not
+// work with non-system fonts. As a result, create the strike specific CTFonts from the underlying
+// CGFont.
static CTFontRef ctfont_create_exact_copy(CTFontRef baseFont, CGFloat textSize,
- const CGAffineTransform* transform, bool setVertical)
+ const CGAffineTransform* transform)
{
- AutoCFRelease<CTFontDescriptorRef> baseExtraDescriptor;
- AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(baseFont, &baseExtraDescriptor));
-
- // Make a mutable copy of baseExtraDescriptor attributes.
- AutoCFRelease<CFMutableDictionaryRef> newAttributes([](CTFontDescriptorRef descriptor) ->
- CFMutableDictionaryRef {
- if (nullptr == descriptor) {
- return CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
- }
- AutoCFRelease<CFDictionaryRef> attributes(CTFontDescriptorCopyAttributes(descriptor));
- return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, attributes);
- }(baseExtraDescriptor));
-
- // Copy all of the attributes out of the CTFont.
- AutoCFRelease<CTFontDescriptorRef> baseDescriptor(CTFontCopyFontDescriptor(baseFont));
- AutoCFRelease<CFDictionaryRef> baseAttributes(CTFontDescriptorCopyAttributes(baseDescriptor));
- CFDictionaryApplyFunction(baseAttributes, [](CFTypeRef key, CFTypeRef value, void* context) {
- CFMutableDictionaryRef self = static_cast<CFMutableDictionaryRef>(context);
- CFDictionarySetValue(self, key, value);
- }, newAttributes.get());
-
- // Set the text size in attributes.
- AutoCFRelease<CFNumberRef> cfTextSize(
- CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &textSize));
- CFDictionarySetValue(newAttributes, kCTFontSizeAttribute, cfTextSize);
-
- // Set the transform in attributes.
- if (nullptr == transform) {
- CFDictionaryRemoveValue(newAttributes, kCTFontMatrixAttribute);
- } else {
- AutoCFRelease<CFDataRef> cfMatrixData(CFDataCreate(
- kCFAllocatorDefault, reinterpret_cast<const UInt8*>(transform), sizeof(*transform)));
- CFDictionarySetValue(newAttributes, kCTFontMatrixAttribute, cfMatrixData);
- }
-
- // Set vertical orientation to attributes if requested.
- if (setVertical) {
- CTFontOrientation ctOrientation = kCTFontVerticalOrientation;
- AutoCFRelease<CFNumberRef> cfVertical(
- CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation));
- CFDictionarySetValue(newAttributes, kCTFontOrientationAttribute, cfVertical);
- }
+ AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(baseFont, nullptr));
- // Create the new CTFont from the baseCGFont.
- AutoCFRelease<CTFontDescriptorRef> newDescriptor(
- CTFontDescriptorCreateWithAttributes(newAttributes));
- return CTFontCreateWithGraphicsFont(baseCGFont, textSize, transform, newDescriptor);
+ // The last parameter (CTFontDescriptorRef attributes) *must* be nullptr.
+ // If non-nullptr then with fonts with variation axes, the copy will fail in
+ // CGFontVariationFromDictCallback when it assumes kCGFontVariationAxisName is CFNumberRef
+ // which it quite obviously is not.
+ // Because we cannot setup the CTFont descriptor to match, the same restriction applies here
+ // as other uses of CTFontCreateWithGraphicsFont which is that such CTFonts should not escape
+ // the scaler context, since they aren't 'normal'.
+ return CTFontCreateWithGraphicsFont(baseCGFont, textSize, transform, nullptr);
}
SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
@@ -803,9 +765,9 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
// Some properties, like 'trak', are based on the text size (before applying the matrix).
CGFloat textSize = ScalarToCG(scale.y());
- fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, &fTransform, fVertical));
+ fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, &fTransform));
fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr));
- fCTUnrotatedFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr, false));
+ fCTUnrotatedFont.reset(ctfont_create_exact_copy(ctFont, textSize, 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)));
@@ -1406,7 +1368,7 @@ void SkScalerContext_Mac::generatePath(const SkGlyph& glyph, SkPath* path) {
}
CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY);
- font = ctfont_create_exact_copy(fCTFont, 1, &xform, false);
+ font = ctfont_create_exact_copy(fCTFont, 1, &xform);
}
CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID();
@@ -1603,7 +1565,7 @@ SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
CTFontRef originalCTFont = fFontRef.get();
AutoCFRelease<CTFontRef> ctFont(ctfont_create_exact_copy(
- originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, false));
+ originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr));
SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
« 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