Skip to content

Commit 91fb8c3

Browse files
authored
Expose the CTFont-creation functions with options parameter (#636)
1 parent e589abe commit 91fb8c3

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

core-text/src/font.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont {
180180
}
181181
}
182182

183+
pub fn new_from_descriptor_and_options(desc: &CTFontDescriptor, pt_size: f64, options: CTFontOptions) -> CTFont {
184+
unsafe {
185+
let font_ref = CTFontCreateWithFontDescriptorAndOptions(
186+
desc.as_concrete_TypeRef(),
187+
pt_size as CGFloat,
188+
ptr::null(),
189+
options,
190+
);
191+
CTFont::wrap_under_create_rule(font_ref)
192+
}
193+
}
194+
183195
pub fn new_from_buffer(buffer: &[u8]) -> Result<CTFont, ()> {
184196
let ct_font_descriptor = create_font_descriptor(buffer)?;
185197
Ok(new_from_descriptor(&ct_font_descriptor, 16.0))
@@ -198,6 +210,19 @@ pub fn new_from_name(name: &str, pt_size: f64) -> Result<CTFont, ()> {
198210
}
199211
}
200212

213+
pub fn new_from_name_and_options(name: &str, pt_size: f64, options: CTFontOptions) -> Result<CTFont, ()> {
214+
unsafe {
215+
let name: CFString = name.parse().unwrap();
216+
let font_ref =
217+
CTFontCreateWithNameAndOptions(name.as_concrete_TypeRef(), pt_size as CGFloat, ptr::null(), options);
218+
if font_ref.is_null() {
219+
Err(())
220+
} else {
221+
Ok(CTFont::wrap_under_create_rule(font_ref))
222+
}
223+
}
224+
}
225+
201226
pub fn new_ui_font_for_language(
202227
ui_type: CTFontUIFontType,
203228
size: f64,
@@ -611,13 +636,23 @@ extern "C" {
611636
size: CGFloat,
612637
matrix: *const CGAffineTransform,
613638
) -> CTFontRef;
614-
//fn CTFontCreateWithNameAndOptions
639+
fn CTFontCreateWithNameAndOptions(
640+
name: CFStringRef,
641+
size: CGFloat,
642+
matrix: *const CGAffineTransform,
643+
options: CTFontOptions,
644+
) -> CTFontRef;
615645
fn CTFontCreateWithFontDescriptor(
616646
descriptor: CTFontDescriptorRef,
617647
size: CGFloat,
618648
matrix: *const CGAffineTransform,
619649
) -> CTFontRef;
620-
//fn CTFontCreateWithFontDescriptorAndOptions
650+
fn CTFontCreateWithFontDescriptorAndOptions(
651+
descriptor: CTFontDescriptorRef,
652+
size: CGFloat,
653+
matrix: *const CGAffineTransform,
654+
options: CTFontOptions,
655+
) -> CTFontRef;
621656
fn CTFontCreateUIFontForLanguage(
622657
uiType: CTFontUIFontType,
623658
size: CGFloat,

0 commit comments

Comments
 (0)