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

Commit 6847e69

Browse files
committed
Fix core-text related warnings (#62)
Fix private-in-public warnings (error E0446) Fix use of extern static warnings by wrapping in unsafe block (error E0133) Fix zero-size struct warnings on certain CT* types
1 parent 91227a0 commit 6847e69

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

src/font.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core_graphics::context::{CGContext, CGContextRef};
2323
use core_graphics::font::{CGGlyph, CGFont, CGFontRef};
2424
use core_graphics::geometry::{CGPoint, CGRect, CGSize};
2525

26-
use libc::{self, size_t};
26+
use libc::{self, size_t, c_void};
2727
use std::mem;
2828
use std::ptr;
2929

@@ -70,7 +70,7 @@ pub const kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0);
7070
pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2);
7171

7272
#[repr(C)]
73-
struct __CTFont;
73+
pub struct __CTFont(c_void);
7474

7575
pub type CTFontRef = *const __CTFont;
7676

@@ -193,23 +193,31 @@ impl CTFont {
193193

194194
// Names
195195
pub fn family_name(&self) -> String {
196-
let value = get_string_by_name_key(self, kCTFontFamilyNameKey);
197-
value.expect("Fonts should always have a family name.")
196+
unsafe {
197+
let value = get_string_by_name_key(self, kCTFontFamilyNameKey);
198+
value.expect("Fonts should always have a family name.")
199+
}
198200
}
199201

200202
pub fn face_name(&self) -> String {
201-
let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey);
202-
value.expect("Fonts should always have a face name.")
203+
unsafe {
204+
let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey);
205+
value.expect("Fonts should always have a face name.")
206+
}
203207
}
204208

205209
pub fn unique_name(&self) -> String {
206-
let value = get_string_by_name_key(self, kCTFontUniqueNameKey);
207-
value.expect("Fonts should always have a unique name.")
210+
unsafe {
211+
let value = get_string_by_name_key(self, kCTFontUniqueNameKey);
212+
value.expect("Fonts should always have a unique name.")
213+
}
208214
}
209215

210216
pub fn postscript_name(&self) -> String {
211-
let value = get_string_by_name_key(self, kCTFontPostScriptNameKey);
212-
value.expect("Fonts should always have a PostScript name.")
217+
unsafe {
218+
let value = get_string_by_name_key(self, kCTFontPostScriptNameKey);
219+
value.expect("Fonts should always have a PostScript name.")
220+
}
213221
}
214222

215223
pub fn all_traits(&self) -> CTFontTraits {
@@ -357,12 +365,14 @@ pub fn debug_font_names(font: &CTFont) {
357365
get_string_by_name_key(font, key).unwrap()
358366
}
359367

360-
println!("kCTFontFamilyNameKey: {}", get_key(font, kCTFontFamilyNameKey));
361-
println!("kCTFontSubFamilyNameKey: {}", get_key(font, kCTFontSubFamilyNameKey));
362-
println!("kCTFontStyleNameKey: {}", get_key(font, kCTFontStyleNameKey));
363-
println!("kCTFontUniqueNameKey: {}", get_key(font, kCTFontUniqueNameKey));
364-
println!("kCTFontFullNameKey: {}", get_key(font, kCTFontFullNameKey));
365-
println!("kCTFontPostScriptNameKey: {}", get_key(font, kCTFontPostScriptNameKey));
368+
unsafe {
369+
println!("kCTFontFamilyNameKey: {}", get_key(font, kCTFontFamilyNameKey));
370+
println!("kCTFontSubFamilyNameKey: {}", get_key(font, kCTFontSubFamilyNameKey));
371+
println!("kCTFontStyleNameKey: {}", get_key(font, kCTFontStyleNameKey));
372+
println!("kCTFontUniqueNameKey: {}", get_key(font, kCTFontUniqueNameKey));
373+
println!("kCTFontFullNameKey: {}", get_key(font, kCTFontFullNameKey));
374+
println!("kCTFontPostScriptNameKey: {}", get_key(font, kCTFontPostScriptNameKey));
375+
}
366376
}
367377

368378
pub fn debug_font_traits(font: &CTFont) {

src/font_collection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use core_foundation::number::CFNumber;
1818
use core_foundation::set::CFSet;
1919
use core_foundation::string::{CFString, CFStringRef};
2020

21+
use libc::c_void;
2122
use std::mem;
2223
use std::ptr;
2324

2425
#[repr(C)]
25-
struct __CTFontCollection;
26+
pub struct __CTFontCollection(c_void);
2627

2728
pub type CTFontCollectionRef = *const __CTFontCollection;
2829

src/font_descriptor.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core_foundation::string::{CFString, CFStringRef};
1818
use core_foundation::url::{CFURL, CFURLRef};
1919
use core_graphics::base::CGFloat;
2020

21+
use libc::c_void;
2122
use std::mem;
2223

2324
/*
@@ -182,7 +183,7 @@ pub const kCTFontPriorityDynamic: CTFontPriority = 50000;
182183
pub const kCTFontPriorityProcess: CTFontPriority = 60000;
183184

184185
#[repr(C)]
185-
struct __CTFontDescriptor;
186+
pub struct __CTFontDescriptor(c_void);
186187

187188
pub type CTFontDescriptorRef = *const __CTFontDescriptor;
188189

@@ -252,23 +253,31 @@ impl CTFontDescriptor {
252253

253254
impl CTFontDescriptor {
254255
pub fn family_name(&self) -> String {
255-
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
256-
value.expect("A font2 must have a non-null font family name.")
256+
unsafe {
257+
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
258+
value.expect("A font2 must have a non-null font family name.")
259+
}
257260
}
258261

259262
pub fn font_name(&self) -> String {
260-
let value = self.get_string_attribute(kCTFontNameAttribute);
261-
value.expect("A font must have a non-null name.")
263+
unsafe {
264+
let value = self.get_string_attribute(kCTFontNameAttribute);
265+
value.expect("A font must have a non-null name.")
266+
}
262267
}
263268

264269
pub fn style_name(&self) -> String {
265-
let value = self.get_string_attribute(kCTFontStyleNameAttribute);
266-
value.expect("A font must have a non-null style name.")
270+
unsafe {
271+
let value = self.get_string_attribute(kCTFontStyleNameAttribute);
272+
value.expect("A font must have a non-null style name.")
273+
}
267274
}
268275

269276
pub fn display_name(&self) -> String {
270-
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
271-
value.expect("A font must have a non-null display name.")
277+
unsafe {
278+
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
279+
value.expect("A font must have a non-null display name.")
280+
}
272281
}
273282

274283
pub fn font_path(&self) -> Option<String> {

0 commit comments

Comments
 (0)