Add custom underline cursor
As mentioned in jwilm/alacritty#931, it can be troublesome if a font has an underline symbol outside of the glyph's bounding box. This can lead to the underline disappearing at the bottom of the terminal. As a solution a symbol from the private use area was used as the character code for the underline symbol. Whenever this symbol is encountered, instead of rendering it, a custom block is rendered. In this implementation the block has the full character as width and sits flush with the bottom of the glyph's bounding box. The height is half the distance between the baseline and the bottom of the bounding box.
This commit is contained in:
parent
958a32767f
commit
bf72b5a326
|
@ -294,6 +294,29 @@ impl FreeTypeRasterizer {
|
|||
|
||||
let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
|
||||
|
||||
// Render a custom symbol for the underline cursor
|
||||
if glyph_key.c == '' {
|
||||
// Get the bottom of the bounding box
|
||||
let size_metrics = face.ft_face.size_metrics()
|
||||
.ok_or(Error::MissingSizeMetrics)?;
|
||||
let descent = (size_metrics.descender / 64) as f32;
|
||||
|
||||
// Create a new rectangle, the height is half the distance between
|
||||
// bounding box bottom and the baseline
|
||||
let height = f32::abs(descent / 2.) as i32;
|
||||
let buf = vec![255u8; (pixel_width * height * 3) as usize];
|
||||
|
||||
// Create a custom glyph with the rectangle data attached to it
|
||||
return Ok(RasterizedGlyph {
|
||||
c: glyph_key.c,
|
||||
top: descent as i32 + height,
|
||||
left: glyph.bitmap_left(),
|
||||
height,
|
||||
width: pixel_width,
|
||||
buf: buf,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(RasterizedGlyph {
|
||||
c: glyph_key.c,
|
||||
top: glyph.bitmap_top(),
|
||||
|
|
|
@ -207,7 +207,8 @@ impl<'a> RenderableCellsIter<'a> {
|
|||
});
|
||||
|
||||
let cursor_color = self.text_cursor_color(&cursor_cell);
|
||||
cursor_cell.c = '▁';
|
||||
// This is part of the private use area and shouldn't be used by any font
|
||||
cursor_cell.c = '';
|
||||
cursor_cell.fg = cursor_color;
|
||||
self.cursor_cells.push_back(Indexed {
|
||||
line: self.cursor.line,
|
||||
|
|
Loading…
Reference in New Issue