1 #ifndef lint 2 static char sccsid[] = "@(#)vfontinfo.c 4.3 (Berkeley) 7/16/83"; 3 #endif 4 5 /* Font Information for VCat-style fonts 6 * Andy Hertzfeld 4/79 7 * 8 * Modified to print Ascii chars 1/80 by Mark Horton 9 * Zoom option added 5/81 by Steve Stone with tables from Mark Horton. 10 * Message option added 5/31 by Mark Horton 11 */ 12 #include <stdio.h> 13 #include <ctype.h> 14 #include <vfont.h> 15 16 struct header FontHeader; 17 struct dispatch disptable[256]; 18 19 char IName[100]; 20 char * rdchar(); 21 long fbase; 22 23 char defascii[256]; 24 char *charswanted = defascii; 25 int verbose; 26 char charbits[4000]; 27 int H, W, WB, base; 28 int zoom = 1; 29 30 char msgout[24][80]; 31 int msgflag = 0; 32 int curline, curcol; /* cursor, numbered from lower left corner */ 33 int minline=24, maxline=0, maxcol=0; 34 35 main(argc,argv) 36 int argc; 37 char **argv; 38 39 { 40 int FID,i,j; 41 42 while (argc > 1 && argv[1][0] == '-') { 43 switch(argv[1][1]) { 44 case 'v': 45 verbose++; 46 break; 47 case 'z': 48 zoom = argv[1][2] - '0'; 49 break; 50 case 'm': 51 msgflag = 1; 52 zoom = 2; 53 for (i=0; i<24; i++) 54 for (j=0; j<80; j++) 55 msgout[i][j] = ' '; 56 curline = 5; curcol = 0; 57 break; 58 default: 59 printf("Bad flag: %s\n", argv[1]); 60 } 61 argc--; argv++; 62 } 63 if (argc < 2) { 64 fprintf(stderr,"Usage: %s filename", argv[0]); 65 exit(2); 66 } 67 68 for (i=0; i<128; i++) 69 defascii[i] = i; 70 if (argc >= 3) 71 charswanted = argv[2]; 72 73 sprintf(IName,"/usr/lib/vfont/%s",argv[1]); 74 if ((FID = open(argv[1],0)) < 0) 75 if ((FID = open(IName,0)) < 0) { 76 printf("Can't find %s\n",argv[1]); 77 exit(8); 78 }; 79 80 if (read(FID,&FontHeader,sizeof FontHeader) != sizeof FontHeader) 81 error("Bad header in Font file."); 82 83 if (read(FID,&disptable[0],sizeof disptable) != sizeof disptable) 84 error("Bad dispatch table in Font file"); 85 86 fbase = sizeof FontHeader + sizeof disptable; 87 88 if (FontHeader.magic != 0436) 89 printf("Magic number %o wrong\n", FontHeader.magic); 90 if (!msgflag) { 91 printf("Font %s, ",argv[1]); 92 printf("raster size %d, ",FontHeader.size); 93 printf("max width %d, max height %d, xtend %d\n", 94 FontHeader.maxx, FontHeader.maxy,FontHeader.xtend); 95 printf("\n"); 96 for (i = strlen(argv[1]) + 1; i > 0; --i) 97 printf(" "); 98 printf("ASCII offset size left right up down width \n"); 99 } 100 101 for (i=0; i<256; i++) { 102 j = charswanted[i]; 103 if (i>0 && j==0) 104 break; 105 if (disptable[j].nbytes != 0) { 106 if (!msgflag) 107 printf("%s %3o %2s %4d %4d %4d %4d %4d %4d %5d\n", 108 argv[1], 109 j, rdchar(j), 110 disptable[j].addr, 111 disptable[j].nbytes, 112 disptable[j].left, 113 disptable[j].right, 114 disptable[j].up, 115 disptable[j].down, 116 disptable[j].width); 117 if (verbose || msgflag) { 118 int len = disptable[j].nbytes; 119 int k, l, last; 120 121 lseek(FID, fbase+disptable[j].addr, 0); 122 read(FID, charbits, len); 123 H = (disptable[j].up) + (disptable[j].down); 124 W = (disptable[j].left) + (disptable[j].right); 125 base = disptable[j].up; 126 WB = (W+7)/8; 127 if (zoom < 0) { 128 /* 129 * Old 1 for 1 code. The aspect ratio 130 * is awful, so we don't use it. 131 */ 132 for (k=0; k<H; k++) { 133 for (last=W-1; last >= 0; last--) 134 if (fbit(k, last)) 135 break; 136 for (l=0; l<=W-1; l++) { 137 printf("%c", fbit(k,l)?'M':' '); 138 } 139 printf("\n"); 140 } 141 printf("\n"); 142 } else { 143 shozoom(); 144 if (msgflag) { 145 k = disptable[j].width; 146 if (zoom == 0) k *= 2; 147 else if (zoom == 2) k /= 2; 148 curcol += k; 149 } 150 } 151 } 152 } 153 } 154 if (msgflag) { 155 for (i=maxline; i>=minline; i--) { 156 for (j=0; j<maxcol; j++) 157 putchar(msgout[i][j]); 158 putchar('\n'); 159 } 160 } 161 } 162 163 error(string) 164 char *string; 165 166 { 167 printf("\nvfontinfo: %s\n",string); 168 exit(8); 169 }; 170 171 char *rdchar(c) 172 char c; 173 { 174 static char ret[3]; 175 ret[0] = isprint(c) ? ' ' : '^'; 176 ret[1] = isprint(c) ? c : c^0100; 177 ret[2] = 0; 178 return (ret); 179 } 180 181 int 182 fbit(row, col) 183 int row, col; 184 { 185 int thisbyte, thisbit, ret; 186 187 if (row<0 || row>=H || col>=W) return(0); 188 thisbyte = charbits[row*WB + (col>>3)] & 0xff; 189 thisbit = 0x80 >> (col&7); 190 ret = thisbyte & thisbit; 191 return (ret != 0); 192 } 193 194 195 /* 196 The implementation would work like this: 197 zoom level method 198 0 2 chars/pixel, 1 is "[]", 0 is " ". 199 1 2 pixels/char 2x1, using " " "," "'" "|" 200 2 8 pixels/char 4x2, using 16x16 table 201 3 32 pixels/char 8x4, mapped into (2) 202 4 and up similar, mapped into (2) 203 204 The 16x16 table maps a 4x2 pattern into a printing ascii character which 205 most closely approximates that pattern, e.g. the pattern 206 |' 207 '' 208 would be represented by the character "[". I have such a table worked out. 209 210 Grainer zoom levels would take the rule of reducing it into a smaller bitmap, 211 or-ing the bits together. (e.g. level 3 would take a 2x2 chunk and map it 212 into a single pixel: 0 if all 4 are 0, 1 otherwise.) These pixels would be 213 displayed as in 2. 214 */ 215 216 /* 217 * graphtab: a table for rudimentary graphics on ordinary terminals. 218 * For each 4x2 bit pattern of the form: 219 * ae 220 * bf 221 * cg 222 * dh 223 * form the 4 bit quantities abcd and efgh and get table entry 224 * graphtab[abcd][efgh] 225 * to display in that character position. 226 * 227 * General philosophies: the dh bits are intended for descenders where 228 * possible. Characters with radically different appearance on different 229 * terminals (e.g. _ and ^) are avoided. 230 * 231 * Version 1.0, March 1981, Mark Horton. 232 */ 233 234 char tab1[4] = { 235 ' ', ',', '\'', '|' 236 }; 237 238 char graphtab[16][16] = { 239 ' ', '.', '.', ',', '.', ';', ':', 'j', '\'', ':', ':', ';', '\'', ';', '!', '|', 240 '.', '.', ':', ',', ';', ';', ';', 'j', '/', ';', ';', ';', 'j', 'j', 'j', 'j', 241 '.', ',', '~', ',', 'r', '<', 'j', 'q', '/', ';', 'I', ';', '/', '|', 'I', '|', 242 ',', ',', 'r', 'x', '/', '/', '/', 'd', '/', '/', '/', 'd', '/', '/', '/', 'd', 243 '.', ':', '\\', ';', '-', '=', 'v', 'q', '\'', ':', '<', '|', '\'', ':', '+', '+', 244 ';', ';', '>', ';', '=', '=', 'g', 'g', '\'', ':', 'S', 'S', '/', '/', '/', '+', 245 ':', '\\', '\\', '\\', 'r', '<', 'w', 'q', '/', '<', '6', '4', '/', '/', 'd', '+', 246 'l', 'L', '+', 'b', 'y', '[', 'p', 'g', '/', '<', '/', '6', '/', '/', '/', '+', 247 '`', ':', ':', ';', '`', '\\', '\\', '\\', '"', ':', ':', ';', '`', '\\', 'Y', 'T', 248 ';', ';', ';', ';', '`', '2', '>', '\\', ':', '=', ';', ';', '?', '?', ']', ']', 249 ':', ';', ';', ';', '>', '2', '>', '\\', 'F', ';', 'O', ';', '7', '?', ']', '7', 250 ';', ';', ';', ';', '?', '2', '>', 'b', ';', ';', ';', ';', '?', '?', ']', '#', 251 '\'', '\\', '\\', '\\', '`', '\\', '\\', '\\', '\'', '\'', '<', '5', '"', '"', 'v', 'q', 252 ';', '\\', '\\', '\\', '`', '=', '\\', '\\', '\'', '\'', '5', '5', '"', '?', 'g', 'g', 253 'I', 'L', 'L', 'L', 'D', '\\', 'b', 'f', 'F', '[', '[', '[', 'P', '?', '#', 'M', 254 '|', '|', '|', '|', '|', '#', '+', '#', 'T', '[', 'F', 'F', 'P', '?', 'P', 'M' 255 }; 256 257 258 shozoom() 259 { 260 register i; 261 262 if (zoom == 0) 263 sho0(); 264 else if (zoom == 1) 265 sho1(); 266 else if (zoom == 2) 267 sho2(); 268 } 269 270 sho0() 271 { 272 register k,l; 273 274 for (k=0; k<H; k++) { 275 for (l=0; l<W; l++) 276 printf("%s", fbit(k,l)?"[]": " "); 277 printf("\n"); 278 } 279 printf("\n"); 280 } 281 282 sho1() 283 { 284 register k,l; 285 286 k = 0; 287 for (k = 0; k <= H; k += 2) { 288 for(l=0;l<W;l++) putchar(tab1[(fbit(k,l) << 1) | fbit(k+1,l)]); 289 putchar('\n'); 290 } 291 putchar('\n'); 292 } 293 294 sho2() 295 { 296 register i,j,k,l; 297 int line = curline + (base+3)/4; 298 int col; 299 300 k = base%4; 301 if (k > 0) k -= 4; 302 while (k < H) { 303 l = 0; 304 col = curcol; 305 while (l<W) { 306 i = fbit(k,l)*8 + fbit(k+1,l)*4 + 307 fbit(k+2,l)*2 + fbit(k+3,l); 308 l++; 309 j = fbit(k,l)*8 + fbit(k+1,l)*4 + 310 fbit(k+2,l)*2 + fbit(k+3,l); 311 312 if (msgflag) { 313 if (graphtab[i][j] != ' ') { 314 if (line > maxline) maxline = line; 315 if (line < minline) minline = line; 316 if (col > maxcol) maxcol = col; 317 } 318 msgout[line][col] = graphtab[i][j]; 319 } else 320 printf("%c",graphtab[i][j]); 321 l++; 322 col++; 323 } 324 if (msgflag == 0) 325 printf("\n"); 326 k += 4; 327 line--; 328 } 329 if (msgflag == 0) 330 printf("\n"); 331 } 332