diff options
author | Quentin Rameau <quinq@fifth.space> | 2016-10-22 16:36:10 +0200 |
---|---|---|
committer | Quentin Rameau <quinq@fifth.space> | 2016-10-23 17:56:46 +0200 |
commit | 8c99915608beee03eca3bae6ed92264a0da87e2f (patch) | |
tree | 4015d54adca3c9480c2c2f7459d85272c4c96013 /st.c | |
parent | 7854fde1ff95ba85239ccfe1b59b555bd245d0db (diff) | |
download | st-8c99915608beee03eca3bae6ed92264a0da87e2f.tar.gz st-8c99915608beee03eca3bae6ed92264a0da87e2f.tar.bz2 |
Do not use color when font attributes are supported
If fontconfig gives us a font without the attributes we asked for,
display an alternative color instead.
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 40 |
1 files changed, 32 insertions, 8 deletions
@@ -354,6 +354,8 @@ typedef struct { int width; int ascent; int descent; + int badslant; + int badweight; short lbearing; short rbearing; XftFont *match; @@ -3373,6 +3375,7 @@ xloadfont(Font *f, FcPattern *pattern) FcPattern *match; FcResult result; XGlyphInfo extents; + int wantattr, haveattr; match = XftFontMatch(xw.dpy, xw.scr, pattern, &result); if (!match) @@ -3383,6 +3386,28 @@ xloadfont(Font *f, FcPattern *pattern) 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); @@ -3780,14 +3805,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i 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)) { |