1
1
mirror of https://github.com/wez/wezterm.git synced 2025-01-03 11:11:43 +03:00

add wezterm ls-fonts --rasterize-ascii --text foo

This renders the glyph in ascii blocks, and shows some
additional data about the glyphs.
This commit is contained in:
Wez Furlong 2022-08-06 12:46:01 -07:00
parent ef532fc7e5
commit 3e298dc63a
2 changed files with 32 additions and 0 deletions

View File

@ -333,6 +333,10 @@ pub struct LsFontsCommand {
/// Explain which fonts are used to render the supplied text string /// Explain which fonts are used to render the supplied text string
#[clap(long = "text", conflicts_with = "list-system")] #[clap(long = "text", conflicts_with = "list-system")]
pub text: Option<String>, pub text: Option<String>,
/// Show rasterized glyphs for the text in --text using ascii blocks.
#[clap(long, requires = "text")]
pub rasterize_ascii: bool,
} }
#[derive(Debug, Parser, Clone)] #[derive(Debug, Parser, Clone)]

View File

@ -875,6 +875,34 @@ pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyho
"", "",
parsed.handle.diagnostic_string() 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(()); return Ok(());