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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 1354323002: Revert of Avoid CTFontCreateCopyWithAttributes. (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 a01c37efc058e31a264ca964f3613b48ca611fee..7d90d84695f386c6ad40d55f33317e9c5bacf09f 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -282,13 +282,15 @@
}
}
-static CGAffineTransform MatrixToCGAffineTransform(const SkMatrix& matrix) {
- return CGAffineTransformMake( ScalarToCG(matrix[SkMatrix::kMScaleX]),
- -ScalarToCG(matrix[SkMatrix::kMSkewY]),
- -ScalarToCG(matrix[SkMatrix::kMSkewX]),
- ScalarToCG(matrix[SkMatrix::kMScaleY]),
- ScalarToCG(matrix[SkMatrix::kMTransX]),
- ScalarToCG(matrix[SkMatrix::kMTransY]));
+static CGAffineTransform MatrixToCGAffineTransform(const SkMatrix& matrix,
+ SkScalar sx = SK_Scalar1,
+ SkScalar sy = SK_Scalar1) {
+ return CGAffineTransformMake( ScalarToCG(matrix[SkMatrix::kMScaleX] * sx),
+ -ScalarToCG(matrix[SkMatrix::kMSkewY] * sy),
+ -ScalarToCG(matrix[SkMatrix::kMSkewX] * sx),
+ ScalarToCG(matrix[SkMatrix::kMScaleY] * sy),
+ ScalarToCG(matrix[SkMatrix::kMTransX] * sx),
+ ScalarToCG(matrix[SkMatrix::kMTransY] * sy));
}
///////////////////////////////////////////////////////////////////////////////
@@ -712,57 +714,6 @@
typedef SkScalerContext INHERITED;
};
-// 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.
-static CTFontRef ctfont_create_exact_copy(CTFontRef baseFont, CGFloat textSize,
- const CGAffineTransform* transform, bool setVertical)
-{
- AutoCFRelease<CTFontDescriptorRef> baseDescriptor;
- AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(baseFont, &baseDescriptor));
-
- // Make a mutable copy of baseDescriptor 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);
- }(baseDescriptor));
-
- // 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);
- }
-
- // Create the new CTFont from the baseCGFont.
- AutoCFRelease<CTFontDescriptorRef> newDescriptor(
- CTFontDescriptorCreateWithAttributes(newAttributes));
- return CTFontCreateWithGraphicsFont(baseCGFont, textSize, transform, newDescriptor);
-
-}
-
SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
const SkDescriptor* desc)
: INHERITED(typeface, desc)
@@ -789,13 +740,30 @@
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));
+ }
+ }
+
// 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());
- fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, &fTransform, fVertical));
+ fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc));
fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr));
- fCTUnrotatedFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr, false));
+ 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)));
@@ -1395,13 +1363,9 @@
break;
}
- CGFloat textSize = CTFontGetSize(fCTFont);
- CGAffineTransform baseTransform = CTFontGetMatrix(fCTFont);
- CGAffineTransform newTransform =
- CGAffineTransformScale(baseTransform, ScalarToCG(scaleX), ScalarToCG(scaleY));
-
- // need to release this font when we're done
- font = ctfont_create_exact_copy(fCTFont, textSize, &newTransform, false);
+ CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY);
+ // need to release font when we're done
+ font = CTFontCreateCopyWithAttributes(fCTFont, 1, &xform, nullptr);
}
CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID();
@@ -1416,7 +1380,7 @@
SkMatrix m;
m.setScale(SkScalarInvert(scaleX), SkScalarInvert(scaleY));
path->transform(m);
- // balance the call to ctfont_create_exact_copy
+ // balance the call to CTFontCreateCopyWithAttributes
CFSafeRelease(font);
}
if (fVertical) {
@@ -1597,9 +1561,8 @@
AUTO_CG_LOCK();
CTFontRef originalCTFont = fFontRef.get();
- AutoCFRelease<CTFontRef> ctFont(ctfont_create_exact_copy(
- originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, false));
-
+ AutoCFRelease<CTFontRef> ctFont(CTFontCreateCopyWithAttributes(
+ originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, 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