←back to thread

178 points dgl | 1 comments | | HN request time: 0s | source
Show context
b0a04gl ◴[] No.44362767[source]
emoji width bugs mostly come down to how terminals interpret Unicode's "grapheme clusters" vs "codepoints" vs "display cells". emoji isn't one codepoint - it's often multiple joined by zero-width joiners, variation selectors, skin tone modifiers. so the terminal asks wcwidth(), gets 1 or 2, but the actual glyph might render wider or combine into a single shape.

some emoji even change width depending on font. family emoji is like 7 codepoints, shows up as one glyph. most terminals don't track that. they just count codepoints and pray.

unless terminal is using a grapheme-aware renderer and syncs with the font's shaping engine (like freetype or coretext), it'll always guess wrong. wezterm and kitty kinda parse it right often

replies(4): >>44362822 #>>44363348 #>>44363640 #>>44363828 #
duped ◴[] No.44363348[source]
Why do you need to sync with the shaping engine?

TBH grapheme clusters are annoying but day 1 learning material for a text display widget that supports beyond ascii. It honestly irks me how many things just fuck it up, because it's not an intractably hard problem - just annoying enough to be intractable for people that are lazy (*).

(*) the actually hard problem with grapheme clusters is that they're potentially unbounded in length and the standard is mutable, so your wcwidth() implementation needs to be updated along with standards to stay valid, particularly with emoji. This basically creates a software maintenance burden out of aether.

replies(2): >>44363609 #>>44364807 #
zarzavat ◴[] No.44364807[source]
> Why do you need to sync with the shaping engine?

GP explained already. Grapheme clusters ≠ glyphs. To find the number of glyphs you need the font.

An emoji can render as one or two or three or more glyphs depending on what font the user has installed, because many emoji are formed by joining two or more emoji by a ZWJ)

(Also even in a monospace font not all glyphs are of ﷽ equal width)

replies(3): >>44365038 #>>44366271 #>>44366577 #
1. mminer237 ◴[] No.44366577[source]
Some monospace fonts do fit ﷽ into one normal-sized character by squeezing it into three mini lines.