static unsigned int mousebg = 0;
/*
- * Colors used, when the specific fg == defaultfg. So in reverse mode this
- * will reverse too. Another logic would only make the simple feature too
- * complex.
+ * Color used to display font attributes when fontconfig selected a font which
+ * doesn't match the ones requested.
*/
-static unsigned int defaultitalic = 11;
-static unsigned int defaultunderline = 7;
+static unsigned int defaultattr = 11;
/*
* Internal mouse shortcuts.
int width;
int ascent;
int descent;
+ int badslant;
+ int badweight;
short lbearing;
short rbearing;
XftFont *match;
FcPattern *match;
FcResult result;
XGlyphInfo extents;
+ int wantattr, haveattr;
match = XftFontMatch(xw.dpy, xw.scr, pattern, &result);
if (!match)
return 1;
}
+ if ((XftPatternGetInteger(pattern, "slant", 0, &wantattr) ==
+ XftResultMatch)) {
+ /*
+ * Check if xft was unable to find a font with the appropriate
+ * slant but gave us one anyway. Try to mitigate.
+ */
+ if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
+ &haveattr) != XftResultMatch) || haveattr < wantattr) {
+ f->badslant = 1;
+ fputs("st: font slant does not match\n", stderr);
+ }
+ }
+
+ if ((XftPatternGetInteger(pattern, "weight", 0, &wantattr) ==
+ XftResultMatch)) {
+ if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
+ &haveattr) != XftResultMatch) || haveattr != wantattr) {
+ f->badweight = 1;
+ fputs("st: font weight does not match\n", stderr);
+ }
+ }
+
XftTextExtentsUtf8(xw.dpy, f->match,
(const FcChar8 *) ascii_printable,
strlen(ascii_printable), &extents);
XRenderColor colfg, colbg;
XRectangle r;
- /* Determine foreground and background colors based on mode. */
- if (base.fg == defaultfg) {
- if (base.mode & ATTR_ITALIC)
- base.fg = defaultitalic;
- else if ((base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD))
- base.fg = defaultitalic;
- else if (base.mode & ATTR_UNDERLINE)
- base.fg = defaultunderline;
+ /* Fallback on color display for attributes not supported by the font */
+ if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
+ if (dc.ibfont.badslant || dc.ibfont.badweight)
+ base.fg = defaultattr;
+ } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) ||
+ (base.mode & ATTR_BOLD && dc.bfont.badweight)) {
+ base.fg = defaultattr;
}
if (IS_TRUECOL(base.fg)) {