summaryrefslogtreecommitdiff
path: root/dviware/umddvi/misc/showfont.c
blob: 870c3d6dcbb6e4c2f6befd08d4c9f9e8f2eb9330 (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
#ifndef lint
static char rcsid[] = "$Header$";
#endif

/*
 * Show font things.
 */

#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	dvimag;
int	dvidsz;
char	*devspec;
int	rotation;

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

	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 [-Ddpi] [-mdvimag] [-ddesignsz] [-ggloblmag] [-sdevspec] font ...",
				ProgName);
			/* NOTREACHED */

		default:
			panic("case %d", c);
			/* NOTREACHED */
		}
	}
	if (optind >= argc)
		goto usage;
	SetConversion(dpi, 1000, 25400000, 473628672, globalmag);
	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 */
	}
}

show(s)
	char *s;
{
	register struct font *f;
	register struct glyph *g;
	register int i;
	char *fname;

	f = GetFont(s, dvimag, dvidsz, devspec, &fname);
	if (f == NULL) {
		GripeCannotGetFont(s, dvimag, dvidsz, devspec, fname);
		exit(1);
	}
	printf("[%s]\n", fname);
	for (i = f->f_lowch; i < f->f_highch; i++) {
		g = GLYPH(f, i);
		if (!GVALID(g))
			continue;
		printf("glyph ");
		if (i >= ' ' && i < 127)
			printf("'%c'", i);
		else
			printf("%3d", i);
		printf(":\n\
\theight = %5d width = %5d yorigin = %5d xorigin = %5d\n\
\tTFM width = %6.2fpt (%d pixels)\n",
			g->g_height, g->g_width, g->g_yorigin, g->g_xorigin,
			g->g_tfmwidth / 65536.0, fromSP(g->g_tfmwidth));
		if (!HASRASTER(g))
			continue;
		showraster(g, RASTER(g, f, rotation));
	}
}

showraster(g, p)
	struct glyph *g;
	register char *p;
{
	register int c, t, i, j, k, w;

	w = g->g_width;
	for (i = g->g_height; --i >= 0;) {
		k = 7;
		t = 0;
		for (j = w; --j >= 0;) {
			if (++k == 8)
				k = 0, c = *p++;
			if (c & 0x80) {
				while (--t >= 0)
					(void) putchar(' ');
				t = 0;
				(void) putchar('*');
			} else
				t++;
			c <<= 1;
		}
		(void) putchar('\n');
	}
	(void) putchar('\n');
}