Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 46213a7

Browse files
committed
Use typed wrap_under_{create,get}_rule() functions
Just some minor cleanup; no functional changes.
1 parent c0c69ae commit 46213a7

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

src/font.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont {
9191
pt_size as CGFloat,
9292
ptr::null(),
9393
ptr::null());
94-
TCFType::wrap_under_create_rule(font_ref)
94+
CTFont::wrap_under_create_rule(font_ref)
9595
}
9696
}
9797

@@ -100,7 +100,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont {
100100
let font_ref = CTFontCreateWithFontDescriptor(desc.as_concrete_TypeRef(),
101101
pt_size as CGFloat,
102102
ptr::null());
103-
TCFType::wrap_under_create_rule(font_ref)
103+
CTFont::wrap_under_create_rule(font_ref)
104104
}
105105
}
106106

@@ -113,7 +113,7 @@ pub fn new_from_name(name: &str, pt_size: f64) -> Result<CTFont, ()> {
113113
if font_ref.is_null() {
114114
Err(())
115115
} else {
116-
Ok(TCFType::wrap_under_create_rule(font_ref))
116+
Ok(CTFont::wrap_under_create_rule(font_ref))
117117
}
118118
}
119119
}
@@ -142,7 +142,7 @@ impl CTFont {
142142
size as CGFloat,
143143
ptr::null(),
144144
ptr::null());
145-
TCFType::wrap_under_create_rule(font_ref)
145+
CTFont::wrap_under_create_rule(font_ref)
146146
}
147147
}
148148

@@ -177,7 +177,7 @@ impl CTFont {
177177

178178
pub fn all_traits(&self) -> CTFontTraits {
179179
unsafe {
180-
TCFType::wrap_under_create_rule(CTFontCopyTraits(self.0))
180+
CTFontTraits::wrap_under_create_rule(CTFontCopyTraits(self.0))
181181
}
182182
}
183183

@@ -262,7 +262,7 @@ impl CTFont {
262262
if result.is_null() {
263263
None
264264
} else {
265-
Some(TCFType::wrap_under_create_rule(result))
265+
Some(CFData::wrap_under_create_rule(result))
266266
}
267267
}
268268
}
@@ -296,7 +296,7 @@ impl CTFont {
296296
if result.is_null() {
297297
None
298298
} else {
299-
Some(TCFType::wrap_under_create_rule(result as CFURLRef))
299+
Some(CFURL::wrap_under_create_rule(result as CFURLRef))
300300
}
301301
}
302302
}
@@ -321,8 +321,7 @@ fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<String
321321
if result.is_null() {
322322
None
323323
} else {
324-
let string: CFString = TCFType::wrap_under_create_rule(result);
325-
Some(string.to_string())
324+
Some(CFString::wrap_under_create_rule(result).to_string())
326325
}
327326
}
328327
}
@@ -362,7 +361,7 @@ pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray<CF
362361
let font_collection_ref =
363362
CTFontCopyDefaultCascadeListForLanguages(font.as_concrete_TypeRef(),
364363
language_pref_list.as_concrete_TypeRef());
365-
TCFType::wrap_under_create_rule(font_collection_ref)
364+
CFArray::wrap_under_create_rule(font_collection_ref)
366365
}
367366
}
368367

@@ -419,7 +418,7 @@ extern {
419418
matrix: *const CGAffineTransform) -> CTFontRef;
420419
//fn CTFontCreateWithFontDescriptorAndOptions
421420
//fn CTFontCreateUIFontForLanguage
422-
fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *const CGAffineTransform,
421+
fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *const CGAffineTransform,
423422
attributes: CTFontDescriptorRef) -> CTFontRef;
424423
//fn CTFontCreateCopyWithSymbolicTraits
425424
//fn CTFontCreateCopyWithFamily
@@ -439,7 +438,7 @@ extern {
439438
//fn CTFontCopyFullName(font: CTFontRef) -> CFStringRef;
440439
//fn CTFontCopyDisplayName(font: CTFontRef) -> CFStringRef;
441440
fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef;
442-
//fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef,
441+
//fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef,
443442
// language: *CFStringRef) -> CFStringRef;
444443
#[cfg(feature = "mountainlion")]
445444
fn CTFontCopyDefaultCascadeListForLanguages(font: CTFontRef, languagePrefList: CFArrayRef) -> CFArrayRef;
@@ -496,8 +495,8 @@ extern {
496495
/* Converting Fonts */
497496
fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *mut CTFontDescriptorRef)
498497
-> CGFontRef;
499-
fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat,
500-
matrix: *const CGAffineTransform,
498+
fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat,
499+
matrix: *const CGAffineTransform,
501500
attributes: CTFontDescriptorRef) -> CTFontRef;
502501
//fn CTFontGetPlatformFont
503502
//fn CTFontCreateWithPlatformFont

src/font_collection.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,39 @@ impl CTFontCollection {
3838
// surprise! this function follows the Get rule, despite being named *Create*.
3939
// So we have to addRef it to avoid CTFontCollection from double freeing it later.
4040
unsafe {
41-
TCFType::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0))
41+
CFArray::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0))
4242
}
4343
}
4444
}
4545

