Make CTFontCollection::get_descriptors() return an Option.

It returns null if there are no matching fonts.
This commit is contained in:
Patrick Walton
2018-07-27 15:09:13 -07:00
parent 912a7f00d7
commit f89d2345de
2 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -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"
+8 -2
View File
@@ -33,11 +33,17 @@ impl_CFTypeDescription!(CTFontCollection);
impl CTFontCollection {
pub fn get_descriptors(&self) -> CFArray<CTFontDescriptor> {
pub fn get_descriptors(&self) -> Option<CFArray<CTFontDescriptor>> {
// 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))
}
}
}
}