Permalink
Browse files

Merge branch 'master' of github.com:github/twui

  • Loading branch information...
2 parents d476dae + 45309bd commit 903908e377551818e0d38fbb6d23416d6b63661c @joshaber joshaber committed Jul 25, 2012
@@ -22,8 +22,8 @@
TUITableView *_tableView;
ExampleTabBar *_tabBar;
- TUIFont *exampleFont1;
- TUIFont *exampleFont2;
+ NSFont *exampleFont1;
+ NSFont *exampleFont2;
}
@end
@@ -28,8 +28,8 @@ - (id)initWithFrame:(CGRect)frame
self.backgroundColor = [TUIColor colorWithWhite:0.9 alpha:1.0];
// if you're using a font a lot, it's best to allocate it once and re-use it
- exampleFont1 = [TUIFont fontWithName:@"HelveticaNeue" size:15];
- exampleFont2 = [TUIFont fontWithName:@"HelveticaNeue-Bold" size:15];
+ exampleFont1 = [NSFont fontWithName:@"HelveticaNeue" size:15];
+ exampleFont2 = [NSFont fontWithName:@"HelveticaNeue-Bold" size:15];
CGRect b = self.bounds;
b.origin.y += TAB_HEIGHT;
@@ -32,7 +32,6 @@
5EE983C713BE7834005F430D /* TUIControl+TargetAction.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4B13BE6E1900C85CB5 /* TUIControl+TargetAction.m */; };
5EE983C813BE7834005F430D /* TUIControl.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */; };
5EE983C913BE7834005F430D /* TUIFastIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */; };
- 5EE983CA13BE7834005F430D /* TUIFont.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5113BE6E1900C85CB5 /* TUIFont.m */; };
5EE983CB13BE7834005F430D /* TUIGeometry.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */; };
5EE983CC13BE7834005F430D /* TUIImage+Drawing.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5513BE6E1900C85CB5 /* TUIImage+Drawing.m */; };
5EE983CD13BE7834005F430D /* TUIImage.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5713BE6E1900C85CB5 /* TUIImage.m */; };
@@ -147,7 +146,6 @@
CB5E322913BE70CA004B7899 /* TUIControl+TargetAction.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4B13BE6E1900C85CB5 /* TUIControl+TargetAction.m */; };
CB5E322B13BE70CA004B7899 /* TUIControl.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */; };
CB5E322D13BE70CA004B7899 /* TUIFastIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */; };
- CB5E322F13BE70CA004B7899 /* TUIFont.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5113BE6E1900C85CB5 /* TUIFont.m */; };
CB5E323113BE70CA004B7899 /* TUIGeometry.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */; };
CB5E323313BE70CA004B7899 /* TUIImage+Drawing.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5513BE6E1900C85CB5 /* TUIImage+Drawing.m */; };
CB5E323513BE70CA004B7899 /* TUIImage.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5713BE6E1900C85CB5 /* TUIImage.m */; };
@@ -205,8 +203,6 @@
CBB74CA413BE6E1900C85CB5 /* TUIControl.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */; };
CBB74CA513BE6E1900C85CB5 /* TUIFastIndexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C4E13BE6E1900C85CB5 /* TUIFastIndexPath.h */; settings = {ATTRIBUTES = (Public, ); }; };
CBB74CA613BE6E1900C85CB5 /* TUIFastIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */; };
- CBB74CA713BE6E1900C85CB5 /* TUIFont.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C5013BE6E1900C85CB5 /* TUIFont.h */; settings = {ATTRIBUTES = (Public, ); }; };
- CBB74CA813BE6E1900C85CB5 /* TUIFont.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5113BE6E1900C85CB5 /* TUIFont.m */; };
CBB74CA913BE6E1900C85CB5 /* TUIGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C5213BE6E1900C85CB5 /* TUIGeometry.h */; settings = {ATTRIBUTES = (Public, ); }; };
CBB74CAA13BE6E1900C85CB5 /* TUIGeometry.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */; };
CBB74CAB13BE6E1900C85CB5 /* TUIImage+Drawing.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C5413BE6E1900C85CB5 /* TUIImage+Drawing.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -501,8 +497,6 @@
CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIControl.m; sourceTree = "<group>"; };
CBB74C4E13BE6E1900C85CB5 /* TUIFastIndexPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIFastIndexPath.h; sourceTree = "<group>"; };
CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIFastIndexPath.m; sourceTree = "<group>"; };
- CBB74C5013BE6E1900C85CB5 /* TUIFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIFont.h; sourceTree = "<group>"; };
- CBB74C5113BE6E1900C85CB5 /* TUIFont.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIFont.m; sourceTree = "<group>"; };
CBB74C5213BE6E1900C85CB5 /* TUIGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIGeometry.h; sourceTree = "<group>"; };
CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIGeometry.m; sourceTree = "<group>"; };
CBB74C5413BE6E1900C85CB5 /* TUIImage+Drawing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIImage+Drawing.h"; sourceTree = "<group>"; };
@@ -796,8 +790,6 @@
CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */,
CBB74C4E13BE6E1900C85CB5 /* TUIFastIndexPath.h */,
CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */,
- CBB74C5013BE6E1900C85CB5 /* TUIFont.h */,
- CBB74C5113BE6E1900C85CB5 /* TUIFont.m */,
CBB74C5213BE6E1900C85CB5 /* TUIGeometry.h */,
CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */,
D0C7650415B6156A00E7AC2C /* TUIHostView.h */,
@@ -968,7 +960,6 @@
CBB74CA013BE6E1900C85CB5 /* TUIColor.h in Headers */,
CBB74CA313BE6E1900C85CB5 /* TUIControl.h in Headers */,
CBB74CA513BE6E1900C85CB5 /* TUIFastIndexPath.h in Headers */,
- CBB74CA713BE6E1900C85CB5 /* TUIFont.h in Headers */,
CBB74CA913BE6E1900C85CB5 /* TUIGeometry.h in Headers */,
CBB74CAB13BE6E1900C85CB5 /* TUIImage+Drawing.h in Headers */,
88D81CFF1577EF0D009D453B /* TUIStyledView.h in Headers */,
@@ -1282,7 +1273,6 @@
5EE983C713BE7834005F430D /* TUIControl+TargetAction.m in Sources */,
5EE983C813BE7834005F430D /* TUIControl.m in Sources */,
5EE983C913BE7834005F430D /* TUIFastIndexPath.m in Sources */,
- 5EE983CA13BE7834005F430D /* TUIFont.m in Sources */,
5EE983CB13BE7834005F430D /* TUIGeometry.m in Sources */,
5EE983CC13BE7834005F430D /* TUIImage+Drawing.m in Sources */,
5EE983CD13BE7834005F430D /* TUIImage.m in Sources */,
@@ -1357,7 +1347,6 @@
CBB74CA213BE6E1900C85CB5 /* TUIControl+TargetAction.m in Sources */,
CBB74CA413BE6E1900C85CB5 /* TUIControl.m in Sources */,
CBB74CA613BE6E1900C85CB5 /* TUIFastIndexPath.m in Sources */,
- CBB74CA813BE6E1900C85CB5 /* TUIFont.m in Sources */,
CBB74CAA13BE6E1900C85CB5 /* TUIGeometry.m in Sources */,
CBB74CAC13BE6E1900C85CB5 /* TUIImage+Drawing.m in Sources */,
CBB74CAE13BE6E1900C85CB5 /* TUIImage.m in Sources */,
@@ -1445,7 +1434,6 @@
CB5E322913BE70CA004B7899 /* TUIControl+TargetAction.m in Sources */,
CB5E322B13BE70CA004B7899 /* TUIControl.m in Sources */,
CB5E322D13BE70CA004B7899 /* TUIFastIndexPath.m in Sources */,
- CB5E322F13BE70CA004B7899 /* TUIFont.m in Sources */,
CB5E323113BE70CA004B7899 /* TUIGeometry.m in Sources */,
CB5E323313BE70CA004B7899 /* TUIImage+Drawing.m in Sources */,
CB5E323513BE70CA004B7899 /* TUIImage.m in Sources */,
@@ -20,7 +20,6 @@ extern NSString * const TUIAttributedStringBackgroundColorAttributeName;
extern NSString * const TUIAttributedStringBackgroundFillStyleName;
extern NSString * const TUIAttributedStringPreDrawBlockName;
-@class TUIFont;
@class TUIColor;
typedef void (^TUIAttributedStringPreDrawBlock)(NSAttributedString *attributedString, NSRange substringRange, CGRect rects[], CFIndex rectCount);
@@ -61,7 +60,7 @@ typedef enum {
@interface NSMutableAttributedString (TUIAdditions)
// write-only properties, reading will return nil
-@property (nonatomic, retain) TUIFont *font;
+@property (nonatomic, retain) NSFont *font;
@property (nonatomic, retain) TUIColor *color;
@property (nonatomic, retain) TUIColor *backgroundColor;
@property (nonatomic, assign) TUIBackgroundFillStyle backgroundFillStyle;
@@ -74,7 +73,7 @@ typedef enum {
- (void)setAlignment:(TUITextAlignment)alignment lineBreakMode:(TUILineBreakMode)lineBreakMode;
- (NSRange)_stringRange;
-- (void)setFont:(TUIFont *)font inRange:(NSRange)range;
+- (void)setFont:(NSFont *)font inRange:(NSRange)range;
- (void)setColor:(TUIColor *)color inRange:(NSRange)range;
- (void)setBackgroundColor:(TUIColor *)color inRange:(NSRange)range;
- (void)setBackgroundFillStyle:(TUIBackgroundFillStyle)fillStyle inRange:(NSRange)range;
@@ -15,7 +15,6 @@
*/
#import "TUIAttributedString.h"
-#import "TUIFont.h"
#import "TUIColor.h"
NSString * const TUIAttributedStringBackgroundColorAttributeName = @"TUIAttributedStringBackgroundColorAttributeName";
@@ -38,9 +37,10 @@ - (NSRange)_stringRange
return NSMakeRange(0, [self length]);
}
-- (void)setFont:(TUIFont *)font inRange:(NSRange)range
+- (void)setFont:(NSFont *)font inRange:(NSRange)range
{
- [self addAttribute:(NSString *)kCTFontAttributeName value:(id)[font ctFont] range:range];
+ // NSFont and CTFont are toll-free bridged.
+ [self addAttribute:(NSString *)kCTFontAttributeName value:font range:range];
}
- (void)setColor:(TUIColor *)color inRange:(NSRange)range
@@ -58,7 +58,7 @@ - (void)setKerning:(CGFloat)k inRange:(NSRange)range
[self addAttribute:(NSString *)kCTKernAttributeName value:[NSNumber numberWithFloat:k] range:range];
}
-- (void)setFont:(TUIFont *)font
+- (void)setFont:(NSFont *)font
{
[self setFont:font inRange:[self _stringRange]];
}
@@ -199,7 +199,7 @@ - (void)setAlignment:(TUITextAlignment)alignment
[self setAlignment:alignment lineBreakMode:TUILineBreakModeWordWrap];
}
-- (TUIFont *)font
+- (NSFont *)font
{
return nil;
}
View
@@ -1,44 +0,0 @@
-/*
- Copyright 2011 Twitter, Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this work except in compliance with the License.
- You may obtain a copy of the License in the LICENSE file, or 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.
- */
-
-#import <Foundation/Foundation.h>
-
-/*
- Your best bet is to build commonly used fonts at launch, cache for the lifetime of the app
- */
-
-@interface TUIFont : NSObject
-{
- CTFontRef _ctFont;
-}
-
-+ (TUIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;
-
-+ (TUIFont *)systemFontOfSize:(CGFloat)fontSize;
-+ (TUIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
-
-@property(nonatomic,readonly,strong) NSString *familyName;
-@property(nonatomic,readonly,strong) NSString *fontName;
-@property(nonatomic,readonly) CGFloat pointSize;
-@property(nonatomic,readonly) CGFloat ascender;
-@property(nonatomic,readonly) CGFloat descender;
-@property(nonatomic,readonly) CGFloat leading;
-@property(nonatomic,readonly) CGFloat capHeight;
-@property(nonatomic,readonly) CGFloat xHeight;
-
-@property (nonatomic, readonly) CTFontRef ctFont;
-
-@end
View
@@ -1,148 +0,0 @@
-/*
- Copyright 2011 Twitter, Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this work except in compliance with the License.
- You may obtain a copy of the License in the LICENSE file, or 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.
- */
-
-#import "TUIFont.h"
-
-@implementation TUIFont
-
-- (id)initWithCTFont:(CTFontRef)f
-{
- if((self = [super init]))
- {
- _ctFont = f;
- CFRetain(_ctFont);
- }
- return self;
-}
-
-- (void)dealloc
-{
- if(_ctFont)
- CFRelease(_ctFont);
-}
-
-static NSRange MakeNSRangeFromEndpoints(NSUInteger first, NSUInteger last) {
- return NSMakeRange(first, last - first + 1);
-}
-
-static NSFontDescriptor *arialUniDescFallback = nil;
-static NSDictionary *CachedFontDescriptors = nil;
-
-+ (void)initialize
-{
- if(self == [TUIFont class]) {
-
- // fallback stuff prevents massive stalls
- NSRange range = MakeNSRangeFromEndpoints(0x2100, 0x214F);
- NSCharacterSet *letterlikeSymbolsSet = [NSCharacterSet characterSetWithRange:range];
- arialUniDescFallback = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- @"ArialUnicodeMS", NSFontNameAttribute,
- letterlikeSymbolsSet, NSFontCharacterSetAttribute,
- nil]];
- NSString *normalFontName;
- NSString *lightFontName;
- NSString *mediumFontName;
- NSString *boldFontName;
- normalFontName = @"HelveticaNeue";
- lightFontName = @"HelveticaNeue-Light";
- mediumFontName = @"HelveticaNeue-Medium";
- boldFontName = @"HelveticaNeue-Bold";
-
- NSFontDescriptor *D_HelveticaNeue = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- normalFontName, NSFontNameAttribute,
- [NSArray arrayWithObject:arialUniDescFallback], NSFontCascadeListAttribute,
- nil]];
- NSFontDescriptor *D_HelveticaNeue_Light = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- lightFontName, NSFontNameAttribute,
- [NSArray arrayWithObject:arialUniDescFallback], NSFontCascadeListAttribute,
- nil]];
- NSFontDescriptor *D_HelveticaNeue_Medium = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- mediumFontName, NSFontNameAttribute,
- [NSArray arrayWithObject:arialUniDescFallback], NSFontCascadeListAttribute,
- nil]];
- NSFontDescriptor *D_HelveticaNeue_Bold = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- boldFontName, NSFontNameAttribute,
- [NSArray arrayWithObject:arialUniDescFallback], NSFontCascadeListAttribute,
- nil]];
-
- CachedFontDescriptors = [NSDictionary dictionaryWithObjectsAndKeys:
- D_HelveticaNeue, @"HelveticaNeue",
- D_HelveticaNeue_Light, @"HelveticaNeue-Light",
- D_HelveticaNeue_Medium, @"HelveticaNeue-Medium",
- D_HelveticaNeue_Bold, @"HelveticaNeue-Bold",
- nil];
- }
-}
-
-+ (TUIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize
-{
- NSFontDescriptor *desc = [CachedFontDescriptors objectForKey:fontName];
- if(!desc) {
- desc = [NSFontDescriptor fontDescriptorWithFontAttributes:
- [NSDictionary dictionaryWithObjectsAndKeys:
- fontName, NSFontNameAttribute,
- [NSArray arrayWithObject:arialUniDescFallback], NSFontCascadeListAttribute, // oh thank you jesus
- nil]];
-
- }
- CTFontRef font = CTFontCreateWithFontDescriptor((__bridge CTFontDescriptorRef)desc, fontSize, NULL);
- TUIFont *uiFont = [[TUIFont alloc] initWithCTFont:font];
- CFRelease(font);
-
- return uiFont;
-}
-
-+ (TUIFont *)systemFontOfSize:(CGFloat)fontSize
-{
- CTFontRef f = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, fontSize, NULL);
- TUIFont *uifont = [[TUIFont alloc] initWithCTFont:f];
- CFRelease(f);
- return uifont;
-}
-
-+ (TUIFont *)boldSystemFontOfSize:(CGFloat)fontSize
-{
- CTFontRef f = CTFontCreateUIFontForLanguage(kCTFontEmphasizedSystemFontType, fontSize, NULL);
- TUIFont *uifont = [[TUIFont alloc] initWithCTFont:f];
- CFRelease(f);
- return uifont;
-}
-
-- (NSString *)familyName { return (__bridge_transfer NSString *)CTFontCopyFamilyName(_ctFont); }
-- (NSString *)fontName { return (__bridge_transfer NSString *)CTFontCopyPostScriptName(_ctFont); }
-- (CGFloat)pointSize { return CTFontGetSize(_ctFont); }
-- (CGFloat)ascender { return CTFontGetAscent(_ctFont); }
-- (CGFloat)descender { return CTFontGetDescent(_ctFont); }
-- (CGFloat)leading { return CTFontGetLeading(_ctFont); }
-- (CGFloat)capHeight { return CTFontGetCapHeight(_ctFont); }
-- (CGFloat)xHeight { return CTFontGetXHeight(_ctFont); }
-
-- (TUIFont *)fontWithSize:(CGFloat)fontSize
-{
- return nil;
-}
-
-- (CTFontRef)ctFont
-{
- return _ctFont;
-}
-
-@end
View
@@ -29,7 +29,6 @@
#import "TUICGAdditions.h"
#import "TUIColor.h"
#import "TUIFastIndexPath.h"
-#import "TUIFont.h"
#import "TUIHostView.h"
#import "TUIImage.h"
#import "TUIImageView.h"
View
@@ -30,7 +30,7 @@
} _textLabelFlags;
NSString *_text;
- TUIFont *_font;
+ NSFont *_font;
TUIColor *_textColor;
TUITextAlignment _alignment;
TUILineBreakMode _lineBreakMode;
@@ -41,7 +41,7 @@
@property(nonatomic,getter=isSelectable) BOOL selectable;
@property(nonatomic, readonly) TUITextRenderer *renderer;
-@property(nonatomic,strong) TUIFont *font;
+@property(nonatomic,strong) NSFont *font;
@property(nonatomic,strong) TUIColor *textColor;
@property(nonatomic,assign) TUITextAlignment alignment;
@property(nonatomic, assign) TUILineBreakMode lineBreakMode;
View
@@ -16,7 +16,6 @@
#import "TUILabel.h"
#import "TUIColor.h"
-#import "TUIFont.h"
#import "TUINSView.h"
#import "TUIStringDrawing.h"
#import "TUITextRenderer.h"
@@ -130,7 +129,7 @@ - (void)setText:(NSString *)text
self.attributedString = nil;
}
-- (void)setFont:(TUIFont *)font
+- (void)setFont:(NSFont *)font
{
if(font == _font) return;
Oops, something went wrong.

0 comments on commit 903908e

Please sign in to comment.