/* $Id: Fonts.c,v 1.1 1997/04/15 10:09:32 archer Exp $
 *	FONTS.C - Font caching
 *
 * Include common fonts, and the like
 */
#include <Widget/Perror.h>
#include <Widget/fontsP.h>


/**
 ** Common font names
 **/
char	x11__font_courrier12[] =
		"-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1";
char	x11__font_helvetica10[] =
		"-adobe-helvetica-medium-r-normal-*-10-*-*-*-*-*-iso8859-1";
char	x11__font_helvetica12[] =
		"-adobe-helvetica-medium-r-normal-*-12-*-*-*-*-*-iso8859-1";
char	x11__font_helveticabold12[] =
		"-adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-iso8859-1";
char	x11__font_lucida12[] =
		"-*-lucida sans-medium-r-normal-*-12-*-*-*-*-*-iso8859-1";
char	x11__font_lucidabold12[] =
		"-*-lucida sans-bold-r-normal-*-12-*-*-*-*-*-iso8859-1";


/**
 ** Private variable
 **/
static x11__font	*font_list;


/**
 ** X11_FONT_FIND
 **	Find a font, using the local cache
 **/
XFontStruct *x11__font_find(char *name)
{
x11__font	*f;
/*
 * Font in cache?
 */
	for (f = font_list; f; f = f->next)
		if (strcmp(name, f->name) == 0)
			return f->info;
/*
 * New font
 */
	f         = allocator(x11__font);
	if ((f->name = strdup(name)) == 0)
		X11_Perror("Can't allocate font name");
	f->next   = font_list;
	font_list = f;
	f->info   = XLoadQueryFont(x11__screen, name);
	return f->info;
}


/**
 ** X11_FONT_RESOURCE
 **	Find out a .Font resource, with a default
 **/
XFontStruct *x11__font_resource(char *def)
{
XFontStruct	*f;
char		*s;
/*
 * As specified by .Font
 */
	if ((s = x11__resource_value("Font")) != 0 &&
	    (f = x11__font_find(s)) != 0)
		return f;
/*
 * As appropriate widget default
 */
	if ((f = x11__font_find(def)) != 0)
		return f;
/*
 * As approriate generic default
 */
	if ((f = x11__font_find("9x15")) != 0)
		return f;
/*
 * Catastrophic failure!
 */
/*** HACK ***/
	fprintf(stderr, "Fatal font error\n");
	abort();
}
