|
|
1.1 root 1: #include <X/mit-copyright.h>
2:
3: /* Copyright 1985, Massachusetts Institute of Technology */
4: #ifndef lint
5: static char *rcsid_xfd_c = "$Header: xfd.c,v 1.1 86/06/08 19:33:55 andrew Exp $";
6: #endif
7:
8: #include <X/Xlib.h>
9: #include <stdio.h>
10: #include <strings.h>
11: #include <ctype.h>
12:
13: short gray_bits[16] = {
14: 0xaaaa, 0x5555, 0xaaaa, 0x5555,
15: 0xaaaa, 0x5555, 0xaaaa, 0x5555,
16: 0xaaaa, 0x5555, 0xaaaa, 0x5555,
17: 0xaaaa, 0x5555, 0xaaaa, 0x5555
18: };
19:
20: char *trueFalse[] = {"False", "True"};
21:
22: char chars[9];
23: int last_line;
24:
25: main(argc, argv)
26: int argc;
27: char **argv;
28: {
29: Window w;
30: FontInfo *fontInfo;
31: int width;
32: char *fontname = "vtsingle";
33: register char *option;
34: char *border_color;
35: char *back_color;
36: char *fore_color;
37: int border_width;
38: int reverse = 0;
39: char *geometry; /* user supplied geometry spec */
40: char def[32]; /* default size */
41: int defwidth;
42: int defheight;
43: char display[128];
44: register int i;
45: OpaqueFrame window; /* frame for the window */
46: Pixmap border_pixmap;
47: int background; /* color of background */
48: int foreground; /* color of graph */
49: int highlight; /* color of text, scale */
50: Color cdef;
51:
52: if ((option = XGetDefault(argv[0], "ReverseVideo")) != NULL)
53: if (strcmp(option, "on") == 0)
54: reverse = 1;
55: if ((option = XGetDefault(argv[0], "BorderWidth")) != NULL)
56: border_width = atoi(option);
57: if ((border_color = XGetDefault(argv[0], "Border")) == NULL)
58: border_color = XGetDefault(argv[0], "BorderColor");
59: back_color = XGetDefault(argv[0], "Background");
60: fore_color = XGetDefault(argv[0], "Foreground");
61: display[0] = '\0';
62:
63: for (i = 1; i < argc; i++) { /* Parse line */
64: if (argv[i][0] == '=') {
65: geometry = argv[i];
66: continue;
67: }
68: if (index(argv[i], ':') != NULL) { /* host:display */
69: (void) strncpy(display, argv[i], sizeof(display));
70: continue;
71: }
72: if (strcmp(argv[i], "-rv") == 0 ||
73: strcmp(argv[i], "-reverse") == 0) { /* black on white */
74: reverse = 1;
75: continue;
76: }
77: if (strcmp(argv[i], "-fw") == 0 ||
78: strcmp(argv[i], "-forward") == 0) { /* white on black */
79: reverse = 0;
80: continue;
81: }
82: if (strcmp(argv[i], "-bw") == 0 ||
83: strcmp(argv[i], "-border") == 0) { /* border width */
84: if (++i >= argc)
85: usage(argv[0]);
86: border_width = atoi(argv[i]);
87: continue;
88: }
89: if (strcmp(argv[i], "-bd") == 0 ||
90: strcmp(argv[i], "-color") == 0) { /* border color */
91: if (++i >= argc)
92: usage(argv[0]);
93: border_color = argv[i];
94: continue;
95: }
96: /* foreground color */
97: if (strcmp(argv[i], "-fg") == 0 ||
98: strcmp(argv[i], "-foreground") == 0) {
99: if (++i >= argc)
100: usage(argv[0]);
101: fore_color = argv[i];
102: continue;
103: }
104: /* background color */
105: if (strcmp(argv[i], "-bg") == 0 ||
106: strcmp(argv[i], "-background") == 0) {
107: if (++i >= argc)
108: usage(argv[0]);
109: back_color = argv[i];
110: continue;
111: }
112: if (argv[i][0] == '-')
113: usage(argv[0]);
114: fontname = argv[i];
115: }
116: if (!XOpenDisplay(display)) {
117: fprintf(stderr, "%s: Could not open display %s!\n",
118: argv[0], display);
119: exit(1);
120: }
121: if (!(fontInfo = XOpenFont(fontname))) {
122: fprintf(stderr, "%s: Could not open font %s!\n",
123: argv[0], fontname);
124: exit(1);
125: }
126: printf("Font info:\n");
127: printf(" id: %d\n", fontInfo->id);
128: printf(" height: %d\n", fontInfo->height);
129: printf(" width: %d\n", fontInfo->width);
130: printf(" baseline: %d\n", fontInfo->baseline);
131: printf(" firstchar: %d\n", fontInfo->firstchar);
132: printf(" lastchar: %d\n", fontInfo->lastchar);
133: printf(" fixed width: ");
134: if (fontInfo->fixedwidth)
135: printf("true\n");
136: else {
137: printf("false");
138:
139: for (i = fontInfo->firstchar; i <= fontInfo->lastchar; i++) {
140: if (i % 4 == 0 || i == fontInfo->firstchar) {
141: printf("\n\t");
142: }
143: if (i < 32) {
144: printf("%3d ^%c %2d | ",
145: i, i + 64, fontInfo->widths[i]);
146: } else if (i > 160) {
147: printf("%3d M%c %2d | ",
148: i, i - 128, fontInfo->widths[i]);
149: } else if (i > 127) {
150: printf("%3d M%c %2d | ",
151: i, i - 64, fontInfo->widths[i]);
152: } else {
153: printf("%3d %c %2d | ",
154: i, i, fontInfo->widths[i]);
155: }
156: }
157: printf("\n");
158: }
159:
160: last_line = (unsigned char) (fontInfo->lastchar) / 8;
161: width = ComputeWidth(fontInfo);
162:
163: if (border_color && DisplayCells() > 2 &&
164: XParseColor(border_color, &cdef) && XGetHardwareColor(&cdef))
165: border_pixmap = XMakeTile(cdef.pixel);
166: else if (border_color && strcmp(border_color, "black") == 0)
167: border_pixmap = BlackPixmap;
168: else if (border_color && strcmp(border_color, "white") == 0)
169: border_pixmap = WhitePixmap;
170: else
171: border_pixmap = XMakePixmap(XStoreBitmap(16, 16, gray_bits),
172: BlackPixel, WhitePixel);
173:
174: if (back_color && DisplayCells() > 2 &&
175: XParseColor(back_color, &cdef) && XGetHardwareColor(&cdef)) {
176: background = cdef.pixel;
177: } else if (back_color && strcmp(back_color, "white") == 0) {
178: background = WhitePixel;
179: reverse = 0;
180: } else if (back_color && strcmp(back_color, "black") == 0) {
181: background = BlackPixel;
182: reverse = 0;
183: } else
184: background = BlackPixel;
185:
186: if (fore_color && DisplayCells() > 2 &&
187: XParseColor(fore_color, &cdef) && XGetHardwareColor(&cdef)) {
188: foreground = cdef.pixel;
189: } else if (fore_color && strcmp(fore_color, "black") == 0) {
190: foreground = BlackPixel;
191: reverse = 0;
192: } else if (fore_color && strcmp(fore_color, "white") == 0) {
193: foreground = WhitePixel;
194: reverse = 0;
195: } else
196: foreground = WhitePixel;
197:
198: if (reverse) {
199: highlight = background;
200: background = foreground;
201: foreground = highlight;
202: }
203: window.bdrwidth = border_width;
204: window.border = border_pixmap;
205: window.background = XMakeTile(background);
206:
207: defwidth = width + 10;
208: defheight = fontInfo->height * (last_line + 1) + 10;
209: (void) sprintf(def, "=%dx%d+300+300", defwidth, defheight);
210: w = XCreate("Font Display", argv[0], geometry, def, &window,
211: defwidth, defheight);
212:
213: if (!w) {
214: fprintf(stderr, "XCreateWindow failed\n");
215: exit(1);
216: }
217: XSelectInput(w, ExposeWindow | ButtonPressed);
218: XMapWindow(w);
219: while (1) {
220: XEvent event;
221: int i, j;
222: XWindowEvent(w, ExposeWindow | ButtonPressed, &event);
223: if (event.type == ButtonPressed)
224: exit(0);
225: for (i = 0; i <= last_line; i++) {
226: for (j = 0; j < 8; j++)
227: chars[j] = (char) ((8 * i) + j);
228: XText(w, 5, 5 + (i * fontInfo->height), chars, 8,
229: fontInfo->id, foreground, background);
230: }
231: }
232: }
233:
234: usage(program)
235: char *program;
236: {
237: fprintf(stderr, "usage: %s [host:display] [=geom] [-fw] ", program);
238: fprintf(stderr, "[-rv] [-bw] [-bd] [-fg] [-bg] <fontname>\n");
239: exit(1);
240: }
241:
242: ComputeWidth(fontInfo)
243: FontInfo *fontInfo;
244: {
245: int maxwidth, i, j;
246: /* Horrible hack needed for first line because line starts with \0, and
247: * XStringWidth considers \0 to terminate string */
248: for (j = 1; j < 8; j++)
249: chars[j] = j;
250: maxwidth = XStringWidth(&chars[1], fontInfo, 0, 0);
251: /* add the width of the '\0' character, if it has one */
252: if (fontInfo->firstchar == '\0')
253: maxwidth += (fontInfo->fixedwidth ?
254: fontInfo->width : fontInfo->widths[0]);
255:
256: /* now measure the width of remaining lines */
257: for (i = 1; i <= last_line; i++) {
258: int this_width;
259: for (j = 0; j < 8; j++)
260: chars[j] = (char) ((8 * i) + j);
261: this_width = XStringWidth(chars, fontInfo, 0, 0);
262: if (this_width > maxwidth)
263: maxwidth = this_width;
264: }
265: return (maxwidth);
266: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.