+ if(base.mode & ATTR_REVERSE) {
+ temp = fg;
+ fg = bg;
+ bg = temp;
+ }
+
+ if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
+ fg = bg;
+
+ /* Intelligent cleaning up of the borders. */
+ if(x == 0) {
+ xclear(0, (y == 0)? 0 : winy, borderpx,
+ winy + xw.ch + ((y >= term.row-1)? xw.h : 0));
+ }
+ if(x + charlen >= term.col) {
+ xclear(winx + width, (y == 0)? 0 : winy, xw.w,
+ ((y >= term.row-1)? xw.h : (winy + xw.ch)));
+ }
+ if(y == 0)
+ xclear(winx, 0, winx + width, borderpx);
+ if(y == term.row-1)
+ xclear(winx, winy + xw.ch, winx + width, xw.h);
+
+ /* Clean up the region we want to draw to. */
+ XftDrawRect(xw.draw, bg, winx, winy, width, xw.ch);
+
+ /* Set the clip region because Xft is sometimes dirty. */
+ r.x = 0;
+ r.y = 0;
+ r.height = xw.ch;
+ r.width = width;
+ XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
+
+ for(xp = winx; bytelen > 0;) {
+ /*
+ * Search for the range in the to be printed string of glyphs
+ * that are in the main font. Then print that range. If
+ * some glyph is found that is not in the font, do the
+ * fallback dance.
+ */
+ u8fs = s;
+ u8fblen = 0;
+ u8fl = 0;
+ oneatatime = font->width != xw.cw;
+ for(;;) {
+ u8c = s;
+ u8cblen = utf8decode(s, &unicodep, UTF_SIZ);
+ s += u8cblen;
+ bytelen -= u8cblen;
+
+ doesexist = XftCharExists(xw.dpy, font->match, unicodep);
+ if(oneatatime || !doesexist || bytelen <= 0) {
+ if(oneatatime || bytelen <= 0) {
+ if(doesexist) {
+ u8fl++;
+ u8fblen += u8cblen;
+ }
+ }
+
+ if(u8fl > 0) {
+ XftDrawStringUtf8(xw.draw, fg,
+ font->match, xp,
+ winy + font->ascent,
+ (FcChar8 *)u8fs,
+ u8fblen);
+ xp += xw.cw * u8fl;
+
+ }
+ break;
+ }
+
+ u8fl++;
+ u8fblen += u8cblen;
+ }
+ if(doesexist) {
+ if(oneatatime)
+ continue;
+ break;
+ }
+
+ /* 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;