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

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 752183002: Use text size on Mac. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments. Created 6 years, 1 month 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 | « src/core/SkScalerContext.cpp ('k') | 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 7fd645bdae6b472edade9c528a2d340657cd1700..dea72c7358a124359d571303a0563f27c316018c 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -717,8 +717,9 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
SkASSERT(numGlyphs >= 1 && numGlyphs <= 0xFFFF);
fGlyphCount = SkToU16(numGlyphs);
- fRec.getSingleMatrix(&fFUnitMatrix);
- CGAffineTransform transform = MatrixToCGAffineTransform(fFUnitMatrix);
+ SkMatrix skTransform;
+ fRec.getSingleMatrixWithoutTextSize(&skTransform);
+ CGAffineTransform transform = MatrixToCGAffineTransform(skTransform);
AutoCFRelease<CTFontDescriptorRef> ctFontDesc;
if (fVertical) {
@@ -734,15 +735,27 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
ctFontDesc.reset(CTFontDescriptorCreateWithAttributes(cfAttributes));
}
}
- // Since our matrix includes everything, we pass 1 for size.
- fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, 1, &transform, ctFontDesc));
+
+ // 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(fRec.fTextSize);
+
+ // If a text size of 0 is requested, CoreGraphics will use 12 instead.
+ // If the text size is 0, set it to something tiny.
+ if (textSize < CGFLOAT_MIN) {
+ textSize = CGFLOAT_MIN;
+ }
+
+ fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &transform, ctFontDesc));
fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, NULL));
if (fVertical) {
CGAffineTransform rotateLeft = CGAffineTransformMake(0, -1, 1, 0, 0, 0);
transform = CGAffineTransformConcat(rotateLeft, transform);
- fCTVerticalFont.reset(CTFontCreateCopyWithAttributes(ctFont, 1, &transform, NULL));
+ fCTVerticalFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &transform, NULL));
}
+ // The fUnitMatrix includes the text size (and em) as it is used to scale the raw font data.
+ fRec.getSingleMatrix(&fFUnitMatrix);
SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFont)));
fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit);
}
@@ -793,7 +806,7 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
CGContextSetTextDrawingMode(fCG, kCGTextFill);
CGContextSetFont(fCG, context.fCGFont);
- CGContextSetFontSize(fCG, 1 /*CTFontGetSize(context.fCTFont)*/);
+ CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont));
CGContextSetTextMatrix(fCG, CTFontGetMatrix(context.fCTFont));
// Because CG always draws from the horizontal baseline,
« no previous file with comments | « src/core/SkScalerContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698