From a465378dc49dce47ca839a760aed63846777594d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 15 Dec 2019 08:07:13 -0800 Subject: [PATCH] fonts: readjust the glyph scaling code As mentioned in f204ad9a827e43434e8f3e06e1a37ba035392da2, this has gone back and forth a few times. This version avoids some artifacts by avoiding scaling in most cases. The test scenario for this is to tab complete a directory name in zsh; that causes a bold `/` glyph to be rendered which selects a typeface with different metrics and would render a horizontal line at either the top of bottom of the glyph. Similarly, a `/` in italics (eg: comments in vim) would select a third different font and have different artifact properties. Now both of those artifacts are eliminated. --- src/frontend/gui/glyphcache.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/frontend/gui/glyphcache.rs b/src/frontend/gui/glyphcache.rs index 48f66a875..6572214fd 100644 --- a/src/frontend/gui/glyphcache.rs +++ b/src/frontend/gui/glyphcache.rs @@ -131,9 +131,15 @@ impl GlyphCache { let (cell_width, cell_height) = (metrics.cell_width, metrics.cell_height); let nominal_width = cell_width.get() * info.num_cells as f64; - let scale = if glyph.width as f64 > nominal_width { + let scale = if glyph.width as f64 > nominal_width * 1.5 { + // This is for the case where the glyph is a big bitmap that hasn't + // yet been scaled nominal_width / glyph.width as f64 - } else if PixelLength::new(glyph.height as f64) > cell_height { + } else if (info.x_advance.get() / f64::from(info.num_cells)).floor() > cell_width.get() { + // This is to handle double-width replacements such as ligatures + nominal_width / info.x_advance.get() as f64 + } else if PixelLength::new(glyph.height as f64) > cell_height * 1.5 { + // This is another way to detect overside glyph images cell_height.get() / glyph.height as f64 } else { 1.0f64 @@ -163,6 +169,15 @@ impl GlyphCache { let y_offset = info.y_offset * scale; let (scale, raw_im) = if scale != 1.0 { + log::trace!( + "physically scaling {:?} by {} bcos {}x{} > {}x{}", + info, + scale, + glyph.width, + glyph.height, + cell_width, + cell_height + ); (1.0, raw_im.scale_by(scale)) } else { (scale, raw_im)