Merge from Chromium at DEPS revision 40.0.2214.10

This commit was generated by merge_to_master.py.

Change-Id: I01ec9fc92af1d8d7aef59c8bef66e29bd71b7a75
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index a631528..4d346e6 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -351,13 +351,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static bool find_dict_traits(CFDictionaryRef dict, CTFontSymbolicTraits* traits) {
-    CFNumberRef num;
-    return CFDictionaryGetValueIfPresent(dict, kCTFontSymbolicTrait, (const void**)&num)
-    && CFNumberIsFloatType(num)
-    && CFNumberGetValue(num, kCFNumberSInt32Type, traits);
-}
-
 static bool find_dict_float(CFDictionaryRef dict, CFStringRef name, float* value) {
     CFNumberRef num;
     return CFDictionaryGetValueIfPresent(dict, name, (const void**)&num)
@@ -385,30 +378,22 @@
     return sk_float_round2int(value);
 }
 
-static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc, bool* isFixedPitch) {
+static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc) {
     AutoCFRelease<CFDictionaryRef> dict(
             (CFDictionaryRef)CTFontDescriptorCopyAttribute(desc, kCTFontTraitsAttribute));
     if (NULL == dict.get()) {
         return SkFontStyle();
     }
 
-    CTFontSymbolicTraits traits;
-    if (!find_dict_traits(dict, &traits)) {
-        traits = 0;
-    }
-    if (isFixedPitch) {
-        *isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait);
-    }
-
     float weight, width, slant;
     if (!find_dict_float(dict, kCTFontWeightTrait, &weight)) {
-        weight = (traits & kCTFontBoldTrait) ? 0.5f : 0;
+        weight = 0;
     }
     if (!find_dict_float(dict, kCTFontWidthTrait, &width)) {
         width = 0;
     }
     if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) {
-        slant = (traits & kCTFontItalicTrait) ? 0.5f : 0;
+        slant = 0;
     }
 
     return SkFontStyle(unit_weight_to_fontstyle(weight),
@@ -417,6 +402,22 @@
                        : SkFontStyle::kUpright_Slant);
 }
 
+static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isFixedPitch) {
+    unsigned style = SkTypeface::kNormal;
+    CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
+
+    if (traits & kCTFontBoldTrait) {
+        style |= SkTypeface::kBold;
+    }
+    if (traits & kCTFontItalicTrait) {
+        style |= SkTypeface::kItalic;
+    }
+    if (isFixedPitch) {
+        *isFixedPitch = (traits & kCTFontMonoSpaceTrait) != 0;
+    }
+    return (SkTypeface::Style)style;
+}
+
 static SkFontID CTFontRef_to_SkFontID(CTFontRef fontRef) {
     SkFontID id = 0;
 // CTFontGetPlatformFont and ATSFontRef are not supported on iOS, so we have to
@@ -491,8 +492,7 @@
 static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isLocalStream) {
     SkASSERT(fontRef);
     bool isFixedPitch;
-    AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef));
-    SkFontStyle style = fontstyle_from_descriptor(desc, &isFixedPitch);
+    SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch));
     SkFontID fontID = CTFontRef_to_SkFontID(fontRef);
 
     return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name, isLocalStream);
@@ -2022,7 +2022,7 @@
     SkString skFamilyName;
     CFStringToSkString(cfFamilyName, &skFamilyName);
     cacheRequest.fName = skFamilyName.c_str();
-    cacheRequest.fStyle = fontstyle_from_descriptor(desc, NULL);
+    cacheRequest.fStyle = fontstyle_from_descriptor(desc);
 
     SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cacheRequest);
     if (face) {
@@ -2042,8 +2042,7 @@
     }
 
     bool isFixedPitch;
-    AutoCFRelease<CTFontDescriptorRef> ctFontDesc(CTFontCopyFontDescriptor(ctFont));
-    (void)fontstyle_from_descriptor(ctFontDesc, &isFixedPitch);
+    (void)computeStyleBits(ctFont, &isFixedPitch);
     SkFontID fontID = CTFontRef_to_SkFontID(ctFont);
 
     face = SkNEW_ARGS(SkTypeface_Mac, (cacheRequest.fStyle, fontID, isFixedPitch,
@@ -2078,7 +2077,7 @@
         SkASSERT((unsigned)index < (unsigned)fCount);
         CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, index);
         if (style) {
-            *style = fontstyle_from_descriptor(desc, NULL);
+            *style = fontstyle_from_descriptor(desc);
         }
         if (name) {
             if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) {
@@ -2112,7 +2111,7 @@
 
         for (int i = 0; i < fCount; ++i) {
             CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, i);
-            int metric = compute_metric(pattern, fontstyle_from_descriptor(desc, NULL));
+            int metric = compute_metric(pattern, fontstyle_from_descriptor(desc));
             if (0 == metric) {
                 return desc;
             }