+ /* Search the font cache. */
+ for(i = 0; i < frclen; i++) {
+ if(XftCharExists(xw.dpy, frc[i].font, unicodep)
+ && frc[i].flags == frcflags) {
+ break;
+ }
+ }
+
+ /* Nothing was found. */
+ if(i >= frclen) {
+ if(!font->set)
+ xloadfontset(font);
+ fcsets[0] = font->set;
+
+ /*
+ * Nothing was found in the cache. Now use
+ * some dozen of Fontconfig calls to get the
+ * font for one single character.
+ *
+ * Xft and fontconfig are design failures.
+ */
+ fcpattern = FcPatternDuplicate(font->pattern);
+ fccharset = FcCharSetCreate();
+
+ FcCharSetAddChar(fccharset, unicodep);
+ FcPatternAddCharSet(fcpattern, FC_CHARSET,
+ fccharset);
+ FcPatternAddBool(fcpattern, FC_SCALABLE,
+ FcTrue);
+
+ FcConfigSubstitute(0, fcpattern,
+ FcMatchPattern);
+ FcDefaultSubstitute(fcpattern);
+
+ fontpattern = FcFontSetMatch(0, fcsets,
+ FcTrue, fcpattern, &fcres);
+
+ /*
+ * Overwrite or create the new cache entry.
+ */
+ if(frclen >= LEN(frc)) {
+ frclen = LEN(frc) - 1;
+ XftFontClose(xw.dpy, frc[frclen].font);
+ }
+
+ frc[frclen].font = XftFontOpenPattern(xw.dpy,
+ fontpattern);
+ frc[frclen].flags = frcflags;
+
+ i = frclen;
+ frclen++;
+
+ FcPatternDestroy(fcpattern);
+ FcCharSetDestroy(fccharset);
+ }
+
+ XftDrawStringUtf8(xw.draw, fg, frc[i].font,
+ xp, winy + frc[i].font->ascent,
+ (FcChar8 *)u8c, u8cblen);
+
+ xp += xw.cw * wcwidth(unicodep);
+ }
+
+ /*
+ * This is how the loop above actually should be. Why does the
+ * application have to care about font details?
+ *
+ * I have to repeat: Xft and Fontconfig are design failures.
+ */
+ /*
+ XftDrawStringUtf8(xw.draw, fg, font->set, winx,
+ winy + font->ascent, (FcChar8 *)s, bytelen);
+ */
+
+ if(base.mode & ATTR_UNDERLINE) {
+ XftDrawRect(xw.draw, fg, winx, winy + font->ascent + 1,
+ width, 1);
+ }
+
+ /* Reset clip to none. */
+ XftDrawSetClip(xw.draw, 0);