Skip to content

Commit

Permalink
added +[NSFont tui_fontWithName:size:fallbackNames:]
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Jul 26, 2012
1 parent 608c042 commit a9a0919
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TwUI.xcodeproj/project.pbxproj
Expand Up @@ -95,6 +95,8 @@
886EBA8313D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
886EBA8413D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
886EBA8513D64393006DE018 /* TUIControl+Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 886EBA7E13D64393006DE018 /* TUIControl+Private.m */; };
887C227B15C1C7BB006EC31D /* NSFont+TUIExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 887C227915C1C7BB006EC31D /* NSFont+TUIExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
887C227C15C1C7BB006EC31D /* NSFont+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 887C227A15C1C7BB006EC31D /* NSFont+TUIExtensions.m */; };
887F272C13F9969800D75DE6 /* TUITableViewSectionHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 887F272A13F9969800D75DE6 /* TUITableViewSectionHeader.h */; settings = {ATTRIBUTES = (Public, ); }; };
887F272D13F9969800D75DE6 /* TUITableViewSectionHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 887F272A13F9969800D75DE6 /* TUITableViewSectionHeader.h */; };
887F272E13F9969800D75DE6 /* TUITableViewSectionHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 887F272A13F9969800D75DE6 /* TUITableViewSectionHeader.h */; };
Expand Down Expand Up @@ -443,6 +445,8 @@
884E8F5A1538809C000F7A8D /* CAAnimation+TUIExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CAAnimation+TUIExtensions.m"; sourceTree = "<group>"; };
886EBA7D13D64393006DE018 /* TUIControl+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUIControl+Private.h"; sourceTree = "<group>"; };
886EBA7E13D64393006DE018 /* TUIControl+Private.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TUIControl+Private.m"; sourceTree = "<group>"; };
887C227915C1C7BB006EC31D /* NSFont+TUIExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFont+TUIExtensions.h"; sourceTree = "<group>"; };
887C227A15C1C7BB006EC31D /* NSFont+TUIExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFont+TUIExtensions.m"; sourceTree = "<group>"; };
887F272A13F9969800D75DE6 /* TUITableViewSectionHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUITableViewSectionHeader.h; sourceTree = "<group>"; };
887F272B13F9969800D75DE6 /* TUITableViewSectionHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUITableViewSectionHeader.m; sourceTree = "<group>"; };
88A4AFDC145A16C90071CF22 /* TUITextRenderer+Accessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TUITextRenderer+Accessibility.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -743,6 +747,8 @@
D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */,
D0C7656F15B6341800E7AC2C /* TUICAAction.h */,
D0C7657015B6341800E7AC2C /* TUICAAction.m */,
887C227915C1C7BB006EC31D /* NSFont+TUIExtensions.h */,
887C227A15C1C7BB006EC31D /* NSFont+TUIExtensions.m */,
);
name = Support;
path = lib/Support;
Expand Down Expand Up @@ -957,6 +963,7 @@
CBB74CAB13BE6E1900C85CB5 /* TUIImage+Drawing.h in Headers */,
88D81CFF1577EF0D009D453B /* TUIStyledView.h in Headers */,
CBB74CAD13BE6E1900C85CB5 /* TUIImage.h in Headers */,
887C227B15C1C7BB006EC31D /* NSFont+TUIExtensions.h in Headers */,
CBB74CAF13BE6E1900C85CB5 /* TUIImageView.h in Headers */,
CBB74CB113BE6E1900C85CB5 /* TUIKit.h in Headers */,
CBB74CB313BE6E1900C85CB5 /* TUILabel.h in Headers */,
Expand Down Expand Up @@ -1397,6 +1404,7 @@
48A10E8415B7769A007F9EE3 /* TUILayoutManager.m in Sources */,
48A10E8915B778E8007F9EE3 /* TUIView+Layout.m in Sources */,
D07AA82915BDD79900F736C0 /* TUINSView+NSTextInputClient.m in Sources */,
887C227C15C1C7BB006EC31D /* NSFont+TUIExtensions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 18 additions & 0 deletions lib/Support/NSFont+TUIExtensions.h
@@ -0,0 +1,18 @@
//
// NSFont+TUIExtensions.h
// TwUI
//
// Created by Josh Abernathy on 7/26/12.
//
//

#import <Cocoa/Cocoa.h>


@interface NSFont (TUIExtensions)

// Creates and returns a new font with the given size and fallback font names.
// The fallback fonts all use the font size passed in.
+ (NSFont *)tui_fontWithName:(NSString *)fontName size:(CGFloat)fontSize fallbackNames:(NSArray *)fallbackNames;

@end
23 changes: 23 additions & 0 deletions lib/Support/NSFont+TUIExtensions.m
@@ -0,0 +1,23 @@
//
// NSFont+TUIExtensions.m
// TwUI
//
// Created by Josh Abernathy on 7/26/12.
//
//

#import "NSFont+TUIExtensions.h"


@implementation NSFont (TUIExtensions)

+ (NSFont *)tui_fontWithName:(NSString *)fontName size:(CGFloat)fontSize fallbackNames:(NSArray *)fallbackNames {
NSMutableArray *fallbackDescriptors = [NSMutableArray arrayWithCapacity:fallbackNames.count];
for(NSString *fallbackName in fallbackNames) {
[fallbackDescriptors addObject:[NSFontDescriptor fontDescriptorWithName:fallbackName size:fontSize]];
}

return [NSFont fontWithDescriptor:[NSFontDescriptor fontDescriptorWithFontAttributes:@{ NSFontNameAttribute: fontName, NSFontCascadeListAttribute: fallbackDescriptors }] size:fontSize];
}

@end
1 change: 1 addition & 0 deletions lib/UIKit/TUIKit.h
Expand Up @@ -57,5 +57,6 @@
#import "TUIView+TUIBridgedView.h"
#import "TUIViewController.h"
#import "TUIViewNSViewContainer.h"
#import "NSFont+TUIExtensions.h"

extern BOOL AtLeastLion; // set at launch

0 comments on commit a9a0919

Please sign in to comment.