Skip to content

Commit

Permalink
Limit font replacement to Emoji only
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Apr 5, 2021
1 parent 6edcd56 commit 4375a9f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ void convertToVerticalGlyph(NSMutableAttributedString *originalText, NSRange str
}
}

void fixDefaultFont(NSMutableAttributedString *text, NSSet<NSFont *> *fonts) {
void fixDefaultFont(NSMutableAttributedString *text) {
[text fixFontAttributeInRange:NSMakeRange(0, text.length)];
NSRange currentFontRange = NSMakeRange(NSNotFound, 0);
long i = 0;
while (i < text.length) {
NSFont *charFont = [text attributesAtIndex:i effectiveRange:&currentFontRange][NSFontAttributeName];
if (![fonts containsObject:charFont]) {
NSFont *charFont = [text attribute:NSFontAttributeName atIndex:i effectiveRange:&currentFontRange];
if ([charFont.fontName isEqualToString:@"AppleColorEmoji"]) {
NSFont *defaultFont = [NSFont systemFontOfSize:charFont.pointSize];
[text addAttribute:NSFontAttributeName value:defaultFont range:currentFontRange];
}
Expand Down Expand Up @@ -1156,11 +1156,7 @@ - (void)showPreedit:(NSString *)preedit
}

// Fix font rendering
fixDefaultFont(text, [NSSet setWithArray:@[
theme.attrs[NSFontAttributeName],
theme.labelAttrs[NSFontAttributeName],
theme.commentAttrs[NSFontAttributeName]
]]);
fixDefaultFont(text);

// text done!
[_view setText:text];
Expand Down

0 comments on commit 4375a9f

Please sign in to comment.