summaryrefslogtreecommitdiff
path: root/dviware/umddvi/misc/makesunfont.c
blob: a90437eb67692920904931f1dd44651f282f5932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef lint
static char rcsid[] = "$Header$";
#endif

/*
 * Convert a TeX format font (pxl, gf, pk) into SUN vfont format
 * Quick and dirty implementation.
 *
 *	Lou Salkind
 *	New York University
 */

#include <stdio.h>
#include "../h/types.h"
#include "../h/conv.h"
#include "../h/font.h"

char *ProgName;
extern int errno;
extern char *optarg;
extern int optind;

#define	PTTOSP(x) ((x) << 16)	/* points to scaled points */

int	dpi;
int	dvimag;
int	dvidsz;
int	globalmag;
char	*devspec;
int	rotation;

main(argc, argv)
	register int argc;
	register char **argv;
{
	register int c;

	ProgName = *argv;
	dvimag = PTTOSP(10);
	dvidsz = PTTOSP(10);
	globalmag = 1000;
	dpi = 200;
	rotation = ROT_NORM;
	while ((c = getopt(argc, argv, "D:d:m:g:r:s:")) != EOF) {
		switch (c) {

		case 'D':
			dpi = atoi(optarg);
			break;

		case 'd':
			dvidsz = atoi(optarg);
			break;

		case 'm':
			dvimag = atoi(optarg);
			break;

		case 'g':
			globalmag = atoi(optarg);
			break;

		case 'r':
			rotation = makerot(optarg);
			break;

		case 's':
			devspec = optarg;
			break;

		case '?':
usage:
			error(1, 0, "\
usage: %s [-m dvimag] [-d designsize] [-g globalmag] [-s devspec] font ...",
				ProgName);
			/* NOTREACHED */

		default:
			panic("case %d", c);
			/* NOTREACHED */
		}
	}
	if (optind >= argc)
		goto usage;
	SetConversion(dpi, 1000, 25400000, 473628672, 1000);
	for (c = optind; c < argc; c++)
		show(argv[c]);
	exit(0);
}

makerot(s)
	char *s;
{

	switch (*s) {

	case 'n':
		return (ROT_NORM);

	case 'l':
		return (ROT_LEFT);

	case 'd':
		return (ROT_DOWN);

	case 'r':
		return (ROT_RIGHT);

	case '0': case '1': case '2': case '3':
		return (*s - '0');

	default:
		error(1, 0, "\
valid rotations are `n'ormal, `l'eft, `right', and `d'own");
		/* NOTREACHED */
	}
}

#include <vfont.h>

struct header header;
struct dispatch dispatch[NUM_DISPATCH];

show(s)
	char *s;
{
	register struct font *f;
	register struct glyph *g;
	register int i;
	char *fname;
	int maxx, maxy, offset, rsize;
	char *rast;
	char newfile[256];

	f = GetFont(s, dvimag, dvidsz, devspec, &fname);
	if (f == NULL) {
		GripeCannotGetFont(s, dvimag, dvidsz, devspec, fname);
		exit(1);
	}
	strcpy(newfile, s);
	strcat(newfile, ".v");
	freopen(newfile, "w", stdout);
	if (fseek(stdout, (long)sizeof(header) + sizeof(dispatch), 0) == -1)
		exit(1);
	maxx = 0;
	maxy = 0;
	offset = 0;
	for (i = f->f_lowch; i < f->f_highch; i++) {
		g = GLYPH(f, i);
		if (!GVALID(g))
			continue;
#ifdef notdef
		if (fromSP(g->g_tfmwidth) > maxx)
			maxx = fromSP(g->g_tfmwidth);
#endif
		if (!HASRASTER(g))
			continue;
		rast = RASTER(g, f, rotation);
		if (g->g_height > maxy)
			maxy = g->g_height;
		if (g->g_width > maxx)
			maxx = g->g_width;
		dispatch[i].up = g->g_yorigin;
		dispatch[i].down = g->g_height - g->g_yorigin;
		dispatch[i].left = g->g_xorigin;
		dispatch[i].right = g->g_width - g->g_xorigin;
		dispatch[i].width = fromSP(g->g_tfmwidth);
		rsize = ((g->g_width + 7) / 8) * g->g_height;
		dispatch[i].addr = offset;
		dispatch[i].nbytes = rsize;
		fwrite(rast, rsize, 1, stdout);
		offset += rsize;
	}
	header.magic = VFONT_MAGIC;
	header.size = offset;
	header.maxx = maxx;
	header.maxy = maxy;
	header.xtend = 0;
	if (fseek(stdout, 0L, 0) == -1)
		exit(1);
	fwrite(&header, sizeof(header), 1, stdout);
	fwrite(dispatch, sizeof(dispatch), 1, stdout);
}