Skip to content

Commit 3775965

Browse files
authored
Merge pull request #3 from warpdotdev/aloke/ventura_fix
Fix Ventura Crash
2 parents 570ef9c + 895838e commit 3775965

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_graphics::base::CGFloat;
2020

2121
use std::os::raw::c_void;
2222
use std::path::PathBuf;
23+
use core_foundation::boolean::CFBoolean;
2324

2425
/*
2526
* CTFontTraits.h
@@ -132,7 +133,19 @@ trait TraitAccessorPrivate {
132133
impl TraitAccessorPrivate for CTFontTraits {
133134
fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
134135
let cftype = self.get(key);
135-
cftype.downcast::<CFNumber>().unwrap()
136+
let number = cftype.downcast::<CFNumber>();
137+
match number {
138+
Some(number) => number,
139+
None => {
140+
// The value was not able to be converted to a CFNumber, this violates the Core
141+
// Foundation's docs (see https://developer.apple.com/documentation/coretext/kctfontsymbolictrait)
142+
// but can occur in practice with certain fonts in MacOS 13 (Ventura). When this
143+
// does occur in Ventura, the value returned is always a CFBoolean, so we attempt to
144+
// convert into a boolean and create a number from there.
145+
let value_as_bool = bool::from(cftype.downcast::<CFBoolean>().expect("Should be able to convert value into CFBoolean"));
146+
CFNumber::from(value_as_bool as i32)
147+
}
148+
}
136149
}
137150

138151
}

0 commit comments

Comments
 (0)