From 616c216871041e48b44bc052529c00b282ce9256 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 19 Oct 2012 14:01:14 -0700 Subject: [PATCH 001/126] Initial commit. --- .gitignore | 11 +++++++++++ Makefile.in | 23 +++++++++++++++++++++++ configure | 5 +++++ core_text.rc | 10 ++++++++++ font.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile.in create mode 100755 configure create mode 100644 core_text.rc create mode 100644 font.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f68b7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*~ +*# +*.o +*.a +*.so +*.dylib +*.dSYM +*.dll +*.dummy +cocoa-test +build diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..1c08250 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,23 @@ +VPATH=%VPATH% + +RUSTC ?= rustc +RUSTFLAGS ?= + +RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') + +.PHONY: all clean +all: librustcoretext.dummy + +librustcoretext.dummy: core_text.rc $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< -o $@ + touch $@ + +rustcoretext-test: core_text.rc $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< -o $@ --test + +check: rustcoretext-test + ./rustcoretext-test + +clean: + rm -f *.o *.a *.so *.dylib *.dll *.dummy + diff --git a/configure b/configure new file mode 100755 index 0000000..ed6c06e --- /dev/null +++ b/configure @@ -0,0 +1,5 @@ +#!/bin/bash + +SRCDIR="$(cd $(dirname $0) && pwd)" +sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile + diff --git a/core_text.rc b/core_text.rc new file mode 100644 index 0000000..35b8e57 --- /dev/null +++ b/core_text.rc @@ -0,0 +1,10 @@ +#[link(name = "core_text", + vers = "0.1")]; +#[crate_type = "lib"]; + +extern mod std; + +extern mod core_foundation; +extern mod core_graphics; + +pub mod font; \ No newline at end of file diff --git a/font.rs b/font.rs new file mode 100644 index 0000000..c1b3f88 --- /dev/null +++ b/font.rs @@ -0,0 +1,50 @@ +extern mod core_foundation; +extern mod core_graphics; + +use libc::c_uint; + +use cf = core_foundation; +use cf::string::UniChar; +use cf::base::CFIndex; + +use cg = core_graphics; +use cg::base::{ + CGAffineTransform, + CGFloat, +} +use cg::font::{ + CGGlyph, + CGFontRef, +} +use cg::geometry::{ + CGRect, + CGSize, +} + +pub type CTFontRef = *u8; +pub type CTFontOrientation = u32; +pub type CTFontDescriptorRef = *u8; + +pub const kCTFontDefaultOrientation: CTFontOrientation = 0; +pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; +pub const kCTFontVerticalOrientation: CTFontOrientation = 2; + +#[nolink] +#[link_args = "-framework ApplicationServices"] +extern { + pub fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; + pub fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; + pub fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double; + + pub fn CTFontGetSize(font: CTFontRef) -> CGFloat; + + /* metrics API */ + pub fn CTFontGetAscent(font: CTFontRef) -> CGFloat; + pub fn CTFontGetDescent(font: CTFontRef) -> CGFloat; + pub fn CTFontGetLeading(font: CTFontRef) -> CGFloat; + pub fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; + pub fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; + pub fn CTFontGetUnderlineThickness(font: CTFontRef) -> CGFloat; + pub fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; + pub fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; +} From 21ad07b922ecfb869017250f95d8c55979a17235 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 19 Oct 2012 14:22:46 -0700 Subject: [PATCH 002/126] Fix compilation errors. --- font.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/font.rs b/font.rs index c1b3f88..154ef85 100644 --- a/font.rs +++ b/font.rs @@ -11,15 +11,15 @@ use cg = core_graphics; use cg::base::{ CGAffineTransform, CGFloat, -} +}; use cg::font::{ CGGlyph, CGFontRef, -} +}; use cg::geometry::{ CGRect, CGSize, -} +}; pub type CTFontRef = *u8; pub type CTFontOrientation = u32; From 2d142a2bafc34553dd669d5d96bcc4e74cc472ef Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 1 Nov 2012 15:12:36 -0700 Subject: [PATCH 003/126] Start adding bindings for CTFontDescriptor and CTFontManager. --- core_text.rc | 4 +++- font_descriptor.rs | 0 font_manager.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 font_descriptor.rs create mode 100644 font_manager.rs diff --git a/core_text.rc b/core_text.rc index 35b8e57..86cc542 100644 --- a/core_text.rc +++ b/core_text.rc @@ -7,4 +7,6 @@ extern mod std; extern mod core_foundation; extern mod core_graphics; -pub mod font; \ No newline at end of file +pub mod font; +pub mod font_descriptor; +pub mod font_manager; diff --git a/font_descriptor.rs b/font_descriptor.rs new file mode 100644 index 0000000..e69de29 diff --git a/font_manager.rs b/font_manager.rs new file mode 100644 index 0000000..e9a0ab2 --- /dev/null +++ b/font_manager.rs @@ -0,0 +1,26 @@ +use cf = core_foundation; +use cf::array::CFArrayRef; +use cf::url::CFURLRef; + +extern { + /* + * CTFontManager.h + */ + + // Incomplete function bindings are mostly related to CoreText font matching, which + // we implement in a platform-independent manner using FontMatcher. + + //fn CTFontManagerCompareFontFamilyNames + fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef; + fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef; + fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef; + fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef; + //fn CTFontManagerCreateFontRequestRunLoopSource + //fn CTFontManagerEnableFontDescriptors + //fn CTFontManagerGetAutoActivationSetting + //fn CTFontManagerGetScopeForURL + fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool; + //fn CTFontManagerRegisterFontsForURL + //fn CTFontManagerRegisterFontsForURLs + //fn +} \ No newline at end of file From d3f19703e93297f0eefd9e932999d54a346abce1 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 2 Nov 2012 16:22:10 -0700 Subject: [PATCH 004/126] Add a ton of stubs and bindings. Add CTFont wrapper type. Add CTFontCollection and CTFontDescriptor. --- core_text.rc | 1 + font.rs | 228 ++++++++++++++++++++++++++++++++++++++++----- font_collection.rs | 65 +++++++++++++ font_descriptor.rs | 160 +++++++++++++++++++++++++++++++ font_manager.rs | 8 +- 5 files changed, 439 insertions(+), 23 deletions(-) create mode 100644 font_collection.rs diff --git a/core_text.rc b/core_text.rc index 86cc542..01f24db 100644 --- a/core_text.rc +++ b/core_text.rc @@ -8,5 +8,6 @@ extern mod core_foundation; extern mod core_graphics; pub mod font; +pub mod font_collection; pub mod font_descriptor; pub mod font_manager; diff --git a/font.rs b/font.rs index 154ef85..868961b 100644 --- a/font.rs +++ b/font.rs @@ -3,9 +3,18 @@ extern mod core_graphics; use libc::c_uint; +use font_descriptor::{CTFontDescriptorRef, CTFontOrientation}; + use cf = core_foundation; -use cf::string::UniChar; -use cf::base::CFIndex; +use cf::string::{CFStringRef, UniChar}; +use cf::base::{ + AbstractCFType, + AbstractCFTypeRef, + CFIndex, + CFOptionFlags, + CFRelease, + CFTypeRef, +}; use cg = core_graphics; use cg::base::{ @@ -21,30 +30,205 @@ use cg::geometry::{ CGSize, }; -pub type CTFontRef = *u8; -pub type CTFontOrientation = u32; -pub type CTFontDescriptorRef = *u8; +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 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 type CTFontOptions = CFOptionFlags; +pub const kCTFontOptionsDefault: CTFontOptions = 0; +pub const kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0); +pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); + +struct __CTFont { private: () } +pub type CTFontRef = *__CTFont; + +impl CTFontRef : AbstractCFTypeRef { + pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +} + +struct CTFont { + obj: CTFontRef, + + drop { + unsafe { + CFRelease(cast::transmute(self.obj)) + } + } +} + +pub impl CTFont : AbstractCFType { + static fn wrap(obj: CTFontRef) -> CTFont { + CTFont { obj: obj } + } + + static fn unwrap(wrapper: CTFont) -> CTFontRef { + wrapper.obj + } + + pure fn as_type_ref(&self) -> CFTypeRef { + unsafe { + cast::transmute(self.obj) + } + } +} -pub const kCTFontDefaultOrientation: CTFontOrientation = 0; -pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; -pub const kCTFontVerticalOrientation: CTFontOrientation = 2; #[nolink] #[link_args = "-framework ApplicationServices"] extern { - pub fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; - pub fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; - pub fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double; - - pub fn CTFontGetSize(font: CTFontRef) -> CGFloat; + /* + * CTFont.h + */ - /* metrics API */ - pub fn CTFontGetAscent(font: CTFontRef) -> CGFloat; - pub fn CTFontGetDescent(font: CTFontRef) -> CGFloat; - pub fn CTFontGetLeading(font: CTFontRef) -> CGFloat; - pub fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; - pub fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; - pub fn CTFontGetUnderlineThickness(font: CTFontRef) -> CGFloat; - pub fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; - pub fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; + /* 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; + + const kCTFontVariationAxisIdentifierKey: CFStringRef; + const kCTFontVariationAxisMinimumValueKey: CFStringRef; + const kCTFontVariationAxisMaximumValueKey: CFStringRef; + const kCTFontVariationAxisDefaultValueKey: CFStringRef; + const 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; + + // 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. + + /* Creating Fonts */ + //fn CTFontCreateWithName + //fn CTFontCreateWithNameAndOptions + //fn CTFontCreateWithFontDescriptor + //fn CTFontCreateWithFontDescriptorAndOptions + //fn CTFontCreateUIFontForLanguage + //fn CTFontCreateCopyWithAttributes + //fn CTFontCreateCopyWithSymbolicTraits + //fn CTFontCreateCopyWithFamily + //fn CTFontCreateForString + + /* Getting Font Data */ + //fn CTFontCopyFontDescriptor + //fn CTFontCopyAttribute + fn CTFontGetSize(font: CTFontRef) -> CGFloat; + //fn CTFontGetMatricx + //fn CTFontGetSymbolicTraits + //fn CTFontCopyTraits + + /* Getting Font Names */ + //fn CTFontCopyPostScriptName + //fn CTFontCopyFamilyName + //fn CTFontCopyFullName + //fn CTFontCopyDisplayName + //fn CTFontCopyName + //fn CTFontCopyLocalizedName + + /* Working With Encoding */ + //fn CTFontCopyCharacterSet + //fn CTFontGetStringEncoding + //fn CTFontCopySupportedLanguages + + /* Getting Font Metrics */ + fn CTFontGetAscent(font: CTFontRef) -> CGFloat; + fn CTFontGetDescent(font: CTFontRef) -> CGFloat; + fn CTFontGetLeading(font: CTFontRef) -> CGFloat; + fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; + //fn CTFontGetGlyphCount + fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; + fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; + fn CTFontGetUnderlineThickness(font: CTFontRef) -> CGFloat; + //fn CTFontGetSlantAngle + //fn CTFontGetCapHeight + fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; + + /* Getting Glyph Data */ + //fn CTFontCreatePathForGlyph + //fn CTFontGetGlyphWithName + //fn CTFontGetBoundingRectsForGlyphs + fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double; + //fn CTFontGetVerticalTranslationsForGlyphs + + /* Working With Font Variations */ + //fn CTFontCopyVariationAxes + //fn CTFontCopyVariation + + /* Getting Font Features */ + //fn CTFontCopyFeatures + //fn CTFontCopyFeatureSettings + + /* Working with Glyphs */ + fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; + //fn CTFontDrawGlyphs + //fn CTFontGetLigatureCaretPositions + + /* Converting Fonts */ + //fn CTFontCopyGraphicsFont + fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, + matrix: *CGAffineTransform, + attributes: CTFontDescriptorRef) -> CTFontRef; + //fn CTFontGetPlatformFont + //fn CTFontCreateWithPlatformFont + //fn CTFontCreateWithQuickdrawInstance + + /* Getting Font Table Data */ + //fn CTFontCopyAvailableTables + //fn CTFontCopyTable + + //fn CTFontGetTypeID + } diff --git a/font_collection.rs b/font_collection.rs new file mode 100644 index 0000000..839a2b5 --- /dev/null +++ b/font_collection.rs @@ -0,0 +1,65 @@ +use cf = core_foundation; +use cf::array::CFArrayRef; +use cf::base::{ + AbstractCFType, + AbstractCFTypeRef, + CFAllocatorRef, + CFIndex, + CFRange, + CFRelease, + CFTypeRef, + kCFAllocatorDefault, +}; +use cf::dictionary::CFDictionaryRef; +use cf::string::CFStringRef; +use libc::c_void; + +struct __CTFontCollection { private: () } +pub type CTFontCollectionRef = *__CTFontCollection; + +impl CTFontCollectionRef : AbstractCFTypeRef { + pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +} + +struct CTFontCollection { + obj: CTFontCollectionRef, + + drop { + unsafe { + CFRelease(cast::transmute(self.obj)) + } + } +} + +pub impl CTFontCollection : AbstractCFType { + static fn wrap(obj: CTFontCollectionRef) -> CTFontCollection { + CTFontCollection { obj: obj } + } + + static fn unwrap(wrapper: CTFontCollection) -> CTFontCollectionRef { + wrapper.obj + } + + pure fn as_type_ref(&self) -> CFTypeRef { + unsafe { + cast::transmute(self.obj) + } + } +} + +extern { + /* + * CTFontCollection.h + */ + + const kCTFontCollectionRemoveDuplicatesOption: CFStringRef; + + fn CTFontCollectionCreateCopyWithFontDescriptors(descriptors: CFArrayRef, options: CFDictionaryRef) ->CTFontCollectionRef; + fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef; + fn CTFontCollectionCreateMatchingFontDescriptors(collection: CTFontCollectionRef) -> CFArrayRef; + fn CTFontCollectionCreateWithFontDescriptors(original: CTFontCollectionRef, + descriptors: CFArrayRef, + options: CFDictionaryRef) -> CTFontCollectionRef; + //fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback; + //fn CTFontCollectionGetTypeID; +} \ No newline at end of file diff --git a/font_descriptor.rs b/font_descriptor.rs index e69de29..0b233f1 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -0,0 +1,160 @@ +use cf = core_foundation; +use cf::array::CFArrayRef; +use cf::base::{ + AbstractCFType, + AbstractCFTypeRef, + CFAllocatorRef, + CFIndex, + CFRange, + CFRelease, + CFTypeRef, + CFTypeID, + kCFAllocatorDefault, +}; +use cf::dictionary::CFDictionaryRef; +use cf::number::CFNumberRef; +use cf::set::CFSetRef; +use cf::string::CFStringRef; + +use cg = core_graphics; +use cg::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 const 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 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); + +/* +* CTFontDescriptor.h +*/ +pub type CTFontOrientation = u32; +pub const kCTFontDefaultOrientation: CTFontOrientation = 0; +pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; +pub const 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; + +struct __CTFontDescriptor { private: () } +pub type CTFontDescriptorRef = *__CTFontDescriptor; + +impl CTFontDescriptorRef : AbstractCFTypeRef { + pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +} + +struct CTFontDescriptor { + obj: CTFontDescriptorRef, + + drop { + unsafe { + CFRelease(cast::transmute(self.obj)) + } + } +} + +pub impl CTFontDescriptor : AbstractCFType { + static fn wrap(obj: CTFontDescriptorRef) -> CTFontDescriptor { + CTFontDescriptor { obj: obj } + } + + static fn unwrap(wrapper: CTFontDescriptor) -> CTFontDescriptorRef { + wrapper.obj + } + + pure fn as_type_ref(&self) -> CFTypeRef { + unsafe { + cast::transmute(self.obj) + } + } +} + +extern { + /* + * CTFontTraits.h + */ + + // font trait constants + const kCTFontSymbolicTrait: CFStringRef; + const kCTFontWeightTrait: CFStringRef; + const kCTFontWidthTrait: CFStringRef; + const kCTFontSlantTrait: CFStringRef; + + /* + * CTFontDescriptor.h + */ + + // font attribute constants + const kCTFontURLAttribute: CFStringRef; + const kCTFontNameAttribute: CFStringRef; + const kCTFontDisplayNameAttribute: CFStringRef; + const kCTFontFamilyNameAttribute: CFStringRef; + const kCTFontStyleNameAttribute: 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; + + fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef) -> CFTypeRef; + fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; + fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef, language: *CFStringRef) -> CFTypeRef; + fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, attributes: CFDictionaryRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, featureTypeIdentifier: CFNumberRef, featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, variationIdentifier: CFNumberRef, variationValue: CGFloat) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef, mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef, mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateWithNameAndSize(name: CFStringRef, size: CGFloat) -> CTFontDescriptorRef; + fn CTFontDescriptorGetTypeID() -> CFTypeID; +} \ No newline at end of file diff --git a/font_manager.rs b/font_manager.rs index e9a0ab2..98f1a38 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -19,8 +19,14 @@ extern { //fn CTFontManagerEnableFontDescriptors //fn CTFontManagerGetAutoActivationSetting //fn CTFontManagerGetScopeForURL + //fn CTFontManagerGetAutoActivationSetting + //fn CTFontManagerGetScopeForURL fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool; //fn CTFontManagerRegisterFontsForURL //fn CTFontManagerRegisterFontsForURLs - //fn + //fn CTFontManagerRegisterGraphicsFont + //fn CTFontManagerSetAutoActivationSetting + //fn CTFontManagerUnregisterFontsForURL + //fn CTFontManagerUnregisterFontsForURLs + //fn CTFontManagerUnregisterGraphicsFont } \ No newline at end of file From 7de2f045b290164437346d2f94013ec27a42c70c Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 2 Nov 2012 17:19:23 -0700 Subject: [PATCH 005/126] Add CTFontCollection::new() --- font_collection.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/font_collection.rs b/font_collection.rs index 839a2b5..f00ccfa 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -10,8 +10,10 @@ use cf::base::{ CFTypeRef, kCFAllocatorDefault, }; -use cf::dictionary::CFDictionaryRef; -use cf::string::CFStringRef; +use cf::dictionary::{CFDictionary, CFDictionaryRef}; +use cf::number::CFNumber; +use cf::string::{CFString, CFStringRef}; + use libc::c_void; struct __CTFontCollection { private: () } @@ -47,6 +49,17 @@ pub impl CTFontCollection : AbstractCFType { } } +pub impl CTFontCollection { + static fn new() -> CTFontCollection { + let options = CFDictionary::new([ + (CFString::new_wrapped(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) + ]); + let collection = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + + CTFontCollection { obj: move collection } + } +} + extern { /* * CTFontCollection.h From 9119482c91527526b7d9aeae562d4ff48844722b Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 2 Nov 2012 18:42:12 -0700 Subject: [PATCH 006/126] Update for CF bindings changes. --- font.rs | 8 ++------ font_collection.rs | 13 ++++--------- font_descriptor.rs | 8 ++------ 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/font.rs b/font.rs index 868961b..9fbb507 100644 --- a/font.rs +++ b/font.rs @@ -90,6 +90,8 @@ struct CTFont { } pub impl CTFont : AbstractCFType { + pure fn get_ref() -> CTFontRef { self.obj } + static fn wrap(obj: CTFontRef) -> CTFont { CTFont { obj: obj } } @@ -97,12 +99,6 @@ pub impl CTFont : AbstractCFType { static fn unwrap(wrapper: CTFont) -> CTFontRef { wrapper.obj } - - pure fn as_type_ref(&self) -> CFTypeRef { - unsafe { - cast::transmute(self.obj) - } - } } diff --git a/font_collection.rs b/font_collection.rs index f00ccfa..4e4933c 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -34,6 +34,8 @@ struct CTFontCollection { } pub impl CTFontCollection : AbstractCFType { + pure fn get_ref() -> CTFontCollectionRef { self.obj } + static fn wrap(obj: CTFontCollectionRef) -> CTFontCollection { CTFontCollection { obj: obj } } @@ -41,21 +43,14 @@ pub impl CTFontCollection : AbstractCFType { static fn unwrap(wrapper: CTFontCollection) -> CTFontCollectionRef { wrapper.obj } - - pure fn as_type_ref(&self) -> CFTypeRef { - unsafe { - cast::transmute(self.obj) - } - } } pub impl CTFontCollection { static fn new() -> CTFontCollection { let options = CFDictionary::new([ - (CFString::new_wrapped(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) + (CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) ]); - let collection = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); - + let collection = CTFontCollectionCreateFromAvailableFonts(options.get_ref()); CTFontCollection { obj: move collection } } } diff --git a/font_descriptor.rs b/font_descriptor.rs index 0b233f1..c93d1e9 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -92,6 +92,8 @@ struct CTFontDescriptor { } pub impl CTFontDescriptor : AbstractCFType { + pure fn get_ref() -> CTFontDescriptorRef { self.obj } + static fn wrap(obj: CTFontDescriptorRef) -> CTFontDescriptor { CTFontDescriptor { obj: obj } } @@ -99,12 +101,6 @@ pub impl CTFontDescriptor : AbstractCFType { static fn unwrap(wrapper: CTFontDescriptor) -> CTFontDescriptorRef { wrapper.obj } - - pure fn as_type_ref(&self) -> CFTypeRef { - unsafe { - cast::transmute(self.obj) - } - } } extern { From c2a49dab0bc5c3c32b6ab5ff6e2b1685f6702613 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 09:22:09 -0800 Subject: [PATCH 007/126] make clean should remove the test binary. --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 1c08250..c9dc835 100644 --- a/Makefile.in +++ b/Makefile.in @@ -19,5 +19,5 @@ check: rustcoretext-test ./rustcoretext-test clean: - rm -f *.o *.a *.so *.dylib *.dll *.dummy + rm -f *.o *.a *.so *.dylib *.dll *.dummy rustcoretext-test From a12d1d023d701493d6c926d3c6ac35f0a97a8308 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 09:22:48 -0800 Subject: [PATCH 008/126] Implement CTFontDescriptor::family_name(). --- font_descriptor.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/font_descriptor.rs b/font_descriptor.rs index c93d1e9..a9d8c4d 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -5,6 +5,7 @@ use cf::base::{ AbstractCFTypeRef, CFAllocatorRef, CFIndex, + CFGetTypeID, CFRange, CFRelease, CFTypeRef, @@ -14,7 +15,11 @@ use cf::base::{ use cf::dictionary::CFDictionaryRef; use cf::number::CFNumberRef; use cf::set::CFSetRef; -use cf::string::CFStringRef; +use cf::string::{ + CFString, + CFStringRef, + CFStringGetTypeID, +}; use cg = core_graphics; use cg::base::CGFloat; @@ -103,6 +108,18 @@ pub impl CTFontDescriptor : AbstractCFType { } } +pub impl CTFontDescriptor { + fn family_name() -> ~str { + let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontDisplayNameAttribute); + // family name should never be null. + assert value.is_not_null(); + assert CFGetTypeID(value) == CFStringGetTypeID(); + + let name : CFString = cf::base::wrap(value as CFStringRef); + return name.to_str(); + } +} + extern { /* * CTFontTraits.h From 03050d5d816462582c4506e1fb6f507b5c6653bc Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 09:42:49 -0800 Subject: [PATCH 009/126] Add CTFontCollection::get_descriptocrs, and bind CTFontCollectionGetTypeID. --- font_collection.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/font_collection.rs b/font_collection.rs index 4e4933c..2ba15a2 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,5 +1,5 @@ use cf = core_foundation; -use cf::array::CFArrayRef; +use cf::array::{CFArray, CFArrayRef}; use cf::base::{ AbstractCFType, AbstractCFTypeRef, @@ -7,6 +7,7 @@ use cf::base::{ CFIndex, CFRange, CFRelease, + CFTypeID, CFTypeRef, kCFAllocatorDefault, }; @@ -14,6 +15,8 @@ use cf::dictionary::{CFDictionary, CFDictionaryRef}; use cf::number::CFNumber; use cf::string::{CFString, CFStringRef}; +use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef}; + use libc::c_void; struct __CTFontCollection { private: () } @@ -53,6 +56,10 @@ pub impl CTFontCollection { let collection = CTFontCollectionCreateFromAvailableFonts(options.get_ref()); CTFontCollection { obj: move collection } } + + fn get_descriptors() -> CFArray { + cf::base::wrap(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + } } extern { @@ -62,12 +69,12 @@ extern { const kCTFontCollectionRemoveDuplicatesOption: CFStringRef; - fn CTFontCollectionCreateCopyWithFontDescriptors(descriptors: CFArrayRef, options: CFDictionaryRef) ->CTFontCollectionRef; + fn CTFontCollectionCreateCopyWithFontDescriptors(descriptors: CFArrayRef, options: CFDictionaryRef) -> CTFontCollectionRef; fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef; fn CTFontCollectionCreateMatchingFontDescriptors(collection: CTFontCollectionRef) -> CFArrayRef; fn CTFontCollectionCreateWithFontDescriptors(original: CTFontCollectionRef, descriptors: CFArrayRef, options: CFDictionaryRef) -> CTFontCollectionRef; //fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback; - //fn CTFontCollectionGetTypeID; + fn CTFontCollectionGetTypeID() -> CFTypeID; } \ No newline at end of file From c1450887c2e21a4cddfa57c4d3fc4d4eb02da425 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 15:23:01 -0800 Subject: [PATCH 010/126] Add font_path(), and debug_descriptor() --- font_descriptor.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/font_descriptor.rs b/font_descriptor.rs index a9d8c4d..a367183 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -8,8 +8,9 @@ use cf::base::{ CFGetTypeID, CFRange, CFRelease, - CFTypeRef, CFTypeID, + CFTypeOps, + CFTypeRef, kCFAllocatorDefault, }; use cf::dictionary::CFDictionaryRef; @@ -20,6 +21,11 @@ use cf::string::{ CFStringRef, CFStringGetTypeID, }; +use cf::url::{ + CFURL, + CFURLRef, + CFURLGetTypeID, +}; use cg = core_graphics; use cg::base::CGFloat; @@ -118,6 +124,21 @@ pub impl CTFontDescriptor { let name : CFString = cf::base::wrap(value as CFStringRef); return name.to_str(); } + + fn font_path() -> ~str { + let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); + assert value.is_not_null(); + assert CFGetTypeID(value) == CFURLGetTypeID(); + + let cfurl : CFURL = cf::base::wrap(value as CFURLRef); + return cfurl.to_str(); + } +} + +pub fn debug_descriptor(desc: &CTFontDescriptor) { + io::println(fmt!("family: %s", desc.family_name())); + io::println(fmt!("path: %s", desc.font_path())); + desc.show(); } extern { From aa6fb82a7390f4ef1dd596b67cec130ab33519ff Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 16:21:56 -0800 Subject: [PATCH 011/126] Flesh out some more name-attribute getters in CTFontDescriptor. --- font_descriptor.rs | 86 ++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/font_descriptor.rs b/font_descriptor.rs index a367183..6e273d7 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -115,14 +115,35 @@ pub impl CTFontDescriptor : AbstractCFType { } pub impl CTFontDescriptor { - fn family_name() -> ~str { - let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontDisplayNameAttribute); - // family name should never be null. - assert value.is_not_null(); - assert CFGetTypeID(value) == CFStringGetTypeID(); + priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { + let value = CTFontDescriptorCopyAttribute(self.obj, attribute); + if value.is_null() { + return None; + } - let name : CFString = cf::base::wrap(value as CFStringRef); - return name.to_str(); + assert CFGetTypeID(value) == CFStringGetTypeID(); + let cfstr: CFString = cf::base::wrap(value as CFStringRef); + return Some(cfstr.to_str()); + } + + fn family_name() -> ~str { + let value = self.get_string_attribute(kCTFontDisplayNameAttribute); + return option::expect(move value, ~"A font must have a non-null font family name."); + } + + fn font_name() -> ~str { + let value = self.get_string_attribute(kCTFontNameAttribute); + return option::expect(move value, ~"A font must have a non-null name."); + } + + fn style_name() -> ~str { + let value = self.get_string_attribute(kCTFontStyleNameAttribute); + return option::expect(move value, ~"A font must have a non-null style name."); + } + + fn display_name() -> ~str { + let value = self.get_string_attribute(kCTFontDisplayNameAttribute); + return move option::expect(move value, ~"A font must have a non-null display name."); } fn font_path() -> ~str { @@ -137,6 +158,9 @@ pub impl CTFontDescriptor { pub fn debug_descriptor(desc: &CTFontDescriptor) { io::println(fmt!("family: %s", desc.family_name())); + io::println(fmt!("name: %s", desc.font_name())); + io::println(fmt!("style: %s", desc.style_name())); + io::println(fmt!("display: %s", desc.display_name())); io::println(fmt!("path: %s", desc.font_path())); desc.show(); } @@ -156,29 +180,31 @@ extern { * CTFontDescriptor.h */ - // font attribute constants - const kCTFontURLAttribute: CFStringRef; - const kCTFontNameAttribute: CFStringRef; - const kCTFontDisplayNameAttribute: CFStringRef; - const kCTFontFamilyNameAttribute: CFStringRef; - const kCTFontStyleNameAttribute: 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; + // 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; fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef) -> CFTypeRef; fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; From 29baa9c4e16f5b900570427cc7e01dd602c1dee4 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 18:29:52 -0800 Subject: [PATCH 012/126] Add CTFont bindings that we already use. --- font.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/font.rs b/font.rs index 9fbb507..1efd693 100644 --- a/font.rs +++ b/font.rs @@ -101,6 +101,57 @@ pub impl CTFont : AbstractCFType { } } +pub impl CTFont { + static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { + assert cgfont.is_not_null(); + let value = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); + return move cf::base::wrap(value); + } + + fn copy_to_CGFont() -> CGFontRef { + CTFontCopyGraphicsFont(self.obj, ptr::null()) + } + + pure fn ascent() -> CGFloat unsafe { + CTFontGetAscent(self.obj) + } + + pure fn descent() -> CGFloat unsafe { + CTFontGetDescent(self.obj) + } + + pure fn underline_thickness() -> CGFloat unsafe { + CTFontGetUnderlineThickness(self.obj) + } + + pure fn underline_position() -> CGFloat unsafe { + CTFontGetUnderlinePosition(self.obj) + } + + pure fn bounding_box() -> CGRect unsafe { + CTFontGetBoundingBox(self.obj) + } + + pure fn leading() -> CGFloat unsafe { + CTFontGetLeading(self.obj) + } + + pure fn x_height() -> CGFloat unsafe { + CTFontGetXHeight(self.obj) + } + + pure fn pt_size() -> CGFloat unsafe { + CTFontGetSize(self.obj) + } + + fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool unsafe { + CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) + } + + fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float { + CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float + } +} #[nolink] #[link_args = "-framework ApplicationServices"] @@ -213,7 +264,7 @@ extern { //fn CTFontGetLigatureCaretPositions /* Converting Fonts */ - //fn CTFontCopyGraphicsFont + fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *CTFontDescriptorRef) -> CGFontRef; fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; From 6fde7833913c8152ac41f5584f4d7f2e59d0f59f Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 19:13:32 -0800 Subject: [PATCH 013/126] Add some more bindings for CTFont, especially for getting out font names. --- font.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/font.rs b/font.rs index 1efd693..d040911 100644 --- a/font.rs +++ b/font.rs @@ -6,13 +6,20 @@ use libc::c_uint; use font_descriptor::{CTFontDescriptorRef, CTFontOrientation}; use cf = core_foundation; -use cf::string::{CFStringRef, UniChar}; +use cf::string::{ + CFStringGetTypeID, + CFString, + CFStringRef, + UniChar +}; use cf::base::{ AbstractCFType, AbstractCFTypeRef, + CFGetTypeID, CFIndex, CFOptionFlags, CFRelease, + CFTypeID, CFTypeRef, }; @@ -30,6 +37,10 @@ use cg::geometry::{ CGSize, }; +use font_descriptor::{ + CTFontDescriptor +}; + pub type CTFontUIFontType = u32; // kCTFontNoFontType: CTFontUIFontType = -1; pub const kCTFontUserFontType: CTFontUIFontType = 0; @@ -102,16 +113,29 @@ pub impl CTFont : AbstractCFType { } pub impl CTFont { + // Creation methods static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { assert cgfont.is_not_null(); let value = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); return move cf::base::wrap(value); } + static fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { + let value = CTFontCreateWithFontDescriptor(desc.get_ref(), pt_size as CGFloat, ptr::null()); + return move cf::base::wrap(value); + } + fn copy_to_CGFont() -> CGFontRef { CTFontCopyGraphicsFont(self.obj, ptr::null()) } + // Names + pure fn face_name() -> ~str unsafe { + let value = get_string_by_name_key(&self, kCTFontStyleNameKey); + return move option::expect(move value, ~"Fonts should always have a face name."); + } + + // Font metrics pure fn ascent() -> CGFloat unsafe { CTFontGetAscent(self.obj) } @@ -153,6 +177,31 @@ pub impl CTFont { } } +// Helper methods +priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { + let value = CTFontCopyName(font.get_ref(), name_key); + if value.is_null() { + return None; + } + + assert CFGetTypeID(value.as_type_ref()) == CFStringGetTypeID(); + let cfstr: CFString = cf::base::wrap(value as CFStringRef); + return Some(cfstr.to_str()); +} + +pub fn debug_font_names(font: &CTFont) { + fn get_key(font: &CTFont, key: CFStringRef) -> ~str { + option::unwrap(move get_string_by_name_key(font, key)) + } + + io::println(fmt!("kCTFontFamilyNameKey: %s", get_key(font, kCTFontFamilyNameKey))); + io::println(fmt!("kCTFontSubFamilyNameKey: %s", get_key(font, kCTFontSubFamilyNameKey))); + io::println(fmt!("kCTFontStyleNameKey: %s", get_key(font, kCTFontStyleNameKey))); + io::println(fmt!("kCTFontUniqueNameKey: %s", get_key(font, kCTFontUniqueNameKey))); + io::println(fmt!("kCTFontFullNameKey: %s", get_key(font, kCTFontFullNameKey))); + io::println(fmt!("kCTFontPostScriptNameKey: %s", get_key(font, kCTFontPostScriptNameKey))); +} + #[nolink] #[link_args = "-framework ApplicationServices"] extern { @@ -201,7 +250,8 @@ extern { /* Creating Fonts */ //fn CTFontCreateWithName //fn CTFontCreateWithNameAndOptions - //fn CTFontCreateWithFontDescriptor + fn CTFontCreateWithFontDescriptor(descriptor: CTFontDescriptorRef, size: CGFloat, + matrix: *CGAffineTransform) -> CTFontRef; //fn CTFontCreateWithFontDescriptorAndOptions //fn CTFontCreateUIFontForLanguage //fn CTFontCreateCopyWithAttributes @@ -210,20 +260,21 @@ extern { //fn CTFontCreateForString /* Getting Font Data */ - //fn CTFontCopyFontDescriptor - //fn CTFontCopyAttribute + fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; + fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; fn CTFontGetSize(font: CTFontRef) -> CGFloat; - //fn CTFontGetMatricx + //fn CTFontGetMatrix //fn CTFontGetSymbolicTraits //fn CTFontCopyTraits /* Getting Font Names */ - //fn CTFontCopyPostScriptName - //fn CTFontCopyFamilyName - //fn CTFontCopyFullName - //fn CTFontCopyDisplayName - //fn CTFontCopyName - //fn CTFontCopyLocalizedName + fn CTFontCopyPostScriptName(font: CTFontRef) -> CFStringRef; + fn CTFontCopyFamilyName(font: CTFontRef) -> CFStringRef; + fn CTFontCopyFullName(font: CTFontRef) -> CFStringRef; + fn CTFontCopyDisplayName(font: CTFontRef) -> CFStringRef; + fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; + fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, + language: *CFStringRef) -> CFStringRef; /* Working With Encoding */ //fn CTFontCopyCharacterSet @@ -276,6 +327,6 @@ extern { //fn CTFontCopyAvailableTables //fn CTFontCopyTable - //fn CTFontGetTypeID + fn CTFontGetTypeID() -> CFTypeID; } From 833fed1d93e56da6af51e9ece5c3c5e41c8c05d0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 8 Nov 2012 19:32:16 -0800 Subject: [PATCH 014/126] Add a binding to CTFontCopyGraphicsFont --- font.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/font.rs b/font.rs index d040911..f865b9b 100644 --- a/font.rs +++ b/font.rs @@ -100,9 +100,20 @@ struct CTFont { } } +pub impl CTFont { + static pub fn new_with_cg_font(cg_font: CGFontRef, size: CGFloat) -> CTFont { + let ct_font = CTFontCreateWithGraphicsFont(cg_font, size, ptr::null(), ptr::null()); + cf::base::wrap(move ct_font) + } +} + pub impl CTFont : AbstractCFType { pure fn get_ref() -> CTFontRef { self.obj } + fn copy_cg_font(&const self) -> CGFontRef { + CTFontCopyGraphicsFont(self.obj, ptr::null()) + } + static fn wrap(obj: CTFontRef) -> CTFont { CTFont { obj: obj } } From 7a82d824c50dd5647c120565acdbea6b00e51a40 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 8 Nov 2012 19:59:31 -0800 Subject: [PATCH 015/126] Botched merge --- font.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/font.rs b/font.rs index f865b9b..03bb257 100644 --- a/font.rs +++ b/font.rs @@ -100,13 +100,6 @@ struct CTFont { } } -pub impl CTFont { - static pub fn new_with_cg_font(cg_font: CGFontRef, size: CGFloat) -> CTFont { - let ct_font = CTFontCreateWithGraphicsFont(cg_font, size, ptr::null(), ptr::null()); - cf::base::wrap(move ct_font) - } -} - pub impl CTFont : AbstractCFType { pure fn get_ref() -> CTFontRef { self.obj } From 3447665bc6fb1f7a192114723e6822840d1f12bd Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 9 Nov 2012 11:04:24 -0800 Subject: [PATCH 016/126] Add accessors for CTFont names; start debugging symbolic traits; fix duplicate to_CGFont method used by rust-azure. --- font.rs | 63 +++++++++++++++++++++++++++++++++++----------- font_descriptor.rs | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 15 deletions(-) diff --git a/font.rs b/font.rs index 03bb257..2e70d20 100644 --- a/font.rs +++ b/font.rs @@ -3,15 +3,14 @@ extern mod core_graphics; use libc::c_uint; -use font_descriptor::{CTFontDescriptorRef, CTFontOrientation}; +use font_descriptor::{ + CTFontDescriptorRef, + CTFontOrientation, + CTFontSymbolicTraits, + SymbolicTraitAccessors, +}; use cf = core_foundation; -use cf::string::{ - CFStringGetTypeID, - CFString, - CFStringRef, - UniChar -}; use cf::base::{ AbstractCFType, AbstractCFTypeRef, @@ -22,6 +21,15 @@ use cf::base::{ CFTypeID, CFTypeRef, }; +use cf::dictionary::{ + CFDictionaryRef, +}; +use cf::string::{ + CFStringGetTypeID, + CFString, + CFStringRef, + UniChar +}; use cg = core_graphics; use cg::base::{ @@ -103,10 +111,6 @@ struct CTFont { pub impl CTFont : AbstractCFType { pure fn get_ref() -> CTFontRef { self.obj } - fn copy_cg_font(&const self) -> CGFontRef { - CTFontCopyGraphicsFont(self.obj, ptr::null()) - } - static fn wrap(obj: CTFontRef) -> CTFont { CTFont { obj: obj } } @@ -129,16 +133,36 @@ pub impl CTFont { return move cf::base::wrap(value); } - fn copy_to_CGFont() -> CGFontRef { + fn copy_to_CGFont(&const self) -> CGFontRef { CTFontCopyGraphicsFont(self.obj, ptr::null()) } // Names + pure fn family_name() -> ~str unsafe { + let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); + return move option::expect(move value, ~"Fonts should always have a family name."); + } + pure fn face_name() -> ~str unsafe { - let value = get_string_by_name_key(&self, kCTFontStyleNameKey); + let value = get_string_by_name_key(&self, kCTFontSubFamilyNameKey); return move option::expect(move value, ~"Fonts should always have a face name."); } + pure fn unique_name() -> ~str unsafe { + let value = get_string_by_name_key(&self, kCTFontUniqueNameKey); + return move option::expect(move value, ~"Fonts should always have a unique name."); + } + + pure fn postscript_name() -> ~str unsafe { + let value = get_string_by_name_key(&self, kCTFontPostScriptNameKey); + return move option::expect(move value, ~"Fonts should always have a PostScript name."); + } + + // Properties + priv pure fn symbolic_traits() -> CTFontSymbolicTraits unsafe { + CTFontGetSymbolicTraits(self.obj) + } + // Font metrics pure fn ascent() -> CGFloat unsafe { CTFontGetAscent(self.obj) @@ -206,6 +230,15 @@ pub fn debug_font_names(font: &CTFont) { io::println(fmt!("kCTFontPostScriptNameKey: %s", get_key(font, kCTFontPostScriptNameKey))); } +pub fn debug_font_traits(font: &CTFont) { + let sym = font.symbolic_traits() as SymbolicTraitAccessors; + io::println(fmt!("kCTFontItalicTrait: %b", sym.is_italic())); + io::println(fmt!("kCTFontBoldTrait: %b", sym.is_bold())); + io::println(fmt!("kCTFontExpandedTrait: %b", sym.is_expanded())); + io::println(fmt!("kCTFontCondensedTrait: %b", sym.is_condensed())); + io::println(fmt!("kCTFontMonoSpaceTrait: %b", sym.is_monospace())); +} + #[nolink] #[link_args = "-framework ApplicationServices"] extern { @@ -268,8 +301,8 @@ extern { fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; fn CTFontGetSize(font: CTFontRef) -> CGFloat; //fn CTFontGetMatrix - //fn CTFontGetSymbolicTraits - //fn CTFontCopyTraits + fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits; + fn CTFontCopyTraits(font: CTFontRef) -> CFDictionaryRef; /* Getting Font Names */ fn CTFontCopyPostScriptName(font: CTFontRef) -> CFStringRef; diff --git a/font_descriptor.rs b/font_descriptor.rs index 6e273d7..7601224 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -56,6 +56,22 @@ pub const kCTFontVerticalTrait: CTFontSymbolicTraits = (1 << 11); pub const kCTFontUIOptimizedTrait: CTFontSymbolicTraits = (1 << 12); pub const 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; +} + +pub impl CTFontSymbolicTraits : SymbolicTraitAccessors { + 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 } +} + pub type CTFontStylisticClass = u32; pub const kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift); pub const kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift); @@ -69,6 +85,43 @@ pub const kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMask pub const kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift); pub const 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; +} + +pub impl CTFontStylisticClass : StylisticClassAccessors { + pure fn is_serif() -> bool { + let any_serif_class = kCTFontOldStyleSerifsClass + | kCTFontTransitionalSerifsClass + | kCTFontModernSerifsClass + | kCTFontClarendonSerifsClass + | kCTFontSlabSerifsClass + | kCTFontFreeformSerifsClass; + + return (self & any_serif_class) != 0; + } + + pure fn is_sans_serif() -> bool { + return (self & kCTFontSansSerifClass) != 0; + } + + pure fn is_script() -> bool { + return (self & kCTFontScriptsClass) != 0; + } + + pure fn is_fantasy() -> bool { + return (self & kCTFontOrnamentalsClass) != 0; + } + + pure fn is_symbols() -> bool { + return (self & kCTFontSymbolicClass) != 0; + } +} + /* * CTFontDescriptor.h */ From 0b37b31edb11c94916b1255221d522c170dce739 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 9 Nov 2012 15:12:20 -0800 Subject: [PATCH 017/126] Debug the rest of font traits. --- font.rs | 15 +++++++++++++- font_descriptor.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/font.rs b/font.rs index 2e70d20..07dadde 100644 --- a/font.rs +++ b/font.rs @@ -7,7 +7,9 @@ use font_descriptor::{ CTFontDescriptorRef, CTFontOrientation, CTFontSymbolicTraits, + CTFontTraits, SymbolicTraitAccessors, + TraitAccessors, }; use cf = core_foundation; @@ -23,6 +25,7 @@ use cf::base::{ }; use cf::dictionary::{ CFDictionaryRef, + UntypedCFDictionary, }; use cf::string::{ CFStringGetTypeID, @@ -163,6 +166,11 @@ pub impl CTFont { CTFontGetSymbolicTraits(self.obj) } + pure fn all_traits() -> CTFontTraits unsafe { + let value = CTFontCopyTraits(self.obj); + return cf::base::wrap(value); + } + // Font metrics pure fn ascent() -> CGFloat unsafe { CTFontGetAscent(self.obj) @@ -231,12 +239,17 @@ pub fn debug_font_names(font: &CTFont) { } pub fn debug_font_traits(font: &CTFont) { - let sym = font.symbolic_traits() as SymbolicTraitAccessors; + let sym = font.symbolic_traits(); io::println(fmt!("kCTFontItalicTrait: %b", sym.is_italic())); io::println(fmt!("kCTFontBoldTrait: %b", sym.is_bold())); io::println(fmt!("kCTFontExpandedTrait: %b", sym.is_expanded())); io::println(fmt!("kCTFontCondensedTrait: %b", sym.is_condensed())); io::println(fmt!("kCTFontMonoSpaceTrait: %b", sym.is_monospace())); + + let traits = font.all_traits(); + io::println(fmt!("kCTFontWeightTrait: %f", traits.normalized_weight())); +// io::println(fmt!("kCTFontWidthTrait: %f", traits.normalized_width())); +// io::println(fmt!("kCTFontSlantTrait: %f", traits.normalized_slant())); } #[nolink] diff --git a/font_descriptor.rs b/font_descriptor.rs index 7601224..e818ad5 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -8,13 +8,19 @@ use cf::base::{ CFGetTypeID, CFRange, CFRelease, + CFRetain, + CFType, CFTypeID, CFTypeOps, CFTypeRef, kCFAllocatorDefault, }; -use cf::dictionary::CFDictionaryRef; -use cf::number::CFNumberRef; +use cf::dictionary::{ + CFDictionary, + CFDictionaryRef, + UntypedCFDictionary, +}; +use cf::number::{CFNumber, CFNumberRef}; use cf::set::CFSetRef; use cf::string::{ CFString, @@ -122,6 +128,47 @@ pub impl CTFontStylisticClass : StylisticClassAccessors { } } +pub type CTFontTraits = UntypedCFDictionary; + +pub trait TraitAccessors { + fn symbolic_traits() -> CTFontSymbolicTraits; + fn normalized_weight() -> float; + fn normalized_width() -> float; + fn normalized_slant() -> float; +} + +impl CTFontTraits : TraitAccessors { + priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { + let value : CFType = self.get(&CFString::wrap_extern(key)); + // TODO(Issue #185): use wrap_borrowed + // addref'd since we don't own the reference. + CFRetain(value.get_ref()); + assert value.type_id() == CFNumber::type_id(); + let number : CFNumber = cf::base::convert_from_CFType::(move value); + return move number; + } + + fn symbolic_traits() -> CTFontSymbolicTraits unsafe { + let number = self.extract_number_for_key(kCTFontSymbolicTrait); + return cast::transmute(number.to_i32()); + } + + fn normalized_weight() -> float unsafe { + let number = self.extract_number_for_key(kCTFontWeightTrait); + return cast::transmute(number.to_float()); + } + + fn normalized_width() -> float unsafe { + let number = self.extract_number_for_key(kCTFontWidthTrait); + return cast::transmute(number.to_float()); + } + + fn normalized_slant() -> float unsafe { + let number = self.extract_number_for_key(kCTFontSlantTrait); + return cast::transmute(number.to_float()); + } +} + /* * CTFontDescriptor.h */ From 9c398db2b0627b150eba88edc0eb861dfb4a28ac Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 9 Nov 2012 17:43:13 -0800 Subject: [PATCH 018/126] Make CTFontCollection.get_descriptors() pure. --- font_collection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/font_collection.rs b/font_collection.rs index 2ba15a2..9ea07a1 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -57,7 +57,7 @@ pub impl CTFontCollection { CTFontCollection { obj: move collection } } - fn get_descriptors() -> CFArray { + pure fn get_descriptors() -> CFArray unsafe { cf::base::wrap(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } From 7a42dc503a6b4578f3957c69574e07175b2ca3c5 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Mon, 12 Nov 2012 11:04:46 -0800 Subject: [PATCH 019/126] Add binding for CTFontCreateCopyWithAttributes; expose via wrapper with clone_with_font_size() --- font.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/font.rs b/font.rs index 07dadde..62bf4b8 100644 --- a/font.rs +++ b/font.rs @@ -140,6 +140,11 @@ pub impl CTFont { CTFontCopyGraphicsFont(self.obj, ptr::null()) } + fn clone_with_font_size(&const self, size: float) -> CTFont { + let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, ptr::null(), ptr::null()); + return cf::base::wrap(result); + } + // Names pure fn family_name() -> ~str unsafe { let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); @@ -304,7 +309,8 @@ extern { matrix: *CGAffineTransform) -> CTFontRef; //fn CTFontCreateWithFontDescriptorAndOptions //fn CTFontCreateUIFontForLanguage - //fn CTFontCreateCopyWithAttributes + fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *CGAffineTransform, + attributes: CTFontDescriptorRef) -> CTFontRef; //fn CTFontCreateCopyWithSymbolicTraits //fn CTFontCreateCopyWithFamily //fn CTFontCreateForString From dab5176896750f512410e24e33852ccaf13dbf08 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Mon, 12 Nov 2012 14:07:17 -0800 Subject: [PATCH 020/126] Add API for getting font table data from CTFonts. --- font.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/font.rs b/font.rs index 62bf4b8..b17be07 100644 --- a/font.rs +++ b/font.rs @@ -13,6 +13,9 @@ use font_descriptor::{ }; use cf = core_foundation; +use cf::array::{ + CFArrayRef, +}; use cf::base::{ AbstractCFType, AbstractCFTypeRef, @@ -23,6 +26,10 @@ use cf::base::{ CFTypeID, CFTypeRef, }; +use cf::data::{ + CFData, + CFDataRef, +}; use cf::dictionary::{ CFDictionaryRef, UntypedCFDictionary, @@ -216,6 +223,14 @@ pub impl CTFont { fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float { CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float } + + fn get_font_table(tag: u32) -> Option { + let result = CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic); + return match result.is_null() { + true => None, + false => Some(cf::base::wrap(result)), + } + } } // Helper methods @@ -380,8 +395,8 @@ extern { //fn CTFontCreateWithQuickdrawInstance /* Getting Font Table Data */ - //fn CTFontCopyAvailableTables - //fn CTFontCopyTable + fn CTFontCopyAvailableTables(font: CTFontRef, options: CTFontTableOptions) -> CFArrayRef; + fn CTFontCopyTable(font: CTFontRef, table: CTFontTableTag, options: CTFontTableOptions) -> CFDataRef; fn CTFontGetTypeID() -> CFTypeID; From 4c38ba65d4929ba418317c9fd9d16a0aa83945c9 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Mon, 12 Nov 2012 19:21:47 -0800 Subject: [PATCH 021/126] Add constructor for making CTFonts by (postscript) name. --- font.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/font.rs b/font.rs index b17be07..064dcba 100644 --- a/font.rs +++ b/font.rs @@ -143,6 +143,15 @@ pub impl CTFont { return move cf::base::wrap(value); } + static fn new_from_name(name: ~str, pt_size: float) -> Result { + let cfname = CFString::new(name); + let value = CTFontCreateWithName(cfname.get_ref(), pt_size as CGFloat, ptr::null()); + + if value.is_null() { return Err(()); } + + return Ok(move cf::base::wrap(value)); + } + fn copy_to_CGFont(&const self) -> CGFontRef { CTFontCopyGraphicsFont(self.obj, ptr::null()) } @@ -318,7 +327,7 @@ extern { // to the documentation's Functions By Task listing, because there so many functions. /* Creating Fonts */ - //fn CTFontCreateWithName + fn CTFontCreateWithName(name: CFStringRef, size: CGFloat, matrix: *CGAffineTransform) -> CTFontRef; //fn CTFontCreateWithNameAndOptions fn CTFontCreateWithFontDescriptor(descriptor: CTFontDescriptorRef, size: CGFloat, matrix: *CGAffineTransform) -> CTFontRef; From 4914947bb5663f1b3f83757edc5be38f8f6f6d0d Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Wed, 14 Nov 2012 14:34:15 -0800 Subject: [PATCH 022/126] Support enumeration of faces per font family. Add workarounds for bug in Apple's CTFontCollectionCreateMatchingFontDescriptors. --- font_collection.rs | 66 +++++++++++++++++++++++++++++++++++++++++----- font_descriptor.rs | 30 ++++++++++++++++----- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/font_collection.rs b/font_collection.rs index 9ea07a1..0b17ede 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -8,14 +8,21 @@ use cf::base::{ CFRange, CFRelease, CFTypeID, + CFTypeOps, CFTypeRef, kCFAllocatorDefault, }; use cf::dictionary::{CFDictionary, CFDictionaryRef}; use cf::number::CFNumber; +use cf::set::CFSet; use cf::string::{CFString, CFStringRef}; -use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef}; +use font_descriptor::{ + CTFontDescriptor, + CTFontDescriptorCreateMatchingFontDescriptors, + CTFontDescriptorRef +}; +use font_manager::CTFontManagerCopyAvailableFontFamilyNames; use libc::c_void; @@ -49,7 +56,16 @@ pub impl CTFontCollection : AbstractCFType { } pub impl CTFontCollection { - static fn new() -> CTFontCollection { + static fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { + let options = CFDictionary::new([ + (CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) + ]); + + let collection = CTFontCollectionCreateWithFontDescriptors(descs.get_ref(), options.get_ref()); + CTFontCollection { obj : move collection } + } + + static fn create_for_all_families() -> CTFontCollection { let options = CFDictionary::new([ (CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) ]); @@ -57,8 +73,42 @@ pub impl CTFontCollection { CTFontCollection { obj: move collection } } + static fn create_for_family(family: &str) -> CTFontCollection unsafe { + use font_descriptor::kCTFontFamilyNameAttribute; + + // FIXME: ugly because of Rust #3902 + let family_as_cftype = cf::base::as_CFType::(move CFString::new(family)); + let specified_attrs = CFDictionary::new([ + (CFString::wrap_extern(kCTFontFamilyNameAttribute), move family_as_cftype), + ]); + + let wildcard_desc = CTFontDescriptor::new_from_attributes(&specified_attrs); + let mandatory_attrs = CFSet::new([ + CFString::wrap_extern(kCTFontFamilyNameAttribute) + ]); + + let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(wildcard_desc.get_ref(), + mandatory_attrs.get_ref()); + + let matched_descs : CFArray = cf::base::wrap(matched_descs); + + // I suppose one doesn't even need the CTFontCollection object at this point. + // But we stick descriptors into and out of it just to provide a nice wrapper API. + CTFontCollection::new_from_descriptors(&matched_descs) + } + + static pure fn get_family_names() -> CFArray unsafe { + cf::base::wrap(CTFontManagerCopyAvailableFontFamilyNames()) + } + pure fn get_descriptors() -> CFArray unsafe { - cf::base::wrap(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + use cf::base::CFRetain; + + // 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. + let wrapper : CFArray = cf::base::wrap(CTFontCollectionCreateMatchingFontDescriptors(self.obj)); + CFRetain(wrapper.get_ref().as_type_ref()); + return move wrapper; } } @@ -69,11 +119,15 @@ extern { const kCTFontCollectionRemoveDuplicatesOption: CFStringRef; - fn CTFontCollectionCreateCopyWithFontDescriptors(descriptors: CFArrayRef, options: CFDictionaryRef) -> CTFontCollectionRef; + fn CTFontCollectionCreateCopyWithFontDescriptors(original: CTFontCollectionRef, + descriptors: CFArrayRef, + options: CFDictionaryRef) -> CTFontCollectionRef; fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef; + // this stupid function doesn't actually do any wildcard expansion; + // it just chooses the best match. Use + // CTFontDescriptorCreateMatchingDescriptors instead. fn CTFontCollectionCreateMatchingFontDescriptors(collection: CTFontCollectionRef) -> CFArrayRef; - fn CTFontCollectionCreateWithFontDescriptors(original: CTFontCollectionRef, - descriptors: CFArrayRef, + fn CTFontCollectionCreateWithFontDescriptors(descriptors: CFArrayRef, options: CFDictionaryRef) -> CTFontCollectionRef; //fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback; fn CTFontCollectionGetTypeID() -> CFTypeID; diff --git a/font_descriptor.rs b/font_descriptor.rs index e818ad5..90fb81b 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -128,6 +128,7 @@ pub impl CTFontStylisticClass : StylisticClassAccessors { } } +pub type CTFontAttributes = UntypedCFDictionary; pub type CTFontTraits = UntypedCFDictionary; pub trait TraitAccessors { @@ -215,6 +216,11 @@ pub impl CTFontDescriptor : AbstractCFType { } pub impl CTFontDescriptor { + static fn new_from_attributes(attributes: &CTFontAttributes) -> CTFontDescriptor { + let descriptor = CTFontDescriptorCreateWithAttributes(attributes.get_ref()); + return cf::base::wrap(descriptor) + } + priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { @@ -306,14 +312,24 @@ extern { const kCTFontPriorityAttribute: CFStringRef; const kCTFontEnabledAttribute: CFStringRef; - fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef) -> CFTypeRef; + fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, + attribute: CFStringRef) -> CFTypeRef; fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; - fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef, language: *CFStringRef) -> CFTypeRef; - fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, attributes: CFDictionaryRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, featureTypeIdentifier: CFNumberRef, featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, variationIdentifier: CFNumberRef, variationValue: CGFloat) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef, mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef, mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, + attribute: CFStringRef, + language: *CFStringRef) -> CFTypeRef; + fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, + attributes: CFDictionaryRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, + featureTypeIdentifier: CFNumberRef, + featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; + fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, + variationIdentifier: CFNumberRef, + 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; From 598187ce5b57f4075c6fd29ff41f7dd102223ece Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 15 Nov 2012 11:32:34 -0800 Subject: [PATCH 023/126] Rewrite the Core Foundation wrapper system. --- font.rs | 90 +++++++++++++++++--------------- font_collection.rs | 125 +++++++++++++++++++-------------------------- font_descriptor.rs | 67 ++++++++++-------------- 3 files changed, 130 insertions(+), 152 deletions(-) diff --git a/font.rs b/font.rs index 064dcba..4f11f80 100644 --- a/font.rs +++ b/font.rs @@ -17,14 +17,13 @@ use cf::array::{ CFArrayRef, }; use cf::base::{ - AbstractCFType, AbstractCFTypeRef, CFGetTypeID, CFIndex, CFOptionFlags, - CFRelease, CFTypeID, CFTypeRef, + CFWrapper, }; use cf::data::{ CFData, @@ -108,48 +107,60 @@ impl CTFontRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } } -struct CTFont { - obj: CTFontRef, +pub type CTFont = CFWrapper; - drop { - unsafe { - CFRelease(cast::transmute(self.obj)) - } - } +pub trait CTFontMethods { + // Creation methods + static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont; + static fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont; + static fn new_from_name(name: ~str, pt_size: float) -> Result; + fn copy_to_CGFont(&const self) -> CGFontRef; + fn clone_with_font_size(&const self, size: float) -> CTFont; + + // Names + pure fn family_name() -> ~str; + pure fn face_name() -> ~str; + pure fn unique_name() -> ~str; + pure fn postscript_name() -> ~str; + + // Properties + pure fn all_traits() -> CTFontTraits; + + // Font metrics + pure fn ascent() -> CGFloat; + pure fn descent() -> CGFloat; + pure fn underline_thickness() -> CGFloat; + pure fn underline_position() -> CGFloat; + pure fn bounding_box() -> CGRect; + pure fn leading() -> CGFloat; + pure fn x_height() -> CGFloat; + pure fn pt_size() -> CGFloat; + fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; + fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float; + fn get_font_table(tag: u32) -> Option; } -pub impl CTFont : AbstractCFType { - pure fn get_ref() -> CTFontRef { self.obj } - - static fn wrap(obj: CTFontRef) -> CTFont { - CTFont { obj: obj } - } - - static fn unwrap(wrapper: CTFont) -> CTFontRef { - wrapper.obj - } -} - -pub impl CTFont { +pub impl CTFont : CTFontMethods { // Creation methods static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { assert cgfont.is_not_null(); - let value = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); - return move cf::base::wrap(value); + let result = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); + + CFWrapper::wrap_owned(result) } static fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { - let value = CTFontCreateWithFontDescriptor(desc.get_ref(), pt_size as CGFloat, ptr::null()); - return move cf::base::wrap(value); + let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()); + + CFWrapper::wrap_owned(result) } static fn new_from_name(name: ~str, pt_size: float) -> Result { let cfname = CFString::new(name); - let value = CTFontCreateWithName(cfname.get_ref(), pt_size as CGFloat, ptr::null()); + let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); + if result.is_null() { return Err(()); } - if value.is_null() { return Err(()); } - - return Ok(move cf::base::wrap(value)); + return Ok(move CFWrapper::wrap_owned(result)); } fn copy_to_CGFont(&const self) -> CGFontRef { @@ -158,7 +169,7 @@ pub impl CTFont { fn clone_with_font_size(&const self, size: float) -> CTFont { let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, ptr::null(), ptr::null()); - return cf::base::wrap(result); + CFWrapper::wrap_owned(result) } // Names @@ -188,8 +199,8 @@ pub impl CTFont { } pure fn all_traits() -> CTFontTraits unsafe { - let value = CTFontCopyTraits(self.obj); - return cf::base::wrap(value); + let result = CTFontCopyTraits(self.obj); + CFWrapper::wrap_owned(result) } // Font metrics @@ -237,20 +248,19 @@ pub impl CTFont { let result = CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic); return match result.is_null() { true => None, - false => Some(cf::base::wrap(result)), + false => Some(CFWrapper::wrap_owned(result)), } } } // Helper methods priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { - let value = CTFontCopyName(font.get_ref(), name_key); - if value.is_null() { - return None; - } + let result = CTFontCopyName(*font.borrow_ref(), name_key); + if result.is_null() { return None; } - assert CFGetTypeID(value.as_type_ref()) == CFStringGetTypeID(); - let cfstr: CFString = cf::base::wrap(value as CFStringRef); + // TODO: do this inside wrap_owned + let cfstr: CFString = CFWrapper::wrap_owned(result as CFStringRef); + assert cfstr.type_id() == CFStringGetTypeID(); return Some(cfstr.to_str()); } diff --git a/font_collection.rs b/font_collection.rs index 0b17ede..fe51eba 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,26 +1,25 @@ use cf = core_foundation; use cf::array::{CFArray, CFArrayRef}; use cf::base::{ - AbstractCFType, AbstractCFTypeRef, CFAllocatorRef, CFIndex, CFRange, - CFRelease, CFTypeID, - CFTypeOps, CFTypeRef, + CFWrapper, kCFAllocatorDefault, }; -use cf::dictionary::{CFDictionary, CFDictionaryRef}; +use cf::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary}; use cf::number::CFNumber; use cf::set::CFSet; use cf::string::{CFString, CFStringRef}; use font_descriptor::{ + CTFontAttributes, CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescriptors, - CTFontDescriptorRef + CTFontDescriptorRef, }; use font_manager::CTFontManagerCopyAvailableFontFamilyNames; @@ -33,85 +32,65 @@ impl CTFontCollectionRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } } -struct CTFontCollection { - obj: CTFontCollectionRef, +pub type CTFontCollection = CFWrapper; - drop { - unsafe { - CFRelease(cast::transmute(self.obj)) - } - } +pub trait CTFontCollectionMethods { + pure fn get_descriptors() -> CFArray; } -pub impl CTFontCollection : AbstractCFType { - pure fn get_ref() -> CTFontCollectionRef { self.obj } - - static fn wrap(obj: CTFontCollectionRef) -> CTFontCollection { - CTFontCollection { obj: obj } - } - - static fn unwrap(wrapper: CTFontCollection) -> CTFontCollectionRef { - wrapper.obj - } -} - -pub impl CTFontCollection { - static fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { - let options = CFDictionary::new([ - (CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) - ]); - - let collection = CTFontCollectionCreateWithFontDescriptors(descs.get_ref(), options.get_ref()); - CTFontCollection { obj : move collection } - } - - static fn create_for_all_families() -> CTFontCollection { - let options = CFDictionary::new([ - (CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption), CFNumber::new(1_i8)) - ]); - let collection = CTFontCollectionCreateFromAvailableFonts(options.get_ref()); - CTFontCollection { obj: move collection } - } - - static fn create_for_family(family: &str) -> CTFontCollection unsafe { - use font_descriptor::kCTFontFamilyNameAttribute; - - // FIXME: ugly because of Rust #3902 - let family_as_cftype = cf::base::as_CFType::(move CFString::new(family)); - let specified_attrs = CFDictionary::new([ - (CFString::wrap_extern(kCTFontFamilyNameAttribute), move family_as_cftype), - ]); - - let wildcard_desc = CTFontDescriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::new([ - CFString::wrap_extern(kCTFontFamilyNameAttribute) - ]); - - let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(wildcard_desc.get_ref(), - mandatory_attrs.get_ref()); - - let matched_descs : CFArray = cf::base::wrap(matched_descs); - - // I suppose one doesn't even need the CTFontCollection object at this point. - // But we stick descriptors into and out of it just to provide a nice wrapper API. - CTFontCollection::new_from_descriptors(&matched_descs) - } - - static pure fn get_family_names() -> CFArray unsafe { - cf::base::wrap(CTFontManagerCopyAvailableFontFamilyNames()) - } - - pure fn get_descriptors() -> CFArray unsafe { +pub impl CTFontCollection : CTFontCollectionMethods { + pure fn get_descriptors() -> CFArray unsafe { use cf::base::CFRetain; // 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. - let wrapper : CFArray = cf::base::wrap(CTFontCollectionCreateMatchingFontDescriptors(self.obj)); - CFRetain(wrapper.get_ref().as_type_ref()); + let wrapper : CFArray = CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)); return move wrapper; } } +pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { + let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let value = CFNumber::new(1_i8); + let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let result = CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), *options.borrow_ref()); + CFWrapper::wrap_owned(result) +} + +pub fn create_for_all_families() -> CTFontCollection { + let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let value = CFNumber::new(1_i8); + let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let result = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + CFWrapper::wrap_owned(result) +} + +pub fn create_for_family(family: &str) -> CTFontCollection unsafe { + use font_descriptor::kCTFontFamilyNameAttribute; + + let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); + let family_name = CFString::new(family); + + let specified_attrs : CFWrapper = CFDictionary::new([ + ( *family_attr.borrow_ref(), *family_name.borrow_type_ref() ) + ]); + + let wildcard_desc : CTFontDescriptor = font_descriptor::new_from_attributes(&specified_attrs); + let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); + let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(*wildcard_desc.borrow_ref(), + *mandatory_attrs.borrow_ref()); + + let matched_descs : CFArray = CFWrapper::wrap_owned(matched_descs); + + // I suppose one doesn't even need the CTFontCollection object at this point. + // But we stick descriptors into and out of it just to provide a nice wrapper API. + font_collection::new_from_descriptors(&matched_descs) +} + +pub pure fn get_family_names() -> CFArray unsafe { + CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) +} + extern { /* * CTFontCollection.h diff --git a/font_descriptor.rs b/font_descriptor.rs index 90fb81b..213ee4c 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,18 +1,15 @@ use cf = core_foundation; use cf::array::CFArrayRef; use cf::base::{ - AbstractCFType, AbstractCFTypeRef, CFAllocatorRef, CFIndex, CFGetTypeID, CFRange, - CFRelease, - CFRetain, CFType, CFTypeID, - CFTypeOps, CFTypeRef, + CFWrapper, kCFAllocatorDefault, }; use cf::dictionary::{ @@ -140,13 +137,11 @@ pub trait TraitAccessors { impl CTFontTraits : TraitAccessors { priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { - let value : CFType = self.get(&CFString::wrap_extern(key)); - // TODO(Issue #185): use wrap_borrowed - // addref'd since we don't own the reference. - CFRetain(value.get_ref()); - assert value.type_id() == CFNumber::type_id(); - let number : CFNumber = cf::base::convert_from_CFType::(move value); - return move number; + let value : CFTypeRef = self.get(&key); + let wrapper : CFType = CFWrapper::wrap_shared(value); + // TODO: do this in CFWrapper::wrap_shared + assert wrapper.type_id() == CFNumberRef::type_id(); + CFWrapper::from_CFType::(move wrapper) } fn symbolic_traits() -> CTFontSymbolicTraits unsafe { @@ -193,42 +188,28 @@ impl CTFontDescriptorRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } } -struct CTFontDescriptor { - obj: CTFontDescriptorRef, +pub type CTFontDescriptor = CFWrapper; - drop { - unsafe { - CFRelease(cast::transmute(self.obj)) - } - } +pub trait CTFontDescriptorMethods { + fn family_name() -> ~str; + fn font_name() -> ~str; + fn style_name() -> ~str; + fn display_name() -> ~str; + fn font_path() -> ~str; } -pub impl CTFontDescriptor : AbstractCFType { - pure fn get_ref() -> CTFontDescriptorRef { self.obj } - - static fn wrap(obj: CTFontDescriptorRef) -> CTFontDescriptor { - CTFontDescriptor { obj: obj } - } - - static fn unwrap(wrapper: CTFontDescriptor) -> CTFontDescriptorRef { - wrapper.obj - } -} - -pub impl CTFontDescriptor { - static fn new_from_attributes(attributes: &CTFontAttributes) -> CTFontDescriptor { - let descriptor = CTFontDescriptorCreateWithAttributes(attributes.get_ref()); - return cf::base::wrap(descriptor) - } - +pub impl CTFontDescriptor : CTFontDescriptorMethods { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { return None; } - assert CFGetTypeID(value) == CFStringGetTypeID(); - let cfstr: CFString = cf::base::wrap(value as CFStringRef); + let cfty: CFType = CFWrapper::wrap_owned(value); + // TODO: check in wrap_owned + assert cfty.type_id() == CFStringGetTypeID(); + + let cfstr: CFString = CFWrapper::from_CFType::(move cfty); return Some(cfstr.to_str()); } @@ -255,13 +236,21 @@ pub impl CTFontDescriptor { fn font_path() -> ~str { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); assert value.is_not_null(); + + let cfty = CFWrapper::wrap_owned(value); assert CFGetTypeID(value) == CFURLGetTypeID(); - let cfurl : CFURL = cf::base::wrap(value as CFURLRef); + let cfurl : CFURL = CFWrapper::from_CFType::(move cfty); return cfurl.to_str(); } } +pub fn new_from_attributes(attributes: &CFWrapper) -> CTFontDescriptor { + let result : CTFontDescriptorRef = CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); + let ret : CTFontDescriptor =CFWrapper::wrap_owned(result); + return move ret; +} + pub fn debug_descriptor(desc: &CTFontDescriptor) { io::println(fmt!("family: %s", desc.family_name())); io::println(fmt!("name: %s", desc.font_name())); From a3f597bbbc02d47151a3058905af3fcf6c7482a8 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 16 Nov 2012 11:20:32 -0800 Subject: [PATCH 024/126] Move CTFont static methods outside of trait/impl. --- font.rs | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/font.rs b/font.rs index 4f11f80..212b64b 100644 --- a/font.rs +++ b/font.rs @@ -110,10 +110,7 @@ impl CTFontRef : AbstractCFTypeRef { pub type CTFont = CFWrapper; pub trait CTFontMethods { - // Creation methods - static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont; - static fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont; - static fn new_from_name(name: ~str, pt_size: float) -> Result; + // Creation methods (statics below) fn copy_to_CGFont(&const self) -> CGFontRef; fn clone_with_font_size(&const self, size: float) -> CTFont; @@ -140,29 +137,29 @@ pub trait CTFontMethods { fn get_font_table(tag: u32) -> Option; } +pub fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { + assert cgfont.is_not_null(); + let result = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); + + CFWrapper::wrap_owned(result) +} + +pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { + let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()); + + CFWrapper::wrap_owned(result) +} + +pub fn new_from_name(name: ~str, pt_size: float) -> Result { + let cfname = CFString::new(name); + let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); + if result.is_null() { return Err(()); } + + return Ok(move CFWrapper::wrap_owned(result)); +} + pub impl CTFont : CTFontMethods { // Creation methods - static fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { - assert cgfont.is_not_null(); - let result = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); - - CFWrapper::wrap_owned(result) - } - - static fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { - let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()); - - CFWrapper::wrap_owned(result) - } - - static fn new_from_name(name: ~str, pt_size: float) -> Result { - let cfname = CFString::new(name); - let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); - if result.is_null() { return Err(()); } - - return Ok(move CFWrapper::wrap_owned(result)); - } - fn copy_to_CGFont(&const self) -> CGFontRef { CTFontCopyGraphicsFont(self.obj, ptr::null()) } From ea18d1d47385d64f6a7938c4a9e68423084c9657 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 16 Nov 2012 14:30:17 -0800 Subject: [PATCH 025/126] Implement AbstractCFType::type_id(). Switch to use CFTypeRef::downcast(). --- font.rs | 7 ++----- font_collection.rs | 4 ++-- font_descriptor.rs | 44 +++++++++++++++----------------------------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/font.rs b/font.rs index 212b64b..d2e074d 100644 --- a/font.rs +++ b/font.rs @@ -18,7 +18,6 @@ use cf::array::{ }; use cf::base::{ AbstractCFTypeRef, - CFGetTypeID, CFIndex, CFOptionFlags, CFTypeID, @@ -105,6 +104,7 @@ pub type CTFontRef = *__CTFont; impl CTFontRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + static pure fn type_id() -> CFTypeID unsafe { CTFontGetTypeID() } } pub type CTFont = CFWrapper; @@ -255,10 +255,7 @@ priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~ let result = CTFontCopyName(*font.borrow_ref(), name_key); if result.is_null() { return None; } - // TODO: do this inside wrap_owned - let cfstr: CFString = CFWrapper::wrap_owned(result as CFStringRef); - assert cfstr.type_id() == CFStringGetTypeID(); - return Some(cfstr.to_str()); + return Some(CFWrapper::wrap_owned(result).to_str()); } pub fn debug_font_names(font: &CTFont) { diff --git a/font_collection.rs b/font_collection.rs index fe51eba..95e6b46 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -30,6 +30,7 @@ pub type CTFontCollectionRef = *__CTFontCollection; impl CTFontCollectionRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + static pure fn type_id() -> CFTypeID unsafe { CTFontCollectionGetTypeID() } } pub type CTFontCollection = CFWrapper; @@ -44,8 +45,7 @@ pub impl CTFontCollection : CTFontCollectionMethods { // 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. - let wrapper : CFArray = CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)); - return move wrapper; + CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } diff --git a/font_descriptor.rs b/font_descriptor.rs index 213ee4c..6fceec2 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -137,31 +137,28 @@ pub trait TraitAccessors { impl CTFontTraits : TraitAccessors { priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { - let value : CFTypeRef = self.get(&key); - let wrapper : CFType = CFWrapper::wrap_shared(value); - // TODO: do this in CFWrapper::wrap_shared - assert wrapper.type_id() == CFNumberRef::type_id(); - CFWrapper::from_CFType::(move wrapper) + let value = self.get(&key); + CFWrapper::wrap_shared(cf::base::downcast::(value)) } fn symbolic_traits() -> CTFontSymbolicTraits unsafe { let number = self.extract_number_for_key(kCTFontSymbolicTrait); - return cast::transmute(number.to_i32()); + cast::transmute(number.to_i32()) } fn normalized_weight() -> float unsafe { let number = self.extract_number_for_key(kCTFontWeightTrait); - return cast::transmute(number.to_float()); + cast::transmute(number.to_float()) } fn normalized_width() -> float unsafe { let number = self.extract_number_for_key(kCTFontWidthTrait); - return cast::transmute(number.to_float()); + cast::transmute(number.to_float()) } fn normalized_slant() -> float unsafe { let number = self.extract_number_for_key(kCTFontSlantTrait); - return cast::transmute(number.to_float()); + cast::transmute(number.to_float()) } } @@ -186,6 +183,7 @@ pub type CTFontDescriptorRef = *__CTFontDescriptor; impl CTFontDescriptorRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + static pure fn type_id() -> CFTypeID unsafe { CTFontDescriptorGetTypeID() } } pub type CTFontDescriptor = CFWrapper; @@ -201,54 +199,42 @@ pub trait CTFontDescriptorMethods { pub impl CTFontDescriptor : CTFontDescriptorMethods { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); - if value.is_null() { - return None; - } + if value.is_null() { return None; } - let cfty: CFType = CFWrapper::wrap_owned(value); - // TODO: check in wrap_owned - assert cfty.type_id() == CFStringGetTypeID(); - - let cfstr: CFString = CFWrapper::from_CFType::(move cfty); - return Some(cfstr.to_str()); + Some(CFWrapper::wrap_owned(cf::base::downcast::(value)).to_str()) } fn family_name() -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - return option::expect(move value, ~"A font must have a non-null font family name."); + option::expect(move value, ~"A font must have a non-null font family name.") } fn font_name() -> ~str { let value = self.get_string_attribute(kCTFontNameAttribute); - return option::expect(move value, ~"A font must have a non-null name."); + option::expect(move value, ~"A font must have a non-null name.") } fn style_name() -> ~str { let value = self.get_string_attribute(kCTFontStyleNameAttribute); - return option::expect(move value, ~"A font must have a non-null style name."); + option::expect(move value, ~"A font must have a non-null style name.") } fn display_name() -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - return move option::expect(move value, ~"A font must have a non-null display name."); + option::expect(move value, ~"A font must have a non-null display name.") } fn font_path() -> ~str { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); assert value.is_not_null(); - let cfty = CFWrapper::wrap_owned(value); - assert CFGetTypeID(value) == CFURLGetTypeID(); - - let cfurl : CFURL = CFWrapper::from_CFType::(move cfty); - return cfurl.to_str(); + CFWrapper::wrap_owned(cf::base::downcast::(value)).to_str() } } pub fn new_from_attributes(attributes: &CFWrapper) -> CTFontDescriptor { let result : CTFontDescriptorRef = CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); - let ret : CTFontDescriptor =CFWrapper::wrap_owned(result); - return move ret; + CFWrapper::wrap_owned(result) } pub fn debug_descriptor(desc: &CTFontDescriptor) { From 2b306ea65aaa348ec3158588fa78779fd4a1629b Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 16 Nov 2012 15:18:47 -0800 Subject: [PATCH 026/126] Convert to use CGFont binding. --- font.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/font.rs b/font.rs index d2e074d..8a3cd19 100644 --- a/font.rs +++ b/font.rs @@ -46,6 +46,7 @@ use cg::base::{ }; use cg::font::{ CGGlyph, + CGFont, CGFontRef, }; use cg::geometry::{ @@ -111,7 +112,7 @@ pub type CTFont = CFWrapper; pub trait CTFontMethods { // Creation methods (statics below) - fn copy_to_CGFont(&const self) -> CGFontRef; + fn copy_to_CGFont(&const self) -> CGFont; fn clone_with_font_size(&const self, size: float) -> CTFont; // Names @@ -137,16 +138,13 @@ pub trait CTFontMethods { fn get_font_table(tag: u32) -> Option; } -pub fn new_from_CGFont(cgfont: CGFontRef, pt_size: float) -> CTFont { - assert cgfont.is_not_null(); - let result = CTFontCreateWithGraphicsFont(cgfont, pt_size as CGFloat, ptr::null(), ptr::null()); - +pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { + let result = CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()); CFWrapper::wrap_owned(result) } pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()); - CFWrapper::wrap_owned(result) } @@ -160,8 +158,9 @@ pub fn new_from_name(name: ~str, pt_size: float) -> Result { pub impl CTFont : CTFontMethods { // Creation methods - fn copy_to_CGFont(&const self) -> CGFontRef { - CTFontCopyGraphicsFont(self.obj, ptr::null()) + fn copy_to_CGFont(&const self) -> CGFont { + let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); + CFWrapper::wrap_owned(value) } fn clone_with_font_size(&const self, size: float) -> CTFont { From 87af01643fa7e5cd06a3fb58d66b387046303f9a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 4 Dec 2012 17:02:10 -0800 Subject: [PATCH 027/126] Update for language churn --- font.rs | 17 ++++++++++++----- font_descriptor.rs | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/font.rs b/font.rs index 8a3cd19..308d806 100644 --- a/font.rs +++ b/font.rs @@ -156,6 +156,18 @@ pub fn new_from_name(name: ~str, pt_size: float) -> Result { return Ok(move CFWrapper::wrap_owned(result)); } +priv trait CTFontMethodsPrivate { + pure fn symbolic_traits() -> CTFontSymbolicTraits; +} + +pub impl CTFont: CTFontMethodsPrivate { + + // Properties + priv pure fn symbolic_traits() -> CTFontSymbolicTraits unsafe { + CTFontGetSymbolicTraits(self.obj) + } +} + pub impl CTFont : CTFontMethods { // Creation methods fn copy_to_CGFont(&const self) -> CGFont { @@ -189,11 +201,6 @@ pub impl CTFont : CTFontMethods { return move option::expect(move value, ~"Fonts should always have a PostScript name."); } - // Properties - priv pure fn symbolic_traits() -> CTFontSymbolicTraits unsafe { - CTFontGetSymbolicTraits(self.obj) - } - pure fn all_traits() -> CTFontTraits unsafe { let result = CTFontCopyTraits(self.obj); CFWrapper::wrap_owned(result) diff --git a/font_descriptor.rs b/font_descriptor.rs index 6fceec2..b7ff666 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -135,12 +135,19 @@ pub trait TraitAccessors { fn normalized_slant() -> float; } -impl CTFontTraits : TraitAccessors { +priv trait TraitAccessorPrivate { + fn extract_number_for_key(key: CFStringRef) -> CFNumber; +} + +impl CTFontTraits: TraitAccessorPrivate { priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { let value = self.get(&key); CFWrapper::wrap_shared(cf::base::downcast::(value)) } +} + +impl CTFontTraits : TraitAccessors { fn symbolic_traits() -> CTFontSymbolicTraits unsafe { let number = self.extract_number_for_key(kCTFontSymbolicTrait); cast::transmute(number.to_i32()) @@ -196,7 +203,11 @@ pub trait CTFontDescriptorMethods { fn font_path() -> ~str; } -pub impl CTFontDescriptor : CTFontDescriptorMethods { +priv trait CTFontDescriptorMethodsPrivate { + fn get_string_attribute(attribute: CFStringRef) -> Option<~str>; +} + +impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { return None; } @@ -204,6 +215,9 @@ pub impl CTFontDescriptor : CTFontDescriptorMethods { Some(CFWrapper::wrap_owned(cf::base::downcast::(value)).to_str()) } +} + +pub impl CTFontDescriptor : CTFontDescriptorMethods { fn family_name() -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); option::expect(move value, ~"A font must have a non-null font family name.") From e777e17f054be294792a097d5aaa7a1f56f018bc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 13 Dec 2012 18:39:35 -0800 Subject: [PATCH 028/126] Update for language changes --- font.rs | 67 +++++++++------------------------------------- font_collection.rs | 38 +++++++++----------------- font_descriptor.rs | 59 +++++++++++++--------------------------- font_manager.rs | 7 +++-- 4 files changed, 45 insertions(+), 126 deletions(-) diff --git a/font.rs b/font.rs index 308d806..1859cfd 100644 --- a/font.rs +++ b/font.rs @@ -1,62 +1,19 @@ extern mod core_foundation; extern mod core_graphics; -use libc::c_uint; +use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; +use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; -use font_descriptor::{ - CTFontDescriptorRef, - CTFontOrientation, - CTFontSymbolicTraits, - CTFontTraits, - SymbolicTraitAccessors, - TraitAccessors, -}; - -use cf = core_foundation; -use cf::array::{ - CFArrayRef, -}; -use cf::base::{ - AbstractCFTypeRef, - CFIndex, - CFOptionFlags, - CFTypeID, - CFTypeRef, - CFWrapper, -}; -use cf::data::{ - CFData, - CFDataRef, -}; -use cf::dictionary::{ - CFDictionaryRef, - UntypedCFDictionary, -}; -use cf::string::{ - CFStringGetTypeID, - CFString, - CFStringRef, - UniChar -}; - -use cg = core_graphics; -use cg::base::{ - CGAffineTransform, - CGFloat, -}; -use cg::font::{ - CGGlyph, - CGFont, - CGFontRef, -}; -use cg::geometry::{ - CGRect, - CGSize, -}; - -use font_descriptor::{ - CTFontDescriptor -}; +use core::libc::c_uint; +use core_foundation::array::{CFArrayRef}; +use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef}; +use core_foundation::base::{CFWrapper}; +use core_foundation::data::{CFData, CFDataRef}; +use core_foundation::dictionary::{CFDictionaryRef, UntypedCFDictionary}; +use core_foundation::string::{CFStringGetTypeID, CFString, CFStringRef, UniChar}; +use core_graphics::base::{CGAffineTransform, CGFloat}; +use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; +use core_graphics::geometry::{CGRect, CGSize}; pub type CTFontUIFontType = u32; // kCTFontNoFontType: CTFontUIFontType = -1; diff --git a/font_collection.rs b/font_collection.rs index 95e6b46..cbea144 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,29 +1,15 @@ -use cf = core_foundation; -use cf::array::{CFArray, CFArrayRef}; -use cf::base::{ - AbstractCFTypeRef, - CFAllocatorRef, - CFIndex, - CFRange, - CFTypeID, - CFTypeRef, - CFWrapper, - kCFAllocatorDefault, -}; -use cf::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary}; -use cf::number::CFNumber; -use cf::set::CFSet; -use cf::string::{CFString, CFStringRef}; - -use font_descriptor::{ - CTFontAttributes, - CTFontDescriptor, - CTFontDescriptorCreateMatchingFontDescriptors, - CTFontDescriptorRef, -}; +use font_descriptor::{CTFontAttributes, CTFontDescriptor}; +use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef}; use font_manager::CTFontManagerCopyAvailableFontFamilyNames; -use libc::c_void; +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::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary}; +use core_foundation::number::CFNumber; +use core_foundation::set::CFSet; +use core_foundation::string::{CFString, CFStringRef}; struct __CTFontCollection { private: () } pub type CTFontCollectionRef = *__CTFontCollection; @@ -41,7 +27,7 @@ pub trait CTFontCollectionMethods { pub impl CTFontCollection : CTFontCollectionMethods { pure fn get_descriptors() -> CFArray unsafe { - use cf::base::CFRetain; + use core_foundation::base::CFRetain; // 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. @@ -110,4 +96,4 @@ extern { options: CFDictionaryRef) -> CTFontCollectionRef; //fn CTFontCollectionCreateMatchingFontDescriptorsSortedWithCallback; fn CTFontCollectionGetTypeID() -> CFTypeID; -} \ No newline at end of file +} diff --git a/font_descriptor.rs b/font_descriptor.rs index b7ff666..4264cf1 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,38 +1,12 @@ -use cf = core_foundation; -use cf::array::CFArrayRef; -use cf::base::{ - AbstractCFTypeRef, - CFAllocatorRef, - CFIndex, - CFGetTypeID, - CFRange, - CFType, - CFTypeID, - CFTypeRef, - CFWrapper, - kCFAllocatorDefault, -}; -use cf::dictionary::{ - CFDictionary, - CFDictionaryRef, - UntypedCFDictionary, -}; -use cf::number::{CFNumber, CFNumberRef}; -use cf::set::CFSetRef; -use cf::string::{ - CFString, - CFStringRef, - CFStringGetTypeID, -}; -use cf::url::{ - CFURL, - CFURLRef, - CFURLGetTypeID, -}; - -use cg = core_graphics; -use cg::base::CGFloat; - +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::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; /* @@ -142,7 +116,7 @@ priv trait TraitAccessorPrivate { impl CTFontTraits: TraitAccessorPrivate { priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { let value = self.get(&key); - CFWrapper::wrap_shared(cf::base::downcast::(value)) + CFWrapper::wrap_shared(core_foundation::base::downcast::(value)) } } @@ -212,7 +186,8 @@ impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { return None; } - Some(CFWrapper::wrap_owned(cf::base::downcast::(value)).to_str()) + Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( + value)).to_str()) } } @@ -242,12 +217,14 @@ pub impl CTFontDescriptor : CTFontDescriptorMethods { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); assert value.is_not_null(); - CFWrapper::wrap_owned(cf::base::downcast::(value)).to_str() + CFWrapper::wrap_owned(core_foundation::base::downcast::(value)).to_str() } } -pub fn new_from_attributes(attributes: &CFWrapper) -> CTFontDescriptor { - let result : CTFontDescriptorRef = CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); +pub fn new_from_attributes(attributes: &CFWrapper) + -> CTFontDescriptor { + let result: CTFontDescriptorRef = + CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); CFWrapper::wrap_owned(result) } @@ -322,4 +299,4 @@ extern { fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef; fn CTFontDescriptorCreateWithNameAndSize(name: CFStringRef, size: CGFloat) -> CTFontDescriptorRef; fn CTFontDescriptorGetTypeID() -> CFTypeID; -} \ No newline at end of file +} diff --git a/font_manager.rs b/font_manager.rs index 98f1a38..8538d95 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -1,6 +1,5 @@ -use cf = core_foundation; -use cf::array::CFArrayRef; -use cf::url::CFURLRef; +use core_foundation::array::CFArrayRef; +use core_foundation::url::CFURLRef; extern { /* @@ -29,4 +28,4 @@ extern { //fn CTFontManagerUnregisterFontsForURL //fn CTFontManagerUnregisterFontsForURLs //fn CTFontManagerUnregisterGraphicsFont -} \ No newline at end of file +} From 6e163d5bab3bef6cebe7660867388da5a8681b9f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 20 Jan 2013 18:50:51 -0800 Subject: [PATCH 029/126] Rust upgrade --- font_collection.rs | 3 ++- font_descriptor.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/font_collection.rs b/font_collection.rs index cbea144..7bf0167 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,3 +1,4 @@ +use font_descriptor; use font_descriptor::{CTFontAttributes, CTFontDescriptor}; use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef}; use font_manager::CTFontManagerCopyAvailableFontFamilyNames; @@ -70,7 +71,7 @@ pub fn create_for_family(family: &str) -> CTFontCollection unsafe { // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. - font_collection::new_from_descriptors(&matched_descs) + new_from_descriptors(&matched_descs) } pub pure fn get_family_names() -> CFArray unsafe { diff --git a/font_descriptor.rs b/font_descriptor.rs index 4264cf1..f9e21ee 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,3 +1,4 @@ +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}; From d54ba38e73e2d46f713cf148a44a829d41db44bd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 30 Jan 2013 14:34:16 -0800 Subject: [PATCH 030/126] Rust upgrade --- font.rs | 128 +++++++++++++++++++++++++++++---------------- font_collection.rs | 58 +++++++++++--------- font_descriptor.rs | 68 ++++++++++++++---------- 3 files changed, 155 insertions(+), 99 deletions(-) diff --git a/font.rs b/font.rs index 1859cfd..a1a16ee 100644 --- a/font.rs +++ b/font.rs @@ -62,7 +62,7 @@ pub type CTFontRef = *__CTFont; impl CTFontRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID unsafe { CTFontGetTypeID() } + static pure fn type_id() -> CFTypeID { unsafe { CTFontGetTypeID() } } } pub type CTFont = CFWrapper; @@ -96,18 +96,18 @@ pub trait CTFontMethods { } pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { - let result = CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()); + let result = unsafe { CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()) }; CFWrapper::wrap_owned(result) } pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { - let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()); + let result = unsafe { CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()) }; CFWrapper::wrap_owned(result) } pub fn new_from_name(name: ~str, pt_size: float) -> Result { let cfname = CFString::new(name); - let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); + let result = unsafe { CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()) }; if result.is_null() { return Err(()); } return Ok(move CFWrapper::wrap_owned(result)); @@ -120,92 +120,128 @@ priv trait CTFontMethodsPrivate { pub impl CTFont: CTFontMethodsPrivate { // Properties - priv pure fn symbolic_traits() -> CTFontSymbolicTraits unsafe { - CTFontGetSymbolicTraits(self.obj) + priv pure fn symbolic_traits() -> CTFontSymbolicTraits { + unsafe { + CTFontGetSymbolicTraits(self.obj) + } } } pub impl CTFont : CTFontMethods { // Creation methods fn copy_to_CGFont(&const self) -> CGFont { - let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); - CFWrapper::wrap_owned(value) + unsafe { + let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); + CFWrapper::wrap_owned(value) + } } fn clone_with_font_size(&const self, size: float) -> CTFont { - let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, ptr::null(), ptr::null()); - CFWrapper::wrap_owned(result) + unsafe { + let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, ptr::null(), ptr::null()); + CFWrapper::wrap_owned(result) + } } // Names - pure fn family_name() -> ~str unsafe { - let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); - return move option::expect(move value, ~"Fonts should always have a family name."); + pure fn family_name() -> ~str { + unsafe { + let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); + return move option::expect(move value, ~"Fonts should always have a family name."); + } } - pure fn face_name() -> ~str unsafe { - let value = get_string_by_name_key(&self, kCTFontSubFamilyNameKey); - return move option::expect(move value, ~"Fonts should always have a face name."); + pure fn face_name() -> ~str { + unsafe { + let value = get_string_by_name_key(&self, kCTFontSubFamilyNameKey); + return move option::expect(move value, ~"Fonts should always have a face name."); + } } - pure fn unique_name() -> ~str unsafe { - let value = get_string_by_name_key(&self, kCTFontUniqueNameKey); - return move option::expect(move value, ~"Fonts should always have a unique name."); + pure fn unique_name() -> ~str { + unsafe { + let value = get_string_by_name_key(&self, kCTFontUniqueNameKey); + return move option::expect(move value, ~"Fonts should always have a unique name."); + } } - pure fn postscript_name() -> ~str unsafe { - let value = get_string_by_name_key(&self, kCTFontPostScriptNameKey); - return move option::expect(move value, ~"Fonts should always have a PostScript name."); + pure fn postscript_name() -> ~str { + unsafe { + let value = get_string_by_name_key(&self, kCTFontPostScriptNameKey); + return move option::expect(move value, ~"Fonts should always have a PostScript name."); + } } - pure fn all_traits() -> CTFontTraits unsafe { - let result = CTFontCopyTraits(self.obj); - CFWrapper::wrap_owned(result) + pure fn all_traits() -> CTFontTraits { + unsafe { + let result = CTFontCopyTraits(self.obj); + CFWrapper::wrap_owned(result) + } } // Font metrics - pure fn ascent() -> CGFloat unsafe { - CTFontGetAscent(self.obj) + pure fn ascent() -> CGFloat { + unsafe { + CTFontGetAscent(self.obj) + } } - pure fn descent() -> CGFloat unsafe { - CTFontGetDescent(self.obj) + pure fn descent() -> CGFloat { + unsafe { + CTFontGetDescent(self.obj) + } } - pure fn underline_thickness() -> CGFloat unsafe { - CTFontGetUnderlineThickness(self.obj) + pure fn underline_thickness() -> CGFloat { + unsafe { + CTFontGetUnderlineThickness(self.obj) + } } - pure fn underline_position() -> CGFloat unsafe { - CTFontGetUnderlinePosition(self.obj) + pure fn underline_position() -> CGFloat { + unsafe { + CTFontGetUnderlinePosition(self.obj) + } } - pure fn bounding_box() -> CGRect unsafe { - CTFontGetBoundingBox(self.obj) + pure fn bounding_box() -> CGRect { + unsafe { + CTFontGetBoundingBox(self.obj) + } } - pure fn leading() -> CGFloat unsafe { - CTFontGetLeading(self.obj) + pure fn leading() -> CGFloat { + unsafe { + CTFontGetLeading(self.obj) + } } - pure fn x_height() -> CGFloat unsafe { - CTFontGetXHeight(self.obj) + pure fn x_height() -> CGFloat { + unsafe { + CTFontGetXHeight(self.obj) + } } - pure fn pt_size() -> CGFloat unsafe { - CTFontGetSize(self.obj) + pure fn pt_size() -> CGFloat { + unsafe { + CTFontGetSize(self.obj) + } } - fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool unsafe { - CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) + fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool { + unsafe { + CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) + } } fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float { - CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float + unsafe { + CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float + } } fn get_font_table(tag: u32) -> Option { - let result = CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic); + let result = unsafe { CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic) }; return match result.is_null() { true => None, false => Some(CFWrapper::wrap_owned(result)), @@ -215,7 +251,7 @@ pub impl CTFont : CTFontMethods { // Helper methods priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { - let result = CTFontCopyName(*font.borrow_ref(), name_key); + let result = unsafe { CTFontCopyName(*font.borrow_ref(), name_key) }; if result.is_null() { return None; } return Some(CFWrapper::wrap_owned(result).to_str()); diff --git a/font_collection.rs b/font_collection.rs index 7bf0167..4943032 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -17,7 +17,7 @@ pub type CTFontCollectionRef = *__CTFontCollection; impl CTFontCollectionRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID unsafe { CTFontCollectionGetTypeID() } + static pure fn type_id() -> CFTypeID { unsafe { CTFontCollectionGetTypeID() } } } pub type CTFontCollection = CFWrapper; @@ -27,12 +27,14 @@ pub trait CTFontCollectionMethods { } pub impl CTFontCollection : CTFontCollectionMethods { - pure fn get_descriptors() -> CFArray unsafe { - use core_foundation::base::CFRetain; + pure fn get_descriptors() -> CFArray { + unsafe { + use core_foundation::base::CFRetain; - // 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. - CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + // 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. + CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + } } } @@ -40,7 +42,7 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontColle let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); - let result = CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), *options.borrow_ref()); + let result = unsafe { CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), *options.borrow_ref()) }; CFWrapper::wrap_owned(result) } @@ -48,34 +50,38 @@ pub fn create_for_all_families() -> CTFontCollection { let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); - let result = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + let result = unsafe { CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()) }; CFWrapper::wrap_owned(result) } -pub fn create_for_family(family: &str) -> CTFontCollection unsafe { - use font_descriptor::kCTFontFamilyNameAttribute; - - let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); - let family_name = CFString::new(family); +pub fn create_for_family(family: &str) -> CTFontCollection { + unsafe { + use font_descriptor::kCTFontFamilyNameAttribute; + + let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); + let family_name = CFString::new(family); - let specified_attrs : CFWrapper = CFDictionary::new([ - ( *family_attr.borrow_ref(), *family_name.borrow_type_ref() ) - ]); + let specified_attrs : CFWrapper = CFDictionary::new([ + ( *family_attr.borrow_ref(), *family_name.borrow_type_ref() ) + ]); - let wildcard_desc : CTFontDescriptor = font_descriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); - let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(*wildcard_desc.borrow_ref(), - *mandatory_attrs.borrow_ref()); + let wildcard_desc : CTFontDescriptor = font_descriptor::new_from_attributes(&specified_attrs); + let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); + let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(*wildcard_desc.borrow_ref(), + *mandatory_attrs.borrow_ref()); - let matched_descs : CFArray = CFWrapper::wrap_owned(matched_descs); + let matched_descs : CFArray = CFWrapper::wrap_owned(matched_descs); - // I suppose one doesn't even need the CTFontCollection object at this point. - // But we stick descriptors into and out of it just to provide a nice wrapper API. - new_from_descriptors(&matched_descs) + // I suppose one doesn't even need the CTFontCollection object at this point. + // But we stick descriptors into and out of it just to provide a nice wrapper API. + new_from_descriptors(&matched_descs) + } } -pub pure fn get_family_names() -> CFArray unsafe { - CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) +pub pure fn get_family_names() -> CFArray { + unsafe { + CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) + } } extern { diff --git a/font_descriptor.rs b/font_descriptor.rs index f9e21ee..b95688d 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -73,14 +73,16 @@ pub trait StylisticClassAccessors { pub impl CTFontStylisticClass : StylisticClassAccessors { pure fn is_serif() -> bool { - let any_serif_class = kCTFontOldStyleSerifsClass - | kCTFontTransitionalSerifsClass - | kCTFontModernSerifsClass - | kCTFontClarendonSerifsClass - | kCTFontSlabSerifsClass - | kCTFontFreeformSerifsClass; + unsafe { + let any_serif_class = kCTFontOldStyleSerifsClass + | kCTFontTransitionalSerifsClass + | kCTFontModernSerifsClass + | kCTFontClarendonSerifsClass + | kCTFontSlabSerifsClass + | kCTFontFreeformSerifsClass; - return (self & any_serif_class) != 0; + return (self & any_serif_class) != 0; + } } pure fn is_sans_serif() -> bool { @@ -123,24 +125,32 @@ impl CTFontTraits: TraitAccessorPrivate { } impl CTFontTraits : TraitAccessors { - fn symbolic_traits() -> CTFontSymbolicTraits unsafe { - let number = self.extract_number_for_key(kCTFontSymbolicTrait); - cast::transmute(number.to_i32()) + fn symbolic_traits() -> CTFontSymbolicTraits { + unsafe { + let number = self.extract_number_for_key(kCTFontSymbolicTrait); + cast::transmute(number.to_i32()) + } } - fn normalized_weight() -> float unsafe { - let number = self.extract_number_for_key(kCTFontWeightTrait); - cast::transmute(number.to_float()) + fn normalized_weight() -> float { + unsafe { + let number = self.extract_number_for_key(kCTFontWeightTrait); + cast::transmute(number.to_float()) + } } - fn normalized_width() -> float unsafe { - let number = self.extract_number_for_key(kCTFontWidthTrait); - cast::transmute(number.to_float()) + fn normalized_width() -> float { + unsafe { + let number = self.extract_number_for_key(kCTFontWidthTrait); + cast::transmute(number.to_float()) + } } - fn normalized_slant() -> float unsafe { - let number = self.extract_number_for_key(kCTFontSlantTrait); - cast::transmute(number.to_float()) + fn normalized_slant() -> float { + unsafe { + let number = self.extract_number_for_key(kCTFontSlantTrait); + cast::transmute(number.to_float()) + } } } @@ -165,7 +175,7 @@ pub type CTFontDescriptorRef = *__CTFontDescriptor; impl CTFontDescriptorRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID unsafe { CTFontDescriptorGetTypeID() } + static pure fn type_id() -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() } } } pub type CTFontDescriptor = CFWrapper; @@ -184,7 +194,7 @@ priv trait CTFontDescriptorMethodsPrivate { impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { - let value = CTFontDescriptorCopyAttribute(self.obj, attribute); + let value = unsafe { CTFontDescriptorCopyAttribute(self.obj, attribute) }; if value.is_null() { return None; } Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( @@ -215,18 +225,22 @@ pub impl CTFontDescriptor : CTFontDescriptorMethods { } fn font_path() -> ~str { - let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); - assert value.is_not_null(); + unsafe { + let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); + assert value.is_not_null(); - CFWrapper::wrap_owned(core_foundation::base::downcast::(value)).to_str() + CFWrapper::wrap_owned(core_foundation::base::downcast::(value)).to_str() + } } } pub fn new_from_attributes(attributes: &CFWrapper) -> CTFontDescriptor { - let result: CTFontDescriptorRef = - CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); - CFWrapper::wrap_owned(result) + unsafe { + let result: CTFontDescriptorRef = + CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); + CFWrapper::wrap_owned(result) + } } pub fn debug_descriptor(desc: &CTFontDescriptor) { From b8382613e38459101a7b42b9a1fa5dbb40c8644c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Feb 2013 12:21:15 -0800 Subject: [PATCH 031/126] Update for language changes --- font.rs | 70 +++++++++++++++++++++++++++++++++------------- font_collection.rs | 63 ++++++++++++++++++++++++----------------- font_descriptor.rs | 19 +++++++++---- 3 files changed, 103 insertions(+), 49 deletions(-) diff --git a/font.rs b/font.rs index a1a16ee..a34721d 100644 --- a/font.rs +++ b/font.rs @@ -62,7 +62,12 @@ pub type CTFontRef = *__CTFont; impl CTFontRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID { unsafe { CTFontGetTypeID() } } + + static pure fn type_id() -> CFTypeID { + unsafe { + CTFontGetTypeID() + } + } } pub type CTFont = CFWrapper; @@ -96,21 +101,32 @@ pub trait CTFontMethods { } pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { - let result = unsafe { CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()) }; - CFWrapper::wrap_owned(result) + unsafe { + let result = CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), + pt_size as CGFloat, + ptr::null(), + ptr::null()); + CFWrapper::wrap_owned(result) + } } pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { - let result = unsafe { CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, ptr::null()) }; - CFWrapper::wrap_owned(result) + unsafe { + let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), + pt_size as CGFloat, + ptr::null()); + CFWrapper::wrap_owned(result) + } } pub fn new_from_name(name: ~str, pt_size: float) -> Result { - let cfname = CFString::new(name); - let result = unsafe { CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()) }; - if result.is_null() { return Err(()); } + unsafe { + let cfname = CFString::new(name); + let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); + if result.is_null() { return Err(()); } - return Ok(move CFWrapper::wrap_owned(result)); + return Ok(move CFWrapper::wrap_owned(result)); + } } priv trait CTFontMethodsPrivate { @@ -138,7 +154,10 @@ pub impl CTFont : CTFontMethods { fn clone_with_font_size(&const self, size: float) -> CTFont { unsafe { - let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, ptr::null(), ptr::null()); + let result = CTFontCreateCopyWithAttributes(self.obj, + size as CGFloat, + ptr::null(), + ptr::null()); CFWrapper::wrap_owned(result) } } @@ -228,33 +247,46 @@ pub impl CTFont : CTFontMethods { } } - fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool { + fn get_glyphs_for_characters(characters: *UniChar, + glyphs: *CGGlyph, + count: CFIndex) + -> bool { unsafe { CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) } } - fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float { + fn get_advances_for_glyphs(orientation: CTFontOrientation, + glyphs: *CGGlyph, + advances: *CGSize, + count: CFIndex) + -> float { unsafe { CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float } } fn get_font_table(tag: u32) -> Option { - let result = unsafe { CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic) }; - return match result.is_null() { - true => None, - false => Some(CFWrapper::wrap_owned(result)), + unsafe { + let result = CTFontCopyTable(self.obj, + tag as CTFontTableTag, + kCTFontTableOptionsExcludeSynthetic); + return match result.is_null() { + true => None, + false => Some(CFWrapper::wrap_owned(result)), + } } } } // Helper methods priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { - let result = unsafe { CTFontCopyName(*font.borrow_ref(), name_key) }; - if result.is_null() { return None; } + unsafe { + let result = CTFontCopyName(*font.borrow_ref(), name_key); + if result.is_null() { return None; } - return Some(CFWrapper::wrap_owned(result).to_str()); + return Some(CFWrapper::wrap_owned(result).to_str()); + } } pub fn debug_font_names(font: &CTFont) { diff --git a/font_collection.rs b/font_collection.rs index 4943032..bc60623 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -17,7 +17,12 @@ pub type CTFontCollectionRef = *__CTFontCollection; impl CTFontCollectionRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID { unsafe { CTFontCollectionGetTypeID() } } + + static pure fn type_id() -> CFTypeID { + unsafe { + CTFontCollectionGetTypeID() + } + } } pub type CTFontCollection = CFWrapper; @@ -28,11 +33,11 @@ pub trait CTFontCollectionMethods { pub impl CTFontCollection : CTFontCollectionMethods { pure fn get_descriptors() -> CFArray { - unsafe { - use core_foundation::base::CFRetain; + use core_foundation::base::CFRetain; - // 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. + // 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 { CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } @@ -42,40 +47,48 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontColle let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); - let result = unsafe { CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), *options.borrow_ref()) }; - CFWrapper::wrap_owned(result) + unsafe { + let result = CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), + *options.borrow_ref()); + CFWrapper::wrap_owned(result) + } } pub fn create_for_all_families() -> CTFontCollection { let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); - let result = unsafe { CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()) }; - CFWrapper::wrap_owned(result) + unsafe { + let result = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + CFWrapper::wrap_owned(result) + } } pub fn create_for_family(family: &str) -> CTFontCollection { - unsafe { - use font_descriptor::kCTFontFamilyNameAttribute; - - let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); - let family_name = CFString::new(family); + use font_descriptor::kCTFontFamilyNameAttribute; + + let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); + let family_name = CFString::new(family); - let specified_attrs : CFWrapper = CFDictionary::new([ - ( *family_attr.borrow_ref(), *family_name.borrow_type_ref() ) + let specified_attrs: CFWrapper = + CFDictionary::new([ + (*family_attr.borrow_ref(), *family_name.borrow_type_ref()) ]); - let wildcard_desc : CTFontDescriptor = font_descriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); - let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors(*wildcard_desc.borrow_ref(), - *mandatory_attrs.borrow_ref()); + let wildcard_desc: CTFontDescriptor = + font_descriptor::new_from_attributes(&specified_attrs); + let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); + let matched_descs = unsafe { + CTFontDescriptorCreateMatchingFontDescriptors( + *wildcard_desc.borrow_ref(), + *mandatory_attrs.borrow_ref()) + }; - let matched_descs : CFArray = CFWrapper::wrap_owned(matched_descs); + let matched_descs: CFArray = CFWrapper::wrap_owned(matched_descs); - // I suppose one doesn't even need the CTFontCollection object at this point. - // But we stick descriptors into and out of it just to provide a nice wrapper API. - new_from_descriptors(&matched_descs) - } + // I suppose one doesn't even need the CTFontCollection object at this point. + // But we stick descriptors into and out of it just to provide a nice wrapper API. + new_from_descriptors(&matched_descs) } pub pure fn get_family_names() -> CFArray { diff --git a/font_descriptor.rs b/font_descriptor.rs index b95688d..2f4f57f 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -175,7 +175,12 @@ pub type CTFontDescriptorRef = *__CTFontDescriptor; impl CTFontDescriptorRef : AbstractCFTypeRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } - static pure fn type_id() -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() } } + + static pure fn type_id() -> CFTypeID { + unsafe { + CTFontDescriptorGetTypeID() + } + } } pub type CTFontDescriptor = CFWrapper; @@ -194,11 +199,15 @@ priv trait CTFontDescriptorMethodsPrivate { impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { - let value = unsafe { CTFontDescriptorCopyAttribute(self.obj, attribute) }; - if value.is_null() { return None; } + unsafe { + let value = CTFontDescriptorCopyAttribute(self.obj, attribute); + if value.is_null() { + return None; + } - Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( - value)).to_str()) + Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( + value)).to_str()) + } } } From d3f318c2f7de0ac0c676abc0965591ecc3329a60 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 19 Feb 2013 17:51:22 -0800 Subject: [PATCH 032/126] Update for language changes --- font.rs | 19 +++++++++---------- font_collection.rs | 4 ++-- font_descriptor.rs | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/font.rs b/font.rs index a34721d..b419ad7 100644 --- a/font.rs +++ b/font.rs @@ -60,7 +60,7 @@ pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); struct __CTFont { private: () } pub type CTFontRef = *__CTFont; -impl CTFontRef : AbstractCFTypeRef { +impl AbstractCFTypeRef for CTFontRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } static pure fn type_id() -> CFTypeID { @@ -125,7 +125,7 @@ pub fn new_from_name(name: ~str, pt_size: float) -> Result { let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); if result.is_null() { return Err(()); } - return Ok(move CFWrapper::wrap_owned(result)); + return Ok(CFWrapper::wrap_owned(result)); } } @@ -133,8 +133,7 @@ priv trait CTFontMethodsPrivate { pure fn symbolic_traits() -> CTFontSymbolicTraits; } -pub impl CTFont: CTFontMethodsPrivate { - +pub impl CTFontMethodsPrivate for CTFont { // Properties priv pure fn symbolic_traits() -> CTFontSymbolicTraits { unsafe { @@ -143,7 +142,7 @@ pub impl CTFont: CTFontMethodsPrivate { } } -pub impl CTFont : CTFontMethods { +pub impl CTFontMethods for CTFont { // Creation methods fn copy_to_CGFont(&const self) -> CGFont { unsafe { @@ -166,28 +165,28 @@ pub impl CTFont : CTFontMethods { pure fn family_name() -> ~str { unsafe { let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); - return move option::expect(move value, ~"Fonts should always have a family name."); + return option::expect(value, ~"Fonts should always have a family name."); } } pure fn face_name() -> ~str { unsafe { let value = get_string_by_name_key(&self, kCTFontSubFamilyNameKey); - return move option::expect(move value, ~"Fonts should always have a face name."); + return option::expect(value, ~"Fonts should always have a face name."); } } pure fn unique_name() -> ~str { unsafe { let value = get_string_by_name_key(&self, kCTFontUniqueNameKey); - return move option::expect(move value, ~"Fonts should always have a unique name."); + return option::expect(value, ~"Fonts should always have a unique name."); } } pure fn postscript_name() -> ~str { unsafe { let value = get_string_by_name_key(&self, kCTFontPostScriptNameKey); - return move option::expect(move value, ~"Fonts should always have a PostScript name."); + return option::expect(value, ~"Fonts should always have a PostScript name."); } } @@ -291,7 +290,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(move get_string_by_name_key(font, key)) + option::unwrap(get_string_by_name_key(font, key)) } io::println(fmt!("kCTFontFamilyNameKey: %s", get_key(font, kCTFontFamilyNameKey))); diff --git a/font_collection.rs b/font_collection.rs index bc60623..697540c 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -15,7 +15,7 @@ use core_foundation::string::{CFString, CFStringRef}; struct __CTFontCollection { private: () } pub type CTFontCollectionRef = *__CTFontCollection; -impl CTFontCollectionRef : AbstractCFTypeRef { +impl AbstractCFTypeRef for CTFontCollectionRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } static pure fn type_id() -> CFTypeID { @@ -31,7 +31,7 @@ pub trait CTFontCollectionMethods { pure fn get_descriptors() -> CFArray; } -pub impl CTFontCollection : CTFontCollectionMethods { +pub impl CTFontCollectionMethods for CTFontCollection { pure fn get_descriptors() -> CFArray { use core_foundation::base::CFRetain; diff --git a/font_descriptor.rs b/font_descriptor.rs index 2f4f57f..0c06b15 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -42,7 +42,7 @@ pub trait SymbolicTraitAccessors { pure fn is_monospace() -> bool; } -pub impl CTFontSymbolicTraits : SymbolicTraitAccessors { +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 } @@ -71,7 +71,7 @@ pub trait StylisticClassAccessors { pure fn is_symbols() -> bool; } -pub impl CTFontStylisticClass : StylisticClassAccessors { +pub impl StylisticClassAccessors for CTFontStylisticClass { pure fn is_serif() -> bool { unsafe { let any_serif_class = kCTFontOldStyleSerifsClass @@ -116,7 +116,7 @@ priv trait TraitAccessorPrivate { fn extract_number_for_key(key: CFStringRef) -> CFNumber; } -impl CTFontTraits: TraitAccessorPrivate { +impl TraitAccessorPrivate for CTFontTraits { priv fn extract_number_for_key(key: CFStringRef) -> CFNumber { let value = self.get(&key); CFWrapper::wrap_shared(core_foundation::base::downcast::(value)) @@ -124,7 +124,7 @@ impl CTFontTraits: TraitAccessorPrivate { } -impl CTFontTraits : TraitAccessors { +impl TraitAccessors for CTFontTraits { fn symbolic_traits() -> CTFontSymbolicTraits { unsafe { let number = self.extract_number_for_key(kCTFontSymbolicTrait); @@ -173,7 +173,7 @@ pub const kCTFontPriorityProcess: CTFontPriority = 60000; struct __CTFontDescriptor { private: () } pub type CTFontDescriptorRef = *__CTFontDescriptor; -impl CTFontDescriptorRef : AbstractCFTypeRef { +impl AbstractCFTypeRef for CTFontDescriptorRef { pure fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } static pure fn type_id() -> CFTypeID { @@ -197,7 +197,7 @@ priv trait CTFontDescriptorMethodsPrivate { fn get_string_attribute(attribute: CFStringRef) -> Option<~str>; } -impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { +impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { priv fn get_string_attribute(attribute: CFStringRef) -> Option<~str> { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); @@ -212,25 +212,25 @@ impl CTFontDescriptor: CTFontDescriptorMethodsPrivate { } -pub impl CTFontDescriptor : CTFontDescriptorMethods { +pub impl CTFontDescriptorMethods for CTFontDescriptor { fn family_name() -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - option::expect(move value, ~"A font must have a non-null font family name.") + option::expect(value, ~"A font must have a non-null font family name.") } fn font_name() -> ~str { let value = self.get_string_attribute(kCTFontNameAttribute); - option::expect(move value, ~"A font must have a non-null name.") + option::expect(value, ~"A font must have a non-null name.") } fn style_name() -> ~str { let value = self.get_string_attribute(kCTFontStyleNameAttribute); - option::expect(move value, ~"A font must have a non-null style name.") + option::expect(value, ~"A font must have a non-null style name.") } fn display_name() -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - option::expect(move value, ~"A font must have a non-null display name.") + option::expect(value, ~"A font must have a non-null display name.") } fn font_path() -> ~str { From 97949ebdfd8adb13eea639f1799a3bbb93868512 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 28 Feb 2013 18:14:48 -0800 Subject: [PATCH 033/126] De-implicit-self --- font.rs | 83 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/font.rs b/font.rs index b419ad7..723afc5 100644 --- a/font.rs +++ b/font.rs @@ -78,26 +78,35 @@ pub trait CTFontMethods { fn clone_with_font_size(&const self, size: float) -> CTFont; // Names - pure fn family_name() -> ~str; - pure fn face_name() -> ~str; - pure fn unique_name() -> ~str; - pure fn postscript_name() -> ~str; + pure fn family_name(&self) -> ~str; + pure fn face_name(&self) -> ~str; + pure fn unique_name(&self) -> ~str; + pure fn postscript_name(&self) -> ~str; // Properties - pure fn all_traits() -> CTFontTraits; + pure fn all_traits(&self) -> CTFontTraits; // Font metrics - pure fn ascent() -> CGFloat; - pure fn descent() -> CGFloat; - pure fn underline_thickness() -> CGFloat; - pure fn underline_position() -> CGFloat; - pure fn bounding_box() -> CGRect; - pure fn leading() -> CGFloat; - pure fn x_height() -> CGFloat; - pure fn pt_size() -> CGFloat; - fn get_glyphs_for_characters(characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; - fn get_advances_for_glyphs(orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> float; - fn get_font_table(tag: u32) -> Option; + 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 get_glyphs_for_characters(&self, + characters: *UniChar, + glyphs: *CGGlyph, + count: CFIndex) + -> bool; + fn get_advances_for_glyphs(&self, + orientation: CTFontOrientation, + glyphs: *CGGlyph, + advances: *CGSize, + count: CFIndex) + -> float; + fn get_font_table(&self, tag: u32) -> Option; } pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { @@ -162,35 +171,35 @@ pub impl CTFontMethods for CTFont { } // Names - pure fn family_name() -> ~str { + pure fn family_name(&self) -> ~str { unsafe { - let value = get_string_by_name_key(&self, kCTFontFamilyNameKey); + let value = get_string_by_name_key(self, kCTFontFamilyNameKey); return option::expect(value, ~"Fonts should always have a family name."); } } - pure fn face_name() -> ~str { + pure fn face_name(&self) -> ~str { unsafe { - let value = get_string_by_name_key(&self, kCTFontSubFamilyNameKey); + let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); return option::expect(value, ~"Fonts should always have a face name."); } } - pure fn unique_name() -> ~str { + pure fn unique_name(&self) -> ~str { unsafe { - let value = get_string_by_name_key(&self, kCTFontUniqueNameKey); + let value = get_string_by_name_key(self, kCTFontUniqueNameKey); return option::expect(value, ~"Fonts should always have a unique name."); } } - pure fn postscript_name() -> ~str { + pure fn postscript_name(&self) -> ~str { unsafe { - let value = get_string_by_name_key(&self, kCTFontPostScriptNameKey); + let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); return option::expect(value, ~"Fonts should always have a PostScript name."); } } - pure fn all_traits() -> CTFontTraits { + pure fn all_traits(&self) -> CTFontTraits { unsafe { let result = CTFontCopyTraits(self.obj); CFWrapper::wrap_owned(result) @@ -198,55 +207,56 @@ pub impl CTFontMethods for CTFont { } // Font metrics - pure fn ascent() -> CGFloat { + pure fn ascent(&self) -> CGFloat { unsafe { CTFontGetAscent(self.obj) } } - pure fn descent() -> CGFloat { + pure fn descent(&self) -> CGFloat { unsafe { CTFontGetDescent(self.obj) } } - pure fn underline_thickness() -> CGFloat { + pure fn underline_thickness(&self) -> CGFloat { unsafe { CTFontGetUnderlineThickness(self.obj) } } - pure fn underline_position() -> CGFloat { + pure fn underline_position(&self) -> CGFloat { unsafe { CTFontGetUnderlinePosition(self.obj) } } - pure fn bounding_box() -> CGRect { + pure fn bounding_box(&self) -> CGRect { unsafe { CTFontGetBoundingBox(self.obj) } } - pure fn leading() -> CGFloat { + pure fn leading(&self) -> CGFloat { unsafe { CTFontGetLeading(self.obj) } } - pure fn x_height() -> CGFloat { + pure fn x_height(&self) -> CGFloat { unsafe { CTFontGetXHeight(self.obj) } } - pure fn pt_size() -> CGFloat { + pure fn pt_size(&self) -> CGFloat { unsafe { CTFontGetSize(self.obj) } } - fn get_glyphs_for_characters(characters: *UniChar, + fn get_glyphs_for_characters(&self, + characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool { @@ -255,7 +265,8 @@ pub impl CTFontMethods for CTFont { } } - fn get_advances_for_glyphs(orientation: CTFontOrientation, + fn get_advances_for_glyphs(&self, + orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) @@ -265,7 +276,7 @@ pub impl CTFontMethods for CTFont { } } - fn get_font_table(tag: u32) -> Option { + fn get_font_table(&self, tag: u32) -> Option { unsafe { let result = CTFontCopyTable(self.obj, tag as CTFontTableTag, From 34c703efc723b8dcc1fab308772baad8ad2baf34 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 28 Mar 2013 09:32:54 -0600 Subject: [PATCH 034/126] Update to rust 0.6 syntax. --- font.rs | 209 +++++++++++++++++++------------------- font_collection.rs | 19 ++-- font_descriptor.rs | 246 +++++++++++++++++++++++---------------------- font_manager.rs | 2 +- 4 files changed, 237 insertions(+), 239 deletions(-) diff --git a/font.rs b/font.rs index 723afc5..d32ac4e 100644 --- a/font.rs +++ b/font.rs @@ -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; 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 { } 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. diff --git a/font_collection.rs b/font_collection.rs index 697540c..4da5c9c 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -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; pub trait CTFontCollectionMethods { - pure fn get_descriptors() -> CFArray; + fn get_descriptors(&self) -> CFArray; } -pub impl CTFontCollectionMethods for CTFontCollection { - pure fn get_descriptors() -> CFArray { - use core_foundation::base::CFRetain; - +impl CTFontCollectionMethods for CTFontCollection { + fn get_descriptors(&self) -> CFArray { // 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 { +pub fn get_family_names() -> CFArray { unsafe { CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) } @@ -102,7 +99,7 @@ extern { * CTFontCollection.h */ - const kCTFontCollectionRemoveDuplicatesOption: CFStringRef; + static kCTFontCollectionRemoveDuplicatesOption: CFStringRef; fn CTFontCollectionCreateCopyWithFontDescriptors(original: CTFontCollectionRef, descriptors: CFArrayRef, diff --git a/font_descriptor.rs b/font_descriptor.rs index 0c06b15..04931bb 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -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::(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; 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::(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; +} diff --git a/font_manager.rs b/font_manager.rs index 8538d95..b7cca87 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -1,7 +1,7 @@ use core_foundation::array::CFArrayRef; use core_foundation::url::CFURLRef; -extern { +pub extern { /* * CTFontManager.h */ From ce3ee73e7d4480b9464e1413918b1ee316a9c445 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 1 Apr 2013 21:49:55 -0600 Subject: [PATCH 035/126] Make private trait public. servo-gfx uses this trait for some reason. --- font.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/font.rs b/font.rs index d32ac4e..b5ade67 100644 --- a/font.rs +++ b/font.rs @@ -137,13 +137,13 @@ pub fn new_from_name(name: ~str, pt_size: float) -> Result { } } -priv trait CTFontMethodsPrivate { +pub trait CTFontMethodsPrivate { fn symbolic_traits(&self) -> CTFontSymbolicTraits; } impl CTFontMethodsPrivate for CTFont { // Properties - priv fn symbolic_traits(&self) -> CTFontSymbolicTraits { + fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { CTFontGetSymbolicTraits(self.obj) } From 35f882487c90be5611408fb4789461fbffbab3ad Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 3 Apr 2013 18:20:16 -0700 Subject: [PATCH 036/126] Add license --- COPYING | 5 ++ LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 25 ++++++ 3 files changed, 231 insertions(+) create mode 100644 COPYING create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..8b7291a --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 or the MIT license +, at your +option. All files in the project carrying such notice may not be +copied, modified, or distributed except according to those terms. diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..16fe87b --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..807526f --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2012-2013 Mozilla Foundation + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. From e9d5122476da8c286246fcbbdc968dc86b4e230b Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 3 Apr 2013 22:09:05 -0600 Subject: [PATCH 037/126] Remove unused imports. --- font.rs | 4 ++-- font_collection.rs | 6 +++--- font_descriptor.rs | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/font.rs b/font.rs index b5ade67..d3e8ef6 100644 --- a/font.rs +++ b/font.rs @@ -8,8 +8,8 @@ use core_foundation::array::{CFArrayRef}; use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef}; use core_foundation::base::{CFWrapper}; use core_foundation::data::{CFData, CFDataRef}; -use core_foundation::dictionary::{CFDictionaryRef, UntypedCFDictionary}; -use core_foundation::string::{CFStringGetTypeID, CFString, CFStringRef, UniChar}; +use core_foundation::dictionary::CFDictionaryRef; +use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; diff --git a/font_collection.rs b/font_collection.rs index 4da5c9c..8613f29 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,12 +1,12 @@ use font_descriptor; -use font_descriptor::{CTFontAttributes, CTFontDescriptor}; +use font_descriptor::CTFontDescriptor; use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef}; use font_manager::CTFontManagerCopyAvailableFontFamilyNames; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{AbstractCFTypeRef, CFAllocatorRef, CFIndex, CFRange, CFTypeID}; +use core_foundation::base::{AbstractCFTypeRef, CFTypeID}; use core_foundation::base::{CFTypeRef, CFWrapper}; -use core_foundation::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary}; +use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::CFNumber; use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; diff --git a/font_descriptor.rs b/font_descriptor.rs index 04931bb..86d8bdd 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,12 +1,12 @@ 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}; -use core_foundation::dictionary::{CFDictionary, CFDictionaryRef, UntypedCFDictionary}; +use core_foundation::base::AbstractCFTypeRef; +use core_foundation::base::{CFTypeID, CFTypeRef, CFWrapper}; +use core_foundation::dictionary::{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_foundation::string::CFStringRef; +use core_foundation::url::{CFURLRef}; use core_graphics::base::CGFloat; /* From b32920936a6a848dca42c18435279421b4cd663a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 4 Apr 2013 18:15:50 -0700 Subject: [PATCH 038/126] Add license headers --- core_text.rc | 10 ++++++++++ font.rs | 10 ++++++++++ font_collection.rs | 10 ++++++++++ font_descriptor.rs | 10 ++++++++++ font_manager.rs | 10 ++++++++++ 5 files changed, 50 insertions(+) diff --git a/core_text.rc b/core_text.rc index 01f24db..b0c78c2 100644 --- a/core_text.rc +++ b/core_text.rc @@ -1,3 +1,13 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #[link(name = "core_text", vers = "0.1")]; #[crate_type = "lib"]; diff --git a/font.rs b/font.rs index d3e8ef6..900e65c 100644 --- a/font.rs +++ b/font.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + extern mod core_foundation; extern mod core_graphics; diff --git a/font_collection.rs b/font_collection.rs index 8613f29..660d07b 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use font_descriptor; use font_descriptor::CTFontDescriptor; use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef}; diff --git a/font_descriptor.rs b/font_descriptor.rs index 86d8bdd..44a05b5 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use core_foundation; use core_foundation::array::CFArrayRef; use core_foundation::base::AbstractCFTypeRef; diff --git a/font_manager.rs b/font_manager.rs index b7cca87..e8105d1 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -1,3 +1,13 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use core_foundation::array::CFArrayRef; use core_foundation::url::CFURLRef; From 5ec7feec6365946ca7a0caf890531400fd64ba56 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 4 Apr 2013 18:22:53 -0700 Subject: [PATCH 039/126] Fix license headers --- COPYING => COPYRIGHT | 0 core_text.rc | 3 +-- font.rs | 3 +-- font_collection.rs | 3 +-- font_descriptor.rs | 3 +-- font_manager.rs | 3 +-- 6 files changed, 5 insertions(+), 10 deletions(-) rename COPYING => COPYRIGHT (100%) diff --git a/COPYING b/COPYRIGHT similarity index 100% rename from COPYING rename to COPYRIGHT diff --git a/core_text.rc b/core_text.rc index b0c78c2..f6e245e 100644 --- a/core_text.rc +++ b/core_text.rc @@ -1,6 +1,5 @@ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/font.rs b/font.rs index 900e65c..1ae1361 100644 --- a/font.rs +++ b/font.rs @@ -1,6 +1,5 @@ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/font_collection.rs b/font_collection.rs index 660d07b..c865315 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -1,6 +1,5 @@ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/font_descriptor.rs b/font_descriptor.rs index 44a05b5..8974906 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -1,6 +1,5 @@ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/font_manager.rs b/font_manager.rs index e8105d1..bf3759f 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -1,6 +1,5 @@ // Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. +// file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 or the MIT license From 98ce55f22c9893e3cd1027ab74b825e2d62132a4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 16:38:15 -0700 Subject: [PATCH 040/126] Update for language changes --- font.rs | 20 ++++++++++++-------- font_collection.rs | 36 ++++++++++++++++++++---------------- font_descriptor.rs | 6 +++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/font.rs b/font.rs index 1ae1361..7846c38 100644 --- a/font.rs +++ b/font.rs @@ -17,7 +17,7 @@ use core_foundation::array::{CFArrayRef}; use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef}; use core_foundation::base::{CFWrapper}; use core_foundation::data::{CFData, CFDataRef}; -use core_foundation::dictionary::CFDictionaryRef; +use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; @@ -119,7 +119,7 @@ pub trait CTFontMethods { pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { unsafe { - let result = CTFontCreateWithGraphicsFont(*cgfont.borrow_ref(), + let result = CTFontCreateWithGraphicsFont(*cgfont.contents.borrow_ref(), pt_size as CGFloat, ptr::null(), ptr::null()); @@ -139,8 +139,12 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { pub fn new_from_name(name: ~str, pt_size: float) -> Result { unsafe { let cfname = CFString::new(name); - let result = CTFontCreateWithName(*cfname.borrow_ref(), pt_size as CGFloat, ptr::null()); - if result.is_null() { return Err(()); } + let result = CTFontCreateWithName(*cfname.contents.borrow_ref(), + pt_size as CGFloat, + ptr::null()); + if result.is_null() { + return Err(()); + } return Ok(CFWrapper::wrap_owned(result)); } @@ -164,7 +168,7 @@ impl CTFontMethods for CTFont { fn copy_to_CGFont(&self) -> CGFont { unsafe { let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); - CFWrapper::wrap_owned(value) + CGFont::wrap_owned(value) } } @@ -210,7 +214,7 @@ impl CTFontMethods for CTFont { fn all_traits(&self) -> CTFontTraits { unsafe { let result = CTFontCopyTraits(self.obj); - CFWrapper::wrap_owned(result) + CFDictionary::wrap_owned(result) } } @@ -291,7 +295,7 @@ impl CTFontMethods for CTFont { kCTFontTableOptionsExcludeSynthetic); return match result.is_null() { true => None, - false => Some(CFWrapper::wrap_owned(result)), + false => Some(CFData::wrap_owned(result)), } } } @@ -303,7 +307,7 @@ priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~ let result = CTFontCopyName(*font.borrow_ref(), name_key); if result.is_null() { return None; } - return Some(CFWrapper::wrap_owned(result).to_str()); + return Some(CFString::wrap_owned(result).to_str()); } } diff --git a/font_collection.rs b/font_collection.rs index c865315..196655a 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -44,28 +44,32 @@ impl CTFontCollectionMethods for CTFontCollection { // 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 { - CFWrapper::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + CFArray::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } } pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { - let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let options = CFDictionary::new([ + (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) + ]); unsafe { - let result = CTFontCollectionCreateWithFontDescriptors(*descs.borrow_ref(), - *options.borrow_ref()); + let result = CTFontCollectionCreateWithFontDescriptors(*descs.contents.borrow_ref(), + *options.contents.borrow_ref()); CFWrapper::wrap_owned(result) } } pub fn create_for_all_families() -> CTFontCollection { - let key = CFString::wrap_extern(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ (*key.borrow_ref(), *value.borrow_type_ref()) ]); + let options = CFDictionary::new([ + (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) + ]); unsafe { - let result = CTFontCollectionCreateFromAvailableFonts(*options.borrow_ref()); + let result = CTFontCollectionCreateFromAvailableFonts(*options.contents.borrow_ref()); CFWrapper::wrap_owned(result) } } @@ -73,24 +77,24 @@ pub fn create_for_all_families() -> CTFontCollection { pub fn create_for_family(family: &str) -> CTFontCollection { use font_descriptor::kCTFontFamilyNameAttribute; - let family_attr = CFString::wrap_extern(kCTFontFamilyNameAttribute); + let family_attr = CFString::wrap_shared(kCTFontFamilyNameAttribute); let family_name = CFString::new(family); - let specified_attrs: CFWrapper = + let specified_attrs: CFDictionary = CFDictionary::new([ - (*family_attr.borrow_ref(), *family_name.borrow_type_ref()) + (*family_attr.contents.borrow_ref(), *family_name.contents.borrow_type_ref()) ]); let wildcard_desc: CTFontDescriptor = - font_descriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::new([ *family_attr.borrow_ref() ]); + font_descriptor::new_from_attributes(&specified_attrs.contents); + let mandatory_attrs = CFSet::new([ *family_attr.contents.borrow_ref() ]); let matched_descs = unsafe { CTFontDescriptorCreateMatchingFontDescriptors( *wildcard_desc.borrow_ref(), - *mandatory_attrs.borrow_ref()) + *mandatory_attrs.contents.borrow_ref()) }; - let matched_descs: CFArray = CFWrapper::wrap_owned(matched_descs); + let matched_descs: CFArray = CFArray::wrap_owned(matched_descs); // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. @@ -99,7 +103,7 @@ pub fn create_for_family(family: &str) -> CTFontCollection { pub fn get_family_names() -> CFArray { unsafe { - CFWrapper::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) + CFArray::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) } } diff --git a/font_descriptor.rs b/font_descriptor.rs index 8974906..c8d6c5e 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -14,7 +14,7 @@ use core_foundation::base::{CFTypeID, CFTypeRef, CFWrapper}; use core_foundation::dictionary::{CFDictionaryRef, UntypedCFDictionary}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; -use core_foundation::string::CFStringRef; +use core_foundation::string::{CFString, CFStringRef}; use core_foundation::url::{CFURLRef}; use core_graphics::base::CGFloat; @@ -127,7 +127,7 @@ priv trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { priv fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let value = self.get(&key); - CFWrapper::wrap_shared(core_foundation::base::downcast::(value)) + CFNumber::wrap_shared(core_foundation::base::downcast::(value)) } } @@ -213,7 +213,7 @@ impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { return None; } - Some(CFWrapper::wrap_owned(core_foundation::base::downcast::( + Some(CFString::wrap_owned(core_foundation::base::downcast::( value)).to_str()) } } From 0395229ac48b1abea45594196fd261969078357b Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 10 May 2013 15:01:12 -0600 Subject: [PATCH 041/126] Remove unused unsafe. --- font.rs | 24 ++++++++---------------- font_descriptor.rs | 16 +++++++--------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/font.rs b/font.rs index 7846c38..2f54520 100644 --- a/font.rs +++ b/font.rs @@ -184,31 +184,23 @@ impl CTFontMethods for CTFont { // Names fn family_name(&self) -> ~str { - unsafe { - let value = get_string_by_name_key(self, kCTFontFamilyNameKey); - value.expect(~"Fonts should always have a family name.") - } + let value = get_string_by_name_key(self, kCTFontFamilyNameKey); + value.expect(~"Fonts should always have a family name.") } fn face_name(&self) -> ~str { - unsafe { - let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); - value.expect(~"Fonts should always have a face name.") - } + let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); + value.expect(~"Fonts should always have a face name.") } fn unique_name(&self) -> ~str { - unsafe { - let value = get_string_by_name_key(self, kCTFontUniqueNameKey); - value.expect(~"Fonts should always have a unique name.") - } + let value = get_string_by_name_key(self, kCTFontUniqueNameKey); + value.expect(~"Fonts should always have a unique name.") } fn postscript_name(&self) -> ~str { - unsafe { - let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); - value.expect(~"Fonts should always have a PostScript name.") - } + let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); + value.expect(~"Fonts should always have a PostScript name.") } fn all_traits(&self) -> CTFontTraits { diff --git a/font_descriptor.rs b/font_descriptor.rs index c8d6c5e..c74b33f 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -81,16 +81,14 @@ pub trait StylisticClassAccessors { impl StylisticClassAccessors for CTFontStylisticClass { fn is_serif(&self) -> bool { - unsafe { - let any_serif_class = kCTFontOldStyleSerifsClass - | kCTFontTransitionalSerifsClass - | kCTFontModernSerifsClass - | kCTFontClarendonSerifsClass - | kCTFontSlabSerifsClass - | kCTFontFreeformSerifsClass; + let any_serif_class = kCTFontOldStyleSerifsClass + | kCTFontTransitionalSerifsClass + | kCTFontModernSerifsClass + | kCTFontClarendonSerifsClass + | kCTFontSlabSerifsClass + | kCTFontFreeformSerifsClass; - return (*self & any_serif_class) != 0; - } + return (*self & any_serif_class) != 0; } fn is_sans_serif(&self) -> bool { From 72c7673ac50cc1ffb518de65022fb034df334ed9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 25 Jun 2013 19:47:58 -0700 Subject: [PATCH 042/126] Update for language changes --- font.rs | 12 ++++++++---- font_descriptor.rs | 11 +++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/font.rs b/font.rs index 2f54520..e44bc1e 100644 --- a/font.rs +++ b/font.rs @@ -23,6 +23,10 @@ use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; +use std::libc; +use std::io; +use std::ptr; + pub type CTFontUIFontType = u32; // kCTFontNoFontType: CTFontUIFontType = -1; pub static kCTFontUserFontType: CTFontUIFontType = 0; @@ -185,22 +189,22 @@ impl CTFontMethods for CTFont { // Names fn family_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontFamilyNameKey); - value.expect(~"Fonts should always have a family name.") + value.expect("Fonts should always have a family name.") } fn face_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); - value.expect(~"Fonts should always have a face name.") + value.expect("Fonts should always have a face name.") } fn unique_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontUniqueNameKey); - value.expect(~"Fonts should always have a unique name.") + value.expect("Fonts should always have a unique name.") } fn postscript_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); - value.expect(~"Fonts should always have a PostScript name.") + value.expect("Fonts should always have a PostScript name.") } fn all_traits(&self) -> CTFontTraits { diff --git a/font_descriptor.rs b/font_descriptor.rs index c74b33f..de01022 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -18,6 +18,9 @@ use core_foundation::string::{CFString, CFStringRef}; use core_foundation::url::{CFURLRef}; use core_graphics::base::CGFloat; +use std::cast; +use std::io; + /* * CTFontTraits.h */ @@ -221,22 +224,22 @@ impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { impl CTFontDescriptorMethods for CTFontDescriptor { fn family_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect(~"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(&self) -> ~str { let value = self.get_string_attribute(kCTFontNameAttribute); - value.expect(~"A font must have a non-null name.") + value.expect("A font must have a non-null name.") } fn style_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontStyleNameAttribute); - value.expect(~"A font must have a non-null style name.") + value.expect("A font must have a non-null style name.") } fn display_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect(~"A font must have a non-null display name.") + value.expect("A font must have a non-null display name.") } fn font_path(&self) -> ~str { From 6ace4dfb6e6128311eb1f3a923886311dc8a2dea Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 8 Jul 2013 10:52:04 -0600 Subject: [PATCH 043/126] Upgrade to latest Rust. --- font.rs | 2 ++ font_descriptor.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/font.rs b/font.rs index e44bc1e..4cffd26 100644 --- a/font.rs +++ b/font.rs @@ -7,6 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(non_uppercase_statics)]; + extern mod core_foundation; extern mod core_graphics; diff --git a/font_descriptor.rs b/font_descriptor.rs index de01022..892bc77 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -7,6 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(non_uppercase_statics)]; + use core_foundation; use core_foundation::array::CFArrayRef; use core_foundation::base::AbstractCFTypeRef; From ec60054f4dd495934c82d2b3e05352481764d3ea Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 15 Aug 2013 18:42:59 -0600 Subject: [PATCH 044/126] Fix visibility for mac. --- font.rs | 2 +- font_descriptor.rs | 10 +++++----- font_manager.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/font.rs b/font.rs index 4cffd26..8524bc3 100644 --- a/font.rs +++ b/font.rs @@ -300,7 +300,7 @@ impl CTFontMethods for CTFont { } // Helper methods -priv fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { +fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { unsafe { let result = CTFontCopyName(*font.borrow_ref(), name_key); if result.is_null() { return None; } diff --git a/font_descriptor.rs b/font_descriptor.rs index 892bc77..df7e752 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -123,12 +123,12 @@ pub trait TraitAccessors { fn normalized_slant(&self) -> float; } -priv trait TraitAccessorPrivate { +trait TraitAccessorPrivate { fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber; } impl TraitAccessorPrivate for CTFontTraits { - priv fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { + fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let value = self.get(&key); CFNumber::wrap_shared(core_foundation::base::downcast::(value)) } @@ -204,12 +204,12 @@ pub trait CTFontDescriptorMethods { fn font_path(&self) -> ~str; } -priv trait CTFontDescriptorMethodsPrivate { +trait CTFontDescriptorMethodsPrivate { fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str>; } impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { - priv fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { + fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { @@ -334,7 +334,7 @@ extern { fn CTFontDescriptorGetTypeID() -> CFTypeID; } -pub extern { +extern { fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef, mandatoryAttributes: CFSetRef) -> CFArrayRef; } diff --git a/font_manager.rs b/font_manager.rs index bf3759f..168d147 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -10,7 +10,7 @@ use core_foundation::array::CFArrayRef; use core_foundation::url::CFURLRef; -pub extern { +extern { /* * CTFontManager.h */ From a281f975cbada7fff6c50c1273b473a4c851ec8f Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 16 Aug 2013 14:25:15 -0600 Subject: [PATCH 045/126] Switch from -o to --out-dir. --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index c9dc835..959087d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,11 +9,11 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') all: librustcoretext.dummy librustcoretext.dummy: core_text.rc $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< -o $@ + $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ rustcoretext-test: core_text.rc $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< -o $@ --test + $(RUSTC) $(RUSTFLAGS) $< --out-dir . --test check: rustcoretext-test ./rustcoretext-test From 6c16d712b37de969b7b2e388a9325cd4dabe1e54 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 16 Aug 2013 14:46:53 -0700 Subject: [PATCH 046/126] Revert to using -o for tests --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 959087d..814f377 100644 --- a/Makefile.in +++ b/Makefile.in @@ -13,7 +13,7 @@ librustcoretext.dummy: core_text.rc $(RUST_SRC) touch $@ rustcoretext-test: core_text.rc $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< --out-dir . --test + $(RUSTC) $(RUSTFLAGS) $< -o $@ --test check: rustcoretext-test ./rustcoretext-test From 36b060d0aef4b3d3f644ef221a0aaca4cd31bcdb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 29 Aug 2013 15:33:53 -0700 Subject: [PATCH 047/126] Update for language changes --- font.rs | 20 ++++++++++++++++++++ font_collection.rs | 6 ++++++ font_descriptor.rs | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/font.rs b/font.rs index 8524bc3..9135517 100644 --- a/font.rs +++ b/font.rs @@ -77,6 +77,7 @@ pub type CTFontRef = *__CTFont; impl AbstractCFTypeRef for CTFontRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + #[fixed_stack_segment] fn type_id() -> CFTypeID { unsafe { CTFontGetTypeID() @@ -123,6 +124,7 @@ pub trait CTFontMethods { fn get_font_table(&self, tag: u32) -> Option; } +#[fixed_stack_segment] pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { unsafe { let result = CTFontCreateWithGraphicsFont(*cgfont.contents.borrow_ref(), @@ -133,6 +135,7 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { } } +#[fixed_stack_segment] pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { unsafe { let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), @@ -142,6 +145,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { } } +#[fixed_stack_segment] pub fn new_from_name(name: ~str, pt_size: float) -> Result { unsafe { let cfname = CFString::new(name); @@ -162,6 +166,7 @@ pub trait CTFontMethodsPrivate { impl CTFontMethodsPrivate for CTFont { // Properties + #[fixed_stack_segment] fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { CTFontGetSymbolicTraits(self.obj) @@ -171,6 +176,7 @@ impl CTFontMethodsPrivate for CTFont { impl CTFontMethods for CTFont { // Creation methods + #[fixed_stack_segment] fn copy_to_CGFont(&self) -> CGFont { unsafe { let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); @@ -178,6 +184,7 @@ impl CTFontMethods for CTFont { } } + #[fixed_stack_segment] fn clone_with_font_size(&self, size: float) -> CTFont { unsafe { let result = CTFontCreateCopyWithAttributes(self.obj, @@ -209,6 +216,7 @@ impl CTFontMethods for CTFont { value.expect("Fonts should always have a PostScript name.") } + #[fixed_stack_segment] fn all_traits(&self) -> CTFontTraits { unsafe { let result = CTFontCopyTraits(self.obj); @@ -217,54 +225,63 @@ impl CTFontMethods for CTFont { } // Font metrics + #[fixed_stack_segment] fn ascent(&self) -> CGFloat { unsafe { CTFontGetAscent(self.obj) } } + #[fixed_stack_segment] fn descent(&self) -> CGFloat { unsafe { CTFontGetDescent(self.obj) } } + #[fixed_stack_segment] fn underline_thickness(&self) -> CGFloat { unsafe { CTFontGetUnderlineThickness(self.obj) } } + #[fixed_stack_segment] fn underline_position(&self) -> CGFloat { unsafe { CTFontGetUnderlinePosition(self.obj) } } + #[fixed_stack_segment] fn bounding_box(&self) -> CGRect { unsafe { CTFontGetBoundingBox(self.obj) } } + #[fixed_stack_segment] fn leading(&self) -> CGFloat { unsafe { CTFontGetLeading(self.obj) } } + #[fixed_stack_segment] fn x_height(&self) -> CGFloat { unsafe { CTFontGetXHeight(self.obj) } } + #[fixed_stack_segment] fn pt_size(&self) -> CGFloat { unsafe { CTFontGetSize(self.obj) } } + #[fixed_stack_segment] fn get_glyphs_for_characters(&self, characters: *UniChar, glyphs: *CGGlyph, @@ -275,6 +292,7 @@ impl CTFontMethods for CTFont { } } + #[fixed_stack_segment] fn get_advances_for_glyphs(&self, orientation: CTFontOrientation, glyphs: *CGGlyph, @@ -286,6 +304,7 @@ impl CTFontMethods for CTFont { } } + #[fixed_stack_segment] fn get_font_table(&self, tag: u32) -> Option { unsafe { let result = CTFontCopyTable(self.obj, @@ -300,6 +319,7 @@ impl CTFontMethods for CTFont { } // Helper methods +#[fixed_stack_segment] fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { unsafe { let result = CTFontCopyName(*font.borrow_ref(), name_key); diff --git a/font_collection.rs b/font_collection.rs index 196655a..25f437c 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -26,6 +26,7 @@ pub type CTFontCollectionRef = *__CTFontCollection; impl AbstractCFTypeRef for CTFontCollectionRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + #[fixed_stack_segment] fn type_id() -> CFTypeID { unsafe { CTFontCollectionGetTypeID() @@ -40,6 +41,7 @@ pub trait CTFontCollectionMethods { } impl CTFontCollectionMethods for CTFontCollection { + #[fixed_stack_segment] fn get_descriptors(&self) -> CFArray { // 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. @@ -49,6 +51,7 @@ impl CTFontCollectionMethods for CTFontCollection { } } +#[fixed_stack_segment] pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); @@ -62,6 +65,7 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontColle } } +#[fixed_stack_segment] pub fn create_for_all_families() -> CTFontCollection { let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::new(1_i8); @@ -74,6 +78,7 @@ pub fn create_for_all_families() -> CTFontCollection { } } +#[fixed_stack_segment] pub fn create_for_family(family: &str) -> CTFontCollection { use font_descriptor::kCTFontFamilyNameAttribute; @@ -101,6 +106,7 @@ pub fn create_for_family(family: &str) -> CTFontCollection { new_from_descriptors(&matched_descs) } +#[fixed_stack_segment] pub fn get_family_names() -> CFArray { unsafe { CFArray::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) diff --git a/font_descriptor.rs b/font_descriptor.rs index df7e752..f155422 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -187,6 +187,7 @@ pub type CTFontDescriptorRef = *__CTFontDescriptor; impl AbstractCFTypeRef for CTFontDescriptorRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } + #[fixed_stack_segment] fn type_id() -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() @@ -209,6 +210,7 @@ trait CTFontDescriptorMethodsPrivate { } impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { + #[fixed_stack_segment] fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); @@ -244,6 +246,7 @@ impl CTFontDescriptorMethods for CTFontDescriptor { value.expect("A font must have a non-null display name.") } + #[fixed_stack_segment] fn font_path(&self) -> ~str { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); @@ -254,6 +257,7 @@ impl CTFontDescriptorMethods for CTFontDescriptor { } } +#[fixed_stack_segment] pub fn new_from_attributes(attributes: &CFWrapper) -> CTFontDescriptor { unsafe { From 129e99ff088fad6ea8f3187680c15a0a3e2cc403 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 2 Sep 2013 17:08:43 +0100 Subject: [PATCH 048/126] Upgrade to rustc 0.8-pre (0ac3e02 2013-08-30 05:45:45 -0700) --- font.rs | 2 +- font_collection.rs | 2 +- font_descriptor.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/font.rs b/font.rs index 9135517..e02420b 100644 --- a/font.rs +++ b/font.rs @@ -78,7 +78,7 @@ impl AbstractCFTypeRef for CTFontRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } #[fixed_stack_segment] - fn type_id() -> CFTypeID { + fn type_id(_dummy: Option) -> CFTypeID { unsafe { CTFontGetTypeID() } diff --git a/font_collection.rs b/font_collection.rs index 25f437c..d011bdc 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -27,7 +27,7 @@ impl AbstractCFTypeRef for CTFontCollectionRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } #[fixed_stack_segment] - fn type_id() -> CFTypeID { + fn type_id(_dummy: Option) -> CFTypeID { unsafe { CTFontCollectionGetTypeID() } diff --git a/font_descriptor.rs b/font_descriptor.rs index f155422..fec5560 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -188,7 +188,7 @@ impl AbstractCFTypeRef for CTFontDescriptorRef { fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } #[fixed_stack_segment] - fn type_id() -> CFTypeID { + fn type_id(_dummy: Option) -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() } From 9eaf74b24224f43be1f3861b31ca9818c1a65804 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 3 Oct 2013 15:21:57 -0700 Subject: [PATCH 049/126] Update for language changes --- font.rs | 16 ++++++++-------- font_descriptor.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/font.rs b/font.rs index e02420b..2be88a3 100644 --- a/font.rs +++ b/font.rs @@ -90,7 +90,7 @@ pub type CTFont = CFWrapper; pub trait CTFontMethods { // Creation methods (statics below) fn copy_to_CGFont(&self) -> CGFont; - fn clone_with_font_size(&self, size: float) -> CTFont; + fn clone_with_font_size(&self, size: f64) -> CTFont; // Names fn family_name(&self) -> ~str; @@ -120,12 +120,12 @@ pub trait CTFontMethods { glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) - -> float; + -> f64; fn get_font_table(&self, tag: u32) -> Option; } #[fixed_stack_segment] -pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { +pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { unsafe { let result = CTFontCreateWithGraphicsFont(*cgfont.contents.borrow_ref(), pt_size as CGFloat, @@ -136,7 +136,7 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: float) -> CTFont { } #[fixed_stack_segment] -pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { +pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { unsafe { let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), pt_size as CGFloat, @@ -146,7 +146,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: float) -> CTFont { } #[fixed_stack_segment] -pub fn new_from_name(name: ~str, pt_size: float) -> Result { +pub fn new_from_name(name: ~str, pt_size: f64) -> Result { unsafe { let cfname = CFString::new(name); let result = CTFontCreateWithName(*cfname.contents.borrow_ref(), @@ -185,7 +185,7 @@ impl CTFontMethods for CTFont { } #[fixed_stack_segment] - fn clone_with_font_size(&self, size: float) -> CTFont { + fn clone_with_font_size(&self, size: f64) -> CTFont { unsafe { let result = CTFontCreateCopyWithAttributes(self.obj, size as CGFloat, @@ -298,9 +298,9 @@ impl CTFontMethods for CTFont { glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) - -> float { + -> f64 { unsafe { - CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as float + CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as f64 } } diff --git a/font_descriptor.rs b/font_descriptor.rs index fec5560..015e88f 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -118,9 +118,9 @@ pub type CTFontTraits = UntypedCFDictionary; pub trait TraitAccessors { fn symbolic_traits(&self) -> CTFontSymbolicTraits; - fn normalized_weight(&self) -> float; - fn normalized_width(&self) -> float; - fn normalized_slant(&self) -> float; + fn normalized_weight(&self) -> f64; + fn normalized_width(&self) -> f64; + fn normalized_slant(&self) -> f64; } trait TraitAccessorPrivate { @@ -143,21 +143,21 @@ impl TraitAccessors for CTFontTraits { } } - fn normalized_weight(&self) -> float { + fn normalized_weight(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontWeightTrait); cast::transmute(number.to_float()) } } - fn normalized_width(&self) -> float { + fn normalized_width(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontWidthTrait); cast::transmute(number.to_float()) } } - fn normalized_slant(&self) -> float { + fn normalized_slant(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontSlantTrait); cast::transmute(number.to_float()) From ca88077b8c2a80ce3741f6707fb1e60207d55584 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 15 Oct 2013 18:22:40 -0600 Subject: [PATCH 050/126] Upgrade Rust. --- font_descriptor.rs | 94 +++++++++++++++++++++++----------------------- font_manager.rs | 38 +++++++++---------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/font_descriptor.rs b/font_descriptor.rs index 015e88f..029fcf1 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -282,10 +282,10 @@ extern { */ // font trait constants - static kCTFontSymbolicTrait: CFStringRef; - static kCTFontWeightTrait: CFStringRef; - static kCTFontWidthTrait: CFStringRef; - static kCTFontSlantTrait: CFStringRef; + pub static kCTFontSymbolicTrait: CFStringRef; + pub static kCTFontWeightTrait: CFStringRef; + pub static kCTFontWidthTrait: CFStringRef; + pub static kCTFontSlantTrait: CFStringRef; /* * CTFontDescriptor.h @@ -294,51 +294,51 @@ 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. - 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; + pub static kCTFontURLAttribute: CFStringRef; // value: CFURLRef + pub static kCTFontNameAttribute: CFStringRef; // value: CFStringRef + pub static kCTFontDisplayNameAttribute: CFStringRef; // value: CFStringRef + pub static kCTFontFamilyNameAttribute: CFStringRef; // value: CFStringRef + pub static kCTFontStyleNameAttribute: CFStringRef; // value: CFStringRef + pub static kCTFontTraitsAttribute: CFStringRef; + pub static kCTFontVariationAttribute: CFStringRef; + pub static kCTFontSizeAttribute: CFStringRef; + pub static kCTFontMatrixAttribute: CFStringRef; + pub static kCTFontCascadeListAttribute: CFStringRef; + pub static kCTFontCharacterSetAttribute: CFStringRef; + pub static kCTFontLanguagesAttribute: CFStringRef; + pub static kCTFontBaselineAdjustAttribute: CFStringRef; + pub static kCTFontMacintoshEncodingsAttribute: CFStringRef; + pub static kCTFontFeaturesAttribute: CFStringRef; + pub static kCTFontFeatureSettingsAttribute: CFStringRef; + pub static kCTFontFixedAdvanceAttribute: CFStringRef; + pub static kCTFontOrientationAttribute: CFStringRef; + pub static kCTFontFormatAttribute: CFStringRef; + pub static kCTFontRegistrationScopeAttribute: CFStringRef; + pub static kCTFontPriorityAttribute: CFStringRef; + pub static kCTFontEnabledAttribute: CFStringRef; - fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, - attribute: CFStringRef) -> CFTypeRef; - fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; - fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, - attribute: CFStringRef, - language: *CFStringRef) -> CFTypeRef; - fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, - attributes: CFDictionaryRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, - featureTypeIdentifier: CFNumberRef, - featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, - variationIdentifier: CFNumberRef, - variationValue: CGFloat) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef, - mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef; - fn CTFontDescriptorCreateWithNameAndSize(name: CFStringRef, size: CGFloat) -> CTFontDescriptorRef; - fn CTFontDescriptorGetTypeID() -> CFTypeID; + pub fn CTFontDescriptorCopyAttribute(descriptor: CTFontDescriptorRef, + attribute: CFStringRef) -> CFTypeRef; + pub fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; + pub fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, + attribute: CFStringRef, + language: *CFStringRef) -> CFTypeRef; + pub fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, + attributes: CFDictionaryRef) -> CTFontDescriptorRef; + pub fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, + featureTypeIdentifier: CFNumberRef, + featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; + pub fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, + variationIdentifier: CFNumberRef, + variationValue: CGFloat) -> CTFontDescriptorRef; + pub fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef, + mandatoryAttributes: CFSetRef) -> CTFontDescriptorRef; + pub fn CTFontDescriptorCreateWithAttributes(attributes: CFDictionaryRef) -> CTFontDescriptorRef; + pub fn CTFontDescriptorCreateWithNameAndSize(name: CFStringRef, size: CGFloat) -> CTFontDescriptorRef; + pub fn CTFontDescriptorGetTypeID() -> CFTypeID; } extern { - fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef, - mandatoryAttributes: CFSetRef) -> CFArrayRef; + pub fn CTFontDescriptorCreateMatchingFontDescriptors(descriptor: CTFontDescriptorRef, + mandatoryAttributes: CFSetRef) -> CFArrayRef; } diff --git a/font_manager.rs b/font_manager.rs index 168d147..d9eca05 100644 --- a/font_manager.rs +++ b/font_manager.rs @@ -18,23 +18,23 @@ extern { // Incomplete function bindings are mostly related to CoreText font matching, which // we implement in a platform-independent manner using FontMatcher. - //fn CTFontManagerCompareFontFamilyNames - fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef; - fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef; - fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef; - fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef; - //fn CTFontManagerCreateFontRequestRunLoopSource - //fn CTFontManagerEnableFontDescriptors - //fn CTFontManagerGetAutoActivationSetting - //fn CTFontManagerGetScopeForURL - //fn CTFontManagerGetAutoActivationSetting - //fn CTFontManagerGetScopeForURL - fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool; - //fn CTFontManagerRegisterFontsForURL - //fn CTFontManagerRegisterFontsForURLs - //fn CTFontManagerRegisterGraphicsFont - //fn CTFontManagerSetAutoActivationSetting - //fn CTFontManagerUnregisterFontsForURL - //fn CTFontManagerUnregisterFontsForURLs - //fn CTFontManagerUnregisterGraphicsFont + //pub fn CTFontManagerCompareFontFamilyNames + pub fn CTFontManagerCopyAvailableFontURLs() -> CFArrayRef; + pub fn CTFontManagerCopyAvailableFontFamilyNames() -> CFArrayRef; + pub fn CTFontManagerCopyAvailablePostScriptNames() -> CFArrayRef; + pub fn CTFontManagerCreateFontDescriptorsFromURL(fileURL: CFURLRef) -> CFArrayRef; + //pub fn CTFontManagerCreateFontRequestRunLoopSource + //pub fn CTFontManagerEnableFontDescriptors + //pub fn CTFontManagerGetAutoActivationSetting + //pub fn CTFontManagerGetScopeForURL + //pub fn CTFontManagerGetAutoActivationSetting + //pub fn CTFontManagerGetScopeForURL + pub fn CTFontManagerIsSupportedFont(fontURL: CFURLRef) -> bool; + //pub fn CTFontManagerRegisterFontsForURL + //pub fn CTFontManagerRegisterFontsForURLs + //pub fn CTFontManagerRegisterGraphicsFont + //pub fn CTFontManagerSetAutoActivationSetting + //pub fn CTFontManagerUnregisterFontsForURL + //pub fn CTFontManagerUnregisterFontsForURLs + //pub fn CTFontManagerUnregisterGraphicsFont } From 95c638d715b5600cd9c8a6e53376ce82749c664d Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 28 Oct 2013 20:08:55 -0700 Subject: [PATCH 051/126] fmt! -> format! --- font.rs | 28 ++++++++++++++-------------- font_descriptor.rs | 10 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/font.rs b/font.rs index 2be88a3..ac8f41b 100644 --- a/font.rs +++ b/font.rs @@ -334,26 +334,26 @@ pub fn debug_font_names(font: &CTFont) { get_string_by_name_key(font, key).unwrap() } - io::println(fmt!("kCTFontFamilyNameKey: %s", get_key(font, kCTFontFamilyNameKey))); - io::println(fmt!("kCTFontSubFamilyNameKey: %s", get_key(font, kCTFontSubFamilyNameKey))); - io::println(fmt!("kCTFontStyleNameKey: %s", get_key(font, kCTFontStyleNameKey))); - io::println(fmt!("kCTFontUniqueNameKey: %s", get_key(font, kCTFontUniqueNameKey))); - io::println(fmt!("kCTFontFullNameKey: %s", get_key(font, kCTFontFullNameKey))); - io::println(fmt!("kCTFontPostScriptNameKey: %s", get_key(font, kCTFontPostScriptNameKey))); + io::println(format!("kCTFontFamilyNameKey: {:s}", get_key(font, kCTFontFamilyNameKey))); + io::println(format!("kCTFontSubFamilyNameKey: {:s}", get_key(font, kCTFontSubFamilyNameKey))); + io::println(format!("kCTFontStyleNameKey: {:s}", get_key(font, kCTFontStyleNameKey))); + io::println(format!("kCTFontUniqueNameKey: {:s}", get_key(font, kCTFontUniqueNameKey))); + io::println(format!("kCTFontFullNameKey: {:s}", get_key(font, kCTFontFullNameKey))); + io::println(format!("kCTFontPostScriptNameKey: {:s}", get_key(font, kCTFontPostScriptNameKey))); } pub fn debug_font_traits(font: &CTFont) { let sym = font.symbolic_traits(); - io::println(fmt!("kCTFontItalicTrait: %b", sym.is_italic())); - io::println(fmt!("kCTFontBoldTrait: %b", sym.is_bold())); - io::println(fmt!("kCTFontExpandedTrait: %b", sym.is_expanded())); - io::println(fmt!("kCTFontCondensedTrait: %b", sym.is_condensed())); - io::println(fmt!("kCTFontMonoSpaceTrait: %b", sym.is_monospace())); + io::println(format!("kCTFontItalicTrait: {:b}", sym.is_italic())); + io::println(format!("kCTFontBoldTrait: {:b}", sym.is_bold())); + io::println(format!("kCTFontExpandedTrait: {:b}", sym.is_expanded())); + io::println(format!("kCTFontCondensedTrait: {:b}", sym.is_condensed())); + io::println(format!("kCTFontMonoSpaceTrait: {:b}", sym.is_monospace())); let traits = font.all_traits(); - io::println(fmt!("kCTFontWeightTrait: %f", traits.normalized_weight())); -// io::println(fmt!("kCTFontWidthTrait: %f", traits.normalized_width())); -// io::println(fmt!("kCTFontSlantTrait: %f", traits.normalized_slant())); + io::println(format!("kCTFontWeightTrait: :{f}", traits.normalized_weight())); +// io::println(format!("kCTFontWidthTrait: {:f}", traits.normalized_width())); +// io::println(format!("kCTFontSlantTrait: {:f}", traits.normalized_slant())); } #[nolink] diff --git a/font_descriptor.rs b/font_descriptor.rs index 029fcf1..2cf8de4 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -268,11 +268,11 @@ pub fn new_from_attributes(attributes: &CFWrapper Date: Thu, 31 Oct 2013 14:36:25 +0000 Subject: [PATCH 052/126] Replace usage of the now removed std::io. --- font.rs | 29 ++++++++++++++--------------- font_descriptor.rs | 11 +++++------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/font.rs b/font.rs index ac8f41b..293f2a5 100644 --- a/font.rs +++ b/font.rs @@ -26,7 +26,6 @@ use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; use std::libc; -use std::io; use std::ptr; pub type CTFontUIFontType = u32; @@ -334,26 +333,26 @@ pub fn debug_font_names(font: &CTFont) { get_string_by_name_key(font, key).unwrap() } - io::println(format!("kCTFontFamilyNameKey: {:s}", get_key(font, kCTFontFamilyNameKey))); - io::println(format!("kCTFontSubFamilyNameKey: {:s}", get_key(font, kCTFontSubFamilyNameKey))); - io::println(format!("kCTFontStyleNameKey: {:s}", get_key(font, kCTFontStyleNameKey))); - io::println(format!("kCTFontUniqueNameKey: {:s}", get_key(font, kCTFontUniqueNameKey))); - io::println(format!("kCTFontFullNameKey: {:s}", get_key(font, kCTFontFullNameKey))); - io::println(format!("kCTFontPostScriptNameKey: {:s}", get_key(font, kCTFontPostScriptNameKey))); + println!("kCTFontFamilyNameKey: {:s}", get_key(font, kCTFontFamilyNameKey)); + println!("kCTFontSubFamilyNameKey: {:s}", get_key(font, kCTFontSubFamilyNameKey)); + println!("kCTFontStyleNameKey: {:s}", get_key(font, kCTFontStyleNameKey)); + println!("kCTFontUniqueNameKey: {:s}", get_key(font, kCTFontUniqueNameKey)); + println!("kCTFontFullNameKey: {:s}", get_key(font, kCTFontFullNameKey)); + println!("kCTFontPostScriptNameKey: {:s}", get_key(font, kCTFontPostScriptNameKey)); } pub fn debug_font_traits(font: &CTFont) { let sym = font.symbolic_traits(); - io::println(format!("kCTFontItalicTrait: {:b}", sym.is_italic())); - io::println(format!("kCTFontBoldTrait: {:b}", sym.is_bold())); - io::println(format!("kCTFontExpandedTrait: {:b}", sym.is_expanded())); - io::println(format!("kCTFontCondensedTrait: {:b}", sym.is_condensed())); - io::println(format!("kCTFontMonoSpaceTrait: {:b}", sym.is_monospace())); + println!("kCTFontItalicTrait: {:b}", sym.is_italic()); + println!("kCTFontBoldTrait: {:b}", sym.is_bold()); + println!("kCTFontExpandedTrait: {:b}", sym.is_expanded()); + println!("kCTFontCondensedTrait: {:b}", sym.is_condensed()); + println!("kCTFontMonoSpaceTrait: {:b}", sym.is_monospace()); let traits = font.all_traits(); - io::println(format!("kCTFontWeightTrait: :{f}", traits.normalized_weight())); -// io::println(format!("kCTFontWidthTrait: {:f}", traits.normalized_width())); -// io::println(format!("kCTFontSlantTrait: {:f}", traits.normalized_slant())); + println!("kCTFontWeightTrait: {:f}", traits.normalized_weight()); +// println!("kCTFontWidthTrait: {:f}", traits.normalized_width()); +// println!("kCTFontSlantTrait: {:f}", traits.normalized_slant()); } #[nolink] diff --git a/font_descriptor.rs b/font_descriptor.rs index 2cf8de4..32a23ae 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -21,7 +21,6 @@ use core_foundation::url::{CFURLRef}; use core_graphics::base::CGFloat; use std::cast; -use std::io; /* * CTFontTraits.h @@ -268,11 +267,11 @@ pub fn new_from_attributes(attributes: &CFWrapper Date: Fri, 1 Nov 2013 20:37:21 -0700 Subject: [PATCH 053/126] Update for the Core Foundation bindings revamp --- font.rs | 205 ++++++++++++++++++++------------------------- font_collection.rs | 117 ++++++++++++++------------ font_descriptor.rs | 103 ++++++++++++----------- 3 files changed, 210 insertions(+), 215 deletions(-) diff --git a/font.rs b/font.rs index 293f2a5..c226a0e 100644 --- a/font.rs +++ b/font.rs @@ -16,10 +16,9 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; use core_foundation::array::{CFArrayRef}; -use core_foundation::base::{AbstractCFTypeRef, CFIndex, CFOptionFlags, CFTypeID, CFTypeRef}; -use core_foundation::base::{CFWrapper}; +use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFTypeRef, TCFType}; use core_foundation::data::{CFData, CFDataRef}; -use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; +use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; @@ -70,248 +69,225 @@ pub static kCTFontOptionsDefault: CTFontOptions = 0; pub static kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0); pub static kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); -struct __CTFont { private: () } +struct __CTFont; + pub type CTFontRef = *__CTFont; -impl AbstractCFTypeRef for CTFontRef { - fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +pub struct CTFont { + priv obj: CTFontRef, +} + +impl Drop for CTFont { + #[fixed_stack_segment] + fn drop(&mut self) { + unsafe { + CFRelease(self.as_CFTypeRef()) + } + } +} + +impl TCFType for CTFont { + fn as_concrete_TypeRef(&self) -> CTFontRef { + self.obj + } + + unsafe fn wrap_under_create_rule(obj: CTFontRef) -> CTFont { + CTFont { + obj: obj, + } + } #[fixed_stack_segment] - fn type_id(_dummy: Option) -> CFTypeID { + #[inline] + fn type_id(_: Option) -> CFTypeID { unsafe { CTFontGetTypeID() } } } -pub type CTFont = CFWrapper; - -pub trait CTFontMethods { - // Creation methods (statics below) - fn copy_to_CGFont(&self) -> CGFont; - fn clone_with_font_size(&self, size: f64) -> CTFont; - - // Names - fn family_name(&self) -> ~str; - fn face_name(&self) -> ~str; - fn unique_name(&self) -> ~str; - fn postscript_name(&self) -> ~str; - - // Properties - fn all_traits(&self) -> CTFontTraits; - - // Font metrics - 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, - count: CFIndex) - -> bool; - fn get_advances_for_glyphs(&self, - orientation: CTFontOrientation, - glyphs: *CGGlyph, - advances: *CGSize, - count: CFIndex) - -> f64; - fn get_font_table(&self, tag: u32) -> Option; -} - #[fixed_stack_segment] pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { unsafe { - let result = CTFontCreateWithGraphicsFont(*cgfont.contents.borrow_ref(), - pt_size as CGFloat, - ptr::null(), - ptr::null()); - CFWrapper::wrap_owned(result) + let font_ref = CTFontCreateWithGraphicsFont(cgfont.as_concrete_TypeRef(), + pt_size as CGFloat, + ptr::null(), + ptr::null()); + TCFType::wrap_under_create_rule(font_ref) } } #[fixed_stack_segment] pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { unsafe { - let result = CTFontCreateWithFontDescriptor(*desc.borrow_ref(), - pt_size as CGFloat, - ptr::null()); - CFWrapper::wrap_owned(result) + let font_ref = CTFontCreateWithFontDescriptor(desc.as_concrete_TypeRef(), + pt_size as CGFloat, + ptr::null()); + TCFType::wrap_under_create_rule(font_ref) } } #[fixed_stack_segment] pub fn new_from_name(name: ~str, pt_size: f64) -> Result { unsafe { - let cfname = CFString::new(name); - let result = CTFontCreateWithName(*cfname.contents.borrow_ref(), - pt_size as CGFloat, - ptr::null()); - if result.is_null() { - return Err(()); + let name: CFString = from_str(name).unwrap(); + let font_ref = CTFontCreateWithName(name.as_concrete_TypeRef(), + pt_size as CGFloat, + ptr::null()); + if font_ref.is_null() { + Err(()) + } else { + Ok(TCFType::wrap_under_create_rule(font_ref)) } - - return Ok(CFWrapper::wrap_owned(result)); } } -pub trait CTFontMethodsPrivate { - fn symbolic_traits(&self) -> CTFontSymbolicTraits; -} - -impl CTFontMethodsPrivate for CTFont { +impl CTFont { // Properties #[fixed_stack_segment] - fn symbolic_traits(&self) -> CTFontSymbolicTraits { + pub fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { CTFontGetSymbolicTraits(self.obj) } } } -impl CTFontMethods for CTFont { +impl CTFont { // Creation methods #[fixed_stack_segment] - fn copy_to_CGFont(&self) -> CGFont { + pub fn copy_to_CGFont(&self) -> CGFont { unsafe { - let value = CTFontCopyGraphicsFont(self.obj, ptr::null()); - CGFont::wrap_owned(value) + let CGFont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null()); + TCFType::wrap_under_create_rule(CGFont_ref) } } #[fixed_stack_segment] - fn clone_with_font_size(&self, size: f64) -> CTFont { + pub fn clone_with_font_size(&self, size: f64) -> CTFont { unsafe { - let result = CTFontCreateCopyWithAttributes(self.obj, - size as CGFloat, - ptr::null(), - ptr::null()); - CFWrapper::wrap_owned(result) + let font_ref = CTFontCreateCopyWithAttributes(self.obj, + size as CGFloat, + ptr::null(), + ptr::null()); + TCFType::wrap_under_create_rule(font_ref) } } // Names - fn family_name(&self) -> ~str { + pub fn family_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontFamilyNameKey); value.expect("Fonts should always have a family name.") } - fn face_name(&self) -> ~str { + pub fn face_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); value.expect("Fonts should always have a face name.") } - fn unique_name(&self) -> ~str { + pub fn unique_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontUniqueNameKey); value.expect("Fonts should always have a unique name.") } - fn postscript_name(&self) -> ~str { + pub fn postscript_name(&self) -> ~str { let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); value.expect("Fonts should always have a PostScript name.") } #[fixed_stack_segment] - fn all_traits(&self) -> CTFontTraits { + pub fn all_traits(&self) -> CTFontTraits { unsafe { - let result = CTFontCopyTraits(self.obj); - CFDictionary::wrap_owned(result) + TCFType::wrap_under_create_rule(CTFontCopyTraits(self.obj)) } } // Font metrics #[fixed_stack_segment] - fn ascent(&self) -> CGFloat { + pub fn ascent(&self) -> CGFloat { unsafe { CTFontGetAscent(self.obj) } } #[fixed_stack_segment] - fn descent(&self) -> CGFloat { + pub fn descent(&self) -> CGFloat { unsafe { CTFontGetDescent(self.obj) } } #[fixed_stack_segment] - fn underline_thickness(&self) -> CGFloat { + pub fn underline_thickness(&self) -> CGFloat { unsafe { CTFontGetUnderlineThickness(self.obj) } } #[fixed_stack_segment] - fn underline_position(&self) -> CGFloat { + pub fn underline_position(&self) -> CGFloat { unsafe { CTFontGetUnderlinePosition(self.obj) } } #[fixed_stack_segment] - fn bounding_box(&self) -> CGRect { + pub fn bounding_box(&self) -> CGRect { unsafe { CTFontGetBoundingBox(self.obj) } } #[fixed_stack_segment] - fn leading(&self) -> CGFloat { + pub fn leading(&self) -> CGFloat { unsafe { CTFontGetLeading(self.obj) } } #[fixed_stack_segment] - fn x_height(&self) -> CGFloat { + pub fn x_height(&self) -> CGFloat { unsafe { CTFontGetXHeight(self.obj) } } #[fixed_stack_segment] - fn pt_size(&self) -> CGFloat { + pub fn pt_size(&self) -> CGFloat { unsafe { CTFontGetSize(self.obj) } } #[fixed_stack_segment] - fn get_glyphs_for_characters(&self, - characters: *UniChar, - glyphs: *CGGlyph, - count: CFIndex) - -> bool { + pub fn get_glyphs_for_characters(&self, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) + -> bool { unsafe { CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) } } #[fixed_stack_segment] - fn get_advances_for_glyphs(&self, - orientation: CTFontOrientation, - glyphs: *CGGlyph, - advances: *CGSize, - count: CFIndex) - -> f64 { + pub fn get_advances_for_glyphs(&self, + orientation: CTFontOrientation, + glyphs: *CGGlyph, + advances: *CGSize, + count: CFIndex) + -> f64 { unsafe { CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as f64 } } #[fixed_stack_segment] - fn get_font_table(&self, tag: u32) -> Option { + pub fn get_font_table(&self, tag: u32) -> Option { unsafe { let result = CTFontCopyTable(self.obj, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic); - return match result.is_null() { - true => None, - false => Some(CFData::wrap_owned(result)), + if result.is_null() { + None + } else { + Some(TCFType::wrap_under_create_rule(result)) } } } @@ -321,10 +297,13 @@ impl CTFontMethods for CTFont { #[fixed_stack_segment] fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { unsafe { - let result = CTFontCopyName(*font.borrow_ref(), name_key); - if result.is_null() { return None; } - - return Some(CFString::wrap_owned(result).to_str()); + let result = CTFontCopyName(font.as_concrete_TypeRef(), name_key); + if result.is_null() { + None + } else { + let string: CFString = TCFType::wrap_under_create_rule(result); + Some(string.to_str()) + } } } diff --git a/font_collection.rs b/font_collection.rs index d011bdc..e28fa07 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -8,108 +8,117 @@ // except according to those terms. use font_descriptor; -use font_descriptor::CTFontDescriptor; -use font_descriptor::{CTFontDescriptorCreateMatchingFontDescriptors, CTFontDescriptorRef}; +use font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescriptors}; use font_manager::CTFontManagerCopyAvailableFontFamilyNames; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{AbstractCFTypeRef, CFTypeID}; -use core_foundation::base::{CFTypeRef, CFWrapper}; +use core_foundation::base::{CFRelease, CFTypeID, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::CFNumber; use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; -struct __CTFontCollection { private: () } +struct __CTFontCollection; + pub type CTFontCollectionRef = *__CTFontCollection; -impl AbstractCFTypeRef for CTFontCollectionRef { - fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +pub struct CTFontCollection { + obj: CTFontCollectionRef, +} + +impl Drop for CTFontCollection { + #[fixed_stack_segment] + fn drop(&mut self) { + unsafe { + CFRelease(self.as_CFTypeRef()) + } + } +} + +impl TCFType for CTFontCollection { + fn as_concrete_TypeRef(&self) -> CTFontCollectionRef { + self.obj + } + + unsafe fn wrap_under_create_rule(obj: CTFontCollectionRef) -> CTFontCollection { + CTFontCollection { + obj: obj, + } + } #[fixed_stack_segment] - fn type_id(_dummy: Option) -> CFTypeID { + fn type_id(_: Option) -> CFTypeID { unsafe { CTFontCollectionGetTypeID() } } } -pub type CTFontCollection = CFWrapper; - -pub trait CTFontCollectionMethods { - fn get_descriptors(&self) -> CFArray; -} - -impl CTFontCollectionMethods for CTFontCollection { +impl CTFontCollection { #[fixed_stack_segment] - fn get_descriptors(&self) -> CFArray { + pub fn get_descriptors(&self) -> CFArray { // 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 { - CFArray::wrap_shared(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + TCFType::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) } } } #[fixed_stack_segment] -pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { - let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); - let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ - (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) - ]); +pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { - let result = CTFontCollectionCreateWithFontDescriptors(*descs.contents.borrow_ref(), - *options.contents.borrow_ref()); - CFWrapper::wrap_owned(result) + let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); + let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); + let options = CFDictionary::from_CFType_pairs([ (key.as_CFType(), value.as_CFType()) ]); + let font_collection_ref = + CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(), + options.as_concrete_TypeRef()); + TCFType::wrap_under_create_rule(font_collection_ref) } } #[fixed_stack_segment] pub fn create_for_all_families() -> CTFontCollection { - let key = CFString::wrap_shared(kCTFontCollectionRemoveDuplicatesOption); - let value = CFNumber::new(1_i8); - let options = CFDictionary::new([ - (*key.contents.borrow_ref(), *value.contents.borrow_type_ref()) - ]); unsafe { - let result = CTFontCollectionCreateFromAvailableFonts(*options.contents.borrow_ref()); - CFWrapper::wrap_owned(result) + let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); + let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); + let options = CFDictionary::from_CFType_pairs([ (key.as_CFType(), value.as_CFType()) ]); + let font_collection_ref = + CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef()); + TCFType::wrap_under_create_rule(font_collection_ref) } } #[fixed_stack_segment] pub fn create_for_family(family: &str) -> CTFontCollection { use font_descriptor::kCTFontFamilyNameAttribute; - - let family_attr = CFString::wrap_shared(kCTFontFamilyNameAttribute); - let family_name = CFString::new(family); - let specified_attrs: CFDictionary = - CFDictionary::new([ - (*family_attr.contents.borrow_ref(), *family_name.contents.borrow_type_ref()) + unsafe { + let family_attr: CFString = TCFType::wrap_under_get_rule(kCTFontFamilyNameAttribute); + let family_name: CFString = from_str(family).unwrap(); + let specified_attrs = CFDictionary::from_CFType_pairs([ + (family_attr.as_CFType(), family_name.as_CFType()) ]); - let wildcard_desc: CTFontDescriptor = - font_descriptor::new_from_attributes(&specified_attrs.contents); - let mandatory_attrs = CFSet::new([ *family_attr.contents.borrow_ref() ]); - let matched_descs = unsafe { - CTFontDescriptorCreateMatchingFontDescriptors( - *wildcard_desc.borrow_ref(), - *mandatory_attrs.contents.borrow_ref()) - }; + let wildcard_desc: CTFontDescriptor = + font_descriptor::new_from_attributes(&specified_attrs); + let mandatory_attrs = CFSet::from_slice([ family_attr.as_CFType() ]); + let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors( + wildcard_desc.as_concrete_TypeRef(), + mandatory_attrs.as_concrete_TypeRef()); + let matched_descs: CFArray = TCFType::wrap_under_create_rule(matched_descs); - let matched_descs: CFArray = CFArray::wrap_owned(matched_descs); - - // I suppose one doesn't even need the CTFontCollection object at this point. - // But we stick descriptors into and out of it just to provide a nice wrapper API. - new_from_descriptors(&matched_descs) + // I suppose one doesn't even need the CTFontCollection object at this point. + // But we stick descriptors into and out of it just to provide a nice wrapper API. + new_from_descriptors(&matched_descs) + } } #[fixed_stack_segment] -pub fn get_family_names() -> CFArray { +pub fn get_family_names() -> CFArray { unsafe { - CFArray::wrap_owned(CTFontManagerCopyAvailableFontFamilyNames()) + TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) } } diff --git a/font_descriptor.rs b/font_descriptor.rs index 32a23ae..a92c585 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -9,15 +9,13 @@ #[allow(non_uppercase_statics)]; -use core_foundation; use core_foundation::array::CFArrayRef; -use core_foundation::base::AbstractCFTypeRef; -use core_foundation::base::{CFTypeID, CFTypeRef, CFWrapper}; -use core_foundation::dictionary::{CFDictionaryRef, UntypedCFDictionary}; +use core_foundation::base::{CFRelease, CFType, CFTypeID, CFTypeRef, TCFType}; +use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; use core_foundation::string::{CFString, CFStringRef}; -use core_foundation::url::{CFURLRef}; +use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; use std::cast; @@ -112,8 +110,9 @@ impl StylisticClassAccessors for CTFontStylisticClass { } } -pub type CTFontAttributes = UntypedCFDictionary; -pub type CTFontTraits = UntypedCFDictionary; +pub type CTFontAttributes = CFDictionary; + +pub type CTFontTraits = CFDictionary; pub trait TraitAccessors { fn symbolic_traits(&self) -> CTFontSymbolicTraits; @@ -123,13 +122,12 @@ pub trait TraitAccessors { } trait TraitAccessorPrivate { - fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber; + unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber; } impl TraitAccessorPrivate for CTFontTraits { - fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { - let value = self.get(&key); - CFNumber::wrap_shared(core_foundation::base::downcast::(value)) + unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { + self.get_CFType(cast::transmute(key)).cast::() } } @@ -138,28 +136,28 @@ impl TraitAccessors for CTFontTraits { fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { let number = self.extract_number_for_key(kCTFontSymbolicTrait); - cast::transmute(number.to_i32()) + number.to_u32().unwrap() } } fn normalized_weight(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontWeightTrait); - cast::transmute(number.to_float()) + number.to_f64().unwrap() } } fn normalized_width(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontWidthTrait); - cast::transmute(number.to_float()) + number.to_f64().unwrap() } } fn normalized_slant(&self) -> f64 { unsafe { let number = self.extract_number_for_key(kCTFontSlantTrait); - cast::transmute(number.to_float()) + number.to_f64().unwrap() } } } @@ -180,89 +178,98 @@ pub static kCTFontPriorityUser: CTFontPriority = 40000; pub static kCTFontPriorityDynamic: CTFontPriority = 50000; pub static kCTFontPriorityProcess: CTFontPriority = 60000; -struct __CTFontDescriptor { private: () } +struct __CTFontDescriptor; + pub type CTFontDescriptorRef = *__CTFontDescriptor; -impl AbstractCFTypeRef for CTFontDescriptorRef { - fn as_type_ref(&self) -> CFTypeRef { *self as CFTypeRef } +pub struct CTFontDescriptor { + priv obj: CTFontDescriptorRef, +} + +impl Drop for CTFontDescriptor { + #[fixed_stack_segment] + fn drop(&mut self) { + unsafe { + CFRelease(self.as_CFTypeRef()) + } + } +} + +impl TCFType for CTFontDescriptor { + fn as_concrete_TypeRef(&self) -> CTFontDescriptorRef { + self.obj + } + + unsafe fn wrap_under_create_rule(obj: CTFontDescriptorRef) -> CTFontDescriptor { + CTFontDescriptor { + obj: obj, + } + } #[fixed_stack_segment] - fn type_id(_dummy: Option) -> CFTypeID { + #[inline] + fn type_id(_: Option) -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() } } } -pub type CTFontDescriptor = CFWrapper; - -pub trait CTFontDescriptorMethods { - 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; -} - -trait CTFontDescriptorMethodsPrivate { - fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str>; -} - -impl CTFontDescriptorMethodsPrivate for CTFontDescriptor { +impl CTFontDescriptor { #[fixed_stack_segment] fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { - return None; + return None } - Some(CFString::wrap_owned(core_foundation::base::downcast::( - value)).to_str()) + let value: CFType = TCFType::wrap_under_get_rule(value); + Some(value.cast::().to_str()) } } } -impl CTFontDescriptorMethods for CTFontDescriptor { - fn family_name(&self) -> ~str { +impl CTFontDescriptor { + pub fn family_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); value.expect("A font must have a non-null font family name.") } - fn font_name(&self) -> ~str { + pub fn font_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontNameAttribute); value.expect("A font must have a non-null name.") } - fn style_name(&self) -> ~str { + pub fn style_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontStyleNameAttribute); value.expect("A font must have a non-null style name.") } - fn display_name(&self) -> ~str { + pub fn display_name(&self) -> ~str { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); value.expect("A font must have a non-null display name.") } #[fixed_stack_segment] - fn font_path(&self) -> ~str { + pub fn font_path(&self) -> ~str { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); assert!(value.is_not_null()); - CFWrapper::wrap_owned(core_foundation::base::downcast::(value)).to_str() + let value: CFType = TCFType::wrap_under_get_rule(value); + value.cast::().to_str() } } } #[fixed_stack_segment] -pub fn new_from_attributes(attributes: &CFWrapper) - -> CTFontDescriptor { +pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor { unsafe { let result: CTFontDescriptorRef = - CTFontDescriptorCreateWithAttributes(*attributes.borrow_ref()); - CFWrapper::wrap_owned(result) + CTFontDescriptorCreateWithAttributes(attributes.as_concrete_TypeRef()); + TCFType::wrap_under_create_rule(result) } } From dc573cdb3a4cb3c051fdf39c1af6ce0b946fe333 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 16 Sep 2013 12:46:47 -0600 Subject: [PATCH 054/126] Convert to rustpkg. --- Makefile.in | 6 +++--- font.rs | 3 --- core_text.rc => lib.rs | 8 ++------ 3 files changed, 5 insertions(+), 12 deletions(-) rename core_text.rc => lib.rs (80%) diff --git a/Makefile.in b/Makefile.in index 814f377..7df16b3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -8,11 +8,11 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') .PHONY: all clean all: librustcoretext.dummy -librustcoretext.dummy: core_text.rc $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< --out-dir . +librustcoretext.dummy: lib.rs $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< --lib --out-dir . touch $@ -rustcoretext-test: core_text.rc $(RUST_SRC) +rustcoretext-test: lib.rs $(RUST_SRC) $(RUSTC) $(RUSTFLAGS) $< -o $@ --test check: rustcoretext-test diff --git a/font.rs b/font.rs index 293f2a5..dca7e13 100644 --- a/font.rs +++ b/font.rs @@ -9,9 +9,6 @@ #[allow(non_uppercase_statics)]; -extern mod core_foundation; -extern mod core_graphics; - use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; diff --git a/core_text.rc b/lib.rs similarity index 80% rename from core_text.rc rename to lib.rs index f6e245e..ea41ab4 100644 --- a/core_text.rc +++ b/lib.rs @@ -7,14 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[link(name = "core_text", - vers = "0.1")]; -#[crate_type = "lib"]; - extern mod std; -extern mod core_foundation; -extern mod core_graphics; +extern mod core_foundation = "rust-core-foundation"; +extern mod core_graphics = "rust-core-graphics"; pub mod font; pub mod font_collection; From bedcd98f6bd5b2303217a0850674db58c589db3a Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Wed, 6 Nov 2013 17:49:30 -0800 Subject: [PATCH 055/126] Remove old build system --- Makefile.in | 23 ----------------------- configure | 5 ----- 2 files changed, 28 deletions(-) delete mode 100644 Makefile.in delete mode 100755 configure diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 7df16b3..0000000 --- a/Makefile.in +++ /dev/null @@ -1,23 +0,0 @@ -VPATH=%VPATH% - -RUSTC ?= rustc -RUSTFLAGS ?= - -RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') - -.PHONY: all clean -all: librustcoretext.dummy - -librustcoretext.dummy: lib.rs $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< --lib --out-dir . - touch $@ - -rustcoretext-test: lib.rs $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< -o $@ --test - -check: rustcoretext-test - ./rustcoretext-test - -clean: - rm -f *.o *.a *.so *.dylib *.dll *.dummy rustcoretext-test - diff --git a/configure b/configure deleted file mode 100755 index ed6c06e..0000000 --- a/configure +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -SRCDIR="$(cd $(dirname $0) && pwd)" -sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile - From 5a5fa464b4909549c5181ccb0642149f1b3e10c9 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 26 Dec 2013 19:49:58 -0700 Subject: [PATCH 056/126] Build with make instead of rustpkg. --- Makefile.in | 24 ++++++++++++++++++++++++ configure | 4 ++++ lib.rs | 6 ++++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Makefile.in create mode 100755 configure diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..c0ea080 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,24 @@ +VPATH=%VPATH% + +RUSTC ?= rustc +RUSTFLAGS ?= + +RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') + +.PHONY: all +all: libcore_text.dummy + +libcore_text.dummy: lib.rs $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< --lib --out-dir . + touch $@ + +core_text-test: lib.rs $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< -o $@ --test + +.PHONY: check +check: core_text-test + ./core_text-test $(TEST) + +.PHONY: clean +clean: + rm -f *.o *.a *.so *.dylib *.dll *.dummy *-test diff --git a/configure b/configure new file mode 100755 index 0000000..62a0f4c --- /dev/null +++ b/configure @@ -0,0 +1,4 @@ +#!/bin/bash + +SRCDIR="$(cd $(dirname $0) && pwd)" +sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile diff --git a/lib.rs b/lib.rs index ea41ab4..5b6da39 100644 --- a/lib.rs +++ b/lib.rs @@ -7,10 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[link(name = "core_text", vers = "0.1")]; + extern mod std; -extern mod core_foundation = "rust-core-foundation"; -extern mod core_graphics = "rust-core-graphics"; +extern mod core_foundation; +extern mod core_graphics; pub mod font; pub mod font_collection; From d727e214b4f459c61631b5ee27964fb10882a5f4 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 20 Dec 2013 21:37:56 -0700 Subject: [PATCH 057/126] Upgrade to latest Rust. --- font.rs | 97 ++++++++++++++++++---------------------------- font_collection.rs | 13 ++----- font_descriptor.rs | 5 --- lib.rs | 2 +- 4 files changed, 41 insertions(+), 76 deletions(-) diff --git a/font.rs b/font.rs index 9abb638..181e248 100644 --- a/font.rs +++ b/font.rs @@ -12,8 +12,7 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; -use core_foundation::array::{CFArrayRef}; -use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFTypeRef, TCFType}; +use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, TCFType}; use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; @@ -75,7 +74,6 @@ pub struct CTFont { } impl Drop for CTFont { - #[fixed_stack_segment] fn drop(&mut self) { unsafe { CFRelease(self.as_CFTypeRef()) @@ -94,7 +92,6 @@ impl TCFType for CTFont { } } - #[fixed_stack_segment] #[inline] fn type_id(_: Option) -> CFTypeID { unsafe { @@ -103,7 +100,6 @@ impl TCFType for CTFont { } } -#[fixed_stack_segment] pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { unsafe { let font_ref = CTFontCreateWithGraphicsFont(cgfont.as_concrete_TypeRef(), @@ -114,7 +110,6 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { } } -#[fixed_stack_segment] pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { unsafe { let font_ref = CTFontCreateWithFontDescriptor(desc.as_concrete_TypeRef(), @@ -124,7 +119,6 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { } } -#[fixed_stack_segment] pub fn new_from_name(name: ~str, pt_size: f64) -> Result { unsafe { let name: CFString = from_str(name).unwrap(); @@ -141,7 +135,6 @@ pub fn new_from_name(name: ~str, pt_size: f64) -> Result { impl CTFont { // Properties - #[fixed_stack_segment] pub fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { CTFontGetSymbolicTraits(self.obj) @@ -151,7 +144,6 @@ impl CTFont { impl CTFont { // Creation methods - #[fixed_stack_segment] pub fn copy_to_CGFont(&self) -> CGFont { unsafe { let CGFont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null()); @@ -159,7 +151,6 @@ impl CTFont { } } - #[fixed_stack_segment] pub fn clone_with_font_size(&self, size: f64) -> CTFont { unsafe { let font_ref = CTFontCreateCopyWithAttributes(self.obj, @@ -191,7 +182,6 @@ impl CTFont { value.expect("Fonts should always have a PostScript name.") } - #[fixed_stack_segment] pub fn all_traits(&self) -> CTFontTraits { unsafe { TCFType::wrap_under_create_rule(CTFontCopyTraits(self.obj)) @@ -199,63 +189,54 @@ impl CTFont { } // Font metrics - #[fixed_stack_segment] pub fn ascent(&self) -> CGFloat { unsafe { CTFontGetAscent(self.obj) } } - #[fixed_stack_segment] pub fn descent(&self) -> CGFloat { unsafe { CTFontGetDescent(self.obj) } } - #[fixed_stack_segment] pub fn underline_thickness(&self) -> CGFloat { unsafe { CTFontGetUnderlineThickness(self.obj) } } - #[fixed_stack_segment] pub fn underline_position(&self) -> CGFloat { unsafe { CTFontGetUnderlinePosition(self.obj) } } - #[fixed_stack_segment] pub fn bounding_box(&self) -> CGRect { unsafe { CTFontGetBoundingBox(self.obj) } } - #[fixed_stack_segment] pub fn leading(&self) -> CGFloat { unsafe { CTFontGetLeading(self.obj) } } - #[fixed_stack_segment] pub fn x_height(&self) -> CGFloat { unsafe { CTFontGetXHeight(self.obj) } } - #[fixed_stack_segment] pub fn pt_size(&self) -> CGFloat { unsafe { CTFontGetSize(self.obj) } } - #[fixed_stack_segment] pub fn get_glyphs_for_characters(&self, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool { unsafe { @@ -263,7 +244,6 @@ impl CTFont { } } - #[fixed_stack_segment] pub fn get_advances_for_glyphs(&self, orientation: CTFontOrientation, glyphs: *CGGlyph, @@ -275,7 +255,6 @@ impl CTFont { } } - #[fixed_stack_segment] pub fn get_font_table(&self, tag: u32) -> Option { unsafe { let result = CTFontCopyTable(self.obj, @@ -291,7 +270,6 @@ impl CTFont { } // Helper methods -#[fixed_stack_segment] fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { unsafe { let result = CTFontCopyName(font.as_concrete_TypeRef(), name_key); @@ -331,47 +309,46 @@ pub fn debug_font_traits(font: &CTFont) { // println!("kCTFontSlantTrait: {:f}", traits.normalized_slant()); } -#[nolink] -#[link_args = "-framework ApplicationServices"] +#[link(name = "ApplicationServices", kind = "framework")] extern { /* * CTFont.h */ /* Name Specifier Constants */ - static kCTFontCopyrightNameKey: CFStringRef; + //static kCTFontCopyrightNameKey: CFStringRef; static kCTFontFamilyNameKey: CFStringRef; static kCTFontSubFamilyNameKey: CFStringRef; static kCTFontStyleNameKey: CFStringRef; static kCTFontUniqueNameKey: CFStringRef; static kCTFontFullNameKey: CFStringRef; - static kCTFontVersionNameKey: 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; + //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; - static kCTFontVariationAxisIdentifierKey: CFStringRef; - static kCTFontVariationAxisMinimumValueKey: CFStringRef; - static kCTFontVariationAxisMaximumValueKey: CFStringRef; - static kCTFontVariationAxisDefaultValueKey: CFStringRef; - static kCTFontVariationAxisNameKey: CFStringRef; + //static kCTFontVariationAxisIdentifierKey: CFStringRef; + //static kCTFontVariationAxisMinimumValueKey: CFStringRef; + //static kCTFontVariationAxisMaximumValueKey: CFStringRef; + //static kCTFontVariationAxisDefaultValueKey: CFStringRef; + //static kCTFontVariationAxisNameKey: 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; + //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. @@ -390,21 +367,21 @@ extern { //fn CTFontCreateForString /* Getting Font Data */ - fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; - fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; + //fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; + //fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; fn CTFontGetSize(font: CTFontRef) -> CGFloat; //fn CTFontGetMatrix fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits; fn CTFontCopyTraits(font: CTFontRef) -> CFDictionaryRef; /* Getting Font Names */ - fn CTFontCopyPostScriptName(font: CTFontRef) -> CFStringRef; - fn CTFontCopyFamilyName(font: CTFontRef) -> CFStringRef; - fn CTFontCopyFullName(font: CTFontRef) -> CFStringRef; - fn CTFontCopyDisplayName(font: CTFontRef) -> CFStringRef; + //fn CTFontCopyPostScriptName(font: CTFontRef) -> CFStringRef; + //fn CTFontCopyFamilyName(font: CTFontRef) -> CFStringRef; + //fn CTFontCopyFullName(font: CTFontRef) -> CFStringRef; + //fn CTFontCopyDisplayName(font: CTFontRef) -> CFStringRef; fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; - fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, - language: *CFStringRef) -> CFStringRef; + //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, + // language: *CFStringRef) -> CFStringRef; /* Working With Encoding */ //fn CTFontCopyCharacterSet @@ -415,7 +392,7 @@ extern { fn CTFontGetAscent(font: CTFontRef) -> CGFloat; fn CTFontGetDescent(font: CTFontRef) -> CGFloat; fn CTFontGetLeading(font: CTFontRef) -> CGFloat; - fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; + //fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; //fn CTFontGetGlyphCount fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; @@ -454,7 +431,7 @@ extern { //fn CTFontCreateWithQuickdrawInstance /* Getting Font Table Data */ - fn CTFontCopyAvailableTables(font: CTFontRef, options: CTFontTableOptions) -> CFArrayRef; + //fn CTFontCopyAvailableTables(font: CTFontRef, options: CTFontTableOptions) -> CFArrayRef; fn CTFontCopyTable(font: CTFontRef, table: CTFontTableTag, options: CTFontTableOptions) -> CFDataRef; fn CTFontGetTypeID() -> CFTypeID; diff --git a/font_collection.rs b/font_collection.rs index e28fa07..7467115 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -27,7 +27,6 @@ pub struct CTFontCollection { } impl Drop for CTFontCollection { - #[fixed_stack_segment] fn drop(&mut self) { unsafe { CFRelease(self.as_CFTypeRef()) @@ -46,7 +45,6 @@ impl TCFType for CTFontCollection { } } - #[fixed_stack_segment] fn type_id(_: Option) -> CFTypeID { unsafe { CTFontCollectionGetTypeID() @@ -55,7 +53,6 @@ impl TCFType for CTFontCollection { } impl CTFontCollection { - #[fixed_stack_segment] pub fn get_descriptors(&self) -> CFArray { // 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. @@ -65,7 +62,6 @@ impl CTFontCollection { } } -#[fixed_stack_segment] pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); @@ -78,7 +74,6 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { } } -#[fixed_stack_segment] pub fn create_for_all_families() -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); @@ -90,7 +85,6 @@ pub fn create_for_all_families() -> CTFontCollection { } } -#[fixed_stack_segment] pub fn create_for_family(family: &str) -> CTFontCollection { use font_descriptor::kCTFontFamilyNameAttribute; @@ -115,7 +109,6 @@ pub fn create_for_family(family: &str) -> CTFontCollection { } } -#[fixed_stack_segment] pub fn get_family_names() -> CFArray { unsafe { TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) @@ -129,9 +122,9 @@ extern { static kCTFontCollectionRemoveDuplicatesOption: CFStringRef; - fn CTFontCollectionCreateCopyWithFontDescriptors(original: CTFontCollectionRef, - descriptors: CFArrayRef, - options: CFDictionaryRef) -> CTFontCollectionRef; + //fn CTFontCollectionCreateCopyWithFontDescriptors(original: CTFontCollectionRef, + // descriptors: CFArrayRef, + // options: CFDictionaryRef) -> CTFontCollectionRef; fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef; // this stupid function doesn't actually do any wildcard expansion; // it just chooses the best match. Use diff --git a/font_descriptor.rs b/font_descriptor.rs index a92c585..c50e503 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -187,7 +187,6 @@ pub struct CTFontDescriptor { } impl Drop for CTFontDescriptor { - #[fixed_stack_segment] fn drop(&mut self) { unsafe { CFRelease(self.as_CFTypeRef()) @@ -206,7 +205,6 @@ impl TCFType for CTFontDescriptor { } } - #[fixed_stack_segment] #[inline] fn type_id(_: Option) -> CFTypeID { unsafe { @@ -216,7 +214,6 @@ impl TCFType for CTFontDescriptor { } impl CTFontDescriptor { - #[fixed_stack_segment] fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); @@ -252,7 +249,6 @@ impl CTFontDescriptor { value.expect("A font must have a non-null display name.") } - #[fixed_stack_segment] pub fn font_path(&self) -> ~str { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); @@ -264,7 +260,6 @@ impl CTFontDescriptor { } } -#[fixed_stack_segment] pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor { unsafe { let result: CTFontDescriptorRef = diff --git a/lib.rs b/lib.rs index 5b6da39..a71c0b2 100644 --- a/lib.rs +++ b/lib.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[link(name = "core_text", vers = "0.1")]; +#[crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"]; extern mod std; From cc7f561a44953fe9ef001b963974d8790622f2fc Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Tue, 4 Mar 2014 08:41:14 -0800 Subject: [PATCH 058/126] Rust upgrade --- Makefile.in | 2 +- lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.in b/Makefile.in index c0ea080..eee3eef 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,7 +9,7 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') all: libcore_text.dummy libcore_text.dummy: lib.rs $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< --lib --out-dir . + $(RUSTC) $(RUSTFLAGS) $< --crate-type=lib --out-dir . touch $@ core_text-test: lib.rs $(RUST_SRC) diff --git a/lib.rs b/lib.rs index a71c0b2..bc922ba 100644 --- a/lib.rs +++ b/lib.rs @@ -9,10 +9,10 @@ #[crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"]; -extern mod std; +extern crate std; -extern mod core_foundation; -extern mod core_graphics; +extern crate core_foundation; +extern crate core_graphics; pub mod font; pub mod font_collection; From 0f2839641b3e198bb82573a3f766e0bd3ea9ed9b Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Wed, 19 Mar 2014 13:51:53 -0500 Subject: [PATCH 059/126] Clean rlib files --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index eee3eef..6e20042 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,4 +21,4 @@ check: core_text-test .PHONY: clean clean: - rm -f *.o *.a *.so *.dylib *.dll *.dummy *-test + rm -f *.o *.a *.so *.dylib *.rlib *.dll *.dummy *-test From eb2bef3f2ed56c61997c08f966706d5a3bf1e2fe Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 4 Apr 2014 09:53:36 -0500 Subject: [PATCH 060/126] Generate both dylib and rlib for rustup --- lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib.rs b/lib.rs index bc922ba..afb9e85 100644 --- a/lib.rs +++ b/lib.rs @@ -8,6 +8,9 @@ // except according to those terms. #[crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"]; +#[crate_type = "lib"]; +#[crate_type = "dylib"]; +#[crate_type = "rlib"]; extern crate std; From 442d5de406f55cba36b6cbc428debc20ab6e9828 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 11 Apr 2014 17:37:30 -0500 Subject: [PATCH 061/126] Upgrade to rust --- font.rs | 6 +++--- font_descriptor.rs | 4 ++-- lib.rs | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/font.rs b/font.rs index 181e248..e106dde 100644 --- a/font.rs +++ b/font.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[allow(non_uppercase_statics)]; +#![allow(non_uppercase_statics)] use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; @@ -20,7 +20,7 @@ use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; -use std::libc; +use libc; use std::ptr; pub type CTFontUIFontType = u32; @@ -70,7 +70,7 @@ struct __CTFont; pub type CTFontRef = *__CTFont; pub struct CTFont { - priv obj: CTFontRef, + obj: CTFontRef, } impl Drop for CTFont { diff --git a/font_descriptor.rs b/font_descriptor.rs index c50e503..12ec417 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[allow(non_uppercase_statics)]; +#![allow(non_uppercase_statics)] use core_foundation::array::CFArrayRef; use core_foundation::base::{CFRelease, CFType, CFTypeID, CFTypeRef, TCFType}; @@ -183,7 +183,7 @@ struct __CTFontDescriptor; pub type CTFontDescriptorRef = *__CTFontDescriptor; pub struct CTFontDescriptor { - priv obj: CTFontDescriptorRef, + obj: CTFontDescriptorRef, } impl Drop for CTFontDescriptor { diff --git a/lib.rs b/lib.rs index afb9e85..ff15608 100644 --- a/lib.rs +++ b/lib.rs @@ -7,11 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"]; -#[crate_type = "lib"]; -#[crate_type = "dylib"]; -#[crate_type = "rlib"]; +#![crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"] +#![crate_type = "lib"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] +extern crate libc; extern crate std; extern crate core_foundation; From 5a6f4249c3df2e9c082ef73498cd692fe4ca03d0 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Tue, 13 May 2014 19:49:53 -0500 Subject: [PATCH 062/126] Rust upgrade --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 6e20042..a008297 100644 --- a/Makefile.in +++ b/Makefile.in @@ -9,7 +9,7 @@ RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') all: libcore_text.dummy libcore_text.dummy: lib.rs $(RUST_SRC) - $(RUSTC) $(RUSTFLAGS) $< --crate-type=lib --out-dir . + $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ core_text-test: lib.rs $(RUST_SRC) From 0a04b1edba6fcece226df133edd43b4295dedf3b Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 28 May 2014 17:34:30 -0600 Subject: [PATCH 063/126] Pass in EXT_DEPS for external dependency tracking. --- Makefile.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index a008297..122256a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,17 +2,18 @@ VPATH=%VPATH% RUSTC ?= rustc RUSTFLAGS ?= +EXT_DEPS ?= RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') .PHONY: all all: libcore_text.dummy -libcore_text.dummy: lib.rs $(RUST_SRC) +libcore_text.dummy: lib.rs $(RUST_SRC) $(EXT_DEPS) $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ -core_text-test: lib.rs $(RUST_SRC) +core_text-test: lib.rs $(RUST_SRC) $(EXT_DEPS) $(RUSTC) $(RUSTFLAGS) $< -o $@ --test .PHONY: check From 187c5852d2c285daa3d8c1a0a1e9c8c034a42ffb Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Sat, 31 May 2014 23:35:01 -0600 Subject: [PATCH 064/126] Upgrade Rust. --- font.rs | 18 +++++++++--------- font_descriptor.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/font.rs b/font.rs index e106dde..91fe12d 100644 --- a/font.rs +++ b/font.rs @@ -119,7 +119,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { } } -pub fn new_from_name(name: ~str, pt_size: f64) -> Result { +pub fn new_from_name(name: &str, pt_size: f64) -> Result { unsafe { let name: CFString = from_str(name).unwrap(); let font_ref = CTFontCreateWithName(name.as_concrete_TypeRef(), @@ -146,8 +146,8 @@ impl CTFont { // Creation methods pub fn copy_to_CGFont(&self) -> CGFont { unsafe { - let CGFont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null()); - TCFType::wrap_under_create_rule(CGFont_ref) + let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null()); + TCFType::wrap_under_create_rule(cgfont_ref) } } @@ -162,22 +162,22 @@ impl CTFont { } // Names - pub fn family_name(&self) -> ~str { + pub fn family_name(&self) -> String { let value = get_string_by_name_key(self, kCTFontFamilyNameKey); value.expect("Fonts should always have a family name.") } - pub fn face_name(&self) -> ~str { + pub fn face_name(&self) -> String { let value = get_string_by_name_key(self, kCTFontSubFamilyNameKey); value.expect("Fonts should always have a face name.") } - pub fn unique_name(&self) -> ~str { + pub fn unique_name(&self) -> String { let value = get_string_by_name_key(self, kCTFontUniqueNameKey); value.expect("Fonts should always have a unique name.") } - pub fn postscript_name(&self) -> ~str { + pub fn postscript_name(&self) -> String { let value = get_string_by_name_key(self, kCTFontPostScriptNameKey); value.expect("Fonts should always have a PostScript name.") } @@ -270,7 +270,7 @@ impl CTFont { } // Helper methods -fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> { +fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option { unsafe { let result = CTFontCopyName(font.as_concrete_TypeRef(), name_key); if result.is_null() { @@ -283,7 +283,7 @@ fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option<~str> } pub fn debug_font_names(font: &CTFont) { - fn get_key(font: &CTFont, key: CFStringRef) -> ~str { + fn get_key(font: &CTFont, key: CFStringRef) -> String { get_string_by_name_key(font, key).unwrap() } diff --git a/font_descriptor.rs b/font_descriptor.rs index 12ec417..2923dab 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -18,7 +18,7 @@ use core_foundation::string::{CFString, CFStringRef}; use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; -use std::cast; +use std::mem; /* * CTFontTraits.h @@ -127,7 +127,7 @@ trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { - self.get_CFType(cast::transmute(key)).cast::() + self.get_CFType(mem::transmute(key)).cast::() } } @@ -214,7 +214,7 @@ impl TCFType for CTFontDescriptor { } impl CTFontDescriptor { - fn get_string_attribute(&self, attribute: CFStringRef) -> Option<~str> { + fn get_string_attribute(&self, attribute: CFStringRef) -> Option { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, attribute); if value.is_null() { @@ -229,27 +229,27 @@ impl CTFontDescriptor { } impl CTFontDescriptor { - pub fn family_name(&self) -> ~str { + pub fn family_name(&self) -> String { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect("A font must have a non-null font family name.") + value.expect("A font2 must have a non-null font family name.") } - pub fn font_name(&self) -> ~str { + pub fn font_name(&self) -> String { let value = self.get_string_attribute(kCTFontNameAttribute); value.expect("A font must have a non-null name.") } - pub fn style_name(&self) -> ~str { + pub fn style_name(&self) -> String { let value = self.get_string_attribute(kCTFontStyleNameAttribute); value.expect("A font must have a non-null style name.") } - pub fn display_name(&self) -> ~str { + pub fn display_name(&self) -> String { let value = self.get_string_attribute(kCTFontDisplayNameAttribute); value.expect("A font must have a non-null display name.") } - pub fn font_path(&self) -> ~str { + pub fn font_path(&self) -> String { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); assert!(value.is_not_null()); From 2d6f8cfc43fe72eec8543024a051f8fb42d5182f Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 27 Jun 2014 12:31:14 -0600 Subject: [PATCH 065/126] Upgrade Rust. --- font.rs | 18 +++++++++++++++++- font_collection.rs | 20 +++++++++++++++++++- font_descriptor.rs | 29 +++++++++++++++++++++++++---- lib.rs | 2 ++ 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/font.rs b/font.rs index 91fe12d..dc98acd 100644 --- a/font.rs +++ b/font.rs @@ -12,7 +12,7 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; -use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, TCFType}; +use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFRetain, CFTypeRef, TCFType}; use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; @@ -21,6 +21,7 @@ use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; use libc; +use std::mem; use std::ptr; pub type CTFontUIFontType = u32; @@ -82,16 +83,31 @@ impl Drop for CTFont { } impl TCFType for CTFont { + #[inline] fn as_concrete_TypeRef(&self) -> CTFontRef { self.obj } + #[inline] + unsafe fn wrap_under_get_rule(reference: CTFontRef) -> CTFont { + let reference: CTFontRef = mem::transmute(CFRetain(mem::transmute(reference))); + TCFType::wrap_under_create_rule(reference) + } + + #[inline] unsafe fn wrap_under_create_rule(obj: CTFontRef) -> CTFont { CTFont { obj: obj, } } + #[inline] + fn as_CFTypeRef(&self) -> CFTypeRef { + unsafe { + mem::transmute(self.as_concrete_TypeRef()) + } + } + #[inline] fn type_id(_: Option) -> CFTypeID { unsafe { diff --git a/font_collection.rs b/font_collection.rs index 7467115..694fcdf 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -12,12 +12,14 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescri use font_manager::CTFontManagerCopyAvailableFontFamilyNames; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{CFRelease, CFTypeID, TCFType}; +use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::CFNumber; use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; +use std::mem; + struct __CTFontCollection; pub type CTFontCollectionRef = *__CTFontCollection; @@ -35,16 +37,32 @@ impl Drop for CTFontCollection { } impl TCFType for CTFontCollection { + #[inline] fn as_concrete_TypeRef(&self) -> CTFontCollectionRef { self.obj } + #[inline] + unsafe fn wrap_under_get_rule(reference: CTFontCollectionRef) -> CTFontCollection { + let reference: CTFontCollectionRef = mem::transmute(CFRetain(mem::transmute(reference))); + TCFType::wrap_under_create_rule(reference) + } + + #[inline] unsafe fn wrap_under_create_rule(obj: CTFontCollectionRef) -> CTFontCollection { CTFontCollection { obj: obj, } } + #[inline] + fn as_CFTypeRef(&self) -> CFTypeRef { + unsafe { + mem::transmute(self.as_concrete_TypeRef()) + } + } + + #[inline] fn type_id(_: Option) -> CFTypeID { unsafe { CTFontCollectionGetTypeID() diff --git a/font_descriptor.rs b/font_descriptor.rs index 2923dab..0c0cd7a 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -10,7 +10,7 @@ #![allow(non_uppercase_statics)] use core_foundation::array::CFArrayRef; -use core_foundation::base::{CFRelease, CFType, CFTypeID, CFTypeRef, TCFType}; +use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, CFTypeRef, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; @@ -127,7 +127,9 @@ trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { - self.get_CFType(mem::transmute(key)).cast::() + let cftype = self.get_CFType(mem::transmute(key)); + assert!(cftype.instance_of::()); + TCFType::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef())) } } @@ -195,10 +197,25 @@ impl Drop for CTFontDescriptor { } impl TCFType for CTFontDescriptor { + #[inline] fn as_concrete_TypeRef(&self) -> CTFontDescriptorRef { self.obj } + #[inline] + unsafe fn wrap_under_get_rule(reference: CTFontDescriptorRef) -> CTFontDescriptor { + let reference: CTFontDescriptorRef = mem::transmute(CFRetain(mem::transmute(reference))); + TCFType::wrap_under_create_rule(reference) + } + + #[inline] + fn as_CFTypeRef(&self) -> CFTypeRef { + unsafe { + mem::transmute(self.as_concrete_TypeRef()) + } + } + + #[inline] unsafe fn wrap_under_create_rule(obj: CTFontDescriptorRef) -> CTFontDescriptor { CTFontDescriptor { obj: obj, @@ -222,7 +239,9 @@ impl CTFontDescriptor { } let value: CFType = TCFType::wrap_under_get_rule(value); - Some(value.cast::().to_str()) + assert!(value.instance_of::()); + let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); + Some(s.to_str()) } } @@ -255,7 +274,9 @@ impl CTFontDescriptor { assert!(value.is_not_null()); let value: CFType = TCFType::wrap_under_get_rule(value); - value.cast::().to_str() + assert!(value.instance_of::()); + let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); + url.to_str() } } } diff --git a/lib.rs b/lib.rs index ff15608..ba7e2d2 100644 --- a/lib.rs +++ b/lib.rs @@ -12,6 +12,8 @@ #![crate_type = "dylib"] #![crate_type = "rlib"] +#![allow(non_snake_case_functions)] + extern crate libc; extern crate std; From 5e103c0516c2501c102c0ea66d4dd4c665b013d4 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 24 Jul 2014 21:12:18 -0600 Subject: [PATCH 066/126] Upgrade Rust. --- font.rs | 26 +++++++++++++------------- font_collection.rs | 2 +- font_descriptor.rs | 32 ++++++++++++++++---------------- lib.rs | 4 +--- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/font.rs b/font.rs index dc98acd..61bac65 100644 --- a/font.rs +++ b/font.rs @@ -68,7 +68,7 @@ pub static kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); struct __CTFont; -pub type CTFontRef = *__CTFont; +pub type CTFontRef = *const __CTFont; pub struct CTFont { obj: CTFontRef, @@ -162,7 +162,7 @@ impl CTFont { // Creation methods pub fn copy_to_CGFont(&self) -> CGFont { unsafe { - let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null()); + let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::mut_null()); TCFType::wrap_under_create_rule(cgfont_ref) } } @@ -253,7 +253,7 @@ impl CTFont { } } - pub fn get_glyphs_for_characters(&self, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) + pub fn get_glyphs_for_characters(&self, characters: *const UniChar, glyphs: *mut CGGlyph, count: CFIndex) -> bool { unsafe { CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) @@ -262,8 +262,8 @@ impl CTFont { pub fn get_advances_for_glyphs(&self, orientation: CTFontOrientation, - glyphs: *CGGlyph, - advances: *CGSize, + glyphs: *const CGGlyph, + advances: *mut CGSize, count: CFIndex) -> f64 { unsafe { @@ -293,7 +293,7 @@ fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option CTFontRef; + fn CTFontCreateWithName(name: CFStringRef, size: CGFloat, matrix: *const CGAffineTransform) -> CTFontRef; //fn CTFontCreateWithNameAndOptions fn CTFontCreateWithFontDescriptor(descriptor: CTFontDescriptorRef, size: CGFloat, - matrix: *CGAffineTransform) -> CTFontRef; + matrix: *const CGAffineTransform) -> CTFontRef; //fn CTFontCreateWithFontDescriptorAndOptions //fn CTFontCreateUIFontForLanguage - fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *CGAffineTransform, + fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *const CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; //fn CTFontCreateCopyWithSymbolicTraits //fn CTFontCreateCopyWithFamily @@ -421,7 +421,7 @@ extern { //fn CTFontCreatePathForGlyph //fn CTFontGetGlyphWithName //fn CTFontGetBoundingRectsForGlyphs - fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double; + fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *const CGGlyph, advances: *mut CGSize, count: CFIndex) -> libc::c_double; //fn CTFontGetVerticalTranslationsForGlyphs /* Working With Font Variations */ @@ -433,14 +433,14 @@ extern { //fn CTFontCopyFeatureSettings /* Working with Glyphs */ - fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; + fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *const UniChar, glyphs: *mut CGGlyph, count: CFIndex) -> bool; //fn CTFontDrawGlyphs //fn CTFontGetLigatureCaretPositions /* Converting Fonts */ - fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *CTFontDescriptorRef) -> CGFontRef; + fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *mut CTFontDescriptorRef) -> CGFontRef; fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, - matrix: *CGAffineTransform, + matrix: *const CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; //fn CTFontGetPlatformFont //fn CTFontCreateWithPlatformFont diff --git a/font_collection.rs b/font_collection.rs index 694fcdf..5caeb33 100644 --- a/font_collection.rs +++ b/font_collection.rs @@ -22,7 +22,7 @@ use std::mem; struct __CTFontCollection; -pub type CTFontCollectionRef = *__CTFontCollection; +pub type CTFontCollectionRef = *const __CTFontCollection; pub struct CTFontCollection { obj: CTFontCollectionRef, diff --git a/font_descriptor.rs b/font_descriptor.rs index 0c0cd7a..63fce30 100644 --- a/font_descriptor.rs +++ b/font_descriptor.rs @@ -42,7 +42,7 @@ 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 static kCTFontClassMaskTrait: CTFontSymbolicTraits = (15 << kCTFontClassMaskShift as uint); pub trait SymbolicTraitAccessors { fn is_italic(&self) -> bool; @@ -61,17 +61,17 @@ impl SymbolicTraitAccessors for CTFontSymbolicTraits { } pub type CTFontStylisticClass = u32; -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 static kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift as uint); +pub static kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift as uint); +pub static kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift as uint); +pub static kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift as uint); +pub static kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift as uint); +pub static kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift as uint); +pub static kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift as uint); +pub static kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift as uint); +pub static kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift as uint); +pub static kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift as uint); +pub static kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift as uint); pub trait StylisticClassAccessors { fn is_serif(&self) -> bool; @@ -182,7 +182,7 @@ pub static kCTFontPriorityProcess: CTFontPriority = 60000; struct __CTFontDescriptor; -pub type CTFontDescriptorRef = *__CTFontDescriptor; +pub type CTFontDescriptorRef = *const __CTFontDescriptor; pub struct CTFontDescriptor { obj: CTFontDescriptorRef, @@ -241,7 +241,7 @@ impl CTFontDescriptor { let value: CFType = TCFType::wrap_under_get_rule(value); assert!(value.instance_of::()); let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - Some(s.to_str()) + Some(s.to_string()) } } @@ -276,7 +276,7 @@ impl CTFontDescriptor { let value: CFType = TCFType::wrap_under_get_rule(value); assert!(value.instance_of::()); let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - url.to_str() + url.to_string() } } } @@ -344,7 +344,7 @@ extern { pub fn CTFontDescriptorCopyAttributes(descriptor: CTFontDescriptorRef) -> CFDictionaryRef; pub fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef, - language: *CFStringRef) -> CFTypeRef; + language: *mut CFStringRef) -> CFTypeRef; pub fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, attributes: CFDictionaryRef) -> CTFontDescriptorRef; pub fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, diff --git a/lib.rs b/lib.rs index ba7e2d2..e27a525 100644 --- a/lib.rs +++ b/lib.rs @@ -7,9 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_id = "github.com/mozilla-servo/rust-core-text#core_text:0.1"] -#![crate_type = "lib"] -#![crate_type = "dylib"] +#![crate_name = "core_text"] #![crate_type = "rlib"] #![allow(non_snake_case_functions)] From 7d0bda9029e8f639f288c41b20b30bbc15972fa0 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 25 Aug 2014 22:05:15 -0600 Subject: [PATCH 067/126] Cargoify rust-core-text --- .gitignore | 3 +++ Cargo.toml | 13 +++++++++++++ Makefile.in | 6 +++--- font.rs => src/font.rs | 0 font_collection.rs => src/font_collection.rs | 0 font_descriptor.rs => src/font_descriptor.rs | 0 font_manager.rs => src/font_manager.rs | 0 lib.rs => src/lib.rs | 4 ++++ 8 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 Cargo.toml rename font.rs => src/font.rs (100%) rename font_collection.rs => src/font_collection.rs (100%) rename font_descriptor.rs => src/font_descriptor.rs (100%) rename font_manager.rs => src/font_manager.rs (100%) rename lib.rs => src/lib.rs (87%) diff --git a/.gitignore b/.gitignore index 5f68b7f..c34fbd0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ *.dummy cocoa-test build +/target +/doc +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9e51ae2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] + +name = "core_text" +version = "0.1.0" +authors = ["The Servo Project Developers"] + +[dependencies.core_foundation] + +git = "https://github.com/servo/rust-core-foundation" + +[dependencies.core_graphics] + +git = "https://github.com/servo/rust-core-graphics" diff --git a/Makefile.in b/Makefile.in index 122256a..a7d621b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,16 +4,16 @@ RUSTC ?= rustc RUSTFLAGS ?= EXT_DEPS ?= -RUST_SRC=$(shell find $(VPATH)/. -type f -name '*.rs') +RUST_SRC=$(shell find $(VPATH)/src -type f -name '*.rs') .PHONY: all all: libcore_text.dummy -libcore_text.dummy: lib.rs $(RUST_SRC) $(EXT_DEPS) +libcore_text.dummy: src/lib.rs $(RUST_SRC) $(EXT_DEPS) $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ -core_text-test: lib.rs $(RUST_SRC) $(EXT_DEPS) +core_text-test: src/lib.rs $(RUST_SRC) $(EXT_DEPS) $(RUSTC) $(RUSTFLAGS) $< -o $@ --test .PHONY: check diff --git a/font.rs b/src/font.rs similarity index 100% rename from font.rs rename to src/font.rs diff --git a/font_collection.rs b/src/font_collection.rs similarity index 100% rename from font_collection.rs rename to src/font_collection.rs diff --git a/font_descriptor.rs b/src/font_descriptor.rs similarity index 100% rename from font_descriptor.rs rename to src/font_descriptor.rs diff --git a/font_manager.rs b/src/font_manager.rs similarity index 100% rename from font_manager.rs rename to src/font_manager.rs diff --git a/lib.rs b/src/lib.rs similarity index 87% rename from lib.rs rename to src/lib.rs index e27a525..975a463 100644 --- a/lib.rs +++ b/src/lib.rs @@ -18,7 +18,11 @@ extern crate std; extern crate core_foundation; extern crate core_graphics; +#[cfg(target_os="macos")] pub mod font; +#[cfg(target_os="macos")] pub mod font_collection; +#[cfg(target_os="macos")] pub mod font_descriptor; +#[cfg(target_os="macos")] pub mod font_manager; From 4e7672ab989a978d5ca7691238dfd28692778556 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 16 Sep 2014 11:41:17 -0700 Subject: [PATCH 068/126] Rust upgrade --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 975a463..c1f3d7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ #![allow(non_snake_case_functions)] extern crate libc; -extern crate std; extern crate core_foundation; extern crate core_graphics; From 67f8dbf78d6f2bfd5d1c17f443a676816a32663a Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 21 Oct 2014 14:40:17 +1000 Subject: [PATCH 069/126] Handle create_for_family() not matching any fonts to avoid crash. --- src/font_collection.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/font_collection.rs b/src/font_collection.rs index 5caeb33..feddc71 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -19,6 +19,7 @@ use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; use std::mem; +use std::ptr; struct __CTFontCollection; @@ -103,7 +104,7 @@ pub fn create_for_all_families() -> CTFontCollection { } } -pub fn create_for_family(family: &str) -> CTFontCollection { +pub fn create_for_family(family: &str) -> Option { use font_descriptor::kCTFontFamilyNameAttribute; unsafe { @@ -119,11 +120,13 @@ pub fn create_for_family(family: &str) -> CTFontCollection { let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors( wildcard_desc.as_concrete_TypeRef(), mandatory_attrs.as_concrete_TypeRef()); + if matched_descs == ptr::null() { + return None; + } let matched_descs: CFArray = TCFType::wrap_under_create_rule(matched_descs); - // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. - new_from_descriptors(&matched_descs) + Some(new_from_descriptors(&matched_descs)) } } From 3b37647f7d29dbb4bbe26f74ca1826578b44cf80 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 5 Nov 2014 13:45:50 -0700 Subject: [PATCH 070/126] Upgrade Rust. --- src/font.rs | 2 +- src/font_descriptor.rs | 70 +++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/font.rs b/src/font.rs index 61bac65..5647209 100644 --- a/src/font.rs +++ b/src/font.rs @@ -162,7 +162,7 @@ impl CTFont { // Creation methods pub fn copy_to_CGFont(&self) -> CGFont { unsafe { - let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::mut_null()); + let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null_mut()); TCFType::wrap_under_create_rule(cgfont_ref) } } diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 63fce30..59c751a 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -25,24 +25,24 @@ use std::mem; */ // actually, these are extern enums pub type CTFontFormat = u32; -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 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 kCTFontClassMaskShift: u32 = 28; +pub const kCTFontClassMaskShift: u32 = 28; pub type CTFontSymbolicTraits = u32; -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 as uint); +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 as uint); pub trait SymbolicTraitAccessors { fn is_italic(&self) -> bool; @@ -61,17 +61,17 @@ impl SymbolicTraitAccessors for CTFontSymbolicTraits { } pub type CTFontStylisticClass = u32; -pub static kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift as uint); -pub static kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift as uint); -pub static kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift as uint); -pub static kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift as uint); -pub static kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift as uint); -pub static kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift as uint); -pub static kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift as uint); -pub static kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift as uint); -pub static kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift as uint); -pub static kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift as uint); -pub static kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift as uint); +pub const kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift as uint); +pub const kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift as uint); +pub const kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift as uint); +pub const kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift as uint); +pub const kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift as uint); +pub const kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift as uint); +pub const kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift as uint); +pub const kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift as uint); +pub const kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift as uint); +pub const kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift as uint); +pub const kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift as uint); pub trait StylisticClassAccessors { fn is_serif(&self) -> bool; @@ -168,17 +168,17 @@ impl TraitAccessors for CTFontTraits { * CTFontDescriptor.h */ pub type CTFontOrientation = u32; -pub static kCTFontDefaultOrientation: CTFontOrientation = 0; -pub static kCTFontHorizontalOrientation: CTFontOrientation = 1; -pub static kCTFontVerticalOrientation: CTFontOrientation = 2; +pub const kCTFontDefaultOrientation: CTFontOrientation = 0; +pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; +pub const kCTFontVerticalOrientation: CTFontOrientation = 2; pub type CTFontPriority = u32; -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; +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; struct __CTFontDescriptor; From 33e8676835cc3c215c7b06b28ee25cca6a76df03 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 5 Nov 2014 18:59:55 -0700 Subject: [PATCH 071/126] Fix warnings for new Rust --- src/font.rs | 67 +++++++++++++++++++++--------------------- src/font_collection.rs | 1 + src/font_descriptor.rs | 3 +- src/lib.rs | 2 +- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/font.rs b/src/font.rs index 5647209..6ed6316 100644 --- a/src/font.rs +++ b/src/font.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_statics)] +#![allow(non_upper_case_globals)] use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; @@ -26,46 +26,47 @@ use std::ptr; pub type CTFontUIFontType = u32; // kCTFontNoFontType: CTFontUIFontType = -1; -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 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 type CTFontTableTag = u32; // TODO: create bindings for enum with 'chars' values pub type CTFontTableOptions = u32; -pub static kCTFontTableOptionsNoOptions: CTFontTableOptions = 0; -pub static kCTFontTableOptionsExcludeSynthetic: CTFontTableOptions = (1 << 0); +pub const kCTFontTableOptionsNoOptions: CTFontTableOptions = 0; +pub const kCTFontTableOptionsExcludeSynthetic: CTFontTableOptions = (1 << 0); pub type CTFontOptions = CFOptionFlags; -pub static kCTFontOptionsDefault: CTFontOptions = 0; -pub static kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0); -pub static kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); +pub const kCTFontOptionsDefault: CTFontOptions = 0; +pub const kCTFontOptionsPreventAutoActivation: CTFontOptions = (1 << 0); +pub const kCTFontOptionsPreferSystemFont: CTFontOptions = (1 << 2); +#[repr(C)] struct __CTFont; pub type CTFontRef = *const __CTFont; diff --git a/src/font_collection.rs b/src/font_collection.rs index feddc71..61d35f3 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -21,6 +21,7 @@ use core_foundation::string::{CFString, CFStringRef}; use std::mem; use std::ptr; +#[repr(C)] struct __CTFontCollection; pub type CTFontCollectionRef = *const __CTFontCollection; diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 59c751a..ddbd44e 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(non_uppercase_statics)] +#![allow(non_upper_case_globals)] use core_foundation::array::CFArrayRef; use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, CFTypeRef, TCFType}; @@ -180,6 +180,7 @@ pub const kCTFontPriorityUser: CTFontPriority = 40000; pub const kCTFontPriorityDynamic: CTFontPriority = 50000; pub const kCTFontPriorityProcess: CTFontPriority = 60000; +#[repr(C)] struct __CTFontDescriptor; pub type CTFontDescriptorRef = *const __CTFontDescriptor; diff --git a/src/lib.rs b/src/lib.rs index c1f3d7a..2f362f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ #![crate_name = "core_text"] #![crate_type = "rlib"] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] extern crate libc; From cb369a26a0eb4e83c2128ceb3c685a191113417a Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 5 Jan 2015 11:04:40 -0500 Subject: [PATCH 072/126] Upgrade to latest Rust. --- src/font.rs | 28 ++++++++++++++-------------- src/font_collection.rs | 8 ++++---- src/font_descriptor.rs | 10 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/font.rs b/src/font.rs index 6ed6316..60d69e6 100644 --- a/src/font.rs +++ b/src/font.rs @@ -304,26 +304,26 @@ pub fn debug_font_names(font: &CTFont) { get_string_by_name_key(font, key).unwrap() } - println!("kCTFontFamilyNameKey: {:s}", get_key(font, kCTFontFamilyNameKey)); - println!("kCTFontSubFamilyNameKey: {:s}", get_key(font, kCTFontSubFamilyNameKey)); - println!("kCTFontStyleNameKey: {:s}", get_key(font, kCTFontStyleNameKey)); - println!("kCTFontUniqueNameKey: {:s}", get_key(font, kCTFontUniqueNameKey)); - println!("kCTFontFullNameKey: {:s}", get_key(font, kCTFontFullNameKey)); - println!("kCTFontPostScriptNameKey: {:s}", get_key(font, kCTFontPostScriptNameKey)); + 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) { let sym = font.symbolic_traits(); - println!("kCTFontItalicTrait: {:b}", sym.is_italic()); - println!("kCTFontBoldTrait: {:b}", sym.is_bold()); - println!("kCTFontExpandedTrait: {:b}", sym.is_expanded()); - println!("kCTFontCondensedTrait: {:b}", sym.is_condensed()); - println!("kCTFontMonoSpaceTrait: {:b}", sym.is_monospace()); + println!("kCTFontItalicTrait: {}", sym.is_italic()); + println!("kCTFontBoldTrait: {}", sym.is_bold()); + println!("kCTFontExpandedTrait: {}", sym.is_expanded()); + println!("kCTFontCondensedTrait: {}", sym.is_condensed()); + println!("kCTFontMonoSpaceTrait: {}", sym.is_monospace()); let traits = font.all_traits(); - println!("kCTFontWeightTrait: {:f}", traits.normalized_weight()); -// println!("kCTFontWidthTrait: {:f}", traits.normalized_width()); -// println!("kCTFontSlantTrait: {:f}", traits.normalized_slant()); + println!("kCTFontWeightTrait: {}", traits.normalized_weight()); +// println!("kCTFontWidthTrait: {}", traits.normalized_width()); +// println!("kCTFontSlantTrait: {}", traits.normalized_slant()); } #[link(name = "ApplicationServices", kind = "framework")] diff --git a/src/font_collection.rs b/src/font_collection.rs index 61d35f3..d594d19 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -86,7 +86,7 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); - let options = CFDictionary::from_CFType_pairs([ (key.as_CFType(), value.as_CFType()) ]); + let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(), options.as_concrete_TypeRef()); @@ -98,7 +98,7 @@ pub fn create_for_all_families() -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); - let options = CFDictionary::from_CFType_pairs([ (key.as_CFType(), value.as_CFType()) ]); + let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef()); TCFType::wrap_under_create_rule(font_collection_ref) @@ -111,13 +111,13 @@ pub fn create_for_family(family: &str) -> Option { unsafe { let family_attr: CFString = TCFType::wrap_under_get_rule(kCTFontFamilyNameAttribute); let family_name: CFString = from_str(family).unwrap(); - let specified_attrs = CFDictionary::from_CFType_pairs([ + let specified_attrs = CFDictionary::from_CFType_pairs(&[ (family_attr.as_CFType(), family_name.as_CFType()) ]); let wildcard_desc: CTFontDescriptor = font_descriptor::new_from_attributes(&specified_attrs); - let mandatory_attrs = CFSet::from_slice([ family_attr.as_CFType() ]); + let mandatory_attrs = CFSet::from_slice(&[ family_attr.as_CFType() ]); let matched_descs = CTFontDescriptorCreateMatchingFontDescriptors( wildcard_desc.as_concrete_TypeRef(), mandatory_attrs.as_concrete_TypeRef()); diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index ddbd44e..60a3520 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -291,11 +291,11 @@ pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor { } pub fn debug_descriptor(desc: &CTFontDescriptor) { - println!("family: {:s}", desc.family_name()); - println!("name: {:s}", desc.font_name()); - println!("style: {:s}", desc.style_name()); - println!("display: {:s}", desc.display_name()); - println!("path: {:s}", desc.font_path()); + println!("family: {}", desc.family_name()); + println!("name: {}", desc.font_name()); + println!("style: {}", desc.style_name()); + println!("display: {}", desc.display_name()); + println!("path: {}", desc.font_path()); desc.show(); } From b5cb33905350e99b2a19f5a22f7b1efea7ad48c2 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 15 Jan 2015 15:54:25 -0500 Subject: [PATCH 073/126] Fix usage of from_str and prelude removals. --- src/font.rs | 2 +- src/font_collection.rs | 3 ++- src/font_descriptor.rs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/font.rs b/src/font.rs index 60d69e6..2b69da2 100644 --- a/src/font.rs +++ b/src/font.rs @@ -138,7 +138,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { pub fn new_from_name(name: &str, pt_size: f64) -> Result { unsafe { - let name: CFString = from_str(name).unwrap(); + let name: CFString = name.parse().unwrap(); let font_ref = CTFontCreateWithName(name.as_concrete_TypeRef(), pt_size as CGFloat, ptr::null()); diff --git a/src/font_collection.rs b/src/font_collection.rs index d594d19..4404dc4 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -19,6 +19,7 @@ use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; use std::mem; +use std::num::FromPrimitive; use std::ptr; #[repr(C)] @@ -110,7 +111,7 @@ pub fn create_for_family(family: &str) -> Option { unsafe { let family_attr: CFString = TCFType::wrap_under_get_rule(kCTFontFamilyNameAttribute); - let family_name: CFString = from_str(family).unwrap(); + let family_name: CFString = family.parse().unwrap(); let specified_attrs = CFDictionary::from_CFType_pairs(&[ (family_attr.as_CFType(), family_name.as_CFType()) ]); diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 60a3520..a8434cd 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -19,6 +19,7 @@ use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; use std::mem; +use std::num::ToPrimitive; /* * CTFontTraits.h @@ -272,12 +273,12 @@ impl CTFontDescriptor { pub fn font_path(&self) -> String { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); - assert!(value.is_not_null()); + assert!(!value.is_null()); let value: CFType = TCFType::wrap_under_get_rule(value); assert!(value.instance_of::()); let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - url.to_string() + format!("{:?}", url) } } } From 8809f011445585d023d5e2a0712a1adcbf7ce609 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 13 Mar 2015 11:38:40 -0400 Subject: [PATCH 074/126] Upgrade to rustc 1.0.0-dev (d3c49d214 2015-03-10) (built 2015-02-24) --- src/font.rs | 2 +- src/font_collection.rs | 2 +- src/font_descriptor.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/font.rs b/src/font.rs index 2b69da2..a80330c 100644 --- a/src/font.rs +++ b/src/font.rs @@ -110,7 +110,7 @@ impl TCFType for CTFont { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CTFontGetTypeID() } diff --git a/src/font_collection.rs b/src/font_collection.rs index 4404dc4..d62c2de 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -66,7 +66,7 @@ impl TCFType for CTFontCollection { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CTFontCollectionGetTypeID() } diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index a8434cd..593e989 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -225,7 +225,7 @@ impl TCFType for CTFontDescriptor { } #[inline] - fn type_id(_: Option) -> CFTypeID { + fn type_id() -> CFTypeID { unsafe { CTFontDescriptorGetTypeID() } From bc6994c3765f0660e9c04f5488ba194a9354e8fb Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 23 Apr 2015 18:33:00 +0200 Subject: [PATCH 075/126] Upgrade to rustc 1.0.0-dev (47551b574 2015-04-14) (built 2015-03-18) --- Cargo.toml | 3 +++ src/font_collection.rs | 5 ++--- src/font_descriptor.rs | 27 +++++++++++++-------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e51ae2..76350a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,6 @@ git = "https://github.com/servo/rust-core-foundation" [dependencies.core_graphics] git = "https://github.com/servo/rust-core-graphics" + +[dependencies] +libc = "*" diff --git a/src/font_collection.rs b/src/font_collection.rs index d62c2de..c854410 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -19,7 +19,6 @@ use core_foundation::set::CFSet; use core_foundation::string::{CFString, CFStringRef}; use std::mem; -use std::num::FromPrimitive; use std::ptr; #[repr(C)] @@ -86,7 +85,7 @@ impl CTFontCollection { pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); - let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); + let value = CFNumber::from_i64(1); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(), @@ -98,7 +97,7 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { pub fn create_for_all_families() -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); - let value: CFNumber = FromPrimitive::from_i8(1).unwrap(); + let value = CFNumber::from_i64(1); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef()); diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 593e989..8c93bbd 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -19,7 +19,6 @@ use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::CGFloat; use std::mem; -use std::num::ToPrimitive; /* * CTFontTraits.h @@ -43,7 +42,7 @@ 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 as uint); +pub const kCTFontClassMaskTrait: CTFontSymbolicTraits = (15 << kCTFontClassMaskShift ); pub trait SymbolicTraitAccessors { fn is_italic(&self) -> bool; @@ -62,17 +61,17 @@ impl SymbolicTraitAccessors for CTFontSymbolicTraits { } pub type CTFontStylisticClass = u32; -pub const kCTFontUnknownClass: CTFontStylisticClass = (0 << kCTFontClassMaskShift as uint); -pub const kCTFontOldStyleSerifsClass: CTFontStylisticClass = (1 << kCTFontClassMaskShift as uint); -pub const kCTFontTransitionalSerifsClass: CTFontStylisticClass = (2 << kCTFontClassMaskShift as uint); -pub const kCTFontModernSerifsClass: CTFontStylisticClass = (3 << kCTFontClassMaskShift as uint); -pub const kCTFontClarendonSerifsClass: CTFontStylisticClass = (4 << kCTFontClassMaskShift as uint); -pub const kCTFontSlabSerifsClass: CTFontStylisticClass = (5 << kCTFontClassMaskShift as uint); -pub const kCTFontFreeformSerifsClass: CTFontStylisticClass = (7 << kCTFontClassMaskShift as uint); -pub const kCTFontSansSerifClass: CTFontStylisticClass = (8 << kCTFontClassMaskShift as uint); -pub const kCTFontOrnamentalsClass: CTFontStylisticClass = (9 << kCTFontClassMaskShift as uint); -pub const kCTFontScriptsClass: CTFontStylisticClass = (10 << kCTFontClassMaskShift as uint); -pub const kCTFontSymbolicClass: CTFontStylisticClass = (12 << kCTFontClassMaskShift as uint); +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 trait StylisticClassAccessors { fn is_serif(&self) -> bool; @@ -139,7 +138,7 @@ impl TraitAccessors for CTFontTraits { fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { let number = self.extract_number_for_key(kCTFontSymbolicTrait); - number.to_u32().unwrap() + number.to_i64().unwrap() as u32 } } From 56c2f7bc25d32363e2f6a0a71ef8c94317381f2f Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 2 Jun 2015 23:33:31 -0600 Subject: [PATCH 076/126] Use platform deps and remove cruft. --- Cargo.toml | 14 ++++++-------- Makefile.in | 25 ------------------------- configure | 4 ---- 3 files changed, 6 insertions(+), 37 deletions(-) delete mode 100644 Makefile.in delete mode 100755 configure diff --git a/Cargo.toml b/Cargo.toml index 76350a1..511805f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,11 @@ name = "core_text" version = "0.1.0" authors = ["The Servo Project Developers"] -[dependencies.core_foundation] - -git = "https://github.com/servo/rust-core-foundation" - -[dependencies.core_graphics] - -git = "https://github.com/servo/rust-core-graphics" - [dependencies] libc = "*" + +[target.x86_64-apple-darwin.dependencies.core_foundation] +git = "https://github.com/servo/rust-core-foundation" + +[target.x86_64-apple-darwin.dependencies.core_graphics] +git = "https://github.com/servo/rust-core-graphics" diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index a7d621b..0000000 --- a/Makefile.in +++ /dev/null @@ -1,25 +0,0 @@ -VPATH=%VPATH% - -RUSTC ?= rustc -RUSTFLAGS ?= -EXT_DEPS ?= - -RUST_SRC=$(shell find $(VPATH)/src -type f -name '*.rs') - -.PHONY: all -all: libcore_text.dummy - -libcore_text.dummy: src/lib.rs $(RUST_SRC) $(EXT_DEPS) - $(RUSTC) $(RUSTFLAGS) $< --out-dir . - touch $@ - -core_text-test: src/lib.rs $(RUST_SRC) $(EXT_DEPS) - $(RUSTC) $(RUSTFLAGS) $< -o $@ --test - -.PHONY: check -check: core_text-test - ./core_text-test $(TEST) - -.PHONY: clean -clean: - rm -f *.o *.a *.so *.dylib *.rlib *.dll *.dummy *-test diff --git a/configure b/configure deleted file mode 100755 index 62a0f4c..0000000 --- a/configure +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -SRCDIR="$(cd $(dirname $0) && pwd)" -sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile From fada42a6c892559e367889496430bef88db17d31 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 2 Jun 2015 23:43:28 -0600 Subject: [PATCH 077/126] Remove cfgs. --- src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2f362f8..d564bc6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,11 +17,7 @@ extern crate libc; extern crate core_foundation; extern crate core_graphics; -#[cfg(target_os="macos")] pub mod font; -#[cfg(target_os="macos")] pub mod font_collection; -#[cfg(target_os="macos")] pub mod font_descriptor; -#[cfg(target_os="macos")] pub mod font_manager; From 87015a118740de5cf4670894382c0d64fd0f0c44 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 4 Jun 2015 09:30:40 -0600 Subject: [PATCH 078/126] Use modern crate naming conventions. --- Cargo.toml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 511805f..c7583b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,11 @@ [package] - -name = "core_text" +name = "core-text" version = "0.1.0" authors = ["The Servo Project Developers"] [dependencies] libc = "*" -[target.x86_64-apple-darwin.dependencies.core_foundation] -git = "https://github.com/servo/rust-core-foundation" - -[target.x86_64-apple-darwin.dependencies.core_graphics] -git = "https://github.com/servo/rust-core-graphics" +[target.x86_64-apple-darwin.dependencies] +core-foundation = "*" +core-graphics = "*" From cf701bb1e401fc60db6a614cc44cf2a4288c4bbc Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 9 Jun 2015 20:53:25 -0700 Subject: [PATCH 079/126] Build and test on Travis CI (OSX) --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d5979d3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: rust +rust: nightly +os: osx From 606d3f8d1e85f5eb2b34db284c836d6b2669573e Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 9 Jun 2015 20:53:58 -0700 Subject: [PATCH 080/126] Init README --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b72bf11 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# core-text-rs + +[![Build Status](https://travis-ci.org/servo/core-text-rs.svg?branch=master)](https://travis-ci.org/servo/core-text-rs) From e2fd92cb2388e809e2eb6daf26a8dc210b3b2ed6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 30 Jul 2015 18:05:20 -0700 Subject: [PATCH 081/126] Add a `Clone` impl to `CTFont` --- src/font.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/font.rs b/src/font.rs index a80330c..b93c639 100644 --- a/src/font.rs +++ b/src/font.rs @@ -83,6 +83,15 @@ impl Drop for CTFont { } } +impl Clone for CTFont { + #[inline] + fn clone(&self) -> CTFont { + unsafe { + TCFType::wrap_under_get_rule(self.obj) + } + } +} + impl TCFType for CTFont { #[inline] fn as_concrete_TypeRef(&self) -> CTFontRef { From bde9c0589eb15fbb5b5ca07b0bb26c3d181f7ea5 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 30 Jul 2015 19:52:06 -0600 Subject: [PATCH 082/126] Add Travis notfications for Homu --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d5979d3..701a68b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ language: rust rust: nightly os: osx +notifications: + webhooks: http://build.servo.org:54856/travis From 8380931660052d024a23f2b01cc45dd555e8832a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 30 Sep 2015 17:50:30 -0700 Subject: [PATCH 083/126] Allow the URL of the Core Text font to be fetched. This allows FreeType to load Core Text fonts, which is necessary for WebRender (unless we want a Quartz backend for WebRender). --- src/font.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/font.rs b/src/font.rs index b93c639..80ce3f0 100644 --- a/src/font.rs +++ b/src/font.rs @@ -16,6 +16,7 @@ use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFRetai use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; +use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::{CGAffineTransform, CGFloat}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; use core_graphics::geometry::{CGRect, CGSize}; @@ -293,6 +294,17 @@ impl CTFont { } } } + + pub fn url(&self) -> Option { + unsafe { + let result = CTFontCopyAttribute(self.obj, kCTFontURLAttribute); + if result.is_null() { + None + } else { + Some(TCFType::wrap_under_create_rule(result as CFURLRef)) + } + } + } } // Helper methods @@ -376,6 +388,8 @@ extern { //static kCTFontFeatureSelectorDefaultKey: CFStringRef; //static kCTFontFeatureSelectorSettingKey: CFStringRef; + static kCTFontURLAttribute: 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. @@ -394,7 +408,7 @@ extern { /* Getting Font Data */ //fn CTFontCopyFontDescriptor(font: CTFontRef) -> CTFontDescriptorRef; - //fn CTFontCopyAttribute(font: CTFontRef) -> CFTypeRef; + fn CTFontCopyAttribute(font: CTFontRef, attribute: CFStringRef) -> CFTypeRef; fn CTFontGetSize(font: CTFontRef) -> CGFloat; //fn CTFontGetMatrix fn CTFontGetSymbolicTraits(font: CTFontRef) -> CTFontSymbolicTraits; From ebd9b347ac1abe265b90b05199d3474f83332f44 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 13 Oct 2015 14:31:51 -0700 Subject: [PATCH 084/126] Add support for drawing glyphs and fetching their bounding rects --- Cargo.toml | 2 +- src/font.rs | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7583b9..4dd5242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ libc = "*" [target.x86_64-apple-darwin.dependencies] core-foundation = "*" -core-graphics = "*" +core-graphics = "0.1.2" diff --git a/src/font.rs b/src/font.rs index 80ce3f0..4ca8229 100644 --- a/src/font.rs +++ b/src/font.rs @@ -18,10 +18,11 @@ use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_foundation::url::{CFURL, CFURLRef}; use core_graphics::base::{CGAffineTransform, CGFloat}; +use core_graphics::context::{CGContext, CGContextRef}; use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; -use core_graphics::geometry::{CGRect, CGSize}; +use core_graphics::geometry::{CGPoint, CGRect, CGSize}; -use libc; +use libc::{self, size_t}; use std::mem; use std::ptr; @@ -295,6 +296,29 @@ impl CTFont { } } + pub fn get_bounding_rects_for_glyphs(&self, orientation: CTFontOrientation, glyphs: &[CGGlyph]) + -> CGRect { + unsafe { + let mut result = CTFontGetBoundingRectsForGlyphs(self.as_concrete_TypeRef(), + orientation, + glyphs.as_ptr(), + ptr::null_mut(), + glyphs.len() as CFIndex); + result + } + } + + pub fn draw_glyphs(&self, glyphs: &[CGGlyph], positions: &[CGPoint], context: CGContext) { + assert!(glyphs.len() == positions.len()); + unsafe { + CTFontDrawGlyphs(self.as_concrete_TypeRef(), + glyphs.as_ptr(), + positions.as_ptr(), + glyphs.len() as size_t, + context.as_concrete_TypeRef()) + } + } + pub fn url(&self) -> Option { unsafe { let result = CTFontCopyAttribute(self.obj, kCTFontURLAttribute); @@ -444,7 +468,12 @@ extern { /* Getting Glyph Data */ //fn CTFontCreatePathForGlyph //fn CTFontGetGlyphWithName - //fn CTFontGetBoundingRectsForGlyphs + fn CTFontGetBoundingRectsForGlyphs(font: CTFontRef, + orientation: CTFontOrientation, + glyphs: *const CGGlyph, + boundingRects: *mut CGRect, + count: CFIndex) + -> CGRect; fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *const CGGlyph, advances: *mut CGSize, count: CFIndex) -> libc::c_double; //fn CTFontGetVerticalTranslationsForGlyphs @@ -458,7 +487,11 @@ extern { /* Working with Glyphs */ fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *const UniChar, glyphs: *mut CGGlyph, count: CFIndex) -> bool; - //fn CTFontDrawGlyphs + fn CTFontDrawGlyphs(font: CTFontRef, + glyphs: *const CGGlyph, + positions: *const CGPoint, + count: size_t, + context: CGContextRef); //fn CTFontGetLigatureCaretPositions /* Converting Fonts */ @@ -475,5 +508,5 @@ extern { fn CTFontCopyTable(font: CTFontRef, table: CTFontTableTag, options: CTFontTableOptions) -> CFDataRef; fn CTFontGetTypeID() -> CFTypeID; - } + From 4a20a710f88ba770453f43f9403eaf3d3264b56b Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 8 Dec 2015 09:00:43 -0500 Subject: [PATCH 085/126] Use more explicit dependency versions --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4dd5242..a64f087 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" authors = ["The Servo Project Developers"] [dependencies] -libc = "*" +libc = "0.2" [target.x86_64-apple-darwin.dependencies] -core-foundation = "*" +core-foundation = "0.2" core-graphics = "0.1.2" From 43d0edb2082c073e9bbd07ec2509a010d58106f9 Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Thu, 10 Dec 2015 00:56:29 +0100 Subject: [PATCH 086/126] Derive Debug for CTFont, CTFontCollection, CTFontDescriptor These are all the structs as far as I can see. --- src/font.rs | 1 + src/font_collection.rs | 1 + src/font_descriptor.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/font.rs b/src/font.rs index 4ca8229..9889954 100644 --- a/src/font.rs +++ b/src/font.rs @@ -73,6 +73,7 @@ struct __CTFont; pub type CTFontRef = *const __CTFont; +#[derive(Debug)] pub struct CTFont { obj: CTFontRef, } diff --git a/src/font_collection.rs b/src/font_collection.rs index c854410..c2c5414 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -26,6 +26,7 @@ struct __CTFontCollection; pub type CTFontCollectionRef = *const __CTFontCollection; +#[derive(Debug)] pub struct CTFontCollection { obj: CTFontCollectionRef, } diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 8c93bbd..45915fa 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -185,6 +185,7 @@ struct __CTFontDescriptor; pub type CTFontDescriptorRef = *const __CTFontDescriptor; +#[derive(Debug)] pub struct CTFontDescriptor { obj: CTFontDescriptorRef, } From 86729c688157cf481760cbe1862b7a3a3f4f74d6 Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Fri, 11 Dec 2015 23:39:33 +0100 Subject: [PATCH 087/126] Update core-graphics dependency to 0.2 This is what the rest of Servo is using -- so bump it here as well to avoid test-tidy failure. Note that this is indeed the version Servo is currently using core-text with (as Servo still has a revision of core-text that didn't specify any version constraints) -- so we are rather certain that this combination works. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a64f087..075cca9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.2" -core-graphics = "0.1.2" +core-graphics = "0.2" From 33adff9bc5ea57d931c2ab703ee500ba165bfdba Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 11 Dec 2015 17:57:59 -0500 Subject: [PATCH 088/126] Update the version number. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 075cca9..cc5cc7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "0.1.0" +version = "1.0.0" authors = ["The Servo Project Developers"] [dependencies] From a4ce7a8015f6fe5ec03a5b23cf408c4d6c597523 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 11 Dec 2015 18:05:48 -0500 Subject: [PATCH 089/126] Add some metadata. --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index cc5cc7e..c111c0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,9 @@ name = "core-text" version = "1.0.0" authors = ["The Servo Project Developers"] +description = "Bindings to the Core Text framework." +license = "MIT/Apache-2.0" +repository = "https://github.com/servo/core-text-rs" [dependencies] libc = "0.2" From a14b9c39900fe716bd7fc01b6470bce457a2a3ea Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 9 Mar 2016 03:49:04 +0100 Subject: [PATCH 090/126] Allow core-graphics 0.3 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c111c0d..f42d8f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "1.0.0" +version = "1.1.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -11,4 +11,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.2" -core-graphics = "0.2" +core-graphics = ">=0.2, <0.4" From e3c50e0d56aa277728bcffe836db28fbd1d81b32 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 19 May 2016 08:43:19 -0700 Subject: [PATCH 091/126] Add binding for CTFontGetUnitsPerEm --- Cargo.toml | 2 +- src/font.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f42d8f4..28ef9d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "1.1.0" +version = "1.1.1" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" diff --git a/src/font.rs b/src/font.rs index 9889954..abda98e 100644 --- a/src/font.rs +++ b/src/font.rs @@ -254,6 +254,12 @@ impl CTFont { } } + pub fn units_per_em(&self) -> libc::c_uint { + unsafe { + CTFontGetUnitsPerEm(self.obj) + } + } + pub fn x_height(&self) -> CGFloat { unsafe { CTFontGetXHeight(self.obj) @@ -457,7 +463,7 @@ extern { fn CTFontGetAscent(font: CTFontRef) -> CGFloat; fn CTFontGetDescent(font: CTFontRef) -> CGFloat; fn CTFontGetLeading(font: CTFontRef) -> CGFloat; - //fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; + fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; //fn CTFontGetGlyphCount fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; From 1c751619629d01f8c69e971574a4a64a5285634f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 3 Aug 2016 10:01:41 +0200 Subject: [PATCH 092/126] Update core-graphics to 0.4 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 28ef9d3..2f11c62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "1.1.1" +version = "2.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -11,4 +11,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.2" -core-graphics = ">=0.2, <0.4" +core-graphics = "0.4" From bcac61315e6bb2be511329dbbb197c6bcd4a83fb Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 3 Aug 2016 10:47:11 +0200 Subject: [PATCH 093/126] Test on stable. --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 701a68b..ed3f5dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: rust -rust: nightly +rust: + - nightly + - beta + - stable os: osx notifications: webhooks: http://build.servo.org:54856/travis From 928c0e96d428171af42941550d3391d8b65cae05 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Mon, 31 Oct 2016 13:17:37 -0400 Subject: [PATCH 094/126] Add kCTFontColorGlyphsTrait --- src/font_descriptor.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 45915fa..2b655b9 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -42,6 +42,7 @@ 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 kCTFontColorGlyphsTrait: CTFontSymbolicTraits = (1 << 13); pub const kCTFontClassMaskTrait: CTFontSymbolicTraits = (15 << kCTFontClassMaskShift ); pub trait SymbolicTraitAccessors { From da156f7296243e28184bbc40d0fbbe7cd007671b Mon Sep 17 00:00:00 2001 From: Mason Chang Date: Fri, 13 Jan 2017 17:00:00 -0800 Subject: [PATCH 095/126] Update to use core-graphics 0.5 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2f11c62..0a56701 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "2.0.0" +version = "2.0.1" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -11,4 +11,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.2" -core-graphics = "0.4" +core-graphics = "0.5" From f6320819a0f383ff90561e6541f25c71208493e8 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Thu, 26 Jan 2017 11:25:29 -0500 Subject: [PATCH 096/126] Update core-graphics and core-foundation dependencies --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a56701..f75117e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "2.0.1" +version = "3.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -10,5 +10,5 @@ repository = "https://github.com/servo/core-text-rs" libc = "0.2" [target.x86_64-apple-darwin.dependencies] -core-foundation = "0.2" -core-graphics = "0.5" +core-foundation = "0.3" +core-graphics = "0.6" From cd2d4540eafe786149718f0b5622280466c5913a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 18 Feb 2017 00:38:42 +0100 Subject: [PATCH 097/126] Update core-graphics to 0.7 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f75117e..a773112 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "3.0.0" +version = "4.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -11,4 +11,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.3" -core-graphics = "0.6" +core-graphics = "0.7" From 2e97ea2d63ee20aa4356fd69ab6bc20c5aeb4334 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Mon, 15 May 2017 20:45:03 +0200 Subject: [PATCH 098/126] font_path may be null --- src/font_descriptor.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 2b655b9..9279dca 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -271,15 +271,17 @@ impl CTFontDescriptor { value.expect("A font must have a non-null display name.") } - pub fn font_path(&self) -> String { + pub fn font_path(&self) -> Option { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); - assert!(!value.is_null()); + if (value.is_null()) { + return None; + } let value: CFType = TCFType::wrap_under_get_rule(value); assert!(value.instance_of::()); let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - format!("{:?}", url) + Some(format!("{:?}", url)) } } } @@ -297,7 +299,7 @@ pub fn debug_descriptor(desc: &CTFontDescriptor) { println!("name: {}", desc.font_name()); println!("style: {}", desc.style_name()); println!("display: {}", desc.display_name()); - println!("path: {}", desc.font_path()); + println!("path: {:?}", desc.font_path()); desc.show(); } From 66b4970a4da44da1e19dbde3c11fd71987d55172 Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Mon, 15 May 2017 18:47:04 +0200 Subject: [PATCH 099/126] CTFontCopyDefaultCascadeListForLanguages --- src/font.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/font.rs b/src/font.rs index abda98e..eb9f0d1 100644 --- a/src/font.rs +++ b/src/font.rs @@ -12,6 +12,7 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; +use core_foundation::array::{CFArray, CFArrayRef}; use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFRetain, CFTypeRef, TCFType}; use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; @@ -378,6 +379,15 @@ pub fn debug_font_traits(font: &CTFont) { // println!("kCTFontSlantTrait: {}", traits.normalized_slant()); } +pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) -> CFArray { + unsafe { + let font_collection_ref = + CTFontCopyDefaultCascadeListForLanguages(font.as_concrete_TypeRef(), + language_pref_list.as_concrete_TypeRef()); + TCFType::wrap_under_create_rule(font_collection_ref) + } +} + #[link(name = "ApplicationServices", kind = "framework")] extern { /* @@ -453,6 +463,8 @@ extern { fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, // language: *CFStringRef) -> CFStringRef; + fn CTFontCopyDefaultCascadeListForLanguages(font: CTFontRef, languagePrefList: CFArrayRef) -> CFArrayRef; + /* Working With Encoding */ //fn CTFontCopyCharacterSet From eb6eed213c77832f3cb2c80dba58fb98d6a9f7be Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Wed, 31 May 2017 10:57:41 +0200 Subject: [PATCH 100/126] Update to use core-graphics 0.8 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a773112..8aefe62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.3" -core-graphics = "0.7" +core-graphics = "0.8" From 63d3cde7edc66aff1adcc6fd6de949db330c1ffb Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Wed, 31 May 2017 10:59:20 +0200 Subject: [PATCH 101/126] update major version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8aefe62..c169dc9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "4.0.0" +version = "5.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" From 97923f853520b7a7fd2eb236f83af1140440a68f Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Tue, 20 Jun 2017 11:37:47 -0400 Subject: [PATCH 102/126] Add a lion feature for 10.7 compatibility --- Cargo.toml | 7 ++++++- src/font.rs | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c169dc9..eef82a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,16 @@ [package] name = "core-text" -version = "5.0.0" +version = "5.0.1" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" repository = "https://github.com/servo/core-text-rs" +[features] +default = [] +# For OS X 10.7 compat, use this feature. It will exclude some things +lion = [] + [dependencies] libc = "0.2" diff --git a/src/font.rs b/src/font.rs index eb9f0d1..b52b354 100644 --- a/src/font.rs +++ b/src/font.rs @@ -379,6 +379,7 @@ pub fn debug_font_traits(font: &CTFont) { // println!("kCTFontSlantTrait: {}", traits.normalized_slant()); } +#[cfg(not(feature = "lion"))] pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) -> CFArray { unsafe { let font_collection_ref = @@ -463,6 +464,7 @@ extern { fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, // language: *CFStringRef) -> CFStringRef; + #[cfg(not(feature = "lion"))] fn CTFontCopyDefaultCascadeListForLanguages(font: CTFontRef, languagePrefList: CFArrayRef) -> CFArrayRef; From 9203aad673d6aab9693f908d41b6d8c72cc06451 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Tue, 20 Jun 2017 16:14:05 -0400 Subject: [PATCH 103/126] Flip the lion feature into a mountainlion feature which is additive rather than subtractive --- Cargo.toml | 9 +++++---- src/font.rs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eef82a9..e7a4b57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "core-text" -version = "5.0.1" +version = "6.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" repository = "https://github.com/servo/core-text-rs" [features] -default = [] -# For OS X 10.7 compat, use this feature. It will exclude some things -lion = [] +default = ["mountainlion"] +# For OS X 10.7 compat, exclude this feature. It will exclude some things from +# the exposed APIs in the crate. +mountainlion = [] [dependencies] libc = "0.2" diff --git a/src/font.rs b/src/font.rs index b52b354..d0305e7 100644 --- a/src/font.rs +++ b/src/font.rs @@ -379,7 +379,7 @@ pub fn debug_font_traits(font: &CTFont) { // println!("kCTFontSlantTrait: {}", traits.normalized_slant()); } -#[cfg(not(feature = "lion"))] +#[cfg(feature = "mountainlion")] pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) -> CFArray { unsafe { let font_collection_ref = @@ -464,7 +464,7 @@ extern { fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, // language: *CFStringRef) -> CFStringRef; - #[cfg(not(feature = "lion"))] + #[cfg(feature = "mountainlion")] fn CTFontCopyDefaultCascadeListForLanguages(font: CTFontRef, languagePrefList: CFArrayRef) -> CFArrayRef; From 7ce061519312d1edf953bdcb8d18fe8dc01108e3 Mon Sep 17 00:00:00 2001 From: Thomas Winwood Date: Thu, 29 Jun 2017 08:03:14 +0100 Subject: [PATCH 104/126] Remove unnecessary parentheses around if condition --- src/font_descriptor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 9279dca..3cc40e8 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -274,7 +274,7 @@ impl CTFontDescriptor { pub fn font_path(&self) -> Option { unsafe { let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); - if (value.is_null()) { + if value.is_null() { return None; } From 32a02b591671f0d9617ba39abfbc09f1032464ca Mon Sep 17 00:00:00 2001 From: Thomas Winwood Date: Thu, 29 Jun 2017 08:04:26 +0100 Subject: [PATCH 105/126] Remove unnecessary mutability --- src/font.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/font.rs b/src/font.rs index d0305e7..747a547 100644 --- a/src/font.rs +++ b/src/font.rs @@ -307,11 +307,11 @@ impl CTFont { pub fn get_bounding_rects_for_glyphs(&self, orientation: CTFontOrientation, glyphs: &[CGGlyph]) -> CGRect { unsafe { - let mut result = CTFontGetBoundingRectsForGlyphs(self.as_concrete_TypeRef(), - orientation, - glyphs.as_ptr(), - ptr::null_mut(), - glyphs.len() as CFIndex); + let result = CTFontGetBoundingRectsForGlyphs(self.as_concrete_TypeRef(), + orientation, + glyphs.as_ptr(), + ptr::null_mut(), + glyphs.len() as CFIndex); result } } From 6847e69397f0635746d709f8f23a561191e32cfa Mon Sep 17 00:00:00 2001 From: Omar Akkila Date: Sun, 2 Jul 2017 14:04:14 +0400 Subject: [PATCH 106/126] 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 { From df6cf808706b83c6195cfa176aaae13fd30d86bc Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Mon, 10 Jul 2017 10:40:31 +1000 Subject: [PATCH 107/126] Bump version for private/public nightly error change. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e7a4b57..9272b2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "6.0.0" +version = "6.1.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" From 8aedead6e10659fa0c6c2aec08859c8be0840fd0 Mon Sep 17 00:00:00 2001 From: Ryan Thomas Date: Tue, 1 Aug 2017 20:14:32 +0100 Subject: [PATCH 108/126] Bump foundation and graphics versions for #62. --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9272b2a..5c7a930 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ mountainlion = [] libc = "0.2" [target.x86_64-apple-darwin.dependencies] -core-foundation = "0.3" -core-graphics = "0.8" +core-foundation = "0.4" +core-graphics = "0.9" From ec06a98b00a01f508e2b9395caf0d3c925b83f19 Mon Sep 17 00:00:00 2001 From: Ryan Thomas Date: Tue, 1 Aug 2017 20:19:49 +0100 Subject: [PATCH 109/126] Bump core-text version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5c7a930..3d39ca5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "6.1.0" +version = "6.1.1" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" From a05b8c3f282c2c06961c8a6482d23587e3bb8779 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 21 Aug 2017 08:33:31 -0700 Subject: [PATCH 110/126] Revert previous dependency upgrades. --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3d39ca5..4926641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "6.1.1" +version = "6.1.2" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -16,5 +16,5 @@ mountainlion = [] libc = "0.2" [target.x86_64-apple-darwin.dependencies] -core-foundation = "0.4" -core-graphics = "0.9" +core-foundation = "0.3" +core-graphics = "0.8" From 66fd6344763faa801f5cb0e29067c38e0c6197f2 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 21 Aug 2017 11:37:02 -0700 Subject: [PATCH 111/126] Update dependencies and bump major version. --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4926641..dd9ca8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "6.1.2" +version = "7.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -16,5 +16,5 @@ mountainlion = [] libc = "0.2" [target.x86_64-apple-darwin.dependencies] -core-foundation = "0.3" -core-graphics = "0.8" +core-foundation = "0.4" +core-graphics = "0.9" From b30db59c0ec2d085e13e908774be5b50e3677a59 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Oct 2017 20:42:37 -0700 Subject: [PATCH 112/126] Use the `foreign-types` crate like `core-graphics-rs` does --- Cargo.toml | 1 + src/font.rs | 22 ++++++++++++++-------- src/lib.rs | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd9ca8b..cc0e6f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ default = ["mountainlion"] mountainlion = [] [dependencies] +foreign-types = "0.3" libc = "0.2" [target.x86_64-apple-darwin.dependencies] diff --git a/src/font.rs b/src/font.rs index 1a04b1e..ae057d3 100644 --- a/src/font.rs +++ b/src/font.rs @@ -18,15 +18,20 @@ use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; use core_foundation::url::{CFURL, CFURLRef}; -use core_graphics::base::{CGAffineTransform, CGFloat}; -use core_graphics::context::{CGContext, CGContextRef}; -use core_graphics::font::{CGGlyph, CGFont, CGFontRef}; -use core_graphics::geometry::{CGPoint, CGRect, CGSize}; +use core_graphics::base::CGFloat; +use core_graphics::context::CGContext; +use core_graphics::font::{CGGlyph, CGFont}; +use core_graphics::geometry::{CGAffineTransform, CGPoint, CGRect, CGSize}; +use foreign_types::ForeignType; use libc::{self, size_t, c_void}; use std::mem; use std::ptr; +type CGContextRef = *mut ::CType; +type CGFontRef = *mut ::CType; +type CGPathRef = *mut ::CType; + pub type CTFontUIFontType = u32; // kCTFontNoFontType: CTFontUIFontType = -1; pub const kCTFontUserFontType: CTFontUIFontType = 0; @@ -132,7 +137,7 @@ impl TCFType for CTFont { pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { unsafe { - let font_ref = CTFontCreateWithGraphicsFont(cgfont.as_concrete_TypeRef(), + let font_ref = CTFontCreateWithGraphicsFont(cgfont.as_ptr() as *mut _, pt_size as CGFloat, ptr::null(), ptr::null()); @@ -177,7 +182,7 @@ impl CTFont { pub fn copy_to_CGFont(&self) -> CGFont { unsafe { let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null_mut()); - TCFType::wrap_under_create_rule(cgfont_ref) + CGFont::from_ptr(cgfont_ref as *mut _) } } @@ -331,7 +336,7 @@ impl CTFont { glyphs.as_ptr(), positions.as_ptr(), glyphs.len() as size_t, - context.as_concrete_TypeRef()) + context.as_ptr()) } } @@ -526,7 +531,8 @@ extern { //fn CTFontGetLigatureCaretPositions /* Converting Fonts */ - fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *mut CTFontDescriptorRef) -> CGFontRef; + fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *mut CTFontDescriptorRef) + -> CGFontRef; fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *const CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; diff --git a/src/lib.rs b/src/lib.rs index d564bc6..03d8c3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ #![allow(non_snake_case)] +extern crate foreign_types; extern crate libc; extern crate core_foundation; From 5783a1bb7565482aab147f3f433207c0b2d5c37b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Oct 2017 20:42:59 -0700 Subject: [PATCH 113/126] Add a binding to `CTFontCreatePathForGlyph()` --- Cargo.toml | 2 +- src/font.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc0e6f6..2305818 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ libc = "0.2" [target.x86_64-apple-darwin.dependencies] core-foundation = "0.4" -core-graphics = "0.9" +core-graphics = "0.11" diff --git a/src/font.rs b/src/font.rs index ae057d3..cf14aee 100644 --- a/src/font.rs +++ b/src/font.rs @@ -22,6 +22,7 @@ use core_graphics::base::CGFloat; use core_graphics::context::CGContext; use core_graphics::font::{CGGlyph, CGFont}; use core_graphics::geometry::{CGAffineTransform, CGPoint, CGRect, CGSize}; +use core_graphics::path::CGPath; use foreign_types::ForeignType; use libc::{self, size_t, c_void}; @@ -350,6 +351,18 @@ impl CTFont { } } } + + pub fn create_path_for_glyph(&self, glyph: CGGlyph, matrix: &CGAffineTransform) + -> Result { + unsafe { + let path = CTFontCreatePathForGlyph(self.obj, glyph, matrix); + if path.is_null() { + Err(()) + } else { + Ok(CGPath::from_ptr(path)) + } + } + } } // Helper methods @@ -502,7 +515,8 @@ extern { fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; /* Getting Glyph Data */ - //fn CTFontCreatePathForGlyph + fn CTFontCreatePathForGlyph(font: CTFontRef, glyph: CGGlyph, matrix: *const CGAffineTransform) + -> CGPathRef; //fn CTFontGetGlyphWithName fn CTFontGetBoundingRectsForGlyphs(font: CTFontRef, orientation: CTFontOrientation, From 86271a87b0b667220218ebdf951e2df14f9ef697 Mon Sep 17 00:00:00 2001 From: Natalya Date: Fri, 17 Nov 2017 21:32:21 +0200 Subject: [PATCH 114/126] Add iOS support --- Cargo.toml | 2 -- src/font.rs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2305818..92aaaf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,5 @@ mountainlion = [] [dependencies] foreign-types = "0.3" libc = "0.2" - -[target.x86_64-apple-darwin.dependencies] core-foundation = "0.4" core-graphics = "0.11" diff --git a/src/font.rs b/src/font.rs index cf14aee..b9a06f7 100644 --- a/src/font.rs +++ b/src/font.rs @@ -417,7 +417,7 @@ pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) - } } -#[link(name = "ApplicationServices", kind = "framework")] +#[link(name = "CoreText", kind = "framework")] extern { /* * CTFont.h From a1027037112aba880a5eaaa7c2d82c7a28c63166 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 18 Nov 2017 10:27:00 +0100 Subject: [PATCH 115/126] Update core-graphics to 0.12.1 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 92aaaf0..8d4b659 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "7.0.0" +version = "8.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" @@ -16,4 +16,4 @@ mountainlion = [] foreign-types = "0.3" libc = "0.2" core-foundation = "0.4" -core-graphics = "0.11" +core-graphics = "0.12.1" From 397b5e36c1039dfaa9ca2ab6494e421ad4fe3642 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 23 Jan 2018 21:28:16 +0530 Subject: [PATCH 116/126] Make CTFontDescriptor::family_name() actually return the family name It incorrectly returning the display name, which already has a separate function. --- src/font_descriptor.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index e92fd1f..9c1ca83 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -85,7 +85,7 @@ pub trait StylisticClassAccessors { impl StylisticClassAccessors for CTFontStylisticClass { fn is_serif(&self) -> bool { - let any_serif_class = kCTFontOldStyleSerifsClass + let any_serif_class = kCTFontOldStyleSerifsClass | kCTFontTransitionalSerifsClass | kCTFontModernSerifsClass | kCTFontClarendonSerifsClass @@ -254,8 +254,8 @@ impl CTFontDescriptor { impl CTFontDescriptor { pub fn family_name(&self) -> String { unsafe { - let value = self.get_string_attribute(kCTFontDisplayNameAttribute); - value.expect("A font2 must have a non-null font family name.") + let value = self.get_string_attribute(kCTFontFamilyNameAttribute); + value.expect("A font must have a non-null family name.") } } @@ -359,12 +359,12 @@ extern { pub fn CTFontDescriptorCopyLocalizedAttribute(descriptor: CTFontDescriptorRef, attribute: CFStringRef, language: *mut CFStringRef) -> CFTypeRef; - pub fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, + pub fn CTFontDescriptorCreateCopyWithAttributes(original: CTFontDescriptorRef, attributes: CFDictionaryRef) -> CTFontDescriptorRef; pub fn CTFontDescriptorCreateCopyWithFeature(original: CTFontDescriptorRef, featureTypeIdentifier: CFNumberRef, featureSelectorIdentifier: CFNumberRef) -> CTFontDescriptorRef; - pub fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, + pub fn CTFontDescriptorCreateCopyWithVariation(original: CTFontDescriptorRef, variationIdentifier: CFNumberRef, variationValue: CGFloat) -> CTFontDescriptorRef; pub fn CTFontDescriptorCreateMatchingFontDescriptor(descriptor: CTFontDescriptorRef, From 2a6b5586bd918be917e7d7cdc93071ef60a95c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Wed, 29 Nov 2017 19:16:01 +0100 Subject: [PATCH 117/126] Upgrade to core-foundation 0.5.0 --- Cargo.toml | 4 ++-- src/font.rs | 4 +++- src/font_collection.rs | 4 +++- src/font_descriptor.rs | 12 +++++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d4b659..7bee0a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,5 @@ mountainlion = [] [dependencies] foreign-types = "0.3" libc = "0.2" -core-foundation = "0.4" -core-graphics = "0.12.1" +core-foundation = "0.5" +core-graphics = "0.13" diff --git a/src/font.rs b/src/font.rs index b9a06f7..873e7c0 100644 --- a/src/font.rs +++ b/src/font.rs @@ -102,7 +102,9 @@ impl Clone for CTFont { } } -impl TCFType for CTFont { +impl TCFType for CTFont { + type Ref = CTFontRef; + #[inline] fn as_concrete_TypeRef(&self) -> CTFontRef { self.obj diff --git a/src/font_collection.rs b/src/font_collection.rs index 3304b3c..c978f9e 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -40,7 +40,9 @@ impl Drop for CTFontCollection { } } -impl TCFType for CTFontCollection { +impl TCFType for CTFontCollection { + type Ref = CTFontCollectionRef; + #[inline] fn as_concrete_TypeRef(&self) -> CTFontCollectionRef { self.obj diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 9c1ca83..c10874f 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -15,7 +15,7 @@ use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; use core_foundation::string::{CFString, CFStringRef}; -use core_foundation::url::{CFURL, CFURLRef}; +use core_foundation::url::CFURL; use core_graphics::base::CGFloat; use libc::c_void; @@ -130,7 +130,7 @@ trait TraitAccessorPrivate { impl TraitAccessorPrivate for CTFontTraits { unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let cftype = self.get_CFType(mem::transmute(key)); - assert!(cftype.instance_of::()); + assert!(cftype.instance_of::()); TCFType::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef())) } @@ -200,7 +200,9 @@ impl Drop for CTFontDescriptor { } } -impl TCFType for CTFontDescriptor { +impl TCFType for CTFontDescriptor { + type Ref = CTFontDescriptorRef; + #[inline] fn as_concrete_TypeRef(&self) -> CTFontDescriptorRef { self.obj @@ -243,7 +245,7 @@ impl CTFontDescriptor { } let value: CFType = TCFType::wrap_under_get_rule(value); - assert!(value.instance_of::()); + assert!(value.instance_of::()); let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(s.to_string()) } @@ -288,7 +290,7 @@ impl CTFontDescriptor { } let value: CFType = TCFType::wrap_under_get_rule(value); - assert!(value.instance_of::()); + assert!(value.instance_of::()); let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(format!("{:?}", url)) } From fc9e44f14f7c8b61c174e93bed968d5f6eae4cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Wed, 29 Nov 2017 19:18:40 +0100 Subject: [PATCH 118/126] Update to new CFNumber constructor --- src/font_collection.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/font_collection.rs b/src/font_collection.rs index c978f9e..ba492b9 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -89,7 +89,7 @@ impl CTFontCollection { pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); - let value = CFNumber::from_i64(1); + let value = CFNumber::from(1i64); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(), @@ -101,7 +101,7 @@ pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { pub fn create_for_all_families() -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); - let value = CFNumber::from_i64(1); + let value = CFNumber::from(1i64); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef()); From 2603f28cd0aa815196ba947a2b2109c14d331cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 12 Jan 2018 00:23:32 +0100 Subject: [PATCH 119/126] Bump version to 9.0.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7bee0a1..7de2363 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "8.0.0" +version = "9.0.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" From 907b4f78b3776fb87885c2ce2e31a29433e6102a Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Fri, 26 Jan 2018 16:36:39 -0500 Subject: [PATCH 120/126] Add types to CFArrays --- src/font.rs | 2 +- src/font_collection.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/font.rs b/src/font.rs index 873e7c0..053f2e6 100644 --- a/src/font.rs +++ b/src/font.rs @@ -410,7 +410,7 @@ pub fn debug_font_traits(font: &CTFont) { } #[cfg(feature = "mountainlion")] -pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) -> CFArray { +pub fn cascade_list_for_languages(font: &CTFont, language_pref_list: &CFArray) -> CFArray { unsafe { let font_collection_ref = CTFontCopyDefaultCascadeListForLanguages(font.as_concrete_TypeRef(), diff --git a/src/font_collection.rs b/src/font_collection.rs index ba492b9..df2235a 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -77,7 +77,7 @@ impl TCFType for CTFontCollection { } impl CTFontCollection { - pub fn get_descriptors(&self) -> CFArray { + pub fn get_descriptors(&self) -> CFArray { // 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 { @@ -86,7 +86,7 @@ impl CTFontCollection { } } -pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { +pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::from(1i64); @@ -128,14 +128,14 @@ pub fn create_for_family(family: &str) -> Option { if matched_descs == ptr::null() { return None; } - let matched_descs: CFArray = TCFType::wrap_under_create_rule(matched_descs); + let matched_descs: CFArray = TCFType::wrap_under_create_rule(matched_descs); // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. Some(new_from_descriptors(&matched_descs)) } } -pub fn get_family_names() -> CFArray { +pub fn get_family_names() -> CFArray { unsafe { TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) } From a7cc03d640dbeee61c681319e2a5854e166bea2f Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sat, 27 Jan 2018 15:44:01 -0500 Subject: [PATCH 121/126] Use macros from core-foundation for declaring types This cleans up the code a lot and gives an implementation of Clone. --- src/font.rs | 99 ++++++++++-------------------------------- src/font_collection.rs | 55 +++-------------------- src/font_descriptor.rs | 56 +++--------------------- src/lib.rs | 1 + 4 files changed, 37 insertions(+), 174 deletions(-) diff --git a/src/font.rs b/src/font.rs index 053f2e6..c73d0e9 100644 --- a/src/font.rs +++ b/src/font.rs @@ -13,7 +13,7 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorRef, CTFontOrientation}; use font_descriptor::{CTFontSymbolicTraits, CTFontTraits, SymbolicTraitAccessors, TraitAccessors}; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFRelease, CFRetain, CFTypeRef, TCFType}; +use core_foundation::base::{CFIndex, CFOptionFlags, CFTypeID, CFTypeRef, TCFType}; use core_foundation::data::{CFData, CFDataRef}; use core_foundation::dictionary::CFDictionaryRef; use core_foundation::string::{CFString, CFStringRef, UniChar}; @@ -26,7 +26,6 @@ use core_graphics::path::CGPath; use foreign_types::ForeignType; use libc::{self, size_t, c_void}; -use std::mem; use std::ptr; type CGContextRef = *mut ::CType; @@ -80,63 +79,11 @@ pub struct __CTFont(c_void); pub type CTFontRef = *const __CTFont; -#[derive(Debug)] -pub struct CTFont { - obj: CTFontRef, -} - -impl Drop for CTFont { - fn drop(&mut self) { - unsafe { - CFRelease(self.as_CFTypeRef()) - } - } -} - -impl Clone for CTFont { - #[inline] - fn clone(&self) -> CTFont { - unsafe { - TCFType::wrap_under_get_rule(self.obj) - } - } -} - -impl TCFType for CTFont { - type Ref = CTFontRef; - - #[inline] - fn as_concrete_TypeRef(&self) -> CTFontRef { - self.obj - } - - #[inline] - unsafe fn wrap_under_get_rule(reference: CTFontRef) -> CTFont { - let reference: CTFontRef = mem::transmute(CFRetain(mem::transmute(reference))); - TCFType::wrap_under_create_rule(reference) - } - - #[inline] - unsafe fn wrap_under_create_rule(obj: CTFontRef) -> CTFont { - CTFont { - obj: obj, - } - } - - #[inline] - fn as_CFTypeRef(&self) -> CFTypeRef { - unsafe { - mem::transmute(self.as_concrete_TypeRef()) - } - } - - #[inline] - fn type_id() -> CFTypeID { - unsafe { - CTFontGetTypeID() - } - } +declare_TCFType! { + CTFont, CTFontRef } +impl_TCFType!(CTFont, CTFontRef, CTFontGetTypeID); +impl_CFTypeDescription!(CTFont); pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { unsafe { @@ -175,7 +122,7 @@ impl CTFont { // Properties pub fn symbolic_traits(&self) -> CTFontSymbolicTraits { unsafe { - CTFontGetSymbolicTraits(self.obj) + CTFontGetSymbolicTraits(self.0) } } } @@ -184,14 +131,14 @@ impl CTFont { // Creation methods pub fn copy_to_CGFont(&self) -> CGFont { unsafe { - let cgfont_ref = CTFontCopyGraphicsFont(self.obj, ptr::null_mut()); + let cgfont_ref = CTFontCopyGraphicsFont(self.0, ptr::null_mut()); CGFont::from_ptr(cgfont_ref as *mut _) } } pub fn clone_with_font_size(&self, size: f64) -> CTFont { unsafe { - let font_ref = CTFontCreateCopyWithAttributes(self.obj, + let font_ref = CTFontCreateCopyWithAttributes(self.0, size as CGFloat, ptr::null(), ptr::null()); @@ -230,69 +177,69 @@ impl CTFont { pub fn all_traits(&self) -> CTFontTraits { unsafe { - TCFType::wrap_under_create_rule(CTFontCopyTraits(self.obj)) + TCFType::wrap_under_create_rule(CTFontCopyTraits(self.0)) } } // Font metrics pub fn ascent(&self) -> CGFloat { unsafe { - CTFontGetAscent(self.obj) + CTFontGetAscent(self.0) } } pub fn descent(&self) -> CGFloat { unsafe { - CTFontGetDescent(self.obj) + CTFontGetDescent(self.0) } } pub fn underline_thickness(&self) -> CGFloat { unsafe { - CTFontGetUnderlineThickness(self.obj) + CTFontGetUnderlineThickness(self.0) } } pub fn underline_position(&self) -> CGFloat { unsafe { - CTFontGetUnderlinePosition(self.obj) + CTFontGetUnderlinePosition(self.0) } } pub fn bounding_box(&self) -> CGRect { unsafe { - CTFontGetBoundingBox(self.obj) + CTFontGetBoundingBox(self.0) } } pub fn leading(&self) -> CGFloat { unsafe { - CTFontGetLeading(self.obj) + CTFontGetLeading(self.0) } } pub fn units_per_em(&self) -> libc::c_uint { unsafe { - CTFontGetUnitsPerEm(self.obj) + CTFontGetUnitsPerEm(self.0) } } pub fn x_height(&self) -> CGFloat { unsafe { - CTFontGetXHeight(self.obj) + CTFontGetXHeight(self.0) } } pub fn pt_size(&self) -> CGFloat { unsafe { - CTFontGetSize(self.obj) + CTFontGetSize(self.0) } } pub fn get_glyphs_for_characters(&self, characters: *const UniChar, glyphs: *mut CGGlyph, count: CFIndex) -> bool { unsafe { - CTFontGetGlyphsForCharacters(self.obj, characters, glyphs, count) + CTFontGetGlyphsForCharacters(self.0, characters, glyphs, count) } } @@ -303,13 +250,13 @@ impl CTFont { count: CFIndex) -> f64 { unsafe { - CTFontGetAdvancesForGlyphs(self.obj, orientation, glyphs, advances, count) as f64 + CTFontGetAdvancesForGlyphs(self.0, orientation, glyphs, advances, count) as f64 } } pub fn get_font_table(&self, tag: u32) -> Option { unsafe { - let result = CTFontCopyTable(self.obj, + let result = CTFontCopyTable(self.0, tag as CTFontTableTag, kCTFontTableOptionsExcludeSynthetic); if result.is_null() { @@ -345,7 +292,7 @@ impl CTFont { pub fn url(&self) -> Option { unsafe { - let result = CTFontCopyAttribute(self.obj, kCTFontURLAttribute); + let result = CTFontCopyAttribute(self.0, kCTFontURLAttribute); if result.is_null() { None } else { @@ -357,7 +304,7 @@ impl CTFont { pub fn create_path_for_glyph(&self, glyph: CGGlyph, matrix: &CGAffineTransform) -> Result { unsafe { - let path = CTFontCreatePathForGlyph(self.obj, glyph, matrix); + let path = CTFontCreatePathForGlyph(self.0, glyph, matrix); if path.is_null() { Err(()) } else { diff --git a/src/font_collection.rs b/src/font_collection.rs index df2235a..041d330 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -12,14 +12,13 @@ use font_descriptor::{CTFontDescriptor, CTFontDescriptorCreateMatchingFontDescri use font_manager::CTFontManagerCopyAvailableFontFamilyNames; use core_foundation::array::{CFArray, CFArrayRef}; -use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, TCFType}; +use core_foundation::base::{CFTypeID, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; 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)] @@ -27,61 +26,19 @@ pub struct __CTFontCollection(c_void); pub type CTFontCollectionRef = *const __CTFontCollection; -#[derive(Debug)] -pub struct CTFontCollection { - obj: CTFontCollectionRef, +declare_TCFType! { + CTFontCollection, CTFontCollectionRef } +impl_TCFType!(CTFontCollection, CTFontCollectionRef, CTFontCollectionGetTypeID); +impl_CFTypeDescription!(CTFontCollection); -impl Drop for CTFontCollection { - fn drop(&mut self) { - unsafe { - CFRelease(self.as_CFTypeRef()) - } - } -} - -impl TCFType for CTFontCollection { - type Ref = CTFontCollectionRef; - - #[inline] - fn as_concrete_TypeRef(&self) -> CTFontCollectionRef { - self.obj - } - - #[inline] - unsafe fn wrap_under_get_rule(reference: CTFontCollectionRef) -> CTFontCollection { - let reference: CTFontCollectionRef = mem::transmute(CFRetain(mem::transmute(reference))); - TCFType::wrap_under_create_rule(reference) - } - - #[inline] - unsafe fn wrap_under_create_rule(obj: CTFontCollectionRef) -> CTFontCollection { - CTFontCollection { - obj: obj, - } - } - - #[inline] - fn as_CFTypeRef(&self) -> CFTypeRef { - unsafe { - mem::transmute(self.as_concrete_TypeRef()) - } - } - - #[inline] - fn type_id() -> CFTypeID { - unsafe { - CTFontCollectionGetTypeID() - } - } -} impl CTFontCollection { pub fn get_descriptors(&self) -> CFArray { // 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 { - TCFType::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.obj)) + TCFType::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0)) } } } diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index c10874f..ce7ce09 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -10,7 +10,7 @@ #![allow(non_upper_case_globals)] use core_foundation::array::CFArrayRef; -use core_foundation::base::{CFRelease, CFRetain, CFType, CFTypeID, CFTypeRef, TCFType}; +use core_foundation::base::{CFType, CFTypeID, CFTypeRef, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; @@ -187,59 +187,17 @@ pub struct __CTFontDescriptor(c_void); pub type CTFontDescriptorRef = *const __CTFontDescriptor; -#[derive(Debug)] -pub struct CTFontDescriptor { - obj: CTFontDescriptorRef, +declare_TCFType! { + CTFontDescriptor, CTFontDescriptorRef } +impl_TCFType!(CTFontDescriptor, CTFontDescriptorRef, CTFontDescriptorGetTypeID); +impl_CFTypeDescription!(CTFontDescriptor); -impl Drop for CTFontDescriptor { - fn drop(&mut self) { - unsafe { - CFRelease(self.as_CFTypeRef()) - } - } -} - -impl TCFType for CTFontDescriptor { - type Ref = CTFontDescriptorRef; - - #[inline] - fn as_concrete_TypeRef(&self) -> CTFontDescriptorRef { - self.obj - } - - #[inline] - unsafe fn wrap_under_get_rule(reference: CTFontDescriptorRef) -> CTFontDescriptor { - let reference: CTFontDescriptorRef = mem::transmute(CFRetain(mem::transmute(reference))); - TCFType::wrap_under_create_rule(reference) - } - - #[inline] - fn as_CFTypeRef(&self) -> CFTypeRef { - unsafe { - mem::transmute(self.as_concrete_TypeRef()) - } - } - - #[inline] - unsafe fn wrap_under_create_rule(obj: CTFontDescriptorRef) -> CTFontDescriptor { - CTFontDescriptor { - obj: obj, - } - } - - #[inline] - fn type_id() -> CFTypeID { - unsafe { - CTFontDescriptorGetTypeID() - } - } -} impl CTFontDescriptor { fn get_string_attribute(&self, attribute: CFStringRef) -> Option { unsafe { - let value = CTFontDescriptorCopyAttribute(self.obj, attribute); + let value = CTFontDescriptorCopyAttribute(self.0, attribute); if value.is_null() { return None } @@ -284,7 +242,7 @@ impl CTFontDescriptor { pub fn font_path(&self) -> Option { unsafe { - let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute); + let value = CTFontDescriptorCopyAttribute(self.0, kCTFontURLAttribute); if value.is_null() { return None; } diff --git a/src/lib.rs b/src/lib.rs index 03d8c3e..401146a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ extern crate foreign_types; extern crate libc; +#[macro_use] extern crate core_foundation; extern crate core_graphics; From 33f7081b124cf75e039efc79d6d67dc1dad64fff Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sat, 27 Jan 2018 16:29:18 -0500 Subject: [PATCH 122/126] Bump the version for a new release --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7de2363..a42bde0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "core-text" -version = "9.0.0" +version = "9.1.0" authors = ["The Servo Project Developers"] description = "Bindings to the Core Text framework." license = "MIT/Apache-2.0" From 7b5bee960860ec6f1b0f610832b30deba995ef17 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 29 Jan 2018 20:26:17 +0530 Subject: [PATCH 123/126] Properly release attribute returned by CTFontDescriptorCopyAttribute CTFontDescriptorCopyAttribute returns a retained reference (i.e. it follows the create rule) so were incorrectly retaining it again by using `wrap_under_get_rule`. --- src/font_descriptor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index ce7ce09..c2256b0 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -202,7 +202,7 @@ impl CTFontDescriptor { return None } - let value: CFType = TCFType::wrap_under_get_rule(value); + let value: CFType = TCFType::wrap_under_create_rule(value); assert!(value.instance_of::()); let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(s.to_string()) @@ -247,7 +247,7 @@ impl CTFontDescriptor { return None; } - let value: CFType = TCFType::wrap_under_get_rule(value); + let value: CFType = TCFType::wrap_under_create_rule(value); assert!(value.instance_of::()); let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(format!("{:?}", url)) From 4acd58e155f7b0924de805d6134098f45dd139b6 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 29 Jan 2018 20:38:00 +0530 Subject: [PATCH 124/126] Add CTFontDescriptor::traits() This provides easy access to e.g. the font weight. --- src/font_descriptor.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index c2256b0..7910b96 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -253,6 +253,17 @@ impl CTFontDescriptor { Some(format!("{:?}", url)) } } + + pub fn traits(&self) -> CTFontTraits { + unsafe { + let value = CTFontDescriptorCopyAttribute(self.0, kCTFontTraitsAttribute); + assert!(!value.is_null()); + let value: CFType = TCFType::wrap_under_create_rule(value); + assert!(value.instance_of::()); + let dictionary: CFDictionary = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); + dictionary + } + } } pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor { From 46213a7ab0461b539f90cb5c6f24332f41008c74 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 30 Jan 2018 20:49:10 +0530 Subject: [PATCH 125/126] Use typed wrap_under_{create,get}_rule() functions Just some minor cleanup; no functional changes. --- src/font.rs | 27 +++++++++++++-------------- src/font_collection.rs | 18 +++++++++--------- src/font_descriptor.rs | 17 ++++++++--------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/font.rs b/src/font.rs index c73d0e9..79da411 100644 --- a/src/font.rs +++ b/src/font.rs @@ -91,7 +91,7 @@ pub fn new_from_CGFont(cgfont: &CGFont, pt_size: f64) -> CTFont { pt_size as CGFloat, ptr::null(), ptr::null()); - TCFType::wrap_under_create_rule(font_ref) + CTFont::wrap_under_create_rule(font_ref) } } @@ -100,7 +100,7 @@ pub fn new_from_descriptor(desc: &CTFontDescriptor, pt_size: f64) -> CTFont { let font_ref = CTFontCreateWithFontDescriptor(desc.as_concrete_TypeRef(), pt_size as CGFloat, ptr::null()); - TCFType::wrap_under_create_rule(font_ref) + CTFont::wrap_under_create_rule(font_ref) } } @@ -113,7 +113,7 @@ pub fn new_from_name(name: &str, pt_size: f64) -> Result { if font_ref.is_null() { Err(()) } else { - Ok(TCFType::wrap_under_create_rule(font_ref)) + Ok(CTFont::wrap_under_create_rule(font_ref)) } } } @@ -142,7 +142,7 @@ impl CTFont { size as CGFloat, ptr::null(), ptr::null()); - TCFType::wrap_under_create_rule(font_ref) + CTFont::wrap_under_create_rule(font_ref) } } @@ -177,7 +177,7 @@ impl CTFont { pub fn all_traits(&self) -> CTFontTraits { unsafe { - TCFType::wrap_under_create_rule(CTFontCopyTraits(self.0)) + CTFontTraits::wrap_under_create_rule(CTFontCopyTraits(self.0)) } } @@ -262,7 +262,7 @@ impl CTFont { if result.is_null() { None } else { - Some(TCFType::wrap_under_create_rule(result)) + Some(CFData::wrap_under_create_rule(result)) } } } @@ -296,7 +296,7 @@ impl CTFont { if result.is_null() { None } else { - Some(TCFType::wrap_under_create_rule(result as CFURLRef)) + Some(CFURL::wrap_under_create_rule(result as CFURLRef)) } } } @@ -321,8 +321,7 @@ fn get_string_by_name_key(font: &CTFont, name_key: CFStringRef) -> Option CTFontRef; //fn CTFontCreateWithFontDescriptorAndOptions //fn CTFontCreateUIFontForLanguage - fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *const CGAffineTransform, + fn CTFontCreateCopyWithAttributes(font: CTFontRef, size: CGFloat, matrix: *const CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; //fn CTFontCreateCopyWithSymbolicTraits //fn CTFontCreateCopyWithFamily @@ -439,7 +438,7 @@ extern { //fn CTFontCopyFullName(font: CTFontRef) -> CFStringRef; //fn CTFontCopyDisplayName(font: CTFontRef) -> CFStringRef; fn CTFontCopyName(font: CTFontRef, nameKey: CFStringRef) -> CFStringRef; - //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, + //fn CTFontCopyLocalizedName(font: CTFontRef, nameKey: CFStringRef, // language: *CFStringRef) -> CFStringRef; #[cfg(feature = "mountainlion")] fn CTFontCopyDefaultCascadeListForLanguages(font: CTFontRef, languagePrefList: CFArrayRef) -> CFArrayRef; @@ -496,8 +495,8 @@ extern { /* Converting Fonts */ fn CTFontCopyGraphicsFont(font: CTFontRef, attributes: *mut CTFontDescriptorRef) -> CGFontRef; - fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, - matrix: *const CGAffineTransform, + fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, + matrix: *const CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; //fn CTFontGetPlatformFont //fn CTFontCreateWithPlatformFont diff --git a/src/font_collection.rs b/src/font_collection.rs index 041d330..e1c550e 100644 --- a/src/font_collection.rs +++ b/src/font_collection.rs @@ -38,31 +38,31 @@ impl CTFontCollection { // 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 { - TCFType::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0)) + CFArray::wrap_under_get_rule(CTFontCollectionCreateMatchingFontDescriptors(self.0)) } } } pub fn new_from_descriptors(descs: &CFArray) -> CTFontCollection { unsafe { - let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::from(1i64); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateWithFontDescriptors(descs.as_concrete_TypeRef(), options.as_concrete_TypeRef()); - TCFType::wrap_under_create_rule(font_collection_ref) + CTFontCollection::wrap_under_create_rule(font_collection_ref) } } pub fn create_for_all_families() -> CTFontCollection { unsafe { - let key: CFString = TCFType::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); + let key = CFString::wrap_under_get_rule(kCTFontCollectionRemoveDuplicatesOption); let value = CFNumber::from(1i64); let options = CFDictionary::from_CFType_pairs(&[ (key.as_CFType(), value.as_CFType()) ]); let font_collection_ref = CTFontCollectionCreateFromAvailableFonts(options.as_concrete_TypeRef()); - TCFType::wrap_under_create_rule(font_collection_ref) + CTFontCollection::wrap_under_create_rule(font_collection_ref) } } @@ -70,7 +70,7 @@ pub fn create_for_family(family: &str) -> Option { use font_descriptor::kCTFontFamilyNameAttribute; unsafe { - let family_attr: CFString = TCFType::wrap_under_get_rule(kCTFontFamilyNameAttribute); + let family_attr = CFString::wrap_under_get_rule(kCTFontFamilyNameAttribute); let family_name: CFString = family.parse().unwrap(); let specified_attrs = CFDictionary::from_CFType_pairs(&[ (family_attr.as_CFType(), family_name.as_CFType()) @@ -85,7 +85,7 @@ pub fn create_for_family(family: &str) -> Option { if matched_descs == ptr::null() { return None; } - let matched_descs: CFArray = TCFType::wrap_under_create_rule(matched_descs); + let matched_descs = CFArray::wrap_under_create_rule(matched_descs); // I suppose one doesn't even need the CTFontCollection object at this point. // But we stick descriptors into and out of it just to provide a nice wrapper API. Some(new_from_descriptors(&matched_descs)) @@ -94,7 +94,7 @@ pub fn create_for_family(family: &str) -> Option { pub fn get_family_names() -> CFArray { unsafe { - TCFType::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) + CFArray::wrap_under_create_rule(CTFontManagerCopyAvailableFontFamilyNames()) } } @@ -109,7 +109,7 @@ extern { // descriptors: CFArrayRef, // options: CFDictionaryRef) -> CTFontCollectionRef; fn CTFontCollectionCreateFromAvailableFonts(options: CFDictionaryRef) -> CTFontCollectionRef; - // this stupid function doesn't actually do any wildcard expansion; + // this stupid function doesn't actually do any wildcard expansion; // it just chooses the best match. Use // CTFontDescriptorCreateMatchingDescriptors instead. fn CTFontCollectionCreateMatchingFontDescriptors(collection: CTFontCollectionRef) -> CFArrayRef; diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 7910b96..4c3f5f6 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -131,7 +131,7 @@ impl TraitAccessorPrivate for CTFontTraits { unsafe fn extract_number_for_key(&self, key: CFStringRef) -> CFNumber { let cftype = self.get_CFType(mem::transmute(key)); assert!(cftype.instance_of::()); - TCFType::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef())) + CFNumber::wrap_under_get_rule(mem::transmute(cftype.as_CFTypeRef())) } } @@ -202,9 +202,9 @@ impl CTFontDescriptor { return None } - let value: CFType = TCFType::wrap_under_create_rule(value); + let value = CFType::wrap_under_create_rule(value); assert!(value.instance_of::()); - let s: CFString = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); + let s = CFString::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(s.to_string()) } } @@ -247,9 +247,9 @@ impl CTFontDescriptor { return None; } - let value: CFType = TCFType::wrap_under_create_rule(value); + let value = CFType::wrap_under_create_rule(value); assert!(value.instance_of::()); - let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); + let url = CFURL::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); Some(format!("{:?}", url)) } } @@ -258,10 +258,9 @@ impl CTFontDescriptor { unsafe { let value = CTFontDescriptorCopyAttribute(self.0, kCTFontTraitsAttribute); assert!(!value.is_null()); - let value: CFType = TCFType::wrap_under_create_rule(value); + let value = CFType::wrap_under_create_rule(value); assert!(value.instance_of::()); - let dictionary: CFDictionary = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - dictionary + CFDictionary::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())) } } } @@ -270,7 +269,7 @@ pub fn new_from_attributes(attributes: &CFDictionary) -> CTFontDescriptor { unsafe { let result: CTFontDescriptorRef = CTFontDescriptorCreateWithAttributes(attributes.as_concrete_TypeRef()); - TCFType::wrap_under_create_rule(result) + CTFontDescriptor::wrap_under_create_rule(result) } } From 8bc5c45090e2a1fc62ddf40a2d27d62912b559b1 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 29 Jan 2018 19:57:40 +0530 Subject: [PATCH 126/126] Make CTFontDescriptor::font_path() return filesystem path, not URL Prior to this commit, the return string was in the format `file:///foo/bar.otf`. We now omit the leading `file://` portion. This also properly retains characters that are not URL safe. --- src/font_descriptor.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/font_descriptor.rs b/src/font_descriptor.rs index 4c3f5f6..9ae9680 100644 --- a/src/font_descriptor.rs +++ b/src/font_descriptor.rs @@ -15,7 +15,7 @@ use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::number::{CFNumber, CFNumberRef}; use core_foundation::set::CFSetRef; use core_foundation::string::{CFString, CFStringRef}; -use core_foundation::url::CFURL; +use core_foundation::url::{CFURLCopyFileSystemPath, kCFURLPOSIXPathStyle, CFURL}; use core_graphics::base::CGFloat; use libc::c_void; @@ -250,7 +250,11 @@ impl CTFontDescriptor { let value = CFType::wrap_under_create_rule(value); assert!(value.instance_of::()); let url = CFURL::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef())); - Some(format!("{:?}", url)) + let path = CFString::wrap_under_create_rule(CFURLCopyFileSystemPath( + url.as_concrete_TypeRef(), + kCFURLPOSIXPathStyle, + )).to_string(); + Some(path) } }