Merge pull request #4 from pcwalton/language-changes
Update for language changes
This commit is contained in:
@@ -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<CTFont, ()> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-16
@@ -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<CTFontDescriptorRef>) -> 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<CFDictionaryRef,CFStringRef,CFTypeRef> =
|
||||
let specified_attrs: CFDictionary<CFStringRef,CFTypeRef> =
|
||||
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<CTFontDescriptorRef> = CFWrapper::wrap_owned(matched_descs);
|
||||
let matched_descs: CFArray<CTFontDescriptorRef> = 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<CFStringRef> {
|
||||
unsafe {
|
||||
CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames())
|
||||
CFArray::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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::<CFNumberRef>(value))
|
||||
CFNumber::wrap_shared(core_foundation::base::downcast::<CFNumberRef>(value))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -213,7 +213,7 @@ impl CTFontDescriptorMethodsPrivate for CTFontDescriptor {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(CFWrapper::wrap_owned(core_foundation::base::downcast::<CFStringRef>(
|
||||
Some(CFString::wrap_owned(core_foundation::base::downcast::<CFStringRef>(
|
||||
value)).to_str())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user