From 3e298dc63a85c8a43b3e0041e68d26c2ae82268b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 6 Aug 2022 12:46:01 -0700 Subject: [PATCH] add `wezterm ls-fonts --rasterize-ascii --text foo` This renders the glyph in ascii blocks, and shows some additional data about the glyphs. --- wezterm-gui-subcommands/src/lib.rs | 4 ++++ wezterm-gui/src/main.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/wezterm-gui-subcommands/src/lib.rs b/wezterm-gui-subcommands/src/lib.rs index df78c9bbb..dbd7d2765 100644 --- a/wezterm-gui-subcommands/src/lib.rs +++ b/wezterm-gui-subcommands/src/lib.rs @@ -333,6 +333,10 @@ pub struct LsFontsCommand { /// Explain which fonts are used to render the supplied text string #[clap(long = "text", conflicts_with = "list-system")] pub text: Option, + + /// Show rasterized glyphs for the text in --text using ascii blocks. + #[clap(long, requires = "text")] + pub rasterize_ascii: bool, } #[derive(Debug, Parser, Clone)] diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 9ca8a7ede..a9d4af34a 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -875,6 +875,34 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho "", parsed.handle.diagnostic_string() ); + + if cmd.rasterize_ascii { + let rasterized = font.rasterize_glyph(info.glyph_pos, info.font_idx)?; + let mut x = 0; + let mut glyph = String::new(); + for rgba in rasterized.data.chunks(4) { + if let [r, g, b, a] = rgba { + // Use regular RGB for other terminals, but then + // set RGBA for wezterm + glyph.push_str(&format!( + "\x1b[38:2::{r}:{g}:{b}m\x1b[38:6::{r}:{g}:{b}:{a}m\u{2588}\x1b[0m" + )); + x += 1; + if x >= rasterized.width { + x = 0; + glyph.push('\n'); + } + } + } + println!( + "bearing: x={} y={}, offset: x={} y={}", + rasterized.bearing_x.get(), + rasterized.bearing_y.get(), + info.x_offset.get(), + info.y_offset.get(), + ); + println!("{glyph}"); + } } } return Ok(());