diff --git a/ExampleProject/ConcordeExample/ExampleView.h b/ExampleProject/ConcordeExample/ExampleView.h index 021d9b3..1b0a3a2 100644 --- a/ExampleProject/ConcordeExample/ExampleView.h +++ b/ExampleProject/ConcordeExample/ExampleView.h @@ -22,8 +22,8 @@ TUITableView *_tableView; ExampleTabBar *_tabBar; - TUIFont *exampleFont1; - TUIFont *exampleFont2; + NSFont *exampleFont1; + NSFont *exampleFont2; } @end diff --git a/ExampleProject/ConcordeExample/ExampleView.m b/ExampleProject/ConcordeExample/ExampleView.m index af62b82..fd49b0e 100644 --- a/ExampleProject/ConcordeExample/ExampleView.m +++ b/ExampleProject/ConcordeExample/ExampleView.m @@ -28,8 +28,8 @@ 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; diff --git a/TwUI.xcodeproj/project.pbxproj b/TwUI.xcodeproj/project.pbxproj index f9522a9..319f81d 100644 --- a/TwUI.xcodeproj/project.pbxproj +++ b/TwUI.xcodeproj/project.pbxproj @@ -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 */; }; 5EE983CE13BE7834005F430D /* TUIImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5913BE6E1900C85CB5 /* TUIImageView.m */; }; 5EE983CF13BE7834005F430D /* TUILabel.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5D13BE6E1900C85CB5 /* TUILabel.m */; }; @@ -145,7 +144,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 */; }; CB5E323713BE70CA004B7899 /* TUIImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5913BE6E1900C85CB5 /* TUIImageView.m */; }; CB5E323913BE70CA004B7899 /* TUIKit.m in Sources */ = {isa = PBXBuildFile; fileRef = CBB74C5B13BE6E1900C85CB5 /* TUIKit.m */; }; @@ -201,8 +199,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 */; }; CBB74CAF13BE6E1900C85CB5 /* TUIImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = CBB74C5813BE6E1900C85CB5 /* TUIImageView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -274,9 +270,6 @@ D039724B15B7D7DE0092CD26 /* TUILayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E7D15B7769A007F9EE3 /* TUILayoutConstraint.h */; }; D04007EB15BF2BC000FD49DB /* libExpecta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D04007CD15BF2BB000FD49DB /* libExpecta.a */; }; D04007EC15BF2BC000FD49DB /* libSpecta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D04007E015BF2BB300FD49DB /* libSpecta.a */; }; - D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; }; - D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; }; - D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D040610915B6A77500F753ED /* TUIAnimationManager.m */; }; D040611615B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; }; D040611715B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; }; D040611815B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */; }; @@ -505,8 +498,6 @@ CBB74C4D13BE6E1900C85CB5 /* TUIControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIControl.m; sourceTree = ""; }; CBB74C4E13BE6E1900C85CB5 /* TUIFastIndexPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIFastIndexPath.h; sourceTree = ""; }; CBB74C4F13BE6E1900C85CB5 /* TUIFastIndexPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIFastIndexPath.m; sourceTree = ""; }; - CBB74C5013BE6E1900C85CB5 /* TUIFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIFont.h; sourceTree = ""; }; - CBB74C5113BE6E1900C85CB5 /* TUIFont.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIFont.m; sourceTree = ""; }; CBB74C5213BE6E1900C85CB5 /* TUIGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIGeometry.h; sourceTree = ""; }; CBB74C5313BE6E1900C85CB5 /* TUIGeometry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIGeometry.m; sourceTree = ""; }; CBB74C5813BE6E1900C85CB5 /* TUIImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIImageView.h; sourceTree = ""; }; @@ -568,8 +559,6 @@ D04007C215BF2BAF00FD49DB /* Expecta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Expecta.xcodeproj; path = expecta/Expecta.xcodeproj; sourceTree = ""; }; D04007D515BF2BB300FD49DB /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = specta/Specta.xcodeproj; sourceTree = ""; }; D04007ED15BF2C0700FD49DB /* TwUITests-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TwUITests-Prefix.pch"; sourceTree = ""; }; - D040610815B6A77500F753ED /* TUIAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUIAnimationManager.h; sourceTree = ""; }; - D040610915B6A77500F753ED /* TUIAnimationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TUIAnimationManager.m; sourceTree = ""; }; D040611115B6A7CC00F753ED /* NSTextView+TUIExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTextView+TUIExtensions.h"; sourceTree = ""; }; D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTextView+TUIExtensions.m"; sourceTree = ""; }; D05D239E15BF7239000ED14F /* NSImage+TUIExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+TUIExtensions.h"; sourceTree = ""; }; @@ -756,8 +745,6 @@ D0C7652315B6232100E7AC2C /* CATransaction+TUIExtensions.m */, D040611115B6A7CC00F753ED /* NSTextView+TUIExtensions.h */, D040611215B6A7CC00F753ED /* NSTextView+TUIExtensions.m */, - D040610815B6A77500F753ED /* TUIAnimationManager.h */, - D040610915B6A77500F753ED /* TUIAnimationManager.m */, D0C7656F15B6341800E7AC2C /* TUICAAction.h */, D0C7657015B6341800E7AC2C /* TUICAAction.m */, ); @@ -802,8 +789,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 */, @@ -974,7 +959,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 */, 88D81CFF1577EF0D009D453B /* TUIStyledView.h in Headers */, CBB74CAF13BE6E1900C85CB5 /* TUIImageView.h in Headers */, @@ -1290,7 +1274,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 */, 5EE983CE13BE7834005F430D /* TUIImageView.m in Sources */, 5EE983CF13BE7834005F430D /* TUILabel.m in Sources */, @@ -1338,7 +1321,6 @@ D0C7656215B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */, D0C7656815B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */, D0C7657615B6341800E7AC2C /* TUICAAction.m in Sources */, - D040610F15B6A77500F753ED /* TUIAnimationManager.m in Sources */, D040611815B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */, D039724115B7D7CC0092CD26 /* TUILayoutConstraint.m in Sources */, D039724315B7D7CE0092CD26 /* TUILayoutManager.m in Sources */, @@ -1365,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 */, CBB74CB013BE6E1900C85CB5 /* TUIImageView.m in Sources */, CBB74CB213BE6E1900C85CB5 /* TUIKit.m in Sources */, @@ -1417,7 +1398,6 @@ D0C7656015B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */, D0C7656615B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */, D0C7657415B6341800E7AC2C /* TUICAAction.m in Sources */, - D040610D15B6A77500F753ED /* TUIAnimationManager.m in Sources */, D040611615B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */, 48A10E8215B7769A007F9EE3 /* TUILayoutConstraint.m in Sources */, 48A10E8415B7769A007F9EE3 /* TUILayoutManager.m in Sources */, @@ -1453,7 +1433,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 */, CB5E323713BE70CA004B7899 /* TUIImageView.m in Sources */, CB5E323913BE70CA004B7899 /* TUIKit.m in Sources */, @@ -1502,7 +1481,6 @@ D0C7656115B6297300E7AC2C /* NSClipView+TUIExtensions.m in Sources */, D0C7656715B6297300E7AC2C /* NSScrollView+TUIExtensions.m in Sources */, D0C7657515B6341800E7AC2C /* TUICAAction.m in Sources */, - D040610E15B6A77500F753ED /* TUIAnimationManager.m in Sources */, D040611715B6A7CD00F753ED /* NSTextView+TUIExtensions.m in Sources */, D039723F15B7D7CB0092CD26 /* TUILayoutConstraint.m in Sources */, D039724215B7D7CE0092CD26 /* TUILayoutManager.m in Sources */, diff --git a/lib/Support/TUIAnimationManager.h b/lib/Support/TUIAnimationManager.h deleted file mode 100644 index bc9ab54..0000000 --- a/lib/Support/TUIAnimationManager.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// TUIAnimationManager.h -// -// Created by Justin Spahr-Summers on 10.03.12. -// Copyright (c) 2012 Bitswift. All rights reserved. -// - -#import - -/** - * This private class is responsible for disabling implicit NSView animations. - * - * This class may be expanded in the future to add other global animation - * capabilities. - */ -@interface TUIAnimationManager : NSObject - -/* - * Returns the singleton instance of this class. - */ -+ (TUIAnimationManager *)defaultManager; - -@end diff --git a/lib/Support/TUIAnimationManager.m b/lib/Support/TUIAnimationManager.m deleted file mode 100644 index cf1ad1f..0000000 --- a/lib/Support/TUIAnimationManager.m +++ /dev/null @@ -1,114 +0,0 @@ -// -// TUIAnimationManager.m -// -// Created by Justin Spahr-Summers on 10.03.12. -// Copyright (c) 2012 Bitswift. All rights reserved. -// - -#import "TUIAnimationManager.h" - -/** - * Disables implicit AppKit animations on every run loop iteration. - */ -static void mainRunLoopObserverCallback (CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) { - [[NSAnimationContext currentContext] setDuration:0]; -} - -@interface TUIAnimationManager () -/** - * The observer associated with the main run loop, responsible for invoking the - * mainRunLoopObserverCallback. - */ -@property (nonatomic) CFRunLoopObserverRef mainRunLoopObserver; - -/** - * Invoked on the defaultManager when the application has finished launching. - */ -- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification; - -/** - * Registers an observer on the main run loop which will invoke the - * mainRunLoopObserverCallback. - */ -- (void)registerRunLoopObserver; -@end - -@implementation TUIAnimationManager - -#pragma mark Properties - -@synthesize mainRunLoopObserver = m_mainRunLoopObserver; - -- (void)setMainRunLoopObserver:(CFRunLoopObserverRef)observer { - if (observer == m_mainRunLoopObserver) - return; - - if (m_mainRunLoopObserver) { - CFRunLoopRemoveObserver(CFRunLoopGetMain(), m_mainRunLoopObserver, kCFRunLoopCommonModes); - CFRelease(m_mainRunLoopObserver); - } - - if (observer) - CFRetain(observer); - - m_mainRunLoopObserver = observer; -} - -#pragma mark Lifecycle - -+ (void)load { - @autoreleasepool { - [[NSNotificationCenter defaultCenter] - addObserver:[self defaultManager] - selector:@selector(applicationDidFinishLaunchingNotification:) - name:NSApplicationDidFinishLaunchingNotification - object:nil - ]; - } -} - -+ (TUIAnimationManager *)defaultManager; { - static id singleton = nil; - static dispatch_once_t pred; - - dispatch_once(&pred, ^{ - singleton = [[self alloc] init]; - }); - - return singleton; -} - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - self.mainRunLoopObserver = NULL; -} - -#pragma mark Run Loop Observer - -- (void)registerRunLoopObserver; { - // set up an observer on the main run loop that can disable implicit - // animations - CFRunLoopObserverRef observer = CFRunLoopObserverCreate( - NULL, - kCFRunLoopBeforeTimers, - YES, - 10000, - &mainRunLoopObserverCallback, - NULL - ); - - CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes); - - self.mainRunLoopObserver = observer; - CFRelease(observer); -} - -#pragma mark Notifications - -- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification; { - [[NSNotificationCenter defaultCenter] removeObserver:self name:notification.name object:nil]; - [self registerRunLoopObserver]; -} - -@end diff --git a/lib/UIKit/TUIAttributedString.h b/lib/UIKit/TUIAttributedString.h index 037c916..845c0c9 100644 --- a/lib/UIKit/TUIAttributedString.h +++ b/lib/UIKit/TUIAttributedString.h @@ -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; diff --git a/lib/UIKit/TUIAttributedString.m b/lib/UIKit/TUIAttributedString.m index 180af1b..c212984 100644 --- a/lib/UIKit/TUIAttributedString.m +++ b/lib/UIKit/TUIAttributedString.m @@ -15,7 +15,6 @@ */ #import "TUIAttributedString.h" -#import "TUIFont.h" #import "TUIColor.h" NSString * const TUIAttributedStringBackgroundColorAttributeName = @"TUIAttributedStringBackgroundColorAttributeName"; @@ -38,9 +37,10 @@ NSString * const TUIAttributedStringPreDrawBlockName = @"TUIAttributedStringPreD 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 @@ NSString * const TUIAttributedStringPreDrawBlockName = @"TUIAttributedStringPreD [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 @@ NSParagraphStyle *ABNSParagraphStyleForTextAlignment(TUITextAlignment alignment) [self setAlignment:alignment lineBreakMode:TUILineBreakModeWordWrap]; } -- (TUIFont *)font +- (NSFont *)font { return nil; } diff --git a/lib/UIKit/TUIFont.h b/lib/UIKit/TUIFont.h deleted file mode 100644 index 101b5ee..0000000 --- a/lib/UIKit/TUIFont.h +++ /dev/null @@ -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 - -/* - 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 diff --git a/lib/UIKit/TUIFont.m b/lib/UIKit/TUIFont.m deleted file mode 100644 index 9afc85d..0000000 --- a/lib/UIKit/TUIFont.m +++ /dev/null @@ -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 diff --git a/lib/UIKit/TUIKit.h b/lib/UIKit/TUIKit.h index 04c0b4f..b2cc56b 100644 --- a/lib/UIKit/TUIKit.h +++ b/lib/UIKit/TUIKit.h @@ -30,7 +30,6 @@ #import "TUICGAdditions.h" #import "TUIColor.h" #import "TUIFastIndexPath.h" -#import "TUIFont.h" #import "TUIHostView.h" #import "TUIImageView.h" #import "TUILabel.h" diff --git a/lib/UIKit/TUILabel.h b/lib/UIKit/TUILabel.h index 16f45b5..8e4d29a 100644 --- a/lib/UIKit/TUILabel.h +++ b/lib/UIKit/TUILabel.h @@ -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; diff --git a/lib/UIKit/TUILabel.m b/lib/UIKit/TUILabel.m index af001ee..d3dbd81 100644 --- a/lib/UIKit/TUILabel.m +++ b/lib/UIKit/TUILabel.m @@ -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 @@ self.attributedString = nil; } -- (void)setFont:(TUIFont *)font +- (void)setFont:(NSFont *)font { if(font == _font) return; diff --git a/lib/UIKit/TUINSView.m b/lib/UIKit/TUINSView.m index 2b94a7a..15229c5 100644 --- a/lib/UIKit/TUINSView.m +++ b/lib/UIKit/TUINSView.m @@ -263,6 +263,8 @@ static NSComparisonResult compareNSViewOrdering (NSView *viewA, NSView *viewB, v [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidChangeScreenProfileNotification object:self.window]; } + [self.tuiHostView removeFromSuperview]; + CALayer *hostLayer = self.tuiHostView.layer; if(newWindow != nil && _rootView.layer.superlayer != hostLayer) { _rootView.layer.frame = hostLayer.bounds; @@ -290,6 +292,8 @@ static NSComparisonResult compareNSViewOrdering (NSView *viewA, NSView *viewB, v [self.window setDisplaysWhenScreenProfileChanges:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenProfileOrBackingPropertiesDidChange:) name:NSWindowDidChangeScreenProfileNotification object:self.window]; } + + [self addSubview:self.tuiHostView positioned:NSWindowBelow relativeTo:self.appKitHostView]; } - (void)_updateLayerScaleFactor { diff --git a/lib/UIKit/TUIProgressBar.m b/lib/UIKit/TUIProgressBar.m index 4a39166..12ac7f9 100644 --- a/lib/UIKit/TUIProgressBar.m +++ b/lib/UIKit/TUIProgressBar.m @@ -191,10 +191,10 @@ void GHUIProgressPatternDrawCallback(void *info, CGContextRef context); - (void)dealloc { - [self removeObserver:self forKeyPath:@"drawTrack" context:&GHUIProgressBarSetNeedsDisplayObservationContext]; - [self removeObserver:self forKeyPath:@"drawFill" context:&GHUIProgressBarSetNeedsDisplayObservationContext]; - [self removeObserver:self forKeyPath:@"progress" context:&GHUIProgressBarSetNeedsDisplayObservationContext]; - [self removeObserver:self forKeyPath:@"indeterminate" context:&GHUIProgressBarSetNeedsDisplayObservationContext]; + [self removeObserver:self forKeyPath:@"drawTrack"]; + [self removeObserver:self forKeyPath:@"drawFill"]; + [self removeObserver:self forKeyPath:@"progress"]; + [self removeObserver:self forKeyPath:@"indeterminate"]; } - (void)drawRect:(CGRect)dirtyRect { diff --git a/lib/UIKit/TUIStringDrawing.h b/lib/UIKit/TUIStringDrawing.h index f3fa61b..773c54a 100644 --- a/lib/UIKit/TUIStringDrawing.h +++ b/lib/UIKit/TUIStringDrawing.h @@ -17,7 +17,7 @@ #import #import "TUIAttributedString.h" -@class TUIFont; +@class NSFont; @class TUIColor; @interface NSAttributedString (TUIStringDrawing) @@ -33,15 +33,15 @@ @interface NSString (TUIStringDrawing) -- (CGSize)ab_sizeWithFont:(TUIFont *)font; -- (CGSize)ab_sizeWithFont:(TUIFont *)font constrainedToSize:(CGSize)size; +- (CGSize)ab_sizeWithFont:(NSFont *)font; +- (CGSize)ab_sizeWithFont:(NSFont *)font constrainedToSize:(CGSize)size; #if TARGET_OS_MAC // for ABRowView -//- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment; +//- (CGSize)drawInRect:(CGRect)rect withFont:(NSFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment; #endif -- (CGSize)ab_drawInRect:(CGRect)rect color:(TUIColor *)color font:(TUIFont *)font; -- (CGSize)ab_drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment; +- (CGSize)ab_drawInRect:(CGRect)rect color:(TUIColor *)color font:(NSFont *)font; +- (CGSize)ab_drawInRect:(CGRect)rect withFont:(NSFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment; @end diff --git a/lib/UIKit/TUIStringDrawing.m b/lib/UIKit/TUIStringDrawing.m index 1a2c7d6..f0811a8 100644 --- a/lib/UIKit/TUIStringDrawing.m +++ b/lib/UIKit/TUIStringDrawing.m @@ -17,7 +17,6 @@ #import "TUIAttributedString.h" #import "TUICGAdditions.h" #import "TUIColor.h" -#import "TUIFont.h" #import "TUIStringDrawing.h" #import "TUITextRenderer.h" @@ -69,28 +68,28 @@ #if TARGET_OS_MAC -- (CGSize)ab_sizeWithFont:(TUIFont *)font +- (CGSize)ab_sizeWithFont:(NSFont *)font { TUIAttributedString *s = [TUIAttributedString stringWithString:self]; s.font = font; return [s ab_size]; } -- (CGSize)ab_sizeWithFont:(TUIFont *)font constrainedToSize:(CGSize)size +- (CGSize)ab_sizeWithFont:(NSFont *)font constrainedToSize:(CGSize)size { TUIAttributedString *s = [TUIAttributedString stringWithString:self]; s.font = font; return [s ab_sizeConstrainedToSize:size]; } -//- (CGSize)drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment +//- (CGSize)drawInRect:(CGRect)rect withFont:(NSFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment //{ // return [self ab_drawInRect:rect withFont:font lineBreakMode:lineBreakMode alignment:alignment]; //} #endif -- (CGSize)ab_drawInRect:(CGRect)rect color:(TUIColor *)color font:(TUIFont *)font +- (CGSize)ab_drawInRect:(CGRect)rect color:(TUIColor *)color font:(NSFont *)font { TUIAttributedString *s = [TUIAttributedString stringWithString:self]; s.color = color; @@ -98,7 +97,7 @@ return [s ab_drawInRect:rect]; } -- (CGSize)ab_drawInRect:(CGRect)rect withFont:(TUIFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment +- (CGSize)ab_drawInRect:(CGRect)rect withFont:(NSFont *)font lineBreakMode:(TUILineBreakMode)lineBreakMode alignment:(TUITextAlignment)alignment { TUIAttributedString *s = [TUIAttributedString stringWithString:self]; [s addAttribute:(NSString *)kCTForegroundColorFromContextAttributeName diff --git a/lib/UIKit/TUITextRenderer.h b/lib/UIKit/TUITextRenderer.h index 9b847a3..f21df3f 100644 --- a/lib/UIKit/TUITextRenderer.h +++ b/lib/UIKit/TUITextRenderer.h @@ -17,8 +17,8 @@ #import "TUIResponder.h" #import "CoreText+Additions.h" +@class NSFont; @class TUIColor; -@class TUIFont; @class TUIView; @protocol ABActiveTextRange; diff --git a/lib/UIKit/TUITextRenderer.m b/lib/UIKit/TUITextRenderer.m index b1a9e4c..c33b191 100644 --- a/lib/UIKit/TUITextRenderer.m +++ b/lib/UIKit/TUITextRenderer.m @@ -19,7 +19,6 @@ #import "TUIAttributedString.h" #import "TUICGAdditions.h" #import "TUIColor.h" -#import "TUIFont.h" #import "TUIStringDrawing.h" #import "TUITextRenderer+Event.h" #import "TUIView.h" diff --git a/lib/UIKit/TUITextView.h b/lib/UIKit/TUITextView.h index bb9cead..fa05c3e 100644 --- a/lib/UIKit/TUITextView.h +++ b/lib/UIKit/TUITextView.h @@ -19,7 +19,7 @@ #import "TUIAttributedString.h" @class TUITextEditor; -@class TUIFont; +@class NSFont; @class TUIColor; @protocol TUITextViewDelegate; @@ -32,7 +32,7 @@ NSString *placeholder; TUITextRenderer *placeholderRenderer; - TUIFont *font; + NSFont *font; TUIColor *textColor; TUITextAlignment textAlignment; BOOL editable; @@ -67,7 +67,7 @@ @property (nonatomic, copy) NSString *text; @property (nonatomic, copy) NSString *placeholder; -@property (nonatomic, strong) TUIFont *font; +@property (nonatomic, strong) NSFont *font; @property (nonatomic, strong) TUIColor *textColor; @property (nonatomic, assign) TUITextAlignment textAlignment; @property (nonatomic, assign) TUIEdgeInsets contentInset; diff --git a/lib/UIKit/TUITextView.m b/lib/UIKit/TUITextView.m index 3cdbf7e..33a479c 100644 --- a/lib/UIKit/TUITextView.m +++ b/lib/UIKit/TUITextView.m @@ -17,7 +17,6 @@ #import "TUITextView.h" #import "TUICGAdditions.h" #import "TUIColor.h" -#import "TUIFont.h" #import "TUINSView.h" #import "TUINSWindow.h" #import "TUITextViewEditor.h" @@ -90,12 +89,12 @@ - (void)_updateDefaultAttributes { renderer.defaultAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - (id)[self.font ctFont], kCTFontAttributeName, + self.font, kCTFontAttributeName, [self.textColor CGColor], kCTForegroundColorAttributeName, ABNSParagraphStyleForTextAlignment(textAlignment), NSParagraphStyleAttributeName, nil]; renderer.markedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - [NSFont fontWithName:self.font.fontName size:self.font.pointSize], kCTFontAttributeName, // NSFont and CTFont are toll-free bridged. *BUT* for reasons beyond my understanding, advanced input methods like Japanese and simplified Pinyin break unless this is an NSFont. So there we go. + self.font, kCTFontAttributeName, [self.textColor CGColor], kCTForegroundColorAttributeName, ABNSParagraphStyleForTextAlignment(textAlignment), NSParagraphStyleAttributeName, nil]; @@ -122,7 +121,7 @@ self.autocorrectedResults = [NSMutableDictionary dictionary]; - self.font = [TUIFont fontWithName:@"HelveticaNeue" size:12]; + self.font = [NSFont fontWithName:@"HelveticaNeue" size:12]; self.textColor = [TUIColor blackColor]; [self _updateDefaultAttributes]; @@ -166,7 +165,7 @@ return renderer.initialFirstResponder; } -- (void)setFont:(TUIFont *)f +- (void)setFont:(NSFont *)f { font = f; [self _updateDefaultAttributes]; @@ -323,7 +322,7 @@ static CAAnimation *ThrobAnimation() // Ugh. So this seems to be a decent approximation for the height of the cursor. It doesn't always match the native cursor but what ev. CGRect r = CGRectIntegral([renderer firstRectForCharacterRange:ABCFRangeFromNSRange(selection)]); r.size.width = 2.0f; - CGRect fontBoundingBox = CTFontGetBoundingBox(self.font.ctFont); + CGRect fontBoundingBox = CTFontGetBoundingBox((__bridge CTFontRef)self.font); r.size.height = round(fontBoundingBox.origin.y + fontBoundingBox.size.height); r.origin.y += floor(self.font.leading); //NSLog(@"ascent: %f, descent: %f, leading: %f, cap height: %f, x-height: %f, bounding: %@", self.font.ascender, self.font.descender, self.font.leading, self.font.capHeight, self.font.xHeight, NSStringFromRect(CTFontGetBoundingBox(self.font.ctFont))); diff --git a/lib/UIKit/TUITooltipWindow.m b/lib/UIKit/TUITooltipWindow.m index a5f5792..eb2bda8 100644 --- a/lib/UIKit/TUITooltipWindow.m +++ b/lib/UIKit/TUITooltipWindow.m @@ -17,7 +17,6 @@ #import "TUITooltipWindow.h" #import "TUIAttributedString.h" #import "TUICGAdditions.h" -#import "TUIFont.h" #import "TUIStringDrawing.h" #define TOOLTIP_HEIGHT 18 @@ -140,7 +139,7 @@ static BOOL ShowingTooltip = NO; } CurrentTooltipString = [TUIAttributedString stringWithString:s]; - CurrentTooltipString.font = [TUIFont fontWithName:@"HelveticaNeue" size:11]; + CurrentTooltipString.font = [NSFont fontWithName:@"HelveticaNeue" size:11]; CurrentTooltipString.kerning = 0.2; [CurrentTooltipString setAlignment:TUITextAlignmentCenter lineBreakMode:TUILineBreakModeClip]; } else {