Fix missing fonts by falling back to Menlo or the system font #2

Merged
merged 1 commit into from Jan 4, 2013
@@ -13,7 +13,7 @@ @implementation INOAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self.regexOptions setFloatingPanel:YES];
- NSFont * defaultFont = [NSFont fontWithName:@"Inconsolata" size:14.0];
+ NSFont * defaultFont = [self defaultFont];
[self.testText setFont:defaultFont];
[self.matchText setFont:defaultFont];
[self.regexField setFont:defaultFont];
@@ -33,7 +33,8 @@ - (IBAction)testExpression:(id)sender
NSRange testRange = NSMakeRange(0, [[[self.testText textStorage] string] length]);
NSMutableAttributedString * resultString = [[NSMutableAttributedString alloc] initWithString:[[self.testText textStorage] string]];
- NSFont * defaultFont = [NSFont fontWithName:@"Inconsolata" size:14.0];
+ NSFont * defaultFont = [self defaultFont];
+
[resultString addAttribute:NSFontAttributeName value:defaultFont range:NSMakeRange(0, [[[self.testText textStorage] string] length])];
defaultFont = nil;
@@ -64,4 +65,11 @@ - (IBAction)showReference:(id)sender {
[self.referenceWindow makeKeyAndOrderFront:sender];
}
+- (NSFont *)defaultFont {
+ NSFont *defaultFont = [NSFont fontWithName:@"Inconsolata" size:14.0f];
+ if (!defaultFont) defaultFont = [NSFont fontWithName:@"Menlo" size:14.0f];
+ if (!defaultFont) defaultFont = [NSFont systemFontOfSize:14.0f];
+ return defaultFont;
+}
+
@end