aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2014-11-27 15:41:27 +0000
committerTorne (Richard Coles) <torne@google.com>2014-11-27 15:41:27 +0000
commitfe85239cf2c444e64e1af6aa450e56c11359eb58 (patch)
tree6bac41f9231b5481f955334aeeb491820f68a6b2
parent91910327136cc116c7adceab25ff9b8bcae60be5 (diff)
parentdfe1f486eb3e5299038057e695681dcfbd70f617 (diff)
downloadskia-fe85239cf2c444e64e1af6aa450e56c11359eb58.tar.gz
Merge third_party/skia from https://chromium.googlesource.com/skia.git at dfe1f486eb3e5299038057e695681dcfbd70f617
This commit was generated by merge_from_chromium.py. Change-Id: I5d12d7823f842d175a942613af190d7740e7dd6d
-rwxr-xr-xsrc/ports/SkFontHost_mac.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index a63152817..4d346e636 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;
}