Skip to content

Commit

Permalink
Powerline glyphs being cut for narrow fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov authored and chrisduerr committed Jan 6, 2024
1 parent 652278d commit cd95456
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 14 additions & 4 deletions alacritty/src/renderer/text/builtin_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand All @@ -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));

Expand Down Expand Up @@ -555,15 +565,15 @@ 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,
height: height as i32,
width: width as i32,
buffer,
advance: (width as i32, height as i32),
}
})
}

#[repr(packed)]
Expand Down

0 comments on commit cd95456

Please sign in to comment.