+ /* Clean up the region we want to draw to. */
+ XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
+
+ /*
+ * Step through all UTF-8 characters one by one and search in the font
+ * cache ring buffer, whether there was some font found to display the
+ * unicode value of that UTF-8 character.
+ */
+ fcsets[0] = font->set;
+ for (xp = winx; bytelen > 0; ) {
+ u8c = s;
+ u8clen = utf8decode(s, &u8char);
+ s += u8clen;
+ bytelen -= u8clen;
+
+ sfont = font->match;
+ /*
+ * Only check the font cache or load new fonts, if the
+ * characters is not represented in main font.
+ */
+ if (!XftCharExists(xw.dpy, font->match, u8char)) {
+ frp = frccur;
+ /* Search the font cache. */
+ for (i = 0; i < frclen; i++, frp--) {
+ if (frp <= 0)
+ frp = LEN(frc) - 1;
+
+ if (frc[frp].c == u8char
+ && frc[frp].flags == frcflags) {
+ break;
+ }
+ }
+ if (i >= frclen) {
+ /*
+ * Nothing was found in the cache. Now use
+ * some dozen of Fontconfig calls to get the
+ * font for one single character.
+ */
+ fcpattern = FcPatternDuplicate(font->pattern);
+ fccharset = FcCharSetCreate();
+
+ FcCharSetAddChar(fccharset, u8char);
+ FcPatternAddCharSet(fcpattern, FC_CHARSET,
+ fccharset);
+ FcPatternAddBool(fcpattern, FC_SCALABLE,
+ FcTrue);
+
+ FcConfigSubstitute(0, fcpattern,
+ FcMatchPattern);
+ FcDefaultSubstitute(fcpattern);
+
+ fontpattern = FcFontSetMatch(0, fcsets,
+ FcTrue, fcpattern, &fcres);
+
+ frccur++;
+ frclen++;
+ if (frccur >= LEN(frc))
+ frccur = 0;
+ if (frclen >= LEN(frc)) {
+ frclen = LEN(frc);
+ XftFontClose(xw.dpy, frc[frccur].font);
+ }
+
+ /*
+ * Overwrite or create the new cache entry
+ * entry.
+ */
+ frc[frccur].font = XftFontOpenPattern(xw.dpy,
+ fontpattern);
+ frc[frccur].c = u8char;
+ frc[frccur].flags = frcflags;
+
+ FcPatternDestroy(fcpattern);
+ FcCharSetDestroy(fccharset);
+
+ frp = frccur;
+ }
+ sfont = frc[frp].font;
+ }
+
+ XftDrawStringUtf8(xw.draw, fg, sfont, xp, winy + sfont->ascent,
+ (FcChar8 *)u8c, u8clen);
+
+ xp += font->width;
+ }
+
+ /*
+ XftDrawStringUtf8(xw.draw, fg, font->set, winx,