File tree 1 file changed +14
-1
lines changed 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ use core_graphics::base::CGFloat;
20
20
21
21
use std:: os:: raw:: c_void;
22
22
use std:: path:: PathBuf ;
23
+ use core_foundation:: boolean:: CFBoolean ;
23
24
24
25
/*
25
26
* CTFontTraits.h
@@ -132,7 +133,19 @@ trait TraitAccessorPrivate {
132
133
impl TraitAccessorPrivate for CTFontTraits {
133
134
fn extract_number_for_key ( & self , key : CFStringRef ) -> CFNumber {
134
135
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
+ }
136
149
}
137
150
138
151
}
You can’t perform that action at this time.
0 commit comments