unicode-rs / unicode-width

Displayed width of Unicode characters and strings according to UAX#11 rules.
https://unicode-rs.github.io/unicode-width
Other
201 stars 22 forks source link

Wrong width for ❄️ #22

Closed imsnif closed 2 years ago

imsnif commented 2 years ago

Hey there - we've been using this library extensively for calculating widths and it's frankly been a godsend. Thank you for it.

I recently found an issue which has to do with the character: ❄️ I'm not sure how to better represent it so it won't get lost in formatting, so I'm going to try the output of this snippet:

fn main() {
    let my_chars = "❄️".chars();
    println!("{:?}", my_chars);
}
// prints: Chars(['❄', '\u{fe0f}'])

However, when using unicode-width, it's calculated as 1:

fn main() {
    println!("{:?}", "❄️".width());
}
// prints: 1

I'm far from being an expert here, I just know that this offsets our UI in Zellij in some cases. I hope I'm not barking up the wrong tree?

Thanks!

Manishearth commented 2 years ago

Please read the note in the README. Rendered width is font and engine dependent and is not computable from just the string.

imsnif commented 2 years ago

My apologies - this was a lack of understanding on my part. So just to make sure I understand (if you feel like replying): handling the fe0f character, which as I understand it is: https://emojipedia.org/variation-selector-16/, is something that's the responsibility of the font/rendering engine and not strictly a unicode-width thing?

Manishearth commented 2 years ago

Yes, we follow the Unicode spec here

imsnif commented 2 years ago

fe0f is also part of the spec, and as a newcomer to this discipline this distinction wasn't immediately clear to me. Which is why I appreciate your response.

Manishearth commented 2 years ago

Yes, I'm aware that variation selectors are part of the unicode spec, I'm saying that they're not handled the way you expect in the unicode width spec

Jules-Bertholet commented 3 months ago

https://github.com/unicode-rs/unicode-width/pull/41 added support for U+FE0F. (Emoji ZWJ sequences and skintone modifiers remain unsupported, however.)