silicon icon indicating copy to clipboard operation
silicon copied to clipboard

Add support for emojis

Open orhun opened this issue 1 year ago • 2 comments

I realized silicon is not working when I have emoji in the code. Is this supported?

orhun avatar Nov 19 '23 11:11 orhun

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 `

lost22git avatar Mar 28 '24 09:03 lost22git

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:

screenshot-20240403--00_31_58_AM

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".

chris-av avatar Apr 03 '24 07:04 chris-av