Add CTFontManagerCreateFontDescriptorFromData for avoid CGFont
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
use font_descriptor;
|
||||
use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation};
|
||||
use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors};
|
||||
use font_manager::{create_font_descriptor, CTFontManagerIsSupportedFont};
|
||||
|
||||
use core_foundation::array::{CFArray, CFArrayRef};
|
||||
use core_foundation::base::{CFIndex, CFOptionFlags, CFType, CFTypeID, CFTypeRef, TCFType};
|
||||
@@ -30,6 +31,7 @@ use foreign_types::ForeignType;
|
||||
use libc::{self, size_t};
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
use std::path::Path;
|
||||
|
||||
type CGContextRef = *mut <CGContext as ForeignType>::CType;
|
||||
type CGFontRef = *mut <CGFont as ForeignType>::CType;
|
||||
@@ -124,6 +126,11 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from_buffer(buffer: &[u8]) -> Result<CTFont, ()> {
|
||||
let ct_font_descriptor = create_font_descriptor(buffer)?;
|
||||
Ok(new_from_descriptor(&ct_font_descriptor, 16.0))
|
||||
}
|
||||
|
||||
pub fn new_from_name(name: &str, pt_size: f64) -> Result<CTFont, ()> {
|
||||
unsafe {
|
||||
let name: CFString = name.parse().unwrap();
|
||||
|
||||
@@ -11,6 +11,8 @@ use core_foundation::array::{CFArray, CFArrayRef};
|
||||
use core_foundation::base::TCFType;
|
||||
use core_foundation::string::CFString;
|
||||
use core_foundation::url::CFURLRef;
|
||||
use core_foundation::data::{CFDataRef, CFData};
|
||||
use crate::font_descriptor::{CTFontDescriptorRef, CTFontDescriptor};
|
||||
|
||||
pub fn copy_available_font_family_names() -> CFArray<CFString> {
|
||||
unsafe {
|
||||
@@ -18,6 +20,17 @@ pub fn copy_available_font_family_names() -> CFArray<CFString> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_font_descriptor(buffer: &[u8]) -> Result<CTFontDescriptor, ()> {
|
||||
let cf_data = CFData::from_buffer(buffer);
|
||||
unsafe {
|
||||
let ct_font_descriptor_ref = CTFontManagerCreateFontDescriptorFromData(cf_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
|
||||
@@ -31,6 +44,7 @@ extern {
|
||||
pub fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef;
|
||||
pub fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef;
|
||||
pub fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef;
|
||||
pub fn CTFontManagerCreateFontDescriptorFromData(data: CFDataRef) -> CTFontDescriptorRef;
|
||||
//pub fn CTFontManagerCreateFontRequestRunLoopSource
|
||||
//pub fn CTFontManagerEnableFontDescriptors
|
||||
//pub fn CTFontManagerGetAutoActivationSetting
|
||||
|
||||
Reference in New Issue
Block a user