summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-20 11:11:49 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-20 11:15:20 +0200
commite72ed71f53c3fbfe2bfe3aa1b591632ab24d0d34 (patch)
tree689d7e24ef2bd410d8b23e462154cb138ef55eff
parent28ed7a85a8cbf3173f17e8ca9f7c8a7d5a7c98ed (diff)
downloadnncmpp-e72ed71f53c3fbfe2bfe3aa1b591632ab24d0d34.tar.gz
nncmpp-e72ed71f53c3fbfe2bfe3aa1b591632ab24d0d34.tar.xz
nncmpp-e72ed71f53c3fbfe2bfe3aa1b591632ab24d0d34.zip
X11: support italic fonts as well
The bold + italic combination isn't supported thus far, because it seems unnecessary.
-rw-r--r--NEWS2
-rw-r--r--nncmpp.c22
2 files changed, 21 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 2e2b9ea..c71f7dd 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ Unreleased
* Added ability to look up song lyrics,
using a new scriptable extension interface for the Info tab
+ * Made the X11 interface support italic fonts
+
* Added Readline-like M-u, M-l, M-c editor bindings
diff --git a/nncmpp.c b/nncmpp.c
index 1ef2146..94f5847 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -1397,6 +1397,7 @@ static struct app_context
XftDraw *xft_draw; ///< Xft rendering context
XftFont *xft_regular; ///< Regular font
XftFont *xft_bold; ///< Bold font
+ XftFont *xft_italic; ///< Italic font
char *x11_selection; ///< CLIPBOARD selection
XRenderColor x_fg[ATTRIBUTE_COUNT]; ///< Foreground per attribute
@@ -5865,7 +5866,11 @@ static XErrorHandler x11_default_error_handler;
static XftFont *
x11_font (struct widget *self)
{
- return (self->attrs & A_BOLD) ? g.xft_bold : g.xft_regular;
+ if (self->attrs & A_BOLD)
+ return g.xft_bold;
+ if (self->attrs & A_ITALIC)
+ return g.xft_italic;
+ return g.xft_regular;
}
static XRenderColor *
@@ -6346,6 +6351,7 @@ x11_destroy (void)
XftDrawDestroy (g.xft_draw);
XftFontClose (g.dpy, g.xft_regular);
XftFontClose (g.dpy, g.xft_bold);
+ XftFontClose (g.dpy, g.xft_italic);
cstr_set (&g.x11_selection, NULL);
poller_fd_reset (&g.x11_event);
@@ -6847,8 +6853,11 @@ x11_init_fonts (void)
FcPattern *query_regular = FcNameParse ((const FcChar8 *) name);
FcPattern *query_bold = FcPatternDuplicate (query_regular);
- FcPatternAdd (query_bold, FC_STYLE,
- (FcValue) { .type = FcTypeString, .u.s = (FcChar8 *) "Bold" }, FcFalse);
+ FcPatternAdd (query_bold, FC_STYLE, (FcValue) {
+ .type = FcTypeString, .u.s = (FcChar8 *) "Bold" }, FcFalse);
+ FcPattern *query_italic = FcPatternDuplicate (query_regular);
+ FcPatternAdd (query_italic, FC_STYLE, (FcValue) {
+ .type = FcTypeString, .u.s = (FcChar8 *) "Italic" }, FcFalse);
FcPattern *regular = XftFontMatch (g.dpy, screen, query_regular, &result);
FcPatternDestroy (query_regular);
@@ -6866,6 +6875,13 @@ x11_init_fonts (void)
FcPatternDestroy (bold);
if (!g.xft_bold)
g.xft_bold = XftFontCopy (g.dpy, g.xft_regular);
+
+ FcPattern *italic = XftFontMatch (g.dpy, screen, query_italic, &result);
+ FcPatternDestroy (query_italic);
+ if (italic && !(g.xft_italic = XftFontOpenPattern (g.dpy, italic)))
+ FcPatternDestroy (italic);
+ if (!g.xft_italic)
+ g.xft_italic = XftFontCopy (g.dpy, g.xft_regular);
}
static void