| Index: src/ports/SkFontHost_mac.cpp
|
| diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
|
| index a63152817a684e702aaec932d7627ceece2804b7..4d346e63600e2265185aba563ee342c9de78b89e 100755
|
| --- a/src/ports/SkFontHost_mac.cpp
|
| +++ b/src/ports/SkFontHost_mac.cpp
|
| @@ -351,13 +351,6 @@ Offscreen::Offscreen() : fRGBSpace(NULL), fCG(NULL),
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| -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 @@ static int unit_width_to_fontstyle(float unit) {
|
| 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 @@ static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc, bool* isF
|
| : 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 @@ private:
|
| 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 @@ static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef
|
| 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 @@ static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef
|
| }
|
|
|
| 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 @@ public:
|
| 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 @@ private:
|
|
|
| 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;
|
| }
|
|
|