From 8009863f9b126eb7b9eedd563f1cef8da22e230e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 25 Feb 2021 21:16:10 -0800 Subject: [PATCH] fonts: shaper: also handle ligatures The Cascadia Code font has ligatures for `---` that consist of a triple wide glyph followed by two zero-width glyphs. Rewrite that into a single glyph that spans three cells and remove the zero-width glyphs from the shaped info. refs: https://github.com/wez/wezterm/issues/478 --- wezterm-gui/src/gui/shapecache.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/gui/shapecache.rs b/wezterm-gui/src/gui/shapecache.rs index c9ea5ca8f..bc10a3981 100644 --- a/wezterm-gui/src/gui/shapecache.rs +++ b/wezterm-gui/src/gui/shapecache.rs @@ -48,10 +48,18 @@ where infos: &[GlyphInfo], glyphs: &[Rc>], ) -> Vec> { - let mut pos = vec![]; + let mut pos: Vec> = vec![]; let mut run = None; for (info, glyph) in infos.iter().zip(glyphs.iter()) { if !info.is_space && glyph.texture.is_none() { + if let Some(shaped) = pos.last_mut() { + if shaped.pos.bitmap_pixel_width as f32 > shaped.pos.bearing_x { + // This space-like glyph belongs to the preceding glyph + shaped.pos.num_cells += 1; + continue; + } + } + if run.is_none() { run.replace(ShapedInfo { pos: GlyphPosition { @@ -121,6 +129,14 @@ where }); } } + if let Some(run) = run.take() { + log::warn!( + "leftovers when shaping {:#?} {:#?} -> {:?}", + infos, + glyphs, + run + ); + } pos } }