silicon
silicon copied to clipboard
Add support for emojis
I realized silicon is not working when I have emoji in the code. Is this supported?
same
warning] No font found for character `🤣`
[warning] No font found for character `👻`
[warning] No font found for character `🦉`
`warning] No font found for character `
[warning] No font found for character `🤣`
[warning] No font found for character `👻`
[warning] No font found for character `🦉`
`warning] No font found for character `
So here is what I tried.
silicon --font "Apple Color Emoji" inputfile.sh -o output.png
No error is shown, unless I run Rust in debug mode with RUST_BACKTRACE
. Then I get this:
The panic is being thrown when calling Self:get_glyph_width()
. I think this is the offending line:
fn get_glyph_width(font: &Font, id: u32, size: f32) -> u32 {
let metrics = font.metrics();
let advance = font.advance(id).unwrap();
(advance / metrics.units_per_em as f32 * size).x().ceil() as u32; // offending line here
}
I guess with emoji, the metrics.units_per_em
appears to be zero (see screenshot), but since it is coerced to a number, the end result of get_glyph_width
is a large number that overflows and causes the panic.
Edit: I did verify that "Apple Color Emoji" is a font that is listed by the silicon --list-fonts
output. Same result with other fallback emoji font, like "Noto Color Emoji".