From 22abb78c35e71f88766a8204856df5fee99080f7 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sun, 31 Dec 2023 00:12:41 +0400 Subject: [PATCH] Powerline glyphs being cut for narrow fonts Fixes #7470. --- CHANGELOG.md | 1 + alacritty/src/renderer/text/builtin_font.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0c9775..15a1da4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `chars = "\u000A"` action in bindings inserting `\n` - Alternate keys not sent for `Shift + ` when using kitty protocol - Alternative keys being swapped in kitty protocol implementation +- Powerline glyphs being cut for narrow fonts ## 0.13.0 diff --git a/alacritty/src/renderer/text/builtin_font.rs b/alacritty/src/renderer/text/builtin_font.rs index c3f843b6..f59616d5 100644 --- a/alacritty/src/renderer/text/builtin_font.rs +++ b/alacritty/src/renderer/text/builtin_font.rs @@ -32,7 +32,7 @@ pub fn builtin_glyph( '\u{2500}'..='\u{259f}' => box_drawing(character, metrics, offset), // Powerline symbols: '','','','' POWERLINE_TRIANGLE_LTR..=POWERLINE_ARROW_RTL => { - powerline_drawing(character, metrics, offset) + powerline_drawing(character, metrics, offset)? }, _ => return None, }; @@ -503,7 +503,11 @@ fn box_drawing(character: char, metrics: &Metrics, offset: &Delta) -> Raster } } -fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta) -> RasterizedGlyph { +fn powerline_drawing( + character: char, + metrics: &Metrics, + offset: &Delta, +) -> Option { let height = (metrics.line_height as i32 + offset.y as i32) as usize; let width = (metrics.average_advance as i32 + offset.x as i32) as usize; let extra_thickness = calculate_stroke_size(width) as i32 - 1; @@ -519,6 +523,12 @@ fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta) -> // x = (H - 2) / (2 * slope). let x_intersection = (height as i32 + 1) / 2 - 1; + // Don't use built-in font if we'd cut the tip too much, for example when the font is really + // narrow. + if x_intersection - width as i32 > 1 { + return None; + } + let top_line = (0..x_intersection).map(|x| line_equation(slope, x, top_y)); let bottom_line = (0..x_intersection).map(|x| line_equation(-slope, x, bottom_y)); @@ -555,7 +565,7 @@ fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta) -> let top = height as i32 + metrics.descent as i32; let buffer = BitmapBuffer::Rgb(canvas.into_raw()); - RasterizedGlyph { + Some(RasterizedGlyph { character, top, left: 0, @@ -563,7 +573,7 @@ fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta) -> width: width as i32, buffer, advance: (width as i32, height as i32), - } + }) } #[repr(packed)]