--- ray/src/common/font.c 1992/06/24 17:52:58 2.3 +++ ray/src/common/font.c 1995/05/25 15:14:03 2.10 @@ -15,7 +15,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define galloc(nv) (GLYPH *)malloc(sizeof(GLYPH)+2*sizeof(GORD)*(nv)) -extern char *libpath; /* list of library directories */ +extern char *fgetword(), *getlibpath(); static FONT *fontlist = NULL; /* list of loaded fonts */ @@ -30,7 +30,7 @@ char *fname; unsigned wsum, hsum, ngly; int gn, ngv; register int gv; - register GLYPH *g; + register GLYPH *g; GORD *gp; register FONT *f; @@ -38,7 +38,7 @@ char *fname; if (!strcmp(f->name, fname)) return(f); /* load the font file */ - if ((pathname = getpath(fname, libpath, R_OK)) == NULL) { + if ((pathname = getpath(fname, getlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find font file \"%s\"", fname); error(USER, errmsg); } @@ -122,9 +122,32 @@ memerr: } +freefont(fname) /* free a font (free all if fname==NULL) */ +char *fname; +{ + FONT head; + register FONT *fl, *f; + register int i; + + head.next = fontlist; + fl = &head; + while ((f = fl->next) != NULL) + if (fname == NULL || !strcmp(fname, f->name)) { + fl->next = f->next; + for (i = 0; i < 256; i++) + if (f->fg[i] != NULL) + free((char *)f->fg[i]); + freestr(f->name); + free((char *)f); + } else + fl = f; + fontlist = head.next; +} + + int uniftext(sp, tp, f) /* uniformly space text line */ -register short *sp; /* returned character spacing */ +register short *sp; /* returned character spacing */ register char *tp; /* text line */ register FONT *f; /* font */ { @@ -135,7 +158,7 @@ register FONT *f; /* font */ if (f->fg[*tp++&0xff] == NULL) *sp++ = 0; else - linelen += *sp++ = 256; + linelen += *sp++ = 255; return(linelen); } @@ -148,13 +171,14 @@ FONT *f; /* font */ int cis; /* intercharacter spacing */ { int linelen; - register GLYPH *gp; + register GLYPH *gp; + linelen = 0; gp = NULL; while (*tp && (gp = f->fg[*tp++&0xff]) == NULL) *sp++ = 0; cis /= 2; - linelen = *sp = cis; + *sp = cis; while (gp != NULL) { if (gp->nverts) { /* regular character */ linelen += *sp++ += cis - gp->left; @@ -189,9 +213,9 @@ int nsi; /* minimum number of spaces for indent */ /* start by squeezing it */ squeeztext(sp, tp, f, cis); /* now, realign spacing */ - len = 0; - width = alen = *sp++; + width = *sp++; while (*tp) { + len = alen = 0; nsp = sp; for (end = tp; *end; end = tab) { tab = end + 1; @@ -204,7 +228,7 @@ int nsi; /* minimum number of spaces for indent */ } len += tab - end; } - if (tab - end > nsi) + if (nsi && tab - end > nsi) break; } len *= f->mwidth + cis; /* compute target length */ @@ -215,8 +239,6 @@ int nsi; /* minimum number of spaces for indent */ *sp++ += alen; len -= alen; } - len = 0; - alen = 0; tp = tab; } return(width);