Skip to content

Commit 0f3eaa7

Browse files
committed
Add create_font_descriptor_with_data
This allows create a font from a CFData instead of slice. More importantly this allows using a CFData that was created with a custom allocator.
1 parent e9e0c6e commit 0f3eaa7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core-text/src/font_manager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub fn create_font_descriptor(buffer: &[u8]) -> Result<CTFontDescriptor, ()> {
3131
}
3232
}
3333

34+
pub fn create_font_descriptor_with_data(data: CFData) -> Result<CTFontDescriptor, ()> {
35+
unsafe {
36+
let ct_font_descriptor_ref = CTFontManagerCreateFontDescriptorFromData(data.as_concrete_TypeRef());
37+
if ct_font_descriptor_ref.is_null() {
38+
return Err(());
39+
}
40+
Ok(CTFontDescriptor::wrap_under_create_rule(ct_font_descriptor_ref))
41+
}
42+
}
43+
3444
extern {
3545
/*
3646
* CTFontManager.h

0 commit comments

Comments
 (0)