Skip to content

Commit 5d6dc4f

Browse files
alokedesaivorporeal
authored andcommitted
fix ventura crash
1 parent 1626428 commit 5d6dc4f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core-text/src/font_descriptor.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
2020
use core_graphics::base::CGFloat;
2121

2222
use std::path::PathBuf;
23+
use core_foundation::boolean::CFBoolean;
2324

2425
/*
2526
* CTFontTraits.h
@@ -144,7 +145,19 @@ trait TraitAccessorPrivate {
144145
impl TraitAccessorPrivate for CTFontTraits {
145146
fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
146147
let cftype = self.get(key);
147-
cftype.downcast::<CFNumber>().unwrap()
148+
let number = cftype.downcast::<CFNumber>();
149+
match number {
150+
Some(number) => number,
151+
None => {
152+
// The value was not able to be converted to a CFNumber, this violates the Core
153+
// Foundation's docs (see https://developer.apple.com/documentation/coretext/kctfontsymbolictrait)
154+
// but can occur in practice with certain fonts in MacOS 13 (Ventura). When this
155+
// does occur in Ventura, the value returned is always a CFBoolean, so we attempt to
156+
// convert into a boolean and create a number from there.
157+
let value_as_bool = bool::from(cftype.downcast::<CFBoolean>().expect("Should be able to convert value into CFBoolean"));
158+
CFNumber::from(value_as_bool as i32)
159+
}
160+
}
148161
}
149162
}
150163

0 commit comments

Comments
 (0)