4646
pub fn new_from_descriptors(descs: &CFArray<CTFontDescriptor>) -> CTFontCollection {
4747
unsafe {
48-
let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption);
48+
let key = CFString::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption);
4949
let value = CFNumber::from(1i64);
5050
let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]);
5151
let font_collection_ref =
5252
CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(),
5353
options.as_concrete_TypeRef());
54-
TCFType::wrap_under_create_rule(font_collection_ref)
54+
CTFontCollection::wrap_under_create_rule(font_collection_ref)
5555
}
5656
}
5757

5858
pub fn create_for_all_families() -> CTFontCollection {
5959
unsafe {
60-
let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption);
60+
let key = CFString::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption);
6161
let value = CFNumber::from(1i64);
6262
let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]);
6363
let font_collection_ref =
6464
CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef());
65-
TCFType::wrap_under_create_rule(font_collection_ref)
65+
CTFontCollection::wrap_under_create_rule(font_collection_ref)
6666
}
6767
}
6868

6969
pub fn create_for_family(family: &str) -> Option<CTFontCollection> {
7070
use font_descriptor::kCTFontFamilyNameAttribute;
7171

7272
unsafe {
73-
let family_attr: CFString = TCFType::wrap_under_get_rule(kCTFontFamilyNameAttribute);
73+
let family_attr = CFString::wrap_under_get_rule(kCTFontFamilyNameAttribute);
7474
let family_name: CFString = family.parse().unwrap();
7575
let specified_attrs = CFDictionary::from_CFType_pairs(&[
7676
(family_attr.as_CFType(), family_name.as_CFType())
@@ -85,7 +85,7 @@ pub fn create_for_family(family: &str) -> Option<CTFontCollection> {
8585
if matched_descs == ptr::null() {
8686
return None;
8787
}
88-
let matched_descs: CFArray<CTFontDescriptor> = TCFType::wrap_under_create_rule(matched_descs);
88+
let matched_descs = CFArray::wrap_under_create_rule(matched_descs);
8989
// I suppose one doesn't even need the CTFontCollection object at this point.
9090
// But we stick descriptors into and out of it just to provide a nice wrapper API.
9191
Some(new_from_descriptors(&matched_descs))
@@ -94,7 +94,7 @@ pub fn create_for_family(family: &str) -> Option<CTFontCollection> {
9494

9595
pub fn get_family_names() -> CFArray<CFString> {
9696
unsafe {
97-
TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames())
97+
CFArray::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames())
9898
}
9999
}
100100

@@ -109,7 +109,7 @@ extern {
109109
// descriptors: CFArrayRef,
110110
// options: CFDictionaryRef) -> CTFontCollectionRef;
111111
fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef;
112-
// this stupid function doesn't actually do any wildcard expansion;
112+
// this stupid function doesn't actually do any wildcard expansion;
113113
// it just chooses the best match. Use
114114
// CTFontDescriptorCreateMatchingDescriptors instead.
115115
fn CTFontCollectionCreateMatchingFontDescriptors(collection: CTFontCollectionRef) -> CFArrayRef;

src/font_descriptor.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl TraitAccessorPrivate for CTFontTraits {
131131
unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
132132
let cftype = self.get_CFType(mem::transmute(key));
133133
assert!(cftype.instance_of::<CFNumber>());
134-
TCFType::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef()))
134+
CFNumber::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef()))
135135
}
136136

137137
}
@@ -202,9 +202,9 @@ impl CTFontDescriptor {
202202
return None
203203
}
204204

205-
let value: CFType = TCFType::wrap_under_create_rule(value);
205+
let value = CFType::wrap_under_create_rule(value);
206206
assert!(value.instance_of::<CFString>());
207-
let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
207+
let s = CFString::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
208208
Some(s.to_string())
209209
}
210210
}
@@ -247,9 +247,9 @@ impl CTFontDescriptor {
247247
return None;
248248
}
249249

250-
let value: CFType = TCFType::wrap_under_create_rule(value);
250+
let value = CFType::wrap_under_create_rule(value);
251251
assert!(value.instance_of::<CFURL>());
252-
let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
252+
let url = CFURL::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
253253
Some(format!("{:?}", url))
254254
}
255255
}
@@ -258,10 +258,9 @@ impl CTFontDescriptor {
258258
unsafe {
259259
let value = CTFontDescriptorCopyAttribute(self.0, kCTFontTraitsAttribute);
260260
assert!(!value.is_null());
261-
let value: CFType = TCFType::wrap_under_create_rule(value);
261+
let value = CFType::wrap_under_create_rule(value);
262262
assert!(value.instance_of::<CFDictionary>());
263-
let dictionary: CFDictionary = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
264-
dictionary
263+
CFDictionary::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()))
265264
}
266265
}
267266
}
@@ -270,7 +269,7 @@ pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor {
270269
unsafe {
271270
let result: CTFontDescriptorRef =
272271
CTFontDescriptorCreateWithAttributes(attributes.as_concrete_TypeRef());
273-
TCFType::wrap_under_create_rule(result)
272+
CTFontDescriptor::wrap_under_create_rule(result)
274273
}
275274
}
276275

0 commit comments

Comments
 (0)