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:
1 parent
ef532fc7e5
commit
3e298dc63a
2 files changed
+32
No files matched your search
@@ -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<String>,
|
||||
|
||||
/// Show rasterized glyphs for the text in --text using ascii blocks.
|
||||
#[clap(long, requires = "text")]
|
||||
pub rasterize_ascii: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser, Clone)]
|
||||
|
||||
@@ -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(());
|
||||
|
||||
Reference in new issue
Block a user