--- unix/tkUnixRFont.c.orig	2008-02-14 21:38:54.000000000 +0300
+++ unix/tkUnixRFont.c	2008-02-15 22:37:06.000000000 +0300
@@ -20,6 +20,7 @@
     XftFont *ftFont;
     FcPattern *source;
     FcCharSet *charset;
+    int failed;
 } UnixFtFace;
 
 typedef struct {
@@ -60,6 +61,31 @@
 }
 
 static XftFont *
+GetFontFallback(
+    UnixFtFont *fontPtr)
+{
+    double size;
+    int pxsize;
+    char *type;
+
+    if (XftPatternGetDouble(fontPtr->pattern, XFT_SIZE, 0,
+	    &size) == XftResultMatch) {
+	type = XFT_SIZE;
+    } else if (XftPatternGetInteger(fontPtr->pattern, XFT_PIXEL_SIZE, 0,
+	    &pxsize) == XftResultMatch) {
+	type = XFT_PIXEL_SIZE;
+	size = pxsize;
+    } else {
+	type = XFT_SIZE;
+	size = 12.0;
+    }
+    return XftFontOpen(fontPtr->display, fontPtr->screen,
+	    FC_FAMILY, FcTypeString, "sans",
+	    type, XftTypeDouble, size,
+	    NULL);
+}
+
+static XftFont *
 GetFont(
     UnixFtFont *fontPtr,
     FcChar32 ucs4)
@@ -69,23 +95,57 @@
     if (ucs4) {
 	for (i = 0; i < fontPtr->nfaces; i++) {
 	    FcCharSet *charset = fontPtr->faces[i].charset;
-	    if (charset && FcCharSetHasChar(charset, ucs4)) {
-		break;
+	    if (!(charset && FcCharSetHasChar(charset, ucs4))) {
+		continue;
+	    }
+	    if (fontPtr->faces[i].ftFont) {
+		return fontPtr->faces[i].ftFont;
+	    } else {
+		if (!fontPtr->faces[i].failed) {
+		    FcPattern *pat = FcFontRenderPrepare(0, fontPtr->pattern,
+			    fontPtr->faces[i].source);
+
+		    fontPtr->faces[i].ftFont = XftFontOpenPattern(fontPtr->display, pat);
+		}
+		if (fontPtr->faces[i].ftFont) {
+		    return fontPtr->faces[i].ftFont;
+		} else {
+		    fontPtr->faces[i].failed = 1;
+		}
 	    }
 	}
-	if (i == fontPtr->nfaces) {
-	    i = 0;
+    }
+
+    for (i = 0; i < fontPtr->nfaces; i++) {
+	if (fontPtr->faces[i].ftFont) {
+	    return fontPtr->faces[i].ftFont;
+	} else {
+	    if (!fontPtr->faces[i].failed) {
+		FcPattern *pat = FcFontRenderPrepare(0, fontPtr->pattern,
+			fontPtr->faces[i].source);
+
+		fontPtr->faces[i].ftFont = XftFontOpenPattern(fontPtr->display, pat);
+	    }
+	    if (fontPtr->faces[i].ftFont) {
+		return fontPtr->faces[i].ftFont;
+	    } else {
+		fontPtr->faces[i].failed = 1;
+	    }
 	}
-    } else {
-	i = 0;
     }
-    if (!fontPtr->faces[i].ftFont) {
-	FcPattern *pat = FcFontRenderPrepare(0, fontPtr->pattern,
-		fontPtr->faces[i].source);
 
-	fontPtr->faces[i].ftFont = XftFontOpenPattern(fontPtr->display, pat);
+    if (fontPtr->faces[fontPtr->nfaces].ftFont) {
+	return fontPtr->faces[fontPtr->nfaces].ftFont;
+    } else {
+	fontPtr->faces[fontPtr->nfaces].ftFont = GetFontFallback(fontPtr);
+	if (fontPtr->faces[fontPtr->nfaces].ftFont) {
+	    return fontPtr->faces[fontPtr->nfaces].ftFont;
+	} else {
+	    Tcl_Panic("Cannot find a usable font. Check your fontconfig settings");
+	    /* Never reached */
+	    return NULL;
+	}
     }
-    return fontPtr->faces[i].ftFont;
 }
 
 /*
@@ -184,7 +244,7 @@
     FcCharSet *charset;
     FcResult result;
     XftFont *ftFont;
-    int i;
+    int i, nfont;
 
     if (!fontPtr) {
 	fontPtr = (UnixFtFont *) ckalloc(sizeof(UnixFtFont));
@@ -199,21 +259,22 @@
 
     set = FcFontSort(0, pattern, FcTrue, NULL, &result);
     if (!set) {
-	FcPatternDestroy(pattern);
-	ckfree((char *)fontPtr);
-	return NULL;
+	nfont = 0;
+    } else {
+	nfont = set->nfont;
     }
 
     fontPtr->fontset = set;
     fontPtr->pattern = pattern;
-    fontPtr->faces = (UnixFtFace *) ckalloc(set->nfont * sizeof(UnixFtFace));
-    fontPtr->nfaces = set->nfont;
+    /* Extra slot for possible fallback */
+    fontPtr->faces = (UnixFtFace *) ckalloc((nfont + 1) * sizeof(UnixFtFace));
+    fontPtr->nfaces = nfont;
 
     /*
      * Fill in information about each returned font
      */
 
-    for (i = 0; i < set->nfont; i++) {
+    for (i = 0; i < nfont; i++) {
 	fontPtr->faces[i].ftFont = 0;
 	fontPtr->faces[i].source = set->fonts[i];
 	if (FcPatternGetCharSet(set->fonts[i], FC_CHARSET, 0,
@@ -222,7 +283,13 @@
 	} else {
 	    fontPtr->faces[i].charset = 0;
 	}
+	fontPtr->faces[i].failed = 0;
     }
+    /* Fill in a fallback slot */
+    fontPtr->faces[nfont].ftFont = 0;
+    fontPtr->faces[nfont].source = 0;
+    fontPtr->faces[nfont].charset = 0;
+    fontPtr->faces[nfont].failed = 0;
 
     fontPtr->display = Tk_Display(tkwin);
     fontPtr->screen = Tk_ScreenNumber(tkwin);
@@ -253,7 +320,7 @@
     Tk_ErrorHandler handler = Tk_CreateErrorHandler(display, -1, -1, -1, NULL,
 	    (ClientData) NULL);
 
-    for (i = 0; i < fontPtr->nfaces; i++) {
+    for (i = 0; i <= fontPtr->nfaces; i++) {
 	if (fontPtr->faces[i].ftFont) {
 	    XftFontClose(fontPtr->display, fontPtr->faces[i].ftFont);
 	}
