diff options
author | bungeman <bungeman@google.com> | 2017-05-01 13:02:42 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-01 18:13:02 +0000 |
commit | 7575bb1c389f96db4123783fcd717f3611b3a8eb (patch) | |
tree | ba76ce96b732117155b6fc48c644e9e29f50cd85 | |
parent | fe560a8cc3839b7c4c0a63bdb286fe1e1f89a5dc (diff) |
SkFontMgr::matchFamily should not crash on nullptr.
While all systems can resolve a font from just a style request
(without a name) almost no systems specify a default font family.
BUG=skia:6574
Change-Id: If7c81808b62cd5d8212bce2eb4d9c476c45af80a
Reviewed-on: https://skia-review.googlesource.com/14902
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
-rw-r--r-- | include/ports/SkFontMgr.h | 4 | ||||
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 9 | ||||
-rw-r--r-- | src/ports/SkFontMgr_fontconfig.cpp | 3 | ||||
-rw-r--r-- | src/ports/SkFontMgr_win_dw.cpp | 4 | ||||
-rw-r--r-- | tests/FontMgrTest.cpp | 7 |
5 files changed, 23 insertions, 4 deletions
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index b5879d35b8..b13e113a2e 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -45,7 +45,9 @@ public: * The caller must call unref() on the returned object. * Never returns NULL; will return an empty set if the name is not found. * - * Passing |nullptr| as the parameter will return the default system font. + * Passing nullptr as the parameter will return the default system family. + * Note that most systems don't have a default system family, so passing nullptr will often + * result in the empty set. * * It is possible that this will return a style set not accessible from * createStyleSet(int) due to hidden or auto-activated fonts. diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index b525ed597f..4774eab87f 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -2362,14 +2362,17 @@ protected: } SkFontStyleSet* onMatchFamily(const char familyName[]) const override { + if (!familyName) { + return nullptr; + } UniqueCFRef<CFStringRef> cfName = make_CFString(familyName); return CreateSet(cfName.get()); } SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontStyle) const override { - sk_sp<SkFontStyleSet> sset(this->matchFamily(familyName)); - return sset->matchStyle(fontStyle); + const SkFontStyle& style) const override { + UniqueCFRef<CTFontDescriptorRef> desc = create_descriptor(familyName, style); + return create_from_desc(desc.get()); } SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index bceb4de3bd..f27ad40da6 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -752,6 +752,9 @@ protected: } SkFontStyleSet* onMatchFamily(const char familyName[]) const override { + if (!familyName) { + return nullptr; + } FCLocker lock; SkAutoFcPattern pattern; diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index f985c4f245..1fd300ca1d 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -484,6 +484,10 @@ SkFontStyleSet* SkFontMgr_DirectWrite::onCreateStyleSet(int index) const { } SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) const { + if (!familyName) { + return nullptr; + } + SkSMallocWCHAR dwFamilyName; HRN(sk_cstring_to_wchar(familyName, &dwFamilyName)); diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp index b6a0cc5a74..251eb154a0 100644 --- a/tests/FontMgrTest.cpp +++ b/tests/FontMgrTest.cpp @@ -114,6 +114,12 @@ static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { } } +static void test_match(skiatest::Reporter* reporter) { + sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); + sk_sp<SkFontStyleSet> styleSet(fm->matchFamily(nullptr)); + REPORTER_ASSERT(reporter, styleSet); +} + static void test_matchStyleCSS3(skiatest::Reporter* reporter) { static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); @@ -710,6 +716,7 @@ static void test_matchStyleCSS3(skiatest::Reporter* reporter) { DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); DEF_TEST(FontMgr, reporter) { + test_match(reporter); test_matchStyleCSS3(reporter); test_fontiter(reporter, FLAGS_verboseFontMgr); test_alias_names(reporter); |