@@ -19,6 +19,7 @@ use core_foundation::url::{CFURLRef, CFURL};
1919use core_foundation:: { declare_TCFType, impl_CFTypeDescription, impl_TCFType} ;
2020use core_graphics:: base:: CGFloat ;
2121
22+ use core_foundation:: boolean:: CFBoolean ;
2223use std:: path:: PathBuf ;
2324
2425/*
@@ -144,7 +145,23 @@ trait TraitAccessorPrivate {
144145impl 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 (
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+ }
148165 }
149166}
150167
0 commit comments