From 16d9bc733d96117dc7f2facff1b8924b5339b153 Mon Sep 17 00:00:00 2001 From: alokedesai Date: Thu, 16 Jun 2022 17:22:53 -0400 Subject: [PATCH 1/2] fix ventura crash --- core-text/src/font_descriptor.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core-text/src/font_descriptor.rs b/core-text/src/font_descriptor.rs index d0a03134..e06d674b 100644 --- a/core-text/src/font_descriptor.rs +++ b/core-text/src/font_descriptor.rs @@ -20,6 +20,7 @@ use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; use core_graphics::base::CGFloat; use std::path::PathBuf; +use core_foundation::boolean::CFBoolean; /* * CTFontTraits.h @@ -144,7 +145,19 @@ trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let cftype = self.get(key); - cftype.downcast::().unwrap() + let number = cftype.downcast::(); + 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::().expect("Should be able to convert value into CFBoolean")); + CFNumber::from(value_as_bool as i32) + } + } } } From 19374bd3fe61e462fc07172cf218b80ab1743220 Mon Sep 17 00:00:00 2001 From: David Stern Date: Sat, 12 Jul 2025 14:44:23 -0400 Subject: [PATCH 2/2] formatting --- core-text/src/font_descriptor.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core-text/src/font_descriptor.rs b/core-text/src/font_descriptor.rs index e06d674b..4a8c67bf 100644 --- a/core-text/src/font_descriptor.rs +++ b/core-text/src/font_descriptor.rs @@ -19,8 +19,8 @@ use core_foundation::url::{CFURLRef, CFURL}; use core_foundation::{declare_TCFType, impl_CFTypeDescription, impl_TCFType}; use core_graphics::base::CGFloat; -use std::path::PathBuf; use core_foundation::boolean::CFBoolean; +use std::path::PathBuf; /* * CTFontTraits.h @@ -154,7 +154,11 @@ impl TraitAccessorPrivate for CTFontTraits { // 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::().expect("Should be able to convert value into CFBoolean")); + let value_as_bool = bool::from( + cftype + .downcast::() + .expect("Should be able to convert value into CFBoolean"), + ); CFNumber::from(value_as_bool as i32) } }