diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-12-31 00:12:41 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-31 00:12:41 +0400 |
commit | 2786683e0ebba6b58f7246ba0f2e4b0a6b9679b2 (patch) | |
tree | 891fda6992fa79e4f9cbb00c3346974e32c81454 | |
parent | c78c5f6cc057117c344331601e81c6f5778e4a4a (diff) | |
download | alacritty-2786683e0ebba6b58f7246ba0f2e4b0a6b9679b2.tar.gz alacritty-2786683e0ebba6b58f7246ba0f2e4b0a6b9679b2.zip |
Powerline glyphs being cut for narrow fonts
Fixes #7470.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/renderer/text/builtin_font.rs | 18 |
2 files changed, 15 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0f5ef3..16601355 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 + <number>` 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<i8>) -> Raster } } -fn powerline_drawing(character: char, metrics: &Metrics, offset: &Delta<i8>) -> RasterizedGlyph { +fn powerline_drawing( + character: char, + metrics: &Metrics, + offset: &Delta<i8>, +) -> Option<RasterizedGlyph> { 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<i8>) -> // 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<i8>) -> 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<i8>) -> width: width as i32, buffer, advance: (width as i32, height as i32), - } + }) } #[repr(packed)] |