home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume8
/
xfig2.8
/
part03
/
font.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-02
|
4KB
|
161 lines
/*
* FIG : Facility for Interactive Generation of figures
*
* Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
* January 1985.
* 1st revision : Aug 1985.
*
* %W% %G%
*/
#include "const.h"
#include "fig.h"
#include "resources.h"
#include "font.h"
#include "psfonts.h"
PIX_FONT bold_font;
PIX_FONT roman_font;
PIX_FONT button_font;
extern struct _fstruct fontnames[NUMFONTS];
extern appresStruct appres;
XFontStruct *XLoadQueryFont();
#define MAXNAMES 30
static struct {
char *fn;
int s;
} flist[MAXNAMES];
init_font()
{
struct xfont *newfont, *nf;
int f,count,i,p,ss;
char **fontlist,**fname;
if( appres.boldFont == NULL || *appres.boldFont == NULL)
appres.boldFont = BOLD_FONT;
if( appres.normalFont == NULL || *appres.normalFont == NULL)
appres.normalFont = NORMAL_FONT;
roman_font = XLoadQueryFont(tool_d, appres.normalFont);
if ((bold_font = XLoadQueryFont(tool_d, appres.boldFont)) ==0)
{
fprintf(stderr,"Can't load font: %s, using %s\n",
appres.boldFont,appres.normalFont);
bold_font = XLoadQueryFont(tool_d, appres.normalFont);
}
button_font = XLoadQueryFont(tool_d, NORMAL_FONT);
for (i=0; i<0x10; i++)
{
gc_font[i] = -1;
gc_fontsize[i] = 0;
}
/* Now initialize the font structure for the X fonts corresponding
to the Postscript fonts for the canvas */
for (f=0; f < NUMFONTS; f++)
{
nf = NULL;
if (fontlist = XListFonts(tool_d, fontnames[f].template, MAXNAMES, &count))
{
fname = fontlist; /* go through the list finding point sizes */
p=0;
while (count--)
{
ss = parsesize(*fname); /* get the point size from the name */
flist[p].fn = *fname++; /* save name of this size font */
flist[p++].s = ss; /* and save size */
}
for (ss=4; ss<=40; ss++)
{
for (i=0; i<p; i++)
if (flist[i].s == ss)
break;
if (i<p && flist[i].s == ss)
{
newfont = (struct xfont *) malloc(sizeof(struct xfont));
if (nf==NULL)
fontnames[f].xfontlist = newfont;
else
nf-> next = newfont;
nf = newfont; /* keep current ptr */
nf->size = ss; /* store the size here */
nf->fid = NULL; /* haven't loaded the font yet */
nf->fstruct = NULL; /* ditto */
nf->fname = flist[i].fn; /* keep actual name */
nf->next = NULL;
}
}
}
} /* next font, f */
}
/* parse the point size of font 'name' */
/* e.g. -adobe-courier-bold-o-normal--10-100-75-75-m-60-iso8859-1 */
int
parsesize(name)
char *name;
{
int s;
char *np;
for (np = name; *(np+1); np++)
if (*np=='-' && *(np+1)=='-') /* look for the -- */
break;
s=0;
if (*(np+1))
{
np += 2; /* point past the -- */
s = atoi(np); /* get the point size */
}
else
fprintf(stderr,"Can't parse '%s'\n",name);
return s;
}
/* Lookup an X font corresponding to a Postscript font style that is close in size */
PIX_FONT
lookfont(f,s)
int f,s;
{
struct xfont *xf;
XFontStruct *fontst;
if (f<0) /* use font 0 for default font (-1) */
f=0;
if (s<0)
s=DEF_PRINTFONTSIZE; /* default font size */
xf = fontnames[f].xfontlist; /* go through the linked list looking for match */
if (xf == NULL)
return roman_font; /* use a default font */
while (1)
{
if (s <= xf->size) /* exact or larger point size */
break;
if (xf->next != NULL) /* keep ptr to last if not found */
xf = xf->next;
else
break; /* not found, use largest point size in the list */
}
if (xf->fid == NULL) /* if the font is not yet loaded, load it */
{
if (appres.DEBUG)
fprintf(stderr,"Loading font %s\n",xf->fname);
if (fontst = XLoadQueryFont(tool_d, xf->fname)) /* load it */
{
xf->fid = fontst->fid; /* save the id */
xf->fstruct = fontst; /* and the XFontStruct ptr */
}
else
fprintf(stderr,"What!!?!?! Can't find font %s\n",xf->fname);
}
return xf->fstruct;
}