From f89d2345dec686fe64886137ce53c330a64350b0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 Jul 2018 15:09:13 -0700 Subject: [PATCH] Make `CTFontCollection::get_descriptors()` return an Option. It returns null if there are no matching fonts. --- core-text/Cargo.toml | 2 +- core-text/src/font_collection.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core-text/Cargo.toml b/core-text/Cargo.toml index 94dbc2c..d26d6d4 100644 --- a/core-text/Cargo.toml +++ b/core-text/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "12.0.0" +version = "13.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" diff --git a/core-text/src/font_collection.rs b/core-text/src/font_collection.rs index 0d9b51a..8f3f2c5 100644 --- a/core-text/src/font_collection.rs +++ b/core-text/src/font_collection.rs @@ -33,11 +33,17 @@ impl_CFTypeDescription!(CTFontCollection); impl CTFontCollection { - pub fn get_descriptors(&self) -> CFArray { + pub fn get_descriptors(&self) -> Option> { // surprise! this function follows the Get rule, despite being named *Create*. // So we have to addRef it to avoid CTFontCollection from double freeing it later. unsafe { - CFArray::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0)) + let font_descriptors = CTFontCollectionCreateMatchingFontDescriptors(self.0); + if font_descriptors.is_null() { + // This returns null if there are no matching font descriptors. + None + } else { + Some(CFArray::wrap_under_get_rule(font_descriptors)) + } } } }