[comp.windows.x] Dynamic font change for xterm X10/6.6A

leres@ucbarpa.Berkeley.EDU (Craig Leres) (05/16/87)

I've always wanted to dynamically change the font in xterm windows.
The code I hacked out today is appended. After installing the new code,
an escape sequence similar to "\033]47;fontname\033" will cause a new
font to be loaded. The window is then resized to handle the new
physical size.

		Craig
------
/* Put this new routine right after VTInit() in charproc.c */

VTChangeFont(screen, newfname)
	register Screen *screen;
	char *newfname;
{
	register Vertex *vp;
	FontInfo *fInfo;
	register width, height, border, extra;
 
	/* Make sure we can get the new font */
	if ((fInfo = XOpenFont(newfname)) == NULL)
		return(FALSE);
 
	/* Disallow variable fonts with no average sizes for now */
	if (fInfo->width == 0 || fInfo->height == 0) {
		XCloseFont(fInfo);
		return(FALSE);
	}
 
	/* Destroy old font */
	XFreeFont(screen->fnt_norm);
 
	screen->fnt_norm = fInfo->id;
 
	if (screen->enbolden)
		screen->fnt_bold = screen->fnt_norm;
 
	XSetResizeHint (VWindow(screen), 2 * screen->border + screen->scrollbar,
	 2 * screen->border + Titlebar(screen) + screen->statusheight,
	 fInfo->width, fInfo->height);
 
	screen->fullVwin.f_width = fInfo->width;
	screen->fullVwin.f_height = fInfo->height;
 
	free((char *)fInfo);
 
	width = FontWidth(screen) * (screen->max_col + 1);
	height = FontHeight(screen) * (screen->max_row + 1);
	border = 2 * screen->border;
	extra = Titlebar(screen) + screen->statusheight;
 
	screen->fullVwin.fullwidth = width;
	screen->fullVwin.fullheight = height;
	screen->fullVwin.height = height - border - extra;
	screen->fullVwin.width = width - border - screen->scrollbar;
 
	vp = &VTbox[1];
	(vp++)->x = FontWidth(screen) - 1;
	(vp++)->y = FontHeight(screen) - 1;
	(vp++)->x = -(FontWidth(screen) - 1);
	vp->y = -(FontHeight(screen) - 1);
 
	if(screen->sb)
		ResizeScrollBar(screen->sb, width - SCROLLBARWIDTH,
		    Titlebar(screen) - 1, height - Titlebar(screen),
		    screen->max_row + 1);
	if(screen->title.tbar)
}
		VTTitleResize(width);

/* Insert this new code in the switch in do_osc() in misc.c */

	 case 47:	/* new screen font */
		if (VTChangeFont(screen, buf)) {
			XChangeWindow (VWindow(screen),
			 FontWidth(screen) * (screen->max_col + 1) +
			 2 * screen->border + screen->scrollbar,
			 FontHeight(screen) * (screen->max_row + 1) +
			 screen->statusheight + Titlebar(screen)
			 + 2 * screen->border);
			XSync(FALSE);	/* synchronize */
			if(QLength() > 0)
				xevents();
		}
		break;

/* end */