Skip to content

Commit

Permalink
optimize fixDefaultFont code
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Apr 5, 2021
1 parent 3450416 commit 0d26585
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,10 @@ void fixDefaultFont(NSMutableAttributedString *text, NSSet<NSFont *> *fonts) {
NSRange currentFontRange = NSMakeRange(NSNotFound, 0);
long i = 0;
while (i < text.length) {
NSDictionary *charAttr = [text attributesAtIndex:i effectiveRange:&currentFontRange];
NSFont *charFont = charAttr[NSFontAttributeName];
NSFont *charFont = [text attributesAtIndex:i effectiveRange:&currentFontRange][NSFontAttributeName];
if (![fonts containsObject:charFont]) {
NSMutableDictionary *defaultAttributes = [charAttr mutableCopy];
NSFont *defaultFont = [NSFont systemFontOfSize:charFont.pointSize];
[defaultAttributes setValue:defaultFont forKey:NSFontAttributeName];
[text setAttributes:defaultAttributes range:currentFontRange];
[text addAttribute:NSFontAttributeName value:defaultFont range:currentFontRange];
}
i = currentFontRange.location + currentFontRange.length;
}
Expand Down

0 comments on commit 0d26585

Please sign in to comment.