From c4344498aec64a01fa080fa037640320ef7ad0f9 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 6 Feb 2018 17:39:36 -0800 Subject: [PATCH] Allow creating font descriptor with PostScript name --- core-text/src/font_collection.rs | 8 +++++++- core-text/src/font_descriptor.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core-text/src/font_collection.rs b/core-text/src/font_collection.rs index e4a2763..3e61a23 100644 --- a/core-text/src/font_collection.rs +++ b/core-text/src/font_collection.rs @@ -9,7 +9,7 @@ use font_descriptor; use font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescriptors}; -use font_manager::CTFontManagerCopyAvailableFontFamilyNames; +use font_manager::{CTFontManagerCopyAvailableFontFamilyNames, CTFontManagerCopyAvailablePostScriptNames}; use core_foundation::array::{CFArray, CFArrayRef}; use core_foundation::base::{CFTypeID, TCFType}; @@ -97,6 +97,12 @@ pub fn get_family_names() -> CFArray { } } +pub fn get_postscript_names() -> CFArray { + unsafe { + CFArray::wrap_under_create_rule(CTFontManagerCopyAvailablePostScriptNames()) + } +} + extern { /* * CTFontCollection.h diff --git a/core-text/src/font_descriptor.rs b/core-text/src/font_descriptor.rs index 0da9c8f..904e802 100644 --- a/core-text/src/font_descriptor.rs +++ b/core-text/src/font_descriptor.rs @@ -282,6 +282,14 @@ pub fn new_from_variations(variations: &CFDictionary) -> CTFontD } } +pub fn new_from_postscript_name(name: &CFString) -> CTFontDescriptor { + unsafe { + let result: CTFontDescriptorRef = + CTFontDescriptorCreateWithNameAndSize(name.as_concrete_TypeRef(), 0.0); + CTFontDescriptor::wrap_under_create_rule(result) + } +} + pub fn debug_descriptor(desc: &CTFontDescriptor) { println!("family: {}", desc.family_name()); println!("name: {}", desc.font_name());