if (wbfs == NULL) wbfs = wfs;
xtermLoadFont(TScreen * screen,	      VT_FONTSET(char *nfontname,			 char *bfontname,			 char *wfontname,			 char *wbfontname),	      Bool doresize,	      int fontnum){    /* FIXME: use XFreeFontInfo */    FontNameProperties *fp;    XFontStruct *nfs = NULL;    XFontStruct *bfs = NULL;#if OPT_WIDE_CHARS    XFontStruct *wfs = NULL;    XFontStruct *wbfs = NULL;#endif    XGCValues xgcv;    unsigned long mask;    GC new_normalGC = NULL;    GC new_normalboldGC = NULL;    GC new_reverseGC = NULL;    GC new_reverseboldGC = NULL;    Pixel new_normal;    Pixel new_revers;    char *tmpname = NULL;    char normal[MAX_FONTNAME];    Boolean proportional = False;    int ch;    if (!nfontname)	return 0;    if (fontnum == fontMenu_fontescape	&& nfontname != screen->menu_font_names[fontnum]) {	if ((tmpname = x_strdup(nfontname)) == 0)	    return 0;    }    TRACE(("xtermLoadFont normal %s\n", nfontname));    if (!(nfs = XLoadQueryFont(screen->display, nfontname)))	goto bad;    if (EmptyFont(nfs))	goto bad;		/* can't use a 0-sized font */    strcpy(normal, nfontname);    if (bfontname == 0) {	fp = get_font_name_props(screen->display, nfs, normal);	if (fp != 0) {	    bfontname = bold_font_name(fp);	    TRACE(("...derived bold %s\n", bfontname));	}	if (bfontname == 0	    || (bfs = XLoadQueryFont(screen->display, bfontname)) == 0) {	    bfs = nfs;	    TRACE(("...cannot load a matching bold font\n"));	} else if (same_font_size(nfs, bfs)		   && got_bold_font(screen->display, bfs, bfontname)) {	    TRACE(("...got a matching bold font\n"));	} else {	    XFreeFont(screen->display, bfs);	    bfs = nfs;	    TRACE(("...did not get a matching bold font\n"));	}    } else if ((bfs = XLoadQueryFont(screen->display, bfontname)) == 0) {	bfs = nfs;	TRACE(("...cannot load bold font %s\n", bfontname));    }    /*     * If there is no widefont specified, fake it by doubling AVERAGE_WIDTH     * of normal fonts XLFD, and asking for it.  This plucks out 18x18ja     * and 12x13ja as the corresponding fonts for 9x18 and 6x13.     */    if_OPT_WIDE_CHARS(screen, {	if (wfontname == 0 && !is_double_width_font(nfs)) {	    fp = get_font_name_props(screen->display, nfs, normal);	    if (fp != 0) {		wfontname = wide_font_name(fp);		TRACE(("...derived wide %s\n", wfontname));	    }	}	if (wfontname) {	    wfs = XLoadQueryFont(screen->display, wfontname);	} else {	    wfs = nfs;	}	if (wbfontname) {	    wbfs = XLoadQueryFont(screen->display, wbfontname);	} else if (is_double_width_font(bfs)) {	    wbfs = bfs;	} else {	    wbfs = wfs;	    TRACE(("...cannot load wide bold font %s\n", wbfontname));	}	if (EmptyFont(wbfs))	    goto bad;		/* can't use a 0-sized font */    });    /*     * Most of the time this call to load the font will succeed, even if     * there is no wide font :  the X server doubles the width of the     * normal font, or similar.     *     * But if it did fail for some reason, then nevermind.     */    if (EmptyFont(bfs))	goto bad;		/* can't use a 0-sized font */    if (!same_font_size(nfs, bfs)	&& (is_fixed_font(nfs) && is_fixed_font(bfs))) {	XFreeFont(screen->display, bfs);	bfs = nfs;	TRACE(("...fixing mismatched normal/bold fonts\n"));	/*	 * If we're given a nonnull bfontname here, it came from a	 * resource setting.  Perhaps the user did something like set	 * the "*font" in a resource file.  But they would be startled	 * to see a mismatched bold font.  Try again, asking the font	 * server for the appropriate font.	 */	if (bfontname != 0) {	    return xtermLoadFont(screen,				 VT_FONTSET(nfontname,					    NULL,	/* throw it away! */					    wfontname,					    wbfontname),				 doresize,				 fontnum);	}    }    if_OPT_WIDE_CHARS(screen, {	if (wfs != 0	    && wbfs != 0	    && !same_font_size(wfs, wbfs)	    && (is_fixed_font(wfs) && is_fixed_font(wbfs))) {	    XFreeFont(screen->display, wbfs);	    wbfs = wfs;	    TRACE(("...fixing mismatched normal/bold wide fonts\n"));	    if (bfontname != 0) {		return xtermLoadFont(screen,				     VT_FONTSET(nfontname,						bfontname,						wfontname,						NULL),				     doresize,				     fontnum);	    }	}    });    /*     * Normal/bold fonts should be the same width.  Also, the min/max     * values should be the same.     */    if (!is_fixed_font(nfs)	|| !is_fixed_font(bfs)	|| nfs->max_bounds.width != bfs->max_bounds.width) {	TRACE(("Proportional font! normal %d/%d, bold %d/%d\n",	       nfs->min_bounds.width,	       nfs->max_bounds.width,	       bfs->min_bounds.width,	       bfs->max_bounds.width));	proportional = True;    }    if_OPT_WIDE_CHARS(screen, {	if (wfs != 0	    && wbfs != 0	    && (!is_fixed_font(wfs)		|| !is_fixed_font(wbfs)		|| wfs->max_bounds.width != wbfs->max_bounds.width)) {	    TRACE(("Proportional font! wide %d/%d, wide bold %d/%d\n",		   wfs->min_bounds.width,		   wfs->max_bounds.width,		   wbfs->min_bounds.width,		   wbfs->max_bounds.width));	    proportional = True;	}    });    /* TODO : enforce that the width of the wide font is 2* the width       of the narrow font */    mask = (GCFont | GCForeground | GCBackground | GCGraphicsExposures |	    GCFunction);    new_normal = getXtermForeground(term->flags, term->cur_foreground);    new_revers = getXtermBackground(term->flags, term->cur_background);    xgcv.font = nfs->fid;    xgcv.foreground = new_normal;    xgcv.background = new_revers;    xgcv.graphics_exposures = TRUE;	/* default */    xgcv.function = GXcopy;    new_normalGC = XtGetGC((Widget) term, mask, &xgcv);    if (!new_normalGC)	goto bad;    if (nfs == bfs) {		/* there is no bold font */	new_normalboldGC = new_normalGC;    } else {	xgcv.font = bfs->fid;	new_normalboldGC = XtGetGC((Widget) term, mask, &xgcv);	if (!new_normalboldGC)	    goto bad;    }    xgcv.font = nfs->fid;    xgcv.foreground = new_revers;    xgcv.background = new_normal;    new_reverseGC = XtGetGC((Widget) term, mask, &xgcv);    if (!new_reverseGC)	goto bad;    if (nfs == bfs) {		/* there is no bold font */	new_reverseboldGC = new_reverseGC;    } else {	xgcv.font = bfs->fid;	new_reverseboldGC = XtGetGC((Widget) term, mask, &xgcv);	if (!new_reverseboldGC)	    goto bad;    }    if (NormalGC(screen) != NormalBoldGC(screen))	XtReleaseGC((Widget) term, NormalBoldGC(screen));    XtReleaseGC((Widget) term, NormalGC(screen));    if (ReverseGC(screen) != ReverseBoldGC(screen))	XtReleaseGC((Widget) term, ReverseBoldGC(screen));    XtReleaseGC((Widget) term, ReverseGC(screen));    NormalGC(screen) = new_normalGC;    NormalBoldGC(screen) = new_normalboldGC;    ReverseGC(screen) = new_reverseGC;    ReverseBoldGC(screen) = new_reverseboldGC;    /*     * If we're switching fonts, free the old ones.  Otherwise we'll leak     * the memory that is associated with the old fonts.  The     * XLoadQueryFont call allocates a new XFontStruct.     */    if (screen->fnt_bold != 0	&& screen->fnt_bold != screen->fnt_norm)	XFreeFont(screen->display, screen->fnt_bold);    if (screen->fnt_norm != 0)	XFreeFont(screen->display, screen->fnt_norm);    screen->fnt_norm = nfs;    screen->fnt_bold = bfs;#if OPT_WIDE_CHARS    screen->fnt_dwd = wfs;    screen->fnt_dwdb = wbfs;#endif    screen->fnt_prop = proportional;    screen->fnt_boxes = True;#if OPT_BOX_CHARS    /*     * Xterm uses character positions 1-31 of a font for the line-drawing     * characters.  Check that they are all present.  The null character     * (0) is special, and is not used.     */    for (ch = 1; ch < 32; ch++) {	int n = ch;#if OPT_WIDE_CHARS	if (screen->utf8_mode) {	    n = dec2ucs[ch];	    if (n == UCS_REPL)		continue;	}#endif	if (xtermMissingChar(n, nfs)	    || xtermMissingChar(n, bfs)) {	    screen->fnt_boxes = False;	    break;	}    }    TRACE(("Will %suse internal line-drawing characters\n",	   screen->fnt_boxes ? "not " : ""));#endif    screen->enbolden = screen->bold_mode	&& ((nfs == bfs) || same_font_name(normal, bfontname));    TRACE(("Will %suse 1-pixel offset/overstrike to simulate bold\n",	   screen->enbolden ? "" : "not "));    set_menu_font(False);    screen->menu_font_number = fontnum;    set_menu_font(True);    if (tmpname) {		/* if setting escape or sel */	if (screen->menu_font_names[fontnum])	    free(screen->menu_font_names[fontnum]);	screen->menu_font_names[fontnum] = tmpname;	if (fontnum == fontMenu_fontescape) {	    set_sensitivity(term->screen.fontMenu,			    fontMenuEntries[fontMenu_fontescape].widget,			    TRUE);	}#if OPT_SHIFT_FONTS	screen->menu_font_sizes[fontnum] = FontSize(nfs);#endif    }    set_cursor_gcs(screen);    xtermUpdateFontInfo(screen, doresize);    return 1;  bad:    if (tmpname)	free(tmpname);    if (new_normalGC)	XtReleaseGC((Widget) term, new_normalGC);    if (new_normalboldGC && new_normalGC != new_normalboldGC)	XtReleaseGC((Widget) term, new_normalboldGC);    if (new_reverseGC)	XtReleaseGC((Widget) term, new_reverseGC);    if (new_reverseboldGC && new_reverseGC != new_reverseboldGC)	XtReleaseGC((Widget) term, new_reverseboldGC);    if (nfs)	XFreeFont(screen->display, nfs);    if (bfs && nfs != bfs)	XFreeFont(screen->display, bfs);#if OPT_WIDE_CHARS    if (wfs)	XFreeFont(screen->display, wfs);    if (wbfs && wbfs != wfs)	XFreeFont(screen->display, wbfs);#endif    return 0;}