Skip to content

Commit b7b9d27

Browse files
authored
Merge pull request #5001 from Tyriar/powerline_nf
Don't rescale powerline or nerd fonts
2 parents 44feecf + 6b3d485 commit b7b9d27

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

src/browser/renderer/shared/RendererUtils.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,40 @@ export function isRestrictedPowerlineGlyph(codepoint: number): boolean {
2323
return 0xE0B0 <= codepoint && codepoint <= 0xE0B7;
2424
}
2525

26+
function isNerdFontGlyph(codepoint: number): boolean {
27+
return 0xE000 <= codepoint && codepoint <= 0xF8FF;
28+
}
29+
2630
function isBoxOrBlockGlyph(codepoint: number): boolean {
2731
return 0x2500 <= codepoint && codepoint <= 0x259F;
2832
}
2933

3034
export function isEmoji(codepoint: number): boolean {
3135
return (
3236
codepoint >= 0x1F600 && codepoint <= 0x1F64F || // Emoticons
33-
codepoint >= 0x1F300 && codepoint <= 0x1F5FF || // Misc Symbols and Pictographs
34-
codepoint >= 0x1F680 && codepoint <= 0x1F6FF || // Transport and Map
35-
codepoint >= 0x2600 && codepoint <= 0x26FF || // Misc symbols
36-
codepoint >= 0x2700 && codepoint <= 0x27BF || // Dingbats
37-
codepoint >= 0xFE00 && codepoint <= 0xFE0F || // Variation Selectors
38-
codepoint >= 0x1F900 && codepoint <= 0x1F9FF || // Supplemental Symbols and Pictographs
37+
codepoint >= 0x1F300 && codepoint <= 0x1F5FF || // Misc Symbols and Pictographs
38+
codepoint >= 0x1F680 && codepoint <= 0x1F6FF || // Transport and Map
39+
codepoint >= 0x2600 && codepoint <= 0x26FF || // Misc symbols
40+
codepoint >= 0x2700 && codepoint <= 0x27BF || // Dingbats
41+
codepoint >= 0xFE00 && codepoint <= 0xFE0F || // Variation Selectors
42+
codepoint >= 0x1F900 && codepoint <= 0x1F9FF || // Supplemental Symbols and Pictographs
3943
codepoint >= 0x1F1E6 && codepoint <= 0x1F1FF
4044
);
4145
}
4246

47+
export function allowRescaling(codepoint: number | undefined, width: number, glyphSizeX: number, deviceCellWidth: number): boolean {
48+
return (
49+
// Is single cell width
50+
width === 1 &&
51+
// Glyph exceeds cell bounds, + 1 to avoid hurting readability
52+
glyphSizeX > deviceCellWidth + 1 &&
53+
// Never rescale emoji
54+
codepoint !== undefined && !isEmoji(codepoint) &&
55+
// Never rescale powerline or nerd fonts
56+
!isPowerlineGlyph(codepoint) && !isNerdFontGlyph(codepoint)
57+
);
58+
}
59+
4360
export function treatGlyphAsBackgroundColor(codepoint: number): boolean {
4461
return isPowerlineGlyph(codepoint) || isBoxOrBlockGlyph(codepoint);
4562
}

typings/xterm-headless.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ declare module '@xterm/headless' {
144144
* Whether to rescale glyphs horizontally that are a single cell wide but
145145
* have glyphs that would overlap following cell(s). This typically happens
146146
* for ambiguous width characters (eg. the roman numeral characters U+2160+)
147-
* which aren't featured in monospace fonts. Emoji glyphs are never
148-
* rescaled. This is an important feature for achieving GB18030 compliance.
147+
* which aren't featured in monospace fonts. This is an important feature
148+
* for achieving GB18030 compliance.
149+
*
150+
* The following glyphs will never be rescaled:
151+
*
152+
* - Emoji glyphs
153+
* - Powerline glyphs
154+
* - Nerd font glyphs
149155
*
150156
* Note that this doesn't work with the DOM renderer. The default is false.
151157
*/

typings/xterm.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,14 @@ declare module '@xterm/xterm' {
213213
* Whether to rescale glyphs horizontally that are a single cell wide but
214214
* have glyphs that would overlap following cell(s). This typically happens
215215
* for ambiguous width characters (eg. the roman numeral characters U+2160+)
216-
* which aren't featured in monospace fonts. Emoji glyphs are never
217-
* rescaled. This is an important feature for achieving GB18030 compliance.
216+
* which aren't featured in monospace fonts. This is an important feature
217+
* for achieving GB18030 compliance.
218+
*
219+
* The following glyphs will never be rescaled:
220+
*
221+
* - Emoji glyphs
222+
* - Powerline glyphs
223+
* - Nerd font glyphs
218224
*
219225
* Note that this doesn't work with the DOM renderer. The default is false.
220226
*/

0 commit comments

Comments
 (0)