@@ -19,6 +19,7 @@ use core_foundation::url::{CFURLRef, CFURL};
19
19
use core_foundation:: { declare_TCFType, impl_CFTypeDescription, impl_TCFType} ;
20
20
use core_graphics:: base:: CGFloat ;
21
21
22
+ use core_foundation:: boolean:: CFBoolean ;
22
23
use std:: path:: PathBuf ;
23
24
24
25
/*
@@ -144,7 +145,23 @@ trait TraitAccessorPrivate {
144
145
impl TraitAccessorPrivate for CTFontTraits {
145
146
fn extract_number_for_key ( & self , key : CFStringRef ) -> CFNumber {
146
147
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 (
158
+ cftype
159
+ . downcast :: < CFBoolean > ( )
160
+ . expect ( "Should be able to convert value into CFBoolean" ) ,
161
+ ) ;
162
+ CFNumber :: from ( value_as_bool as i32 )
163
+ }
164
+ }
148
165
}
149
166
}
150
167
0 commit comments