From 0f3eaa7416ff8c4cbcbce26eca0da4e69699154d Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Tue, 3 Nov 2020 10:58:40 -0500 Subject: [PATCH] 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. --- core-text/src/font_manager.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core-text/src/font_manager.rs b/core-text/src/font_manager.rs index 933c8da..cdf65ee 100644 --- a/core-text/src/font_manager.rs +++ b/core-text/src/font_manager.rs @@ -31,6 +31,16 @@ pub fn create_font_descriptor(buffer: &[u8]) -> Result { } } +pub fn create_font_descriptor_with_data(data: CFData) -> Result { + unsafe { + let ct_font_descriptor_ref = CTFontManagerCreateFontDescriptorFromData(data.as_concrete_TypeRef()); + if ct_font_descriptor_ref.is_null() { + return Err(()); + } + Ok(CTFontDescriptor::wrap_under_create_rule(ct_font_descriptor_ref)) + } +} + extern { /* * CTFontManager.h