Compute line-height as a multiple of font size

...instead of using the bounding box. This makes `PragmataPro` and other
fonts render more cleanly.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-03-15 16:35:06 +01:00
parent 8122abeb64
commit 447f350123
4 changed files with 6 additions and 8 deletions

View file

@ -168,9 +168,8 @@ impl FontCache {
advance.x() * self.em_scale(font_id, font_size)
}
pub fn line_height(&self, font_id: FontId, font_size: f32) -> f32 {
let height = self.metric(font_id, |m| m.bounding_box.height());
(height * self.em_scale(font_id, font_size)).ceil()
pub fn line_height(&self, font_size: f32) -> f32 {
(font_size * 1.618).round()
}
pub fn cap_height(&self, font_id: FontId, font_size: f32) -> f32 {
@ -194,7 +193,7 @@ impl FontCache {
}
pub fn baseline_offset(&self, font_id: FontId, font_size: f32) -> f32 {
let line_height = self.line_height(font_id, font_size);
let line_height = self.line_height(font_size);
let ascent = self.ascent(font_id, font_size);
let descent = self.descent(font_id, font_size);
let padding_top = (line_height - ascent - descent) / 2.;