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

Fix core-text related warnings (#62) #65

Merged
merged 1 commit into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/font_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
27 changes: 18 additions & 9 deletions src/font_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> {
Expand Down