From 91fb8c385ac2ea2422a44cd2bf7aa1b97995a093 Mon Sep 17 00:00:00 2001 From: jfkthame Date: Tue, 19 Sep 2023 15:41:56 -0400 Subject: [PATCH] Expose the CTFont-creation functions with `options` parameter (#636) --- core-text/src/font.rs | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 8b77b08b..314fe103 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -180,6 +180,18 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { } } +pub fn new_from_descriptor_and_options(desc: &CTFontDescriptor, pt_size: f64, options: CTFontOptions) -> CTFont { + unsafe { + let font_ref = CTFontCreateWithFontDescriptorAndOptions( + desc.as_concrete_TypeRef(), + pt_size as CGFloat, + ptr::null(), + options, + ); + CTFont::wrap_under_create_rule(font_ref) + } +} + pub fn new_from_buffer(buffer: &[u8]) -> Result { let ct_font_descriptor = create_font_descriptor(buffer)?; Ok(new_from_descriptor(&ct_font_descriptor, 16.0)) @@ -198,6 +210,19 @@ pub fn new_from_name(name: &str, pt_size: f64) -> Result { } } +pub fn new_from_name_and_options(name: &str, pt_size: f64, options: CTFontOptions) -> Result { + unsafe { + let name: CFString = name.parse().unwrap(); + let font_ref = + CTFontCreateWithNameAndOptions(name.as_concrete_TypeRef(), pt_size as CGFloat, ptr::null(), options); + if font_ref.is_null() { + Err(()) + } else { + Ok(CTFont::wrap_under_create_rule(font_ref)) + } + } +} + pub fn new_ui_font_for_language( ui_type: CTFontUIFontType, size: f64, @@ -611,13 +636,23 @@ extern "C" { size: CGFloat, matrix: *const CGAffineTransform, ) -> CTFontRef; - //fn CTFontCreateWithNameAndOptions + fn CTFontCreateWithNameAndOptions( + name: CFStringRef, + size: CGFloat, + matrix: *const CGAffineTransform, + options: CTFontOptions, + ) -> CTFontRef; fn CTFontCreateWithFontDescriptor( descriptor: CTFontDescriptorRef, size: CGFloat, matrix: *const CGAffineTransform, ) -> CTFontRef; - //fn CTFontCreateWithFontDescriptorAndOptions + fn CTFontCreateWithFontDescriptorAndOptions( + descriptor: CTFontDescriptorRef, + size: CGFloat, + matrix: *const CGAffineTransform, + options: CTFontOptions, + ) -> CTFontRef; fn CTFontCreateUIFontForLanguage( uiType: CTFontUIFontType, size: CGFloat,