LoadNewFont (screen, nfontname, bfontname, doresize, fontnum) TScreen *screen; char *nfontname, *bfontname; Bool doresize; int fontnum;
LoadNewFont ( TScreen *screen, char *nfontname, char *bfontname, Bool doresize, int fontnum)
LoadNewFont (screen, nfontname, bfontname, doresize, fontnum)    TScreen *screen;    char *nfontname, *bfontname;    Bool doresize;    int fontnum;{    XFontStruct *nfs = NULL, *bfs = NULL;    XGCValues xgcv;    unsigned long mask;    GC new_normalGC = NULL, new_normalboldGC = NULL;    GC new_reverseGC = NULL, new_reverseboldGC = NULL;    Pixel new_normal, new_revers;    char *tmpname = NULL;    Boolean proportional = False;    if (!nfontname) return 0;    if (fontnum == fontMenu_fontescape &&	nfontname != screen->menu_font_names[fontnum]) {	tmpname = (char *) malloc (strlen(nfontname) + 1);	if (!tmpname) return 0;	strcpy (tmpname, nfontname);    }    if (!(nfs = XLoadQueryFont (screen->display, nfontname))) goto bad;    if (nfs->ascent + nfs->descent == 0  ||  nfs->max_bounds.width == 0)	goto bad;		/* can't use a 0-sized font */    if (!(bfontname &&	  (bfs = XLoadQueryFont (screen->display, bfontname))))      bfs = nfs;    else	if (bfs->ascent + bfs->descent == 0  ||  bfs->max_bounds.width == 0)	    goto bad;		/* can't use a 0-sized font */    if (nfs->min_bounds.width != nfs->max_bounds.width     || bfs->min_bounds.width != bfs->max_bounds.width     || nfs->min_bounds.width != bfs->min_bounds.width     || nfs->max_bounds.width != bfs->max_bounds.width) {	TRACE(("Proportional font!\n"))	proportional = True;    }    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;    screen->fnt_prop = proportional;    screen->enbolden = (nfs == bfs);    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);	}    }    set_cursor_gcs (screen);    update_font_info (screen, doresize);    return 1;  bad:    if (tmpname) free (tmpname);    if (new_normalGC)      XtReleaseGC ((Widget) term, screen->fullVwin.normalGC);    if (new_normalGC && new_normalGC != new_normalboldGC)      XtReleaseGC ((Widget) term, new_normalboldGC);    if (new_reverseGC)      XtReleaseGC ((Widget) term, new_reverseGC);    if (new_reverseGC && new_reverseGC != new_reverseboldGC)      XtReleaseGC ((Widget) term, new_reverseboldGC);    if (nfs) XFreeFont (screen->display, nfs);    if (bfs && nfs != bfs) XFreeFont (screen->display, bfs);    return 0;}