summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-08-23 10:32:39 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-23 10:35:28 +0200
commit1c37b15253292933f5102d0c45399965a2a56e6e (patch)
tree0b00db1e9c948ebd43311fd76bbee9d80ea10840
parent2803a8153b27d1d0096207573a70d0d5e6877156 (diff)
downloadnncmpp-1c37b15253292933f5102d0c45399965a2a56e6e.tar.gz
nncmpp-1c37b15253292933f5102d0c45399965a2a56e6e.tar.xz
nncmpp-1c37b15253292933f5102d0c45399965a2a56e6e.zip
X11: improve rendering of denormalized text
Xft is dumb.
-rw-r--r--nncmpp.c18
1 files 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;
}