From 48c6e96a78d4a4ba76f12786676b4e904ad8124d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:18:26 -0700 Subject: [PATCH 1/2] Don't rescale powerline or nerd fonts Part of #4969 --- src/browser/renderer/shared/RendererUtils.ts | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/browser/renderer/shared/RendererUtils.ts b/src/browser/renderer/shared/RendererUtils.ts index b9fc731241..f99c23a13b 100644 --- a/src/browser/renderer/shared/RendererUtils.ts +++ b/src/browser/renderer/shared/RendererUtils.ts @@ -23,6 +23,10 @@ export function isRestrictedPowerlineGlyph(codepoint: number): boolean { return 0xE0B0 <= codepoint && codepoint <= 0xE0B7; } +function isNerdFontGlyph(codepoint: number): boolean { + return 0xE000 <= codepoint && codepoint <= 0xF8FF; +} + function isBoxOrBlockGlyph(codepoint: number): boolean { return 0x2500 <= codepoint && codepoint <= 0x259F; } @@ -30,16 +34,29 @@ function isBoxOrBlockGlyph(codepoint: number): boolean { export function isEmoji(codepoint: number): boolean { return ( codepoint >= 0x1F600 && codepoint <= 0x1F64F || // Emoticons - codepoint >= 0x1F300 && codepoint <= 0x1F5FF || // Misc Symbols and Pictographs - codepoint >= 0x1F680 && codepoint <= 0x1F6FF || // Transport and Map - codepoint >= 0x2600 && codepoint <= 0x26FF || // Misc symbols - codepoint >= 0x2700 && codepoint <= 0x27BF || // Dingbats - codepoint >= 0xFE00 && codepoint <= 0xFE0F || // Variation Selectors - codepoint >= 0x1F900 && codepoint <= 0x1F9FF || // Supplemental Symbols and Pictographs + codepoint >= 0x1F300 && codepoint <= 0x1F5FF || // Misc Symbols and Pictographs + codepoint >= 0x1F680 && codepoint <= 0x1F6FF || // Transport and Map + codepoint >= 0x2600 && codepoint <= 0x26FF || // Misc symbols + codepoint >= 0x2700 && codepoint <= 0x27BF || // Dingbats + codepoint >= 0xFE00 && codepoint <= 0xFE0F || // Variation Selectors + codepoint >= 0x1F900 && codepoint <= 0x1F9FF || // Supplemental Symbols and Pictographs codepoint >= 0x1F1E6 && codepoint <= 0x1F1FF ); } +export function allowRescaling(codepoint: number | undefined, width: number, glyphSizeX: number, deviceCellWidth: number): boolean { + return ( + // Is single cell width + width === 1 && + // Glyph exceeds cell bounds, + 1 to avoid hurting readability + glyphSizeX > deviceCellWidth + 1 && + // Never rescale emoji + codepoint !== undefined && !isEmoji(codepoint) && + // Never rescale powerline or nerd fonts + !isPowerlineGlyph(codepoint) && !isNerdFontGlyph(codepoint) + ); +} + export function treatGlyphAsBackgroundColor(codepoint: number): boolean { return isPowerlineGlyph(codepoint) || isBoxOrBlockGlyph(codepoint); } From 6b3d485d774d96041afbfee13189f1b34950f1f7 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:30:55 -0700 Subject: [PATCH 2/2] Note new excluded glyphs in API --- typings/xterm-headless.d.ts | 10 ++++++++-- typings/xterm.d.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/typings/xterm-headless.d.ts b/typings/xterm-headless.d.ts index 9c1feaea72..5e84f266ff 100644 --- a/typings/xterm-headless.d.ts +++ b/typings/xterm-headless.d.ts @@ -144,8 +144,14 @@ declare module '@xterm/headless' { * Whether to rescale glyphs horizontally that are a single cell wide but * have glyphs that would overlap following cell(s). This typically happens * for ambiguous width characters (eg. the roman numeral characters U+2160+) - * which aren't featured in monospace fonts. Emoji glyphs are never - * rescaled. This is an important feature for achieving GB18030 compliance. + * which aren't featured in monospace fonts. This is an important feature + * for achieving GB18030 compliance. + * + * The following glyphs will never be rescaled: + * + * - Emoji glyphs + * - Powerline glyphs + * - Nerd font glyphs * * Note that this doesn't work with the DOM renderer. The default is false. */ diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index b4e01d84e4..330082890b 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -213,8 +213,14 @@ declare module '@xterm/xterm' { * Whether to rescale glyphs horizontally that are a single cell wide but * have glyphs that would overlap following cell(s). This typically happens * for ambiguous width characters (eg. the roman numeral characters U+2160+) - * which aren't featured in monospace fonts. Emoji glyphs are never - * rescaled. This is an important feature for achieving GB18030 compliance. + * which aren't featured in monospace fonts. This is an important feature + * for achieving GB18030 compliance. + * + * The following glyphs will never be rescaled: + * + * - Emoji glyphs + * - Powerline glyphs + * - Nerd font glyphs * * Note that this doesn't work with the DOM renderer. The default is false. */