From 6847e69397f0635746d709f8f23a561191e32cfa Mon Sep 17 00:00:00 2001 From: Omar Akkila Date: Sun, 2 Jul 2017 14:04:14 +0400 Subject: [PATCH] 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 --- src/font.rs | 42 ++++++++++++++++++++++++++---------------- src/font_collection.rs | 3 ++- src/font_descriptor.rs | 27 ++++++++++++++++++--------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/font.rs b/src/font.rs index 747a547..1a04b1e 100644 --- a/src/font.rs +++ b/src/font.rs @@ -23,7 +23,7 @@ use core_graphics::context::{CGContext, CGContextRef}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGPoint, CGRect, CGSize}; -use libc::{self, size_t}; +use libc::{self, size_t, c_void}; use std::mem; use std::ptr; @@ -70,7 +70,7 @@ pub const kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0); pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); #[repr(C)] -struct __CTFont; +pub struct __CTFont(c_void); pub type CTFontRef = *const __CTFont; @@ -193,23 +193,31 @@ impl CTFont { // Names pub fn family_name(&self) -> String { - let value = get_string_by_name_key(self, kCTFontFamilyNameKey); - value.expect("Fonts should always have a family name.") + unsafe { + let value = get_string_by_name_key(self, kCTFontFamilyNameKey); + value.expect("Fonts should always have a family name.") + } } pub fn face_name(&self) -> String { - let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); - value.expect("Fonts should always have a face name.") + unsafe { + let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); + value.expect("Fonts should always have a face name.") + } } pub fn unique_name(&self) -> String { - let value = get_string_by_name_key(self, kCTFontUniqueNameKey); - value.expect("Fonts should always have a unique name.") + unsafe { + let value = get_string_by_name_key(self, kCTFontUniqueNameKey); + value.expect("Fonts should always have a unique name.") + } } pub fn postscript_name(&self) -> String { - let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); - value.expect("Fonts should always have a PostScript name.") + unsafe { + let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); + value.expect("Fonts should always have a PostScript name.") + } } pub fn all_traits(&self) -> CTFontTraits { @@ -357,12 +365,14 @@ pub fn debug_font_names(font: &CTFont) { get_string_by_name_key(font, key).unwrap() } - println!("kCTFontFamilyNameKey: {}", get_key(font, kCTFontFamilyNameKey)); - println!("kCTFontSubFamilyNameKey: {}", get_key(font, kCTFontSubFamilyNameKey)); - println!("kCTFontStyleNameKey: {}", get_key(font, kCTFontStyleNameKey)); - println!("kCTFontUniqueNameKey: {}", get_key(font, kCTFontUniqueNameKey)); - println!("kCTFontFullNameKey: {}", get_key(font, kCTFontFullNameKey)); - println!("kCTFontPostScriptNameKey: {}", get_key(font, kCTFontPostScriptNameKey)); + unsafe { + println!("kCTFontFamilyNameKey: {}", get_key(font, kCTFontFamilyNameKey)); + println!("kCTFontSubFamilyNameKey: {}", get_key(font, kCTFontSubFamilyNameKey)); + println!("kCTFontStyleNameKey: {}", get_key(font, kCTFontStyleNameKey)); + println!("kCTFontUniqueNameKey: {}", get_key(font, kCTFontUniqueNameKey)); + println!("kCTFontFullNameKey: {}", get_key(font, kCTFontFullNameKey)); + println!("kCTFontPostScriptNameKey: {}", get_key(font, kCTFontPostScriptNameKey)); + } } pub fn debug_font_traits(font: &CTFont) { diff --git a/src/font_collection.rs b/src/font_collection.rs index c2c5414..3304b3c 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -18,11 +18,12 @@ use core_foundation::number::CFNumber; use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; +use libc::c_void; use std::mem; use std::ptr; #[repr(C)] -struct __CTFontCollection; +pub struct __CTFontCollection(c_void); pub type CTFontCollectionRef = *const __CTFontCollection; diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 3cc40e8..e92fd1f 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -18,6 +18,7 @@ use core_foundation::string::{CFString, CFStringRef}; use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; +use libc::c_void; use std::mem; /* @@ -182,7 +183,7 @@ pub const kCTFontPriorityDynamic: CTFontPriority = 50000; pub const kCTFontPriorityProcess: CTFontPriority = 60000; #[repr(C)] -struct __CTFontDescriptor; +pub struct __CTFontDescriptor(c_void); pub type CTFontDescriptorRef = *const __CTFontDescriptor; @@ -252,23 +253,31 @@ impl CTFontDescriptor { impl CTFontDescriptor { pub fn family_name(&self) -> String { - let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect("A font2 must have a non-null font family name.") + unsafe { + let value = self.get_string_attribute(kCTFontDisplayNameAttribute); + value.expect("A font2 must have a non-null font family name.") + } } pub fn font_name(&self) -> String { - let value = self.get_string_attribute(kCTFontNameAttribute); - value.expect("A font must have a non-null name.") + unsafe { + let value = self.get_string_attribute(kCTFontNameAttribute); + value.expect("A font must have a non-null name.") + } } pub fn style_name(&self) -> String { - let value = self.get_string_attribute(kCTFontStyleNameAttribute); - value.expect("A font must have a non-null style name.") + unsafe { + let value = self.get_string_attribute(kCTFontStyleNameAttribute); + value.expect("A font must have a non-null style name.") + } } pub fn display_name(&self) -> String { - let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect("A font must have a non-null display name.") + unsafe { + let value = self.get_string_attribute(kCTFontDisplayNameAttribute); + value.expect("A font must have a non-null display name.") + } } pub fn font_path(&self) -> Option {