local/transcript/src/psgrind.c
/* Scan the font metrics directory looking for entries that match the
 * entries in ``fonts''.  For entries
 * that are found the data in the font description is filled in,
 * if any are missing, it dies horribly.
 */
Scan the font metrics directory looking for entries that match the
entries in ``fonts''.  For entries
that are found the data in the font description is filled in,
if any are missing, it dies horribly.
Scan the font metrics directory looking for entries that match the entries in ` ` fonts ' ' . For entries that are found the data in the font description is filled in if any are missing it dies horribly .
private ScanFont () {
    register struct font   *f;
    register FILE *FontData;		
    char    *c;
    int     ccode, cwidth, inChars;
    char   *MetricsDir = (char *) getenv ("METRICS");
    char    FontFile[512];		
    char    afmbuf[BUFSIZ];
    if (MetricsDir == 0)
	MetricsDir = LibDir;
    if (!SeenFont & Rotated & TwoColumn) {
	fonts[HeaderFont].dsize = 10;
	fonts[BodyFont].dsize = 7;
	fonts[KwordFont].dsize = 7;
	fonts[LiteralFont].dsize = 8;
	fonts[CommentFont].dsize = 7;
    }
    ForAllFonts (f) {
	mstrcat(FontFile, MetricsDir, "/", sizeof FontFile);
	mstrcat(FontFile, FontFile, f->name, sizeof FontFile);
	mstrcat(FontFile, FontFile, ".afm", sizeof FontFile);
	if ((FontData = fopen(FontFile,"r")) == NULL){
	    fprintf(stderr,"Can't open font metrics file %s\n",FontFile);
	    exit(1);
	}
	for (ccode = 0; ccode < FSIZEMAX; ccode++) f->Xwid[ccode] = NOTDEF;
	inChars = 0;
	while(fgets(afmbuf, sizeof afmbuf, FontData) != NULL) {
	    if ((c = index(afmbuf, '\n')) == 0) {
		fprintf(stderr, "AFM file %s line too long %s\n", FontFile, afmbuf);
		exit(1);
	    }
	    *c = '\0';
	    if (*afmbuf == '\0') continue;
	    if (strcmp(afmbuf, "StartCharMetrics") == 0) {
		inChars++;
		continue;
	    }
	    if (strcmp(afmbuf, "EndCharMetrics") == 0) break;
	    if (inChars == 1) {
		if (sscanf(afmbuf, "C %d ; WX %d ;",&ccode,&cwidth) != 2) {
		    fprintf(stderr,"Trouble with AFM file %s\n",FontFile);
		    exit(1);
		}
		if (ccode == -1) break;
		if (ccode > 255) continue;
		f->Xwid[ccode] = (cwidth * f->dsize * UperPt) / 1000;
		continue;
	    }
	}
    fclose (FontData);
    }
    TabWidth = fonts[BodyFont].Xwid['0'] * 8; 
    BSWidth = fonts[BodyFont].Xwid[' '];  
    UperLine = (fonts[BodyFont].dsize + 1) * UperPt;
    if (LPTsimulate)
	UperHLine = UperLine;
    else
	UperHLine = (fonts[HeaderFont].dsize + 1) * UperPt;
    crX = 0;
    crY = -UperLine;
}
private ScanFont ( ) { register struct font * f ; register FILE * FontData ; char * c ; int ccode , cwidth , inChars ; char * MetricsDir = ( char * ) getenv ( " " ) ; char FontFile [ 512 ] ; char afmbuf [ BUFSIZ ] ; if ( MetricsDir == 0 ) MetricsDir = LibDir ; if ( ! SeenFont & Rotated & TwoColumn ) { fonts [ HeaderFont ] . dsize = 10 ; fonts [ BodyFont ] . dsize = 7 ; fonts [ KwordFont ] . dsize = 7 ; fonts [ LiteralFont ] . dsize = 8 ; fonts [ CommentFont ] . dsize = 7 ; } ForAllFonts ( f ) { mstrcat ( FontFile , MetricsDir , " " , sizeof FontFile ) ; mstrcat ( FontFile , FontFile , f -> name , sizeof FontFile ) ; mstrcat ( FontFile , FontFile , " " , sizeof FontFile ) ; if ( ( FontData = fopen ( FontFile , " " ) ) == NULL ) { fprintf ( stderr , " \n " , FontFile ) ; exit ( 1 ) ; } for ( ccode = 0 ; ccode < FSIZEMAX ; ccode ++ ) f -> Xwid [ ccode ] = NOTDEF ; inChars = 0 ; while ( fgets ( afmbuf , sizeof afmbuf , FontData ) != NULL ) { if ( ( c = index ( afmbuf , ' \n ' ) ) == 0 ) { fprintf ( stderr , " \n " , FontFile , afmbuf ) ; exit ( 1 ) ; } * c = ' \0 ' ; if ( * afmbuf == ' \0 ' ) continue ; if ( strcmp ( afmbuf , " " ) == 0 ) { inChars ++ ; continue ; } if ( strcmp ( afmbuf , " " ) == 0 ) break ; if ( inChars == 1 ) { if ( sscanf ( afmbuf , " " , & ccode , & cwidth ) != 2 ) { fprintf ( stderr , " \n " , FontFile ) ; exit ( 1 ) ; } if ( ccode == -1 ) break ; if ( ccode > 255 ) continue ; f -> Xwid [ ccode ] = ( cwidth * f -> dsize * UperPt ) / 1000 ; continue ; } } fclose ( FontData ) ; } TabWidth = fonts [ BodyFont ] . Xwid [ ' ' ] * 8 ; BSWidth = fonts [ BodyFont ] . Xwid [ ' ' ] ; UperLine = ( fonts [ BodyFont ] . dsize + 1 ) * UperPt ; if ( LPTsimulate ) UperHLine = UperLine ; else UperHLine = ( fonts [ HeaderFont ] . dsize + 1 ) * UperPt ; crX = 0 ; crY = - UperLine ; }
Scan the font metrics directory looking for entries that match the
 entries in ``fonts''.
Scan the font metrics directory looking for entries that match the entries in ` ` fonts ' ' .
/* afm file */ /* afm file name */ /* loop through fonts, find and read metric entry in dir */ /* read the .afm file to get the widths */ /* strip off newline */ /* get out once we see an unencoded char */ /* 8 * figure width */ /* space width */