Merge pull request #1 from metajack/rust-0.6-syntax

Update to rust 0.6 syntax.
This commit is contained in:
Patrick Walton
2013-03-28 10:22:11 -07:00
4 changed files with 237 additions and 239 deletions
+104 -105
View File
@@ -4,7 +4,6 @@ extern mod core_graphics;
use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation};
use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors};
use core::libc::c_uint;
use core_foundation::array::{CFArrayRef};
use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef};
use core_foundation::base::{CFWrapper};
@@ -17,53 +16,53 @@ use core_graphics::geometry::{CGRect, CGSize};
pub type CTFontUIFontType = u32;
// kCTFontNoFontType: CTFontUIFontType = -1;
pub const kCTFontUserFontType: CTFontUIFontType = 0;
pub const kCTFontUserFixedPitchFontType: CTFontUIFontType = 1;
pub const kCTFontSystemFontType: CTFontUIFontType = 2;
pub const kCTFontEmphasizedSystemFontType: CTFontUIFontType = 3;
pub const kCTFontSmallSystemFontType: CTFontUIFontType = 4;
pub const kCTFontSmallEmphasizedSystemFontType: CTFontUIFontType = 5;
pub const kCTFontMiniSystemFontType: CTFontUIFontType = 6;
pub const kCTFontMiniEmphasizedSystemFontType: CTFontUIFontType = 7;
pub const kCTFontViewsFontType: CTFontUIFontType = 8;
pub const kCTFontApplicationFontType: CTFontUIFontType = 9;
pub const kCTFontLabelFontType: CTFontUIFontType = 10;
pub const kCTFontMenuTitleFontType: CTFontUIFontType = 11;
pub const kCTFontMenuItemFontType: CTFontUIFontType = 12;
pub const kCTFontMenuItemMarkFontType: CTFontUIFontType = 13;
pub const kCTFontMenuItemCmdKeyFontType: CTFontUIFontType = 14;
pub const kCTFontWindowTitleFontType: CTFontUIFontType = 15;
pub const kCTFontPushButtonFontType: CTFontUIFontType = 16;
pub const kCTFontUtilityWindowTitleFontType: CTFontUIFontType = 17;
pub const kCTFontAlertHeaderFontType: CTFontUIFontType = 18;
pub const kCTFontSystemDetailFontType: CTFontUIFontType = 19;
pub const kCTFontEmphasizedSystemDetailFontType: CTFontUIFontType = 20;
pub const kCTFontToolbarFontType: CTFontUIFontType = 21;
pub const kCTFontSmallToolbarFontType: CTFontUIFontType = 22;
pub const kCTFontMessageFontType: CTFontUIFontType = 23;
pub const kCTFontPaletteFontType: CTFontUIFontType = 24;
pub const kCTFontToolTipFontType: CTFontUIFontType = 25;
pub const kCTFontControlContentFontType: CTFontUIFontType = 26;
pub static kCTFontUserFontType: CTFontUIFontType = 0;
pub static kCTFontUserFixedPitchFontType: CTFontUIFontType = 1;
pub static kCTFontSystemFontType: CTFontUIFontType = 2;
pub static kCTFontEmphasizedSystemFontType: CTFontUIFontType = 3;
pub static kCTFontSmallSystemFontType: CTFontUIFontType = 4;
pub static kCTFontSmallEmphasizedSystemFontType: CTFontUIFontType = 5;
pub static kCTFontMiniSystemFontType: CTFontUIFontType = 6;
pub static kCTFontMiniEmphasizedSystemFontType: CTFontUIFontType = 7;
pub static kCTFontViewsFontType: CTFontUIFontType = 8;
pub static kCTFontApplicationFontType: CTFontUIFontType = 9;
pub static kCTFontLabelFontType: CTFontUIFontType = 10;
pub static kCTFontMenuTitleFontType: CTFontUIFontType = 11;
pub static kCTFontMenuItemFontType: CTFontUIFontType = 12;
pub static kCTFontMenuItemMarkFontType: CTFontUIFontType = 13;
pub static kCTFontMenuItemCmdKeyFontType: CTFontUIFontType = 14;
pub static kCTFontWindowTitleFontType: CTFontUIFontType = 15;
pub static kCTFontPushButtonFontType: CTFontUIFontType = 16;
pub static kCTFontUtilityWindowTitleFontType: CTFontUIFontType = 17;
pub static kCTFontAlertHeaderFontType: CTFontUIFontType = 18;
pub static kCTFontSystemDetailFontType: CTFontUIFontType = 19;
pub static kCTFontEmphasizedSystemDetailFontType: CTFontUIFontType = 20;
pub static kCTFontToolbarFontType: CTFontUIFontType = 21;
pub static kCTFontSmallToolbarFontType: CTFontUIFontType = 22;
pub static kCTFontMessageFontType: CTFontUIFontType = 23;
pub static kCTFontPaletteFontType: CTFontUIFontType = 24;
pub static kCTFontToolTipFontType: CTFontUIFontType = 25;
pub static kCTFontControlContentFontType: CTFontUIFontType = 26;
pub type CTFontTableTag = u32;
// TODO: create bindings for enum with 'chars' values
pub type CTFontTableOptions = u32;
pub const kCTFontTableOptionsNoOptions: CTFontTableOptions = 0;
pub const kCTFontTableOptionsExcludeSynthetic: CTFontTableOptions = (1 << 0);
pub static kCTFontTableOptionsNoOptions: CTFontTableOptions = 0;
pub static kCTFontTableOptionsExcludeSynthetic: CTFontTableOptions = (1 << 0);
pub type CTFontOptions = CFOptionFlags;
pub const kCTFontOptionsDefault: CTFontOptions = 0;
pub const kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0);
pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2);
pub static kCTFontOptionsDefault: CTFontOptions = 0;
pub static kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0);
pub static kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2);
struct __CTFont { private: () }
pub type CTFontRef = *__CTFont;
impl AbstractCFTypeRef for CTFontRef {
pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
static pure fn type_id() -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CTFontGetTypeID()
}
@@ -74,27 +73,27 @@ pub type CTFont = CFWrapper<CTFontRef, (), ()>;
pub trait CTFontMethods {
// Creation methods (statics below)
fn copy_to_CGFont(&const self) -> CGFont;
fn clone_with_font_size(&const self, size: float) -> CTFont;
fn copy_to_CGFont(&self) -> CGFont;
fn clone_with_font_size(&self, size: float) -> CTFont;
// Names
pure fn family_name(&self) -> ~str;
pure fn face_name(&self) -> ~str;
pure fn unique_name(&self) -> ~str;
pure fn postscript_name(&self) -> ~str;
fn family_name(&self) -> ~str;
fn face_name(&self) -> ~str;
fn unique_name(&self) -> ~str;
fn postscript_name(&self) -> ~str;
// Properties
pure fn all_traits(&self) -> CTFontTraits;
fn all_traits(&self) -> CTFontTraits;
// Font metrics
pure fn ascent(&self) -> CGFloat;
pure fn descent(&self) -> CGFloat;
pure fn underline_thickness(&self) -> CGFloat;
pure fn underline_position(&self) -> CGFloat;
pure fn bounding_box(&self) -> CGRect;
pure fn leading(&self) -> CGFloat;
pure fn x_height(&self) -> CGFloat;
pure fn pt_size(&self) -> CGFloat;
fn ascent(&self) -> CGFloat;
fn descent(&self) -> CGFloat;
fn underline_thickness(&self) -> CGFloat;
fn underline_position(&self) -> CGFloat;
fn bounding_box(&self) -> CGRect;
fn leading(&self) -> CGFloat;
fn x_height(&self) -> CGFloat;
fn pt_size(&self) -> CGFloat;
fn get_glyphs_for_characters(&self,
characters: *UniChar,
glyphs: *CGGlyph,
@@ -139,28 +138,28 @@ pub fn new_from_name(name: ~str, pt_size: float) -> Result<CTFont, ()> {
}
priv trait CTFontMethodsPrivate {
pure fn symbolic_traits() -> CTFontSymbolicTraits;
fn symbolic_traits(&self) -> CTFontSymbolicTraits;
}
pub impl CTFontMethodsPrivate for CTFont {
impl CTFontMethodsPrivate for CTFont {
// Properties
priv pure fn symbolic_traits() -> CTFontSymbolicTraits {
priv fn symbolic_traits(&self) -> CTFontSymbolicTraits {
unsafe {
CTFontGetSymbolicTraits(self.obj)
}
}
}
pub impl CTFontMethods for CTFont {
impl CTFontMethods for CTFont {
// Creation methods
fn copy_to_CGFont(&const self) -> CGFont {
fn copy_to_CGFont(&self) -> CGFont {
unsafe {
let value = CTFontCopyGraphicsFont(self.obj, ptr::null());
CFWrapper::wrap_owned(value)
}
}
fn clone_with_font_size(&const self, size: float) -> CTFont {
fn clone_with_font_size(&self, size: float) -> CTFont {
unsafe {
let result = CTFontCreateCopyWithAttributes(self.obj,
size as CGFloat,
@@ -171,35 +170,35 @@ pub impl CTFontMethods for CTFont {
}
// Names
pure fn family_name(&self) -> ~str {
fn family_name(&self) -> ~str {
unsafe {
let value = get_string_by_name_key(self, kCTFontFamilyNameKey);
return option::expect(value, ~"Fonts should always have a family name.");
value.expect(~"Fonts should always have a family name.")
}
}
pure fn face_name(&self) -> ~str {
fn face_name(&self) -> ~str {
unsafe {
let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey);
return option::expect(value, ~"Fonts should always have a face name.");
value.expect(~"Fonts should always have a face name.")
}
}
pure fn unique_name(&self) -> ~str {
fn unique_name(&self) -> ~str {
unsafe {
let value = get_string_by_name_key(self, kCTFontUniqueNameKey);
return option::expect(value, ~"Fonts should always have a unique name.");
value.expect(~"Fonts should always have a unique name.")
}
}
pure fn postscript_name(&self) -> ~str {
fn postscript_name(&self) -> ~str {
unsafe {
let value = get_string_by_name_key(self, kCTFontPostScriptNameKey);
return option::expect(value, ~"Fonts should always have a PostScript name.");
value.expect(~"Fonts should always have a PostScript name.")
}
}
pure fn all_traits(&self) -> CTFontTraits {
fn all_traits(&self) -> CTFontTraits {
unsafe {
let result = CTFontCopyTraits(self.obj);
CFWrapper::wrap_owned(result)
@@ -207,49 +206,49 @@ pub impl CTFontMethods for CTFont {
}
// Font metrics
pure fn ascent(&self) -> CGFloat {
fn ascent(&self) -> CGFloat {
unsafe {
CTFontGetAscent(self.obj)
}
}
pure fn descent(&self) -> CGFloat {
fn descent(&self) -> CGFloat {
unsafe {
CTFontGetDescent(self.obj)
}
}
pure fn underline_thickness(&self) -> CGFloat {
fn underline_thickness(&self) -> CGFloat {
unsafe {
CTFontGetUnderlineThickness(self.obj)
}
}
pure fn underline_position(&self) -> CGFloat {
fn underline_position(&self) -> CGFloat {
unsafe {
CTFontGetUnderlinePosition(self.obj)
}
}
pure fn bounding_box(&self) -> CGRect {
fn bounding_box(&self) -> CGRect {
unsafe {
CTFontGetBoundingBox(self.obj)
}
}
pure fn leading(&self) -> CGFloat {
fn leading(&self) -> CGFloat {
unsafe {
CTFontGetLeading(self.obj)
}
}
pure fn x_height(&self) -> CGFloat {
fn x_height(&self) -> CGFloat {
unsafe {
CTFontGetXHeight(self.obj)
}
}
pure fn pt_size(&self) -> CGFloat {
fn pt_size(&self) -> CGFloat {
unsafe {
CTFontGetSize(self.obj)
}
@@ -301,7 +300,7 @@ priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~
pub fn debug_font_names(font: &CTFont) {
fn get_key(font: &CTFont, key: CFStringRef) -> ~str {
option::unwrap(get_string_by_name_key(font, key))
get_string_by_name_key(font, key).unwrap()
}
io::println(fmt!("kCTFontFamilyNameKey: %s", get_key(font, kCTFontFamilyNameKey)));
@@ -334,39 +333,39 @@ extern {
*/
/* Name Specifier Constants */
const kCTFontCopyrightNameKey: CFStringRef;
const kCTFontFamilyNameKey: CFStringRef;
const kCTFontSubFamilyNameKey: CFStringRef;
const kCTFontStyleNameKey: CFStringRef;
const kCTFontUniqueNameKey: CFStringRef;
const kCTFontFullNameKey: CFStringRef;
const kCTFontVersionNameKey: CFStringRef;
const kCTFontPostScriptNameKey: CFStringRef;
const kCTFontTrademarkNameKey: CFStringRef;
const kCTFontManufacturerNameKey: CFStringRef;
const kCTFontDesignerNameKey: CFStringRef;
const kCTFontDescriptionNameKey: CFStringRef;
const kCTFontVendorURLNameKey: CFStringRef;
const kCTFontDesignerURLNameKey: CFStringRef;
const kCTFontLicenseNameKey: CFStringRef;
const kCTFontLicenseURLNameKey: CFStringRef;
const kCTFontSampleTextNameKey: CFStringRef;
const kCTFontPostScriptCIDNameKey: CFStringRef;
static kCTFontCopyrightNameKey: CFStringRef;
static kCTFontFamilyNameKey: CFStringRef;
static kCTFontSubFamilyNameKey: CFStringRef;
static kCTFontStyleNameKey: CFStringRef;
static kCTFontUniqueNameKey: CFStringRef;
static kCTFontFullNameKey: CFStringRef;
static kCTFontVersionNameKey: CFStringRef;
static kCTFontPostScriptNameKey: CFStringRef;
static kCTFontTrademarkNameKey: CFStringRef;
static kCTFontManufacturerNameKey: CFStringRef;
static kCTFontDesignerNameKey: CFStringRef;
static kCTFontDescriptionNameKey: CFStringRef;
static kCTFontVendorURLNameKey: CFStringRef;
static kCTFontDesignerURLNameKey: CFStringRef;
static kCTFontLicenseNameKey: CFStringRef;
static kCTFontLicenseURLNameKey: CFStringRef;
static kCTFontSampleTextNameKey: CFStringRef;
static kCTFontPostScriptCIDNameKey: CFStringRef;
const kCTFontVariationAxisIdentifierKey: CFStringRef;
const kCTFontVariationAxisMinimumValueKey: CFStringRef;
const kCTFontVariationAxisMaximumValueKey: CFStringRef;
const kCTFontVariationAxisDefaultValueKey: CFStringRef;
const kCTFontVariationAxisNameKey: CFStringRef;
static kCTFontVariationAxisIdentifierKey: CFStringRef;
static kCTFontVariationAxisMinimumValueKey: CFStringRef;
static kCTFontVariationAxisMaximumValueKey: CFStringRef;
static kCTFontVariationAxisDefaultValueKey: CFStringRef;
static kCTFontVariationAxisNameKey: CFStringRef;
const kCTFontFeatureTypeIdentifierKey: CFStringRef;
const kCTFontFeatureTypeNameKey: CFStringRef;
const kCTFontFeatureTypeExclusiveKey: CFStringRef;
const kCTFontFeatureTypeSelectorsKey: CFStringRef;
const kCTFontFeatureSelectorIdentifierKey: CFStringRef;
const kCTFontFeatureSelectorNameKey: CFStringRef;
const kCTFontFeatureSelectorDefaultKey: CFStringRef;
const kCTFontFeatureSelectorSettingKey: CFStringRef;
static kCTFontFeatureTypeIdentifierKey: CFStringRef;
static kCTFontFeatureTypeNameKey: CFStringRef;
static kCTFontFeatureTypeExclusiveKey: CFStringRef;
static kCTFontFeatureTypeSelectorsKey: CFStringRef;
static kCTFontFeatureSelectorIdentifierKey: CFStringRef;
static kCTFontFeatureSelectorNameKey: CFStringRef;
static kCTFontFeatureSelectorDefaultKey: CFStringRef;
static kCTFontFeatureSelectorSettingKey: CFStringRef;
// N.B. Unlike most Cocoa bindings, this extern block is organized according
// to the documentation's Functions By Task listing, because there so many functions.
+8 -11
View File
@@ -3,10 +3,9 @@ use font_descriptor::{CTFontAttributes, CTFontDescriptor};
use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef};
use font_manager::CTFontManagerCopyAvailableFontFamilyNames;
use core::libc::c_void;
use core_foundation::array::{CFArray, CFArrayRef};
use core_foundation::base::{AbstractCFTypeRef, CFAllocatorRef, CFIndex, CFRange, CFTypeID};
use core_foundation::base::{CFTypeRef, CFWrapper, kCFAllocatorDefault};
use core_foundation::base::{CFTypeRef, CFWrapper};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary};
use core_foundation::number::CFNumber;
use core_foundation::set::CFSet;
@@ -16,9 +15,9 @@ struct __CTFontCollection { private: () }
pub type CTFontCollectionRef = *__CTFontCollection;
impl AbstractCFTypeRef for CTFontCollectionRef {
pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
static pure fn type_id() -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CTFontCollectionGetTypeID()
}
@@ -28,13 +27,11 @@ impl AbstractCFTypeRef for CTFontCollectionRef {
pub type CTFontCollection = CFWrapper<CTFontCollectionRef, (), ()>;
pub trait CTFontCollectionMethods {
pure fn get_descriptors() -> CFArray<CTFontDescriptorRef>;
fn get_descriptors(&self) -> CFArray<CTFontDescriptorRef>;
}
pub impl CTFontCollectionMethods for CTFontCollection {
pure fn get_descriptors() -> CFArray<CTFontDescriptorRef> {
use core_foundation::base::CFRetain;
impl CTFontCollectionMethods for CTFontCollection {
fn get_descriptors(&self) -> CFArray<CTFontDescriptorRef> {
// 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 {
@@ -91,7 +88,7 @@ pub fn create_for_family(family: &str) -> CTFontCollection {
new_from_descriptors(&matched_descs)
}
pub pure fn get_family_names() -> CFArray<CFStringRef> {
pub fn get_family_names() -> CFArray<CFStringRef> {
unsafe {
CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames())
}
@@ -102,7 +99,7 @@ extern {
* CTFontCollection.h
*/
const kCTFontCollectionRemoveDuplicatesOption: CFStringRef;
static kCTFontCollectionRemoveDuplicatesOption: CFStringRef;
fn CTFontCollectionCreateCopyWithFontDescriptors(original: CTFontCollectionRef,
descriptors: CFArrayRef,
+124 -122
View File
@@ -1,78 +1,77 @@
use core_foundation;
use core_foundation::array::CFArrayRef;
use core_foundation::base::{AbstractCFTypeRef, CFAllocatorRef, CFIndex, CFGetTypeID, CFRange};
use core_foundation::base::{CFType, CFTypeID, CFTypeRef, CFWrapper, kCFAllocatorDefault};
use core_foundation::base::{CFType, CFTypeID, CFTypeRef, CFWrapper};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary};
use core_foundation::number::{CFNumber, CFNumberRef};
use core_foundation::set::CFSetRef;
use core_foundation::string::{CFString, CFStringRef, CFStringGetTypeID};
use core_foundation::url::{CFURL, CFURLRef, CFURLGetTypeID};
use core_graphics::base::CGFloat;
use libc::c_void;
/*
* CTFontTraits.h
*/
// actually, these are extern enums
pub type CTFontFormat = u32;
pub const kCTFontFormatUnrecognized: CTFontFormat = 0;
pub const kCTFontFormatOpenTypePostScript: CTFontFormat = 1;
pub const kCTFontFormatOpenTypeTrueType: CTFontFormat = 2;
pub const kCTFontFormatTrueType: CTFontFormat = 3;
pub const kCTFontFormatPostScript: CTFontFormat = 4;
pub const kCTFontFormatBitmap: CTFontFormat = 5;
pub static kCTFontFormatUnrecognized: CTFontFormat = 0;
pub static kCTFontFormatOpenTypePostScript: CTFontFormat = 1;
pub static kCTFontFormatOpenTypeTrueType: CTFontFormat = 2;
pub static kCTFontFormatTrueType: CTFontFormat = 3;
pub static kCTFontFormatPostScript: CTFontFormat = 4;
pub static kCTFontFormatBitmap: CTFontFormat = 5;
pub const kCTFontClassMaskShift: u32 = 28;
pub static kCTFontClassMaskShift: u32 = 28;
pub type CTFontSymbolicTraits = u32;
pub const kCTFontItalicTrait: CTFontSymbolicTraits = (1 << 0);
pub const kCTFontBoldTrait: CTFontSymbolicTraits = (1 << 1);
pub const kCTFontExpandedTrait: CTFontSymbolicTraits = (1 << 5);
pub const kCTFontCondensedTrait: CTFontSymbolicTraits = (1 << 6);
pub const kCTFontMonoSpaceTrait: CTFontSymbolicTraits = (1 << 10);
pub const kCTFontVerticalTrait: CTFontSymbolicTraits = (1 << 11);
pub const kCTFontUIOptimizedTrait: CTFontSymbolicTraits = (1 << 12);
pub const kCTFontClassMaskTrait: CTFontSymbolicTraits = (15 << kCTFontClassMaskShift);
pub static kCTFontItalicTrait: CTFontSymbolicTraits = (1 << 0);
pub static kCTFontBoldTrait: CTFontSymbolicTraits = (1 << 1);
pub static kCTFontExpandedTrait: CTFontSymbolicTraits = (1 << 5);
pub static kCTFontCondensedTrait: CTFontSymbolicTraits = (1 << 6);
pub static kCTFontMonoSpaceTrait: CTFontSymbolicTraits = (1 << 10);
pub static kCTFontVerticalTrait: CTFontSymbolicTraits = (1 << 11);
pub static kCTFontUIOptimizedTrait: CTFontSymbolicTraits = (1 << 12);
pub static kCTFontClassMaskTrait: CTFontSymbolicTraits = (15 << kCTFontClassMaskShift);
pub trait SymbolicTraitAccessors {
pure fn is_italic() -> bool;
pure fn is_bold() -> bool;
pure fn is_expanded() -> bool;
pure fn is_condensed() -> bool;
pure fn is_monospace() -> bool;
fn is_italic(&self) -> bool;
fn is_bold(&self) -> bool;
fn is_expanded(&self) -> bool;
fn is_condensed(&self) -> bool;
fn is_monospace(&self) -> bool;
}
pub impl SymbolicTraitAccessors for CTFontSymbolicTraits {
pure fn is_italic() -> bool { (self & kCTFontItalicTrait) != 0 }
pure fn is_bold() -> bool { (self & kCTFontBoldTrait) != 0 }
pure fn is_expanded() -> bool { (self & kCTFontExpandedTrait) != 0 }
pure fn is_condensed() -> bool { (self & kCTFontCondensedTrait) != 0 }
pure fn is_monospace() -> bool { (self & kCTFontMonoSpaceTrait) != 0 }
impl SymbolicTraitAccessors for CTFontSymbolicTraits {
fn is_italic(&self) -> bool { (*self & kCTFontItalicTrait) != 0 }
fn is_bold(&self) -> bool { (*self & kCTFontBoldTrait) != 0 }
fn is_expanded(&self) -> bool { (*self & kCTFontExpandedTrait) != 0 }
fn is_condensed(&self) -> bool { (*self & kCTFontCondensedTrait) != 0 }
fn is_monospace(&self) -> bool { (*self & kCTFontMonoSpaceTrait) != 0 }
}
pub type CTFontStylisticClass = u32;
pub const kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift);
pub const kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift);
pub const kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift);
pub const kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift);
pub const kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift);
pub const kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift);
pub const kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift);
pub const kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift);
pub const kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift);
pub const kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift);
pub const kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift);
pub static kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift);
pub static kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift);
pub static kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift);
pub static kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift);
pub static kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift);
pub static kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift);
pub static kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift);
pub static kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift);
pub static kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift);
pub static kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift);
pub static kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift);
pub trait StylisticClassAccessors {
pure fn is_serif() -> bool;
pure fn is_sans_serif() -> bool;
pure fn is_script() -> bool;
pure fn is_fantasy() -> bool;
pure fn is_symbols() -> bool;
fn is_serif(&self) -> bool;
fn is_sans_serif(&self) -> bool;
fn is_script(&self) -> bool;
fn is_fantasy(&self) -> bool;
fn is_symbols(&self) -> bool;
}
pub impl StylisticClassAccessors for CTFontStylisticClass {
pure fn is_serif() -> bool {
impl StylisticClassAccessors for CTFontStylisticClass {
fn is_serif(&self) -> bool {
unsafe {
let any_serif_class = kCTFontOldStyleSerifsClass
| kCTFontTransitionalSerifsClass
@@ -81,24 +80,24 @@ pub impl StylisticClassAccessors for CTFontStylisticClass {
| kCTFontSlabSerifsClass
| kCTFontFreeformSerifsClass;
return (self & any_serif_class) != 0;
return (*self & any_serif_class) != 0;
}
}
pure fn is_sans_serif() -> bool {
return (self & kCTFontSansSerifClass) != 0;
fn is_sans_serif(&self) -> bool {
return (*self & kCTFontSansSerifClass) != 0;
}
pure fn is_script() -> bool {
return (self & kCTFontScriptsClass) != 0;
fn is_script(&self) -> bool {
return (*self & kCTFontScriptsClass) != 0;
}
pure fn is_fantasy() -> bool {
return (self & kCTFontOrnamentalsClass) != 0;
fn is_fantasy(&self) -> bool {
return (*self & kCTFontOrnamentalsClass) != 0;
}
pure fn is_symbols() -> bool {
return (self & kCTFontSymbolicClass) != 0;
fn is_symbols(&self) -> bool {
return (*self & kCTFontSymbolicClass) != 0;
}
}
@@ -106,18 +105,18 @@ pub type CTFontAttributes = UntypedCFDictionary;
pub type CTFontTraits = UntypedCFDictionary;
pub trait TraitAccessors {
fn symbolic_traits() -> CTFontSymbolicTraits;
fn normalized_weight() -> float;
fn normalized_width() -> float;
fn normalized_slant() -> float;
fn symbolic_traits(&self) -> CTFontSymbolicTraits;
fn normalized_weight(&self) -> float;
fn normalized_width(&self) -> float;
fn normalized_slant(&self) -> float;
}
priv trait TraitAccessorPrivate {
fn extract_number_for_key(key: CFStringRef) -> CFNumber;
fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber;
}
impl TraitAccessorPrivate for CTFontTraits {
priv fn extract_number_for_key(key: CFStringRef) -> CFNumber {
priv fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber {
let value = self.get(&key);
CFWrapper::wrap_shared(core_foundation::base::downcast::<CFNumberRef>(value))
}
@@ -125,28 +124,28 @@ impl TraitAccessorPrivate for CTFontTraits {
}
impl TraitAccessors for CTFontTraits {
fn symbolic_traits() -> CTFontSymbolicTraits {
fn symbolic_traits(&self) -> CTFontSymbolicTraits {
unsafe {
let number = self.extract_number_for_key(kCTFontSymbolicTrait);
cast::transmute(number.to_i32())
}
}
fn normalized_weight() -> float {
fn normalized_weight(&self) -> float {
unsafe {
let number = self.extract_number_for_key(kCTFontWeightTrait);
cast::transmute(number.to_float())
}
}
fn normalized_width() -> float {
fn normalized_width(&self) -> float {
unsafe {
let number = self.extract_number_for_key(kCTFontWidthTrait);
cast::transmute(number.to_float())
}
}
fn normalized_slant() -> float {
fn normalized_slant(&self) -> float {
unsafe {
let number = self.extract_number_for_key(kCTFontSlantTrait);
cast::transmute(number.to_float())
@@ -158,25 +157,25 @@ impl TraitAccessors for CTFontTraits {
* CTFontDescriptor.h
*/
pub type CTFontOrientation = u32;
pub const kCTFontDefaultOrientation: CTFontOrientation = 0;
pub const kCTFontHorizontalOrientation: CTFontOrientation = 1;
pub const kCTFontVerticalOrientation: CTFontOrientation = 2;
pub static kCTFontDefaultOrientation: CTFontOrientation = 0;
pub static kCTFontHorizontalOrientation: CTFontOrientation = 1;
pub static kCTFontVerticalOrientation: CTFontOrientation = 2;
pub type CTFontPriority = u32;
pub const kCTFontPrioritySystem: CTFontPriority = 10000;
pub const kCTFontPriorityNetwork: CTFontPriority = 20000;
pub const kCTFontPriorityComputer: CTFontPriority = 30000;
pub const kCTFontPriorityUser: CTFontPriority = 40000;
pub const kCTFontPriorityDynamic: CTFontPriority = 50000;
pub const kCTFontPriorityProcess: CTFontPriority = 60000;
pub static kCTFontPrioritySystem: CTFontPriority = 10000;
pub static kCTFontPriorityNetwork: CTFontPriority = 20000;
pub static kCTFontPriorityComputer: CTFontPriority = 30000;
pub static kCTFontPriorityUser: CTFontPriority = 40000;
pub static kCTFontPriorityDynamic: CTFontPriority = 50000;
pub static kCTFontPriorityProcess: CTFontPriority = 60000;
struct __CTFontDescriptor { private: () }
pub type CTFontDescriptorRef = *__CTFontDescriptor;
impl AbstractCFTypeRef for CTFontDescriptorRef {
pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef }
static pure fn type_id() -> CFTypeID {
fn type_id() -> CFTypeID {
unsafe {
CTFontDescriptorGetTypeID()
}
@@ -186,19 +185,19 @@ impl AbstractCFTypeRef for CTFontDescriptorRef {
pub type CTFontDescriptor = CFWrapper<CTFontDescriptorRef, (), ()>;
pub trait CTFontDescriptorMethods {
fn family_name() -> ~str;
fn font_name() -> ~str;
fn style_name() -> ~str;
fn display_name() -> ~str;
fn font_path() -> ~str;
fn family_name(&self) -> ~str;
fn font_name(&self) -> ~str;
fn style_name(&self) -> ~str;
fn display_name(&self) -> ~str;
fn font_path(&self) -> ~str;
}
priv trait CTFontDescriptorMethodsPrivate {
fn get_string_attribute(attribute: CFStringRef) -> Option<~str>;
fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str>;
}
impl CTFontDescriptorMethodsPrivate for CTFontDescriptor {
priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> {
priv fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> {
unsafe {
let value = CTFontDescriptorCopyAttribute(self.obj, attribute);
if value.is_null() {
@@ -212,31 +211,31 @@ impl CTFontDescriptorMethodsPrivate for CTFontDescriptor {
}
pub impl CTFontDescriptorMethods for CTFontDescriptor {
fn family_name() -> ~str {
impl CTFontDescriptorMethods for CTFontDescriptor {
fn family_name(&self) -> ~str {
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
option::expect(value, ~"A font must have a non-null font family name.")
value.expect(~"A font must have a non-null font family name.")
}
fn font_name() -> ~str {
fn font_name(&self) -> ~str {
let value = self.get_string_attribute(kCTFontNameAttribute);
option::expect(value, ~"A font must have a non-null name.")
value.expect(~"A font must have a non-null name.")
}
fn style_name() -> ~str {
fn style_name(&self) -> ~str {
let value = self.get_string_attribute(kCTFontStyleNameAttribute);
option::expect(value, ~"A font must have a non-null style name.")
value.expect(~"A font must have a non-null style name.")
}
fn display_name() -> ~str {
fn display_name(&self) -> ~str {
let value = self.get_string_attribute(kCTFontDisplayNameAttribute);
option::expect(value, ~"A font must have a non-null display name.")
value.expect(~"A font must have a non-null display name.")
}
fn font_path() -> ~str {
fn font_path(&self) -> ~str {
unsafe {
let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute);
assert value.is_not_null();
assert!(value.is_not_null());
CFWrapper::wrap_owned(core_foundation::base::downcast::<CFURLRef>(value)).to_str()
}
@@ -267,10 +266,10 @@ extern {
*/
// font trait constants
const kCTFontSymbolicTrait: CFStringRef;
const kCTFontWeightTrait: CFStringRef;
const kCTFontWidthTrait: CFStringRef;
const kCTFontSlantTrait: CFStringRef;
static kCTFontSymbolicTrait: CFStringRef;
static kCTFontWeightTrait: CFStringRef;
static kCTFontWidthTrait: CFStringRef;
static kCTFontSlantTrait: CFStringRef;
/*
* CTFontDescriptor.h
@@ -279,28 +278,28 @@ extern {
// font attribute constants. Note that the name-related attributes
// here are somewhat flaky. Servo creates CTFont instances and
// then uses CTFontCopyName to get more fine-grained names.
const kCTFontURLAttribute: CFStringRef; // value: CFURLRef
const kCTFontNameAttribute: CFStringRef; // value: CFStringRef
const kCTFontDisplayNameAttribute: CFStringRef; // value: CFStringRef
const kCTFontFamilyNameAttribute: CFStringRef; // value: CFStringRef
const kCTFontStyleNameAttribute: CFStringRef; // value: CFStringRef
const kCTFontTraitsAttribute: CFStringRef;
const kCTFontVariationAttribute: CFStringRef;
const kCTFontSizeAttribute: CFStringRef;
const kCTFontMatrixAttribute: CFStringRef;
const kCTFontCascadeListAttribute: CFStringRef;
const kCTFontCharacterSetAttribute: CFStringRef;
const kCTFontLanguagesAttribute: CFStringRef;
const kCTFontBaselineAdjustAttribute: CFStringRef;
const kCTFontMacintoshEncodingsAttribute: CFStringRef;
const kCTFontFeaturesAttribute: CFStringRef;
const kCTFontFeatureSettingsAttribute: CFStringRef;
const kCTFontFixedAdvanceAttribute: CFStringRef;
const kCTFontOrientationAttribute: CFStringRef;
const kCTFontFormatAttribute: CFStringRef;
const kCTFontRegistrationScopeAttribute: CFStringRef;
const kCTFontPriorityAttribute: CFStringRef;
const kCTFontEnabledAttribute: CFStringRef;
static kCTFontURLAttribute: CFStringRef; // value: CFURLRef
static kCTFontNameAttribute: CFStringRef; // value: CFStringRef
static kCTFontDisplayNameAttribute: CFStringRef; // value: CFStringRef
static kCTFontFamilyNameAttribute: CFStringRef; // value: CFStringRef
static kCTFontStyleNameAttribute: CFStringRef; // value: CFStringRef
static kCTFontTraitsAttribute: CFStringRef;
static kCTFontVariationAttribute: CFStringRef;
static kCTFontSizeAttribute: CFStringRef;
static kCTFontMatrixAttribute: CFStringRef;
static kCTFontCascadeListAttribute: CFStringRef;
static kCTFontCharacterSetAttribute: CFStringRef;
static kCTFontLanguagesAttribute: CFStringRef;
static kCTFontBaselineAdjustAttribute: CFStringRef;
static kCTFontMacintoshEncodingsAttribute: CFStringRef;
static kCTFontFeaturesAttribute: CFStringRef;
static kCTFontFeatureSettingsAttribute: CFStringRef;
static kCTFontFixedAdvanceAttribute: CFStringRef;
static kCTFontOrientationAttribute: CFStringRef;
static kCTFontFormatAttribute: CFStringRef;
static kCTFontRegistrationScopeAttribute: CFStringRef;
static kCTFontPriorityAttribute: CFStringRef;
static kCTFontEnabledAttribute: CFStringRef;
fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef,
attribute: CFStringRef) -> CFTypeRef;
@@ -318,9 +317,12 @@ extern {
variationValue: CGFloat) -> CTFontDescriptorRef;
fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef,
mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef;
fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef,
mandatoryAttributes: CFSetRef) -> CFArrayRef;
fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef;
fn CTFontDescriptorCreateWithNameAndSize(name: CFStringRef, size: CGFloat) -> CTFontDescriptorRef;
fn CTFontDescriptorGetTypeID() -> CFTypeID;
}
pub extern {
fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef,
mandatoryAttributes: CFSetRef) -> CFArrayRef;
}
+1 -1
View File
@@ -1,7 +1,7 @@
use core_foundation::array::CFArrayRef;
use core_foundation::url::CFURLRef;
extern {
pub extern {
/*
* CTFontManager.h
*/