Skip to content

Commit 2e6bad8

Browse files
committed
added non-exact font matching
1 parent 124be7f commit 2e6bad8

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

App/BitBar/Plugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
- (BOOL) refresh;
4242
- (void) cycleLines;
4343
- (void) contentHasChanged;
44-
- (BOOL) isFontValid:(NSString *)fontName;
4544

4645
// actions
4746
- (void)changePluginsDirectorySelected:(id)sender;

App/BitBar/Plugin.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ - (NSAttributedString*) attributedTitleWithParams:(NSDictionary *)params {
161161
NSString * title = truncLength < titleLength ? [[fullTitle substringToIndex:truncLength] stringByAppendingString:@""] : fullTitle;
162162

163163
CGFloat size = params[@"size"] ? [params[@"size"] floatValue] : 14;
164-
NSFont * font = ([self isFontValid:params[@"font"]] ? [NSFont fontWithName:params[@"font"] size:size]
165-
: nil)
164+
NSFont * font = [self validFont:params[@"font"] size:size]
166165
?: [NSFont respondsToSelector:@selector(monospacedDigitSystemFontOfSize:weight:)]
167166
? [NSFont monospacedDigitSystemFontOfSize:size weight:NSFontWeightRegular]
168167
: [NSFont menuFontOfSize:size];
@@ -494,15 +493,13 @@ - (void) contentHasChanged {
494493
_allContentLines = nil;
495494
}
496495

497-
- (BOOL) isFontValid:(NSString *)fontName {
498-
if (fontName == nil) {
499-
return NO;
500-
}
496+
- (NSFont *)validFont:(NSString *)fontName size:(CGFloat)size {
497+
if (!fontName) return nil;
501498

502-
NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontNameAttribute:fontName}];
503-
NSArray *matches = [fontDescriptor matchingFontDescriptorsWithMandatoryKeys: nil];
499+
NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:@{NSFontNameAttribute : fontName}];
500+
NSFontDescriptor *match = [fontDescriptor matchingFontDescriptorWithMandatoryKeys:nil];
504501

505-
return ([matches count] > 0);
502+
return match ? [NSFont fontWithDescriptor:match size:size] : nil;
506503
}
507504

508505
- (void) setContent:(NSString *)content {

0 commit comments

Comments
 (0)