diff --git a/wezterm-font/src/ftwrap.rs b/wezterm-font/src/ftwrap.rs index 8eb10da7e..b99e557e0 100644 --- a/wezterm-font/src/ftwrap.rs +++ b/wezterm-font/src/ftwrap.rs @@ -192,6 +192,23 @@ impl Face { } } + pub fn get_glyph_name(&self, glyph_index: u32) -> Option { + let mut buf = [0u8; 128]; + let res = unsafe { + FT_Get_Glyph_Name( + self.face, + glyph_index, + buf.as_mut_ptr() as *mut _, + buf.len() as _, + ) + }; + if res != 0 { + None + } else { + Some(String::from_utf8_lossy(&buf).into_owned().to_string()) + } + } + pub fn get_sfnt_names(&self) -> HashMap> { let num_names = unsafe { FT_Get_Sfnt_Name_Count(self.face) }; diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 478c1c4d9..6717e8177 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -704,6 +704,8 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho if let Some(text) = &cmd.text { let line = Line::from_text(text, &CellAttributes::default(), SEQ_ZERO); let cell_clusters = line.cluster(bidi_hint); + let ft_lib = wezterm_font::ftwrap::Library::new()?; + for cluster in cell_clusters { let style = font_config.match_style(&config, &cluster.attrs); let font = font_config.resolve_font(style)?; @@ -721,6 +723,10 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho // We must grab the handles after shaping, so that we get the // revised list that includes system fallbacks! let handles = font.clone_handles(); + let faces: Vec<_> = handles + .iter() + .map(|p| ft_lib.face_from_locator(&p.handle).ok()) + .collect(); let mut iter = infos.iter().peekable(); @@ -762,13 +768,22 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho } } + let glyph_name = faces[info.font_idx] + .as_ref() + .and_then(|face| { + face.get_glyph_name(info.glyph_pos) + .map(|name| format!("{},", name)) + }) + .unwrap_or_else(String::new); + println!( - "{:2} {:4} {:12} x_adv={:<2} cells={:<2} glyph={:<4} {}\n{:38}{}", + "{:2} {:4} {:12} x_adv={:<2} cells={:<2} glyph={}{:<4} {}\n{:38}{}", info.cluster, text, escaped, info.x_advance.get(), info.num_cells, + glyph_name, info.glyph_pos, parsed.lua_name(), "",