diff options
author | bungeman <bungeman@google.com> | 2017-02-06 13:21:33 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-07 23:21:45 +0000 |
commit | 83f1f44e3a72830ac7db37ada87ff91221570e10 (patch) | |
tree | a425123842f3e31e1fe084c3e47d192049c354e2 /src/ports/SkFontHost_mac.cpp | |
parent | a51740c4f879b3c15877975118ef7588b99eaaea (diff) |
SkFontHost_mac.cpp#create_descriptor to handle nullptr familyName.
Currently create_descriptor will crash if handed a familyName which is
nullptr. Instead it should simply create a descriptor without a family name
and allow CoreText to resolve a default font. This further simplifies
default font handling on Mac.
BUG=skia:6196
Change-Id: I0a2d081240e4cb5bd51dd3516ea2595277055fe0
Reviewed-on: https://skia-review.googlesource.com/8071
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/ports/SkFontHost_mac.cpp')
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 3aeb0aae32..d221971ef1 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -495,22 +495,6 @@ static SkTypeface* create_from_desc(CTFontDescriptorRef desc) { static UniqueCFRef<CTFontDescriptorRef> create_descriptor(const char familyName[], const SkFontStyle& style) { - CTFontSymbolicTraits ctFontTraits = 0; - if (style.weight() >= SkFontStyle::kBold_Weight) { - ctFontTraits |= kCTFontBoldTrait; - } - if (style.slant() != SkFontStyle::kUpright_Slant) { - ctFontTraits |= kCTFontItalicTrait; - } - - //TODO: add weight width slant - - // Create the font info - UniqueCFRef<CFStringRef> cfFontName = make_CFString(familyName); - - UniqueCFRef<CFNumberRef> cfFontTraits( - CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctFontTraits)); - UniqueCFRef<CFMutableDictionaryRef> cfAttributes( CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, @@ -521,14 +505,34 @@ static UniqueCFRef<CTFontDescriptorRef> create_descriptor(const char familyName[ &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); - if (!cfFontName || !cfFontTraits || !cfAttributes || !cfTraits) { + if (!cfAttributes || !cfTraits) { return nullptr; } - CFDictionaryAddValue(cfTraits.get(), kCTFontSymbolicTrait, cfFontTraits.get()); + // CTFontTraits + CTFontSymbolicTraits ctFontTraits = 0; + if (style.weight() >= SkFontStyle::kBold_Weight) { + ctFontTraits |= kCTFontBoldTrait; + } + if (style.slant() != SkFontStyle::kUpright_Slant) { + ctFontTraits |= kCTFontItalicTrait; + } + UniqueCFRef<CFNumberRef> cfFontTraits( + CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctFontTraits)); + if (cfFontTraits) { + CFDictionaryAddValue(cfTraits.get(), kCTFontSymbolicTrait, cfFontTraits.get()); + CFDictionaryAddValue(cfAttributes.get(), kCTFontTraitsAttribute, cfTraits.get()); + } + + //TODO: add weight width slant - CFDictionaryAddValue(cfAttributes.get(), kCTFontFamilyNameAttribute, cfFontName.get()); - CFDictionaryAddValue(cfAttributes.get(), kCTFontTraitsAttribute, cfTraits.get()); + // CTFontFamilyName + if (familyName) { + UniqueCFRef<CFStringRef> cfFontName = make_CFString(familyName); + if (cfFontName) { + CFDictionaryAddValue(cfAttributes.get(), kCTFontFamilyNameAttribute, cfFontName.get()); + } + } return UniqueCFRef<CTFontDescriptorRef>( CTFontDescriptorCreateWithAttributes(cfAttributes.get())); @@ -2397,11 +2401,6 @@ protected: familyName = map_css_names(familyName); } - static const char FONT_DEFAULT_NAME[] = "Lucida Sans"; - if (!familyName || !*familyName) { - familyName = FONT_DEFAULT_NAME; - } - SkTypeface* face = create_from_name(familyName, style); if (face) { return face; @@ -2409,6 +2408,7 @@ protected: static SkTypeface* gDefaultFace; static SkOnce lookupDefault; + static const char FONT_DEFAULT_NAME[] = "Lucida Sans"; lookupDefault([]{ gDefaultFace = create_from_name(FONT_DEFAULT_NAME, SkFontStyle()); }); |