xref: /csrg-svn/old/vpr/vtools/vwidth.c (revision 11452)
1*11452Sralph /*	vwidth.c	4.1	83/03/09	*/
2*11452Sralph /*
3*11452Sralph  *	Creates a width table for troff from a versatec font for a
4*11452Sralph  *		normal font.
5*11452Sralph  *	Usage: width font [ point_size ]
6*11452Sralph  *		where font is the file name of the versatec font and
7*11452Sralph  *		point_size is it point size.
8*11452Sralph  *	If the point size is omitted it is taken from the suffix of
9*11452Sralph  *	the font name, as bocklin.14 => 14 point.
10*11452Sralph  *	It is better to use as large a point size font as possible
11*11452Sralph  *	to avoid round off.
12*11452Sralph  */
13*11452Sralph 
14*11452Sralph #include <stdio.h>
15*11452Sralph 
16*11452Sralph struct wtable {
17*11452Sralph 	char	charloc;
18*11452Sralph 	char	*name;
19*11452Sralph } wtable[] = {
20*11452Sralph 	'\214',	"space",
21*11452Sralph 	'!',	"!",
22*11452Sralph 	'"',	"\"",
23*11452Sralph 	'#',	"#",
24*11452Sralph 	'$',	"$",
25*11452Sralph 	'%',	"%",
26*11452Sralph 	'&',	"&",
27*11452Sralph 	'\'',	"'",
28*11452Sralph 	'(',	"(",
29*11452Sralph 	')',	")",
30*11452Sralph 	'*',	"*",
31*11452Sralph 	'+',	"+",
32*11452Sralph 	',',	",",
33*11452Sralph 	'-',	"- hyphen",
34*11452Sralph 	'.',	".",
35*11452Sralph 	'/',	"/",
36*11452Sralph 	'0',	"0",
37*11452Sralph 	'1',	"1",
38*11452Sralph 	'2',	"2",
39*11452Sralph 	'3',	"3",
40*11452Sralph 	'4',	"4",
41*11452Sralph 	'5',	"5",
42*11452Sralph 	'6',	"6",
43*11452Sralph 	'7',	"7",
44*11452Sralph 	'8',	"8",
45*11452Sralph 	'9',	"9",
46*11452Sralph 	':',	":",
47*11452Sralph 	';',	";",
48*11452Sralph 	'<',	"<",
49*11452Sralph 	'=',	"=",
50*11452Sralph 	'>',	">",
51*11452Sralph 	'?',	"?",
52*11452Sralph 	'@',	"@",
53*11452Sralph 	'A',	"A",
54*11452Sralph 	'B',	"B",
55*11452Sralph 	'C',	"C",
56*11452Sralph 	'D',	"D",
57*11452Sralph 	'E',	"E",
58*11452Sralph 	'F',	"F",
59*11452Sralph 	'G',	"G",
60*11452Sralph 	'H',	"H",
61*11452Sralph 	'I',	"I",
62*11452Sralph 	'J',	"J",
63*11452Sralph 	'K',	"K",
64*11452Sralph 	'L',	"L",
65*11452Sralph 	'M',	"M",
66*11452Sralph 	'N',	"N",
67*11452Sralph 	'O',	"O",
68*11452Sralph 	'P',	"P",
69*11452Sralph 	'Q',	"Q",
70*11452Sralph 	'R',	"R",
71*11452Sralph 	'S',	"S",
72*11452Sralph 	'T',	"T",
73*11452Sralph 	'U',	"U",
74*11452Sralph 	'V',	"V",
75*11452Sralph 	'W',	"W",
76*11452Sralph 	'X',	"X",
77*11452Sralph 	'Y',	"Y",
78*11452Sralph 	'Z',	"Z",
79*11452Sralph 	'[',	"[",
80*11452Sralph 	'\\',	"\\",
81*11452Sralph 	']',	"]",
82*11452Sralph 	'^',	"^",
83*11452Sralph 	'_',	"_",
84*11452Sralph 	'\`',	"\`",
85*11452Sralph 	'a',	"a",
86*11452Sralph 	'b',	"b",
87*11452Sralph 	'c',	"c",
88*11452Sralph 	'd',	"d",
89*11452Sralph 	'e',	"e",
90*11452Sralph 	'f',	"f",
91*11452Sralph 	'g',	"g",
92*11452Sralph 	'h',	"h",
93*11452Sralph 	'i',	"i",
94*11452Sralph 	'j',	"j",
95*11452Sralph 	'k',	"k",
96*11452Sralph 	'l',	"l",
97*11452Sralph 	'm',	"m",
98*11452Sralph 	'n',	"n",
99*11452Sralph 	'o',	"o",
100*11452Sralph 	'p',	"p",
101*11452Sralph 	'q',	"q",
102*11452Sralph 	'r',	"r",
103*11452Sralph 	's',	"s",
104*11452Sralph 	't',	"t",
105*11452Sralph 	'u',	"u",
106*11452Sralph 	'v',	"v",
107*11452Sralph 	'w',	"w",
108*11452Sralph 	'x',	"x",
109*11452Sralph 	'y',	"y",
110*11452Sralph 	'z',	"z",
111*11452Sralph 	'{',	"{",
112*11452Sralph 	'|',	"|",
113*11452Sralph 	'}',	"}",
114*11452Sralph 	'~',	"~",
115*11452Sralph 	'\206',	"narrow space",
116*11452Sralph 	'-',	"hyphen",
117*11452Sralph 	'\07',	"bullet",
118*11452Sralph 	'\010',	"square",
119*11452Sralph 	'\06',	"3/4 em dash",
120*11452Sralph 	'\05',	"rule",
121*11452Sralph 	'\021',	"1/4",
122*11452Sralph 	'\022',	"1/2",
123*11452Sralph 	'\023',	"3/4",
124*11452Sralph 	'\04',	"minus",
125*11452Sralph 	'\01',	"fi",
126*11452Sralph 	'\02',	"fl",
127*11452Sralph 	'\03',	"ff",
128*11452Sralph 	'\011',	"ffi",
129*11452Sralph 	'\012',	"ffl",
130*11452Sralph 	'\013',	"degree",
131*11452Sralph 	'\014',	"dagger",
132*11452Sralph 	'\200',	"section (unimplem)",
133*11452Sralph 	'\015',	"foot mark",
134*11452Sralph 	'\200',	"acute acc (unimplem)",
135*11452Sralph 	'\200',	"grave acc (unimplem)",
136*11452Sralph 	'\200',	"underrule (unimplem)",
137*11452Sralph 	'\200',	"slash (unimplem)",
138*11452Sralph 	'\203',	"half narrow space",
139*11452Sralph 	'\200',	"null",
140*11452Sralph 	'\200',	"null",
141*11452Sralph 	'\200',	"null",
142*11452Sralph 	'\200',	"null",
143*11452Sralph 	'\200',	"null",
144*11452Sralph 	'\200',	"null",
145*11452Sralph 	'\200',	"null",
146*11452Sralph 	'\200',	"null",
147*11452Sralph 	'\200',	"null",
148*11452Sralph 	'\200',	"null",
149*11452Sralph 	'\200',	"null",
150*11452Sralph 	'\200',	"null",
151*11452Sralph 	'\200',	"null",
152*11452Sralph 	'\200',	"null",
153*11452Sralph 	'\200',	"null",
154*11452Sralph 	'\200',	"null",
155*11452Sralph 	'\200',	"null",
156*11452Sralph 	'\200',	"null",
157*11452Sralph 	'\200',	"null",
158*11452Sralph 	'\200',	"null",
159*11452Sralph 	'\200',	"null",
160*11452Sralph 	'\200',	"null",
161*11452Sralph 	'\200',	"null",
162*11452Sralph 	'\200',	"null",
163*11452Sralph 	'\200',	"null",
164*11452Sralph 	'\200',	"null",
165*11452Sralph 	'\200',	"null",
166*11452Sralph 	'\200',	"null",
167*11452Sralph 	'\200',	"null",
168*11452Sralph 	'\200',	"null",
169*11452Sralph 	'\200',	"null",
170*11452Sralph 	'\200',	"null",
171*11452Sralph 	'\200',	"null",
172*11452Sralph 	'\200',	"null",
173*11452Sralph 	'\200',	"null",
174*11452Sralph 	'\200',	"null",
175*11452Sralph 	'\200',	"null",
176*11452Sralph 	'\200',	"null",
177*11452Sralph 	'\200',	"null",
178*11452Sralph 	'\200',	"null",
179*11452Sralph 	'\200',	"null",
180*11452Sralph 	'\200',	"null",
181*11452Sralph 	'\200',	"null",
182*11452Sralph 	'\200',	"null",
183*11452Sralph 	'\200',	"null",
184*11452Sralph 	'\200',	"null",
185*11452Sralph 	'\200',	"null",
186*11452Sralph 	'\200',	"null",
187*11452Sralph 	'\200',	"null",
188*11452Sralph 	'\200',	"null",
189*11452Sralph 	'\200',	"null",
190*11452Sralph 	'\200',	"null",
191*11452Sralph 	'\200',	"null",
192*11452Sralph 	'\200',	"null",
193*11452Sralph 	'\200',	"null",
194*11452Sralph 	'\200',	"null",
195*11452Sralph 	'\200',	"null",
196*11452Sralph 	'\200',	"null",
197*11452Sralph 	'\200',	"null",
198*11452Sralph 	'\200',	"null",
199*11452Sralph 	'\200',	"null",
200*11452Sralph 	'\200',	"null",
201*11452Sralph 	'\200',	"null",
202*11452Sralph 	'\200',	"null",
203*11452Sralph 	'\200',	"null",
204*11452Sralph 	'\200',	"null",
205*11452Sralph 	'\200',	"null",
206*11452Sralph 	'\200',	"null",
207*11452Sralph 	'\200',	"null",
208*11452Sralph 	'\200',	"null",
209*11452Sralph 	'\200',	"null",
210*11452Sralph 	'\017',	"registered",
211*11452Sralph 	'\016',	"copyright",
212*11452Sralph 	'\200',	"null",
213*11452Sralph 	'\020',	"cent",
214*11452Sralph 	0,	0
215*11452Sralph };
216*11452Sralph 
217*11452Sralph struct desc {
218*11452Sralph 	short	addr;
219*11452Sralph 	short	nbytes;
220*11452Sralph 	char	up;
221*11452Sralph 	char	down;
222*11452Sralph 	char	left;
223*11452Sralph 	char	right;
224*11452Sralph 	short	width;
225*11452Sralph } desc[256];
226*11452Sralph 
227*11452Sralph main(argc, argv)
228*11452Sralph 	int argc;
229*11452Sralph 	char *argv[];
230*11452Sralph {
231*11452Sralph 	register int cl;
232*11452Sralph 	register esc;
233*11452Sralph 	register w;
234*11452Sralph 	int i, psize;
235*11452Sralph 	int fd, high;
236*11452Sralph 
237*11452Sralph 	if (argc != 3 && argc != 2) {
238*11452Sralph 		printf("Usage: vwidth font [pointsize] > font.c\n");
239*11452Sralph 		exit(1);
240*11452Sralph 	}
241*11452Sralph 	fd = open(argv[1], 0);
242*11452Sralph 	if (argc == 3)
243*11452Sralph 		psize = atoi(argv[2]);
244*11452Sralph 	else {
245*11452Sralph 		char *p;
246*11452Sralph 		for (p = argv[1]; *p && *p != '.'; p++)
247*11452Sralph 			;
248*11452Sralph 		if (*p == 0) {
249*11452Sralph 			psize = 10;
250*11452Sralph 			fprintf(stderr, "Assuming %d point\n", psize);
251*11452Sralph 		} else
252*11452Sralph 			psize = atoi(p+1);
253*11452Sralph 	}
254*11452Sralph 	lseek(fd, 10L, 0);
255*11452Sralph 	read(fd, desc, sizeof desc);
256*11452Sralph 	high = desc['a'].up+1;
257*11452Sralph 	printf("char XXw[256-32] = {\n");
258*11452Sralph 	for (i = 0; wtable[i].charloc != 0; i++) {
259*11452Sralph 		cl = wtable[i].charloc & 0377;
260*11452Sralph 		if (cl & 0200)
261*11452Sralph 			w = cl & 0177;
262*11452Sralph 		else
263*11452Sralph 			w = desc[cl].width*(54./25.)*(6./psize)+.5;
264*11452Sralph 		esc = 0;
265*11452Sralph 		if ((cl >= '0' && cl <= '9') || (cl >= 'A' && cl <= 'Z') ||
266*11452Sralph 		    (cl >= 'a' && cl <= 'z')) {
267*11452Sralph 			if (desc[cl].up > high)
268*11452Sralph 				esc |= 0200;
269*11452Sralph 			if (desc[cl].down > 0)
270*11452Sralph 				esc |= 0100;
271*11452Sralph 		}
272*11452Sralph 		if (esc)
273*11452Sralph 			printf("%d+0%o,\t/* %s */\n", w, esc, wtable[i].name);
274*11452Sralph 		else
275*11452Sralph 			printf("%d,\t\t/* %s */\n", w, wtable[i].name);
276*11452Sralph 	}
277*11452Sralph 	printf("};\n");
278*11452Sralph }
279