From 98ce55f22c9893e3cd1027ab74b825e2d62132a4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 16:38:15 -0700 Subject: [PATCH] Update for language changes --- font.rs | 20 ++++++++++++-------- font_collection.rs | 36 ++++++++++++++++++++---------------- font_descriptor.rs | 6 +++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/font.rs b/font.rs index 1ae1361..7846c38 100644 --- a/font.rs +++ b/font.rs @@ -17,7 +17,7 @@ use core_foundation::array::{CFArrayRef}; use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef}; use core_foundation::base::{CFWrapper}; 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_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; @@ -119,7 +119,7 @@ pub trait CTFontMethods { pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { unsafe { - let result = CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), + let result = CTFontCreateWithGraphicsFont(*cgfont.contents.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()); @@ -139,8 +139,12 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { pub fn new_from_name(name: ~str, pt_size: float) -> Result { unsafe { let cfname = CFString::new(name); - let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); - if result.is_null() { return Err(()); } + let result = CTFontCreateWithName(*cfname.contents.borrow_ref(), + pt_size as CGFloat, + ptr::null()); + if result.is_null() { + return Err(()); + } return Ok(CFWrapper::wrap_owned(result)); } @@ -164,7 +168,7 @@ impl CTFontMethods for CTFont { fn copy_to_CGFont(&self) -> CGFont { unsafe { let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); - CFWrapper::wrap_owned(value) + CGFont::wrap_owned(value) } } @@ -210,7 +214,7 @@ impl CTFontMethods for CTFont { fn all_traits(&self) -> CTFontTraits { unsafe { let result = CTFontCopyTraits(self.obj); - CFWrapper::wrap_owned(result) + CFDictionary::wrap_owned(result) } } @@ -291,7 +295,7 @@ impl CTFontMethods for CTFont { kCTFontTableOptionsExcludeSynthetic); return match result.is_null() { true => None, - false => Some(CFWrapper::wrap_owned(result)), + false => Some(CFData::wrap_owned(result)), } } } @@ -303,7 +307,7 @@ priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~ let result = CTFontCopyName(*font.borrow_ref(), name_key); if result.is_null() { return None; } - return Some(CFWrapper::wrap_owned(result).to_str()); + return Some(CFString::wrap_owned(result).to_str()); } } diff --git a/font_collection.rs b/font_collection.rs index c865315..196655a 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -44,28 +44,32 @@ impl CTFontCollectionMethods for CTFontCollection { // surprise! this function follows the Get rule, despite being named *Create*. // So we have to addRef it to avoid CTFontCollection from double freeing it later. unsafe { - CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + CFArray::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } } pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { - let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let options = CFDictionary::new([ + (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) + ]); unsafe { - let result = CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), - *options.borrow_ref()); + let result = CTFontCollectionCreateWithFontDescriptors(*descs.contents.borrow_ref(), + *options.contents.borrow_ref()); CFWrapper::wrap_owned(result) } } pub fn create_for_all_families() -> CTFontCollection { - let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let options = CFDictionary::new([ + (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) + ]); unsafe { - let result = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + let result = CTFontCollectionCreateFromAvailableFonts(*options.contents.borrow_ref()); CFWrapper::wrap_owned(result) } } @@ -73,24 +77,24 @@ pub fn create_for_all_families() -> CTFontCollection { pub fn create_for_family(family: &str) -> CTFontCollection { use font_descriptor::kCTFontFamilyNameAttribute; - let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); + let family_attr = CFString::wrap_shared(kCTFontFamilyNameAttribute); let family_name = CFString::new(family); - let specified_attrs: CFWrapper = + let specified_attrs: CFDictionary = CFDictionary::new([ - (*family_attr.borrow_ref(), *family_name.borrow_type_ref()) + (*family_attr.contents.borrow_ref(), *family_name.contents.borrow_type_ref()) ]); let wildcard_desc: CTFontDescriptor = - font_descriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); + font_descriptor::new_from_attributes(&specified_attrs.contents); + let mandatory_attrs = CFSet::new([ *family_attr.contents.borrow_ref() ]); let matched_descs = unsafe { CTFontDescriptorCreateMatchingFontDescriptors( *wildcard_desc.borrow_ref(), - *mandatory_attrs.borrow_ref()) + *mandatory_attrs.contents.borrow_ref()) }; - let matched_descs: CFArray = CFWrapper::wrap_owned(matched_descs); + let matched_descs: CFArray = CFArray::wrap_owned(matched_descs); // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. @@ -99,7 +103,7 @@ pub fn create_for_family(family: &str) -> CTFontCollection { pub fn get_family_names() -> CFArray { unsafe { - CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) + CFArray::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) } } diff --git a/font_descriptor.rs b/font_descriptor.rs index 8974906..c8d6c5e 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -14,7 +14,7 @@ use core_foundation::base::{CFTypeID, CFTypeRef, CFWrapper}; use core_foundation::dictionary::{CFDictionaryRef, UntypedCFDictionary}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; -use core_foundation::string::CFStringRef; +use core_foundation::string::{CFString, CFStringRef}; use core_foundation::url::{CFURLRef}; use core_graphics::base::CGFloat; @@ -127,7 +127,7 @@ priv trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { priv fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let value = self.get(&key); - CFWrapper::wrap_shared(core_foundation::base::downcast::(value)) + CFNumber::wrap_shared(core_foundation::base::downcast::(value)) } } @@ -213,7 +213,7 @@ impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { return None; } - Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( + Some(CFString::wrap_owned(core_foundation::base::downcast::( value)).to_str()) } }