From 9d0acddf9a0e31f86da1064bd1cf6e8ed8e277ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 2 Sep 2024 21:28:53 +0200 Subject: [PATCH] Implement font fallbacks in the editor Opting for not making any changes in the XUI. --- NEWS | 2 ++ nncmpp.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index b7cc47b..160beff 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ Unreleased * Made global search indicate the search terms, and match on filenames + * X11: added support for font fallbacks to the editor as well + 2.1.1 (2024-02-27) diff --git a/nncmpp.c b/nncmpp.c index 7ac1539..f306f5c 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -5895,28 +5895,36 @@ x11_render_editor (struct widget *self) { x11_render_padding (self); - XftFont *font = x11_widget_font (self)->list->font; + struct x11_font *font = x11_widget_font (self); XftColor color = { .color = *x11_fg (self) }; - // A simplistic adaptation of line_editor_write() follows. - int x = self->x, y = self->y + font->ascent; - XGlyphInfo extents = {}; - if (g.editor.prompt) + // A simplistic adaptation of tui_render_editor() follows. + const struct line_editor *e = &g.editor; + int x = self->x; + if (e->prompt) { - FT_UInt i = XftCharIndex (g_xui.dpy, font, g.editor.prompt); - XftDrawGlyphs (g_xui.xft_draw, &color, font, x, y, &i, 1); - XftGlyphExtents (g_xui.dpy, font, &i, 1, &extents); - x += extents.xOff + g_xui.vunit / 4; + hard_assert (e->prompt < 127); + x += x11_font_draw (font, &color, x, self->y, + (char[2]) { e->prompt, 0 }) + g_xui.vunit / 4; } - // TODO: Adapt x11_font_{hadvance,draw}(). // TODO: Make this scroll around the caret, and fade like labels. - XftDrawString32 (g_xui.xft_draw, &color, font, x, y, - g.editor.line, g.editor.len); + size_t len; + ucs4_t *buf = xcalloc (e->len + 1, sizeof *buf); + *u32_pcpy (buf, e->line, e->point) = 0; + char *a = (char *) u32_to_u8 (buf, u32_strlen (buf) + 1, NULL, &len); + *u32_pcpy (buf, e->line + e->point, e->len - e->point) = 0; + char *b = (char *) u32_to_u8 (buf, u32_strlen (buf) + 1, NULL, &len); + free (buf); + + x += x11_font_draw (font, &color, x, self->y, a); + int caret = x; + x += x11_font_draw (font, &color, x, self->y, b); + free (a); + free (b); - XftTextExtents32 (g_xui.dpy, font, g.editor.line, g.editor.point, &extents); XRenderFillRectangle (g_xui.dpy, PictOpSrc, g_xui.x11_pixmap_picture, - &color.color, x + extents.xOff, self->y, 2, self->height); + &color.color, caret, self->y, 2, self->height); } static struct widget *