From 1c37b15253292933f5102d0c45399965a2a56e6e Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Tue, 23 Aug 2022 10:32:39 +0200 Subject: X11: improve rendering of denormalized text Xft is dumb. --- nncmpp.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nncmpp.c b/nncmpp.c index b8df828..d4b58fd 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -5386,17 +5386,27 @@ x11_render_label (struct widget *self) static struct widget * x11_make_label (chtype attrs, const char *label) { - size_t len = strlen (label); - struct widget *w = xcalloc (1, sizeof *w + len + 1); + // Xft renders combining marks by themselves, NFC improves it a bit. + size_t label_len = strlen (label) + 1, normalized_len = 0; + uint8_t *normalized = u8_normalize (UNINORM_NFC, + (const uint8_t *) label, label_len, NULL, &normalized_len); + if (!normalized) + { + normalized = memcpy (xmalloc (label_len), label, label_len); + normalized_len = label_len; + } + + struct widget *w = xcalloc (1, sizeof *w + normalized_len); w->on_render = x11_render_label; w->attrs = attrs; - memcpy (w + 1, label, len); + memcpy (w + 1, normalized, normalized_len); XftFont *font = x11_font (w); XGlyphInfo extents = {}; - XftTextExtentsUtf8 (g.dpy, font, (const FcChar8 *) label, len, &extents); + XftTextExtentsUtf8 (g.dpy, font, normalized, normalized_len - 1, &extents); w->width = extents.xOff; w->height = font->height; + free (normalized); return w; } -- cgit v1.2.3-70-g09d2