xref: /csrg-svn/old/vpr/vtools/vwidth.c (revision 13950)
1*13950Ssam #ifndef lint
2*13950Ssam static char sccsid[] = "@(#)vwidth.c	4.2 (Berkeley) 07/16/83";
3*13950Ssam #endif
4*13950Ssam 
511452Sralph /*
611452Sralph  *	Creates a width table for troff from a versatec font for a
711452Sralph  *		normal font.
811452Sralph  *	Usage: width font [ point_size ]
911452Sralph  *		where font is the file name of the versatec font and
1011452Sralph  *		point_size is it point size.
1111452Sralph  *	If the point size is omitted it is taken from the suffix of
1211452Sralph  *	the font name, as bocklin.14 => 14 point.
1311452Sralph  *	It is better to use as large a point size font as possible
1411452Sralph  *	to avoid round off.
1511452Sralph  */
1611452Sralph 
1711452Sralph #include <stdio.h>
1811452Sralph 
1911452Sralph struct wtable {
2011452Sralph 	char	charloc;
2111452Sralph 	char	*name;
2211452Sralph } wtable[] = {
2311452Sralph 	'\214',	"space",
2411452Sralph 	'!',	"!",
2511452Sralph 	'"',	"\"",
2611452Sralph 	'#',	"#",
2711452Sralph 	'$',	"$",
2811452Sralph 	'%',	"%",
2911452Sralph 	'&',	"&",
3011452Sralph 	'\'',	"'",
3111452Sralph 	'(',	"(",
3211452Sralph 	')',	")",
3311452Sralph 	'*',	"*",
3411452Sralph 	'+',	"+",
3511452Sralph 	',',	",",
3611452Sralph 	'-',	"- hyphen",
3711452Sralph 	'.',	".",
3811452Sralph 	'/',	"/",
3911452Sralph 	'0',	"0",
4011452Sralph 	'1',	"1",
4111452Sralph 	'2',	"2",
4211452Sralph 	'3',	"3",
4311452Sralph 	'4',	"4",
4411452Sralph 	'5',	"5",
4511452Sralph 	'6',	"6",
4611452Sralph 	'7',	"7",
4711452Sralph 	'8',	"8",
4811452Sralph 	'9',	"9",
4911452Sralph 	':',	":",
5011452Sralph 	';',	";",
5111452Sralph 	'<',	"<",
5211452Sralph 	'=',	"=",
5311452Sralph 	'>',	">",
5411452Sralph 	'?',	"?",
5511452Sralph 	'@',	"@",
5611452Sralph 	'A',	"A",
5711452Sralph 	'B',	"B",
5811452Sralph 	'C',	"C",
5911452Sralph 	'D',	"D",
6011452Sralph 	'E',	"E",
6111452Sralph 	'F',	"F",
6211452Sralph 	'G',	"G",
6311452Sralph 	'H',	"H",
6411452Sralph 	'I',	"I",
6511452Sralph 	'J',	"J",
6611452Sralph 	'K',	"K",
6711452Sralph 	'L',	"L",
6811452Sralph 	'M',	"M",
6911452Sralph 	'N',	"N",
7011452Sralph 	'O',	"O",
7111452Sralph 	'P',	"P",
7211452Sralph 	'Q',	"Q",
7311452Sralph 	'R',	"R",
7411452Sralph 	'S',	"S",
7511452Sralph 	'T',	"T",
7611452Sralph 	'U',	"U",
7711452Sralph 	'V',	"V",
7811452Sralph 	'W',	"W",
7911452Sralph 	'X',	"X",
8011452Sralph 	'Y',	"Y",
8111452Sralph 	'Z',	"Z",
8211452Sralph 	'[',	"[",
8311452Sralph 	'\\',	"\\",
8411452Sralph 	']',	"]",
8511452Sralph 	'^',	"^",
8611452Sralph 	'_',	"_",
8711452Sralph 	'\`',	"\`",
8811452Sralph 	'a',	"a",
8911452Sralph 	'b',	"b",
9011452Sralph 	'c',	"c",
9111452Sralph 	'd',	"d",
9211452Sralph 	'e',	"e",
9311452Sralph 	'f',	"f",
9411452Sralph 	'g',	"g",
9511452Sralph 	'h',	"h",
9611452Sralph 	'i',	"i",
9711452Sralph 	'j',	"j",
9811452Sralph 	'k',	"k",
9911452Sralph 	'l',	"l",
10011452Sralph 	'm',	"m",
10111452Sralph 	'n',	"n",
10211452Sralph 	'o',	"o",
10311452Sralph 	'p',	"p",
10411452Sralph 	'q',	"q",
10511452Sralph 	'r',	"r",
10611452Sralph 	's',	"s",
10711452Sralph 	't',	"t",
10811452Sralph 	'u',	"u",
10911452Sralph 	'v',	"v",
11011452Sralph 	'w',	"w",
11111452Sralph 	'x',	"x",
11211452Sralph 	'y',	"y",
11311452Sralph 	'z',	"z",
11411452Sralph 	'{',	"{",
11511452Sralph 	'|',	"|",
11611452Sralph 	'}',	"}",
11711452Sralph 	'~',	"~",
11811452Sralph 	'\206',	"narrow space",
11911452Sralph 	'-',	"hyphen",
12011452Sralph 	'\07',	"bullet",
12111452Sralph 	'\010',	"square",
12211452Sralph 	'\06',	"3/4 em dash",
12311452Sralph 	'\05',	"rule",
12411452Sralph 	'\021',	"1/4",
12511452Sralph 	'\022',	"1/2",
12611452Sralph 	'\023',	"3/4",
12711452Sralph 	'\04',	"minus",
12811452Sralph 	'\01',	"fi",
12911452Sralph 	'\02',	"fl",
13011452Sralph 	'\03',	"ff",
13111452Sralph 	'\011',	"ffi",
13211452Sralph 	'\012',	"ffl",
13311452Sralph 	'\013',	"degree",
13411452Sralph 	'\014',	"dagger",
13511452Sralph 	'\200',	"section (unimplem)",
13611452Sralph 	'\015',	"foot mark",
13711452Sralph 	'\200',	"acute acc (unimplem)",
13811452Sralph 	'\200',	"grave acc (unimplem)",
13911452Sralph 	'\200',	"underrule (unimplem)",
14011452Sralph 	'\200',	"slash (unimplem)",
14111452Sralph 	'\203',	"half narrow space",
14211452Sralph 	'\200',	"null",
14311452Sralph 	'\200',	"null",
14411452Sralph 	'\200',	"null",
14511452Sralph 	'\200',	"null",
14611452Sralph 	'\200',	"null",
14711452Sralph 	'\200',	"null",
14811452Sralph 	'\200',	"null",
14911452Sralph 	'\200',	"null",
15011452Sralph 	'\200',	"null",
15111452Sralph 	'\200',	"null",
15211452Sralph 	'\200',	"null",
15311452Sralph 	'\200',	"null",
15411452Sralph 	'\200',	"null",
15511452Sralph 	'\200',	"null",
15611452Sralph 	'\200',	"null",
15711452Sralph 	'\200',	"null",
15811452Sralph 	'\200',	"null",
15911452Sralph 	'\200',	"null",
16011452Sralph 	'\200',	"null",
16111452Sralph 	'\200',	"null",
16211452Sralph 	'\200',	"null",
16311452Sralph 	'\200',	"null",
16411452Sralph 	'\200',	"null",
16511452Sralph 	'\200',	"null",
16611452Sralph 	'\200',	"null",
16711452Sralph 	'\200',	"null",
16811452Sralph 	'\200',	"null",
16911452Sralph 	'\200',	"null",
17011452Sralph 	'\200',	"null",
17111452Sralph 	'\200',	"null",
17211452Sralph 	'\200',	"null",
17311452Sralph 	'\200',	"null",
17411452Sralph 	'\200',	"null",
17511452Sralph 	'\200',	"null",
17611452Sralph 	'\200',	"null",
17711452Sralph 	'\200',	"null",
17811452Sralph 	'\200',	"null",
17911452Sralph 	'\200',	"null",
18011452Sralph 	'\200',	"null",
18111452Sralph 	'\200',	"null",
18211452Sralph 	'\200',	"null",
18311452Sralph 	'\200',	"null",
18411452Sralph 	'\200',	"null",
18511452Sralph 	'\200',	"null",
18611452Sralph 	'\200',	"null",
18711452Sralph 	'\200',	"null",
18811452Sralph 	'\200',	"null",
18911452Sralph 	'\200',	"null",
19011452Sralph 	'\200',	"null",
19111452Sralph 	'\200',	"null",
19211452Sralph 	'\200',	"null",
19311452Sralph 	'\200',	"null",
19411452Sralph 	'\200',	"null",
19511452Sralph 	'\200',	"null",
19611452Sralph 	'\200',	"null",
19711452Sralph 	'\200',	"null",
19811452Sralph 	'\200',	"null",
19911452Sralph 	'\200',	"null",
20011452Sralph 	'\200',	"null",
20111452Sralph 	'\200',	"null",
20211452Sralph 	'\200',	"null",
20311452Sralph 	'\200',	"null",
20411452Sralph 	'\200',	"null",
20511452Sralph 	'\200',	"null",
20611452Sralph 	'\200',	"null",
20711452Sralph 	'\200',	"null",
20811452Sralph 	'\200',	"null",
20911452Sralph 	'\200',	"null",
21011452Sralph 	'\200',	"null",
21111452Sralph 	'\200',	"null",
21211452Sralph 	'\200',	"null",
21311452Sralph 	'\017',	"registered",
21411452Sralph 	'\016',	"copyright",
21511452Sralph 	'\200',	"null",
21611452Sralph 	'\020',	"cent",
21711452Sralph 	0,	0
21811452Sralph };
21911452Sralph 
22011452Sralph struct desc {
22111452Sralph 	short	addr;
22211452Sralph 	short	nbytes;
22311452Sralph 	char	up;
22411452Sralph 	char	down;
22511452Sralph 	char	left;
22611452Sralph 	char	right;
22711452Sralph 	short	width;
22811452Sralph } desc[256];
22911452Sralph 
23011452Sralph main(argc, argv)
23111452Sralph 	int argc;
23211452Sralph 	char *argv[];
23311452Sralph {
23411452Sralph 	register int cl;
23511452Sralph 	register esc;
23611452Sralph 	register w;
23711452Sralph 	int i, psize;
23811452Sralph 	int fd, high;
23911452Sralph 
24011452Sralph 	if (argc != 3 && argc != 2) {
24111452Sralph 		printf("Usage: vwidth font [pointsize] > font.c\n");
24211452Sralph 		exit(1);
24311452Sralph 	}
24411452Sralph 	fd = open(argv[1], 0);
24511452Sralph 	if (argc == 3)
24611452Sralph 		psize = atoi(argv[2]);
24711452Sralph 	else {
24811452Sralph 		char *p;
24911452Sralph 		for (p = argv[1]; *p && *p != '.'; p++)
25011452Sralph 			;
25111452Sralph 		if (*p == 0) {
25211452Sralph 			psize = 10;
25311452Sralph 			fprintf(stderr, "Assuming %d point\n", psize);
25411452Sralph 		} else
25511452Sralph 			psize = atoi(p+1);
25611452Sralph 	}
25711452Sralph 	lseek(fd, 10L, 0);
25811452Sralph 	read(fd, desc, sizeof desc);
25911452Sralph 	high = desc['a'].up+1;
26011452Sralph 	printf("char XXw[256-32] = {\n");
26111452Sralph 	for (i = 0; wtable[i].charloc != 0; i++) {
26211452Sralph 		cl = wtable[i].charloc & 0377;
26311452Sralph 		if (cl & 0200)
26411452Sralph 			w = cl & 0177;
26511452Sralph 		else
26611452Sralph 			w = desc[cl].width*(54./25.)*(6./psize)+.5;
26711452Sralph 		esc = 0;
26811452Sralph 		if ((cl >= '0' && cl <= '9') || (cl >= 'A' && cl <= 'Z') ||
26911452Sralph 		    (cl >= 'a' && cl <= 'z')) {
27011452Sralph 			if (desc[cl].up > high)
27111452Sralph 				esc |= 0200;
27211452Sralph 			if (desc[cl].down > 0)
27311452Sralph 				esc |= 0100;
27411452Sralph 		}
27511452Sralph 		if (esc)
27611452Sralph 			printf("%d+0%o,\t/* %s */\n", w, esc, wtable[i].name);
27711452Sralph 		else
27811452Sralph 			printf("%d,\t\t/* %s */\n", w, wtable[i].name);
27911452Sralph 	}
28011452Sralph 	printf("};\n");
28111452Sralph }
282