Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion core-text/src/font_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use core_foundation::url::{CFURLRef, CFURL};
use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType};
use core_graphics::base::CGFloat;

use core_foundation::boolean::CFBoolean;
use std::path::PathBuf;

/*
Expand Down Expand Up @@ -144,7 +145,23 @@ trait TraitAccessorPrivate {
impl TraitAccessorPrivate for CTFontTraits {
fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
let cftype = self.get(key);
cftype.downcast::<CFNumber>().unwrap()
let number = cftype.downcast::<CFNumber>();
match number {
Some(number) => number,
None => {
// The value was not able to be converted to a CFNumber, this violates the Core
// Foundation's docs (see https://developer.apple.com/documentation/coretext/kctfontsymbolictrait)
// but can occur in practice with certain fonts in MacOS 13 (Ventura). When this
// does occur in Ventura, the value returned is always a CFBoolean, so we attempt to
// convert into a boolean and create a number from there.
let value_as_bool = bool::from(
cftype
.downcast::<CFBoolean>()
.expect("Should be able to convert value into CFBoolean"),
);
CFNumber::from(value_as_bool as i32)
}
}
}
}

Expand Down