From 645100cf5f62448d43a43bf3799911461c2bdd9e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 17 Dec 2017 22:20:22 +0100 Subject: [PATCH] Fix linux symbol size With linux every box, line or underline should now have the pixel-perfect size with any font at any size. This uses the default font to get the size of the monospace box. It assumes that the face 0 is always the primary font, if this is not the case, this will probably break. --- font/src/ft/mod.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 44dc0be..a4a118b 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -297,33 +297,37 @@ impl FreeTypeRasterizer { // Render a custom symbol for the underline and beam cursor match glyph_key.c { super::UNDERLINE_CURSOR_CHAR => { - // Get the bottom of the bounding box + // Get the primary face metrics + let face = self.faces.get(&FontKey { token: 0 }).unwrap(); let size_metrics = face.ft_face .size_metrics() .ok_or(Error::MissingSizeMetrics)?; + + // Get the bottom of the bounding box let descent = (size_metrics.descender / 64) as i32; // Get the width of the cell - let metrics = glyph.metrics(); - let width = (metrics.vertAdvance as f32 / 128.).round() as i32; + let width = (size_metrics.max_advance / 64) as i32; // Return the new custom glyph super::get_underline_cursor_glyph(descent, width) } super::BEAM_CURSOR_CHAR | super::BOX_CURSOR_CHAR => { - // Get the top of the bounding box + // Get the primary face metrics + let face = self.faces.get(&FontKey { token: 0 }).unwrap(); let size_metrics = face.ft_face .size_metrics() .ok_or(Error::MissingSizeMetrics)?; - let ascent = (size_metrics.ascender / 64) as i32 - 1; // Get the height of the cell + let height = (size_metrics.height / 64) as i32; + + // Get the top of the bounding box let descent = (size_metrics.descender / 64) as i32; - let height = ascent - descent; + let ascent = height + descent; // Get the width of the cell - let metrics = glyph.metrics(); - let width = (metrics.vertAdvance as f32 / 128.).round() as i32; + let width = (size_metrics.max_advance / 64) as i32; // Return the new custom glyph if glyph_key.c == super::BEAM_CURSOR_CHAR {