X11: improve rendering of denormalized text

Xft is dumb.
This commit is contained in:
Přemysl Eric Janouch 2022-08-23 10:32:39 +02:00
parent 2803a8153b
commit 1c37b15253
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -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;
}