mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Apply scaling to underline
Until now the underline position and thickness has been used without applying any scaling. However they are both specified in font units which do not change with the font size. To make sure the underline looks correct with every size of the font, the thickness and position are now scaled by the `x_scale` stored in the font metrics. This does not fix strikethrough yet, even though it looks significantly better, the implementation is still a hack. To make sure the underline doesn't disappear with small fonts, the minimum underline thickness has been set to `1`. This decision was made because the `Hack` font has an underline thickness under `0.5` with relatively big fonts. This edge-case can lead to some odd behavior when making the font size super tiny (smaller than readable) so just not rendering any underline might be a viable alternative.
This commit is contained in:
parent
fd984f36b7
commit
b818d6acdd
1 changed files with 7 additions and 2 deletions
|
@ -93,10 +93,15 @@ impl ::Rasterize for FreeTypeRasterizer {
|
||||||
|
|
||||||
let height = (full.size_metrics.height / 64) as f64;
|
let height = (full.size_metrics.height / 64) as f64;
|
||||||
let descent = (full.size_metrics.descender / 64) as f32;
|
let descent = (full.size_metrics.descender / 64) as f32;
|
||||||
|
|
||||||
|
// Get underline position and thickness in device pixels
|
||||||
|
let x_scale = full.size_metrics.x_scale as f32 / 65536.0;
|
||||||
let underline_position =
|
let underline_position =
|
||||||
(f32::from(face.ft_face.underline_position()) / 64.).round();
|
(f32::from(face.ft_face.underline_position()) * x_scale / 64.).round();
|
||||||
let underline_thickness =
|
let underline_thickness =
|
||||||
(f32::from(face.ft_face.underline_thickness()) / 64.).round();
|
(f32::from(face.ft_face.underline_thickness()) * x_scale / 64.)
|
||||||
|
.round()
|
||||||
|
.max(1.);
|
||||||
|
|
||||||
Ok(Metrics {
|
Ok(Metrics {
|
||||||
average_advance: full.cell_width,
|
average_advance: full.cell_width,
|
||||||
|
|
Loading…
Reference in a new issue