Browse files

Fall back to the system font if TUITextView.font is set to nil

  • Loading branch information...
1 parent af7c8b5 commit eec844a9e26ecca75f952fd5f4a44bfa68cdf82e Justin Spahr-Summers committed Jul 26, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/UIKit/TUITextView.m
View
12 lib/UIKit/TUITextView.m
@@ -82,6 +82,12 @@ @implementation TUITextView
@synthesize autocorrectedResults;
@synthesize placeholderRenderer;
+- (NSFont *)font {
+ // Fall back to the system font if none (or an invalid one) was set.
+ // Otherwise, text rendering becomes dog slow.
+ return font ?: [NSFont systemFontOfSize:[NSFont systemFontSize]];
+}
+
- (void)dealloc {
renderer.delegate = nil;
}
@@ -94,15 +100,13 @@ - (void)_updateDefaultAttributes
[attributes setObject:(__bridge id)self.textColor.CGColor forKey:(__bridge id)kCTForegroundColorAttributeName];
}
- if (self.font != nil) {
- [attributes setObject:self.font forKey:(__bridge id)kCTFontAttributeName];
- }
-
NSParagraphStyle *style = ABNSParagraphStyleForTextAlignment(textAlignment);
if (style != nil) {
[attributes setObject:style forKey:NSParagraphStyleAttributeName];
}
+ [attributes setObject:self.font forKey:(__bridge id)kCTFontAttributeName];
+
renderer.defaultAttributes = attributes;
renderer.markedAttributes = attributes;
}

0 comments on commit eec844a

Please sign in to comment.