Use text size on Mac.

The current code assumes that text on Mac is freely scalable,
or at least that the text size is just a part of the transform.
However, it appears that application of the 'trak' table,
as well as other optical adjustments, may rely on the text size
directly.

This change passes the text size requested directly to CoreText.

BUG=chromium:427528

Review URL: https://codereview.chromium.org/752183002

Cherry-pick: be2284de556e7ec29489693093d42dc86b762645
Approval: https://code.google.com/p/chromium/issues/detail?id=427528#c24
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 4d7f362..2d14b97 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -735,6 +735,10 @@
     SkPaint::SetTextMatrix(m, fTextSize, fPreScaleX, fPreSkewX);
 }
 
+void SkScalerContextRec::getLocalMatrixWithoutTextSize(SkMatrix* m) const {
+    SkPaint::SetTextMatrix(m, SK_Scalar1, fPreScaleX, fPreSkewX);
+}
+
 void SkScalerContextRec::getSingleMatrix(SkMatrix* m) const {
     this->getLocalMatrix(m);
 
@@ -744,6 +748,15 @@
     m->postConcat(deviceMatrix);
 }
 
+void SkScalerContextRec::getSingleMatrixWithoutTextSize(SkMatrix* m) const {
+    this->getLocalMatrixWithoutTextSize(m);
+
+    //  now concat the device matrix
+    SkMatrix    deviceMatrix;
+    this->getMatrixFrom2x2(&deviceMatrix);
+    m->postConcat(deviceMatrix);
+}
+
 SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) {
     SkASSERT(!matrix.hasPerspective());
 
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index 337b2e0..9604395 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -82,7 +82,9 @@
 
     void    getMatrixFrom2x2(SkMatrix*) const;
     void    getLocalMatrix(SkMatrix*) const;
+    void    getLocalMatrixWithoutTextSize(SkMatrix*) const;
     void    getSingleMatrix(SkMatrix*) const;
+    void    getSingleMatrixWithoutTextSize(SkMatrix*) const;
 
     inline SkPaint::Hinting getHinting() const;
     inline void setHinting(SkPaint::Hinting);
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 4d346e6..2f991c8 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -717,8 +717,9 @@
     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 @@
             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 @@
 
         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,