diff --git a/core-text/Cargo.toml b/core-text/Cargo.toml index fcb99db..615d173 100644 --- a/core-text/Cargo.toml +++ b/core-text/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "9.1.1" +version = "9.1.2" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 570ed95..06713da 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -9,13 +9,14 @@ #![allow(non_upper_case_globals)] +use font_descriptor; use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFTypeRef, TCFType}; +use core_foundation::base::{CFIndex, CFOptionFlags, CFType, CFTypeID, CFTypeRef, TCFType}; use core_foundation::data::{CFData, CFDataRef}; -use core_foundation::dictionary::CFDictionaryRef; +use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; @@ -95,6 +96,20 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { } } +pub fn new_from_CGFont_with_variations(cgfont: &CGFont, + pt_size: f64, + variations: &CFDictionary) + -> CTFont { + unsafe { + let font_desc = font_descriptor::new_from_variations(variations); + let font_ref = CTFontCreateWithGraphicsFont(cgfont.as_ptr() as *mut _, + pt_size as CGFloat, + ptr::null(), + font_desc.as_concrete_TypeRef()); + CTFont::wrap_under_create_rule(font_ref) + } +} + pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { unsafe { let font_ref = CTFontCreateWithFontDescriptor(desc.as_concrete_TypeRef(), diff --git a/core-text/src/font_descriptor.rs b/core-text/src/font_descriptor.rs index c7bf0f7..0da9c8f 100644 --- a/core-text/src/font_descriptor.rs +++ b/core-text/src/font_descriptor.rs @@ -273,6 +273,15 @@ pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontD } } +pub fn new_from_variations(variations: &CFDictionary) -> CTFontDescriptor { + unsafe { + let var_key = CFType::wrap_under_get_rule(mem::transmute(kCTFontVariationAttribute)); + let var_val = CFType::wrap_under_get_rule(variations.as_CFTypeRef()); + let attributes = CFDictionary::from_CFType_pairs(&[(var_key, var_val)]); + new_from_attributes(&attributes) + } +} + pub fn debug_descriptor(desc: &CTFontDescriptor) { println!("family: {}", desc.family_name()); println!("name: {}", desc.font_name());