| 1 |
/* |
| 2 |
* CHecK DVI FONTs (CHKDVIFONT) |
| 3 |
* Dec 1990, originally written by SHIMA |
| 4 |
* Apr 1992, second version |
| 5 |
* May 1992, third version |
| 6 |
* Sep 1992, fifth version |
| 7 |
* May 1996, sixth version |
| 8 |
* |
| 9 |
* Usage: chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-d] dvi_file_name |
| 10 |
* chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-t] tfm_file_name |
| 11 |
* chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-p] font_file_name |
| 12 |
* |
| 13 |
* "c" means check mode |
| 14 |
* "s" means silent check mode |
| 15 |
* "f" means user defined font data |
| 16 |
* "F" means user defined font data and ignore default data |
| 17 |
* "t" means tfm_file |
| 18 |
* "p" means font_file |
| 19 |
* |
| 20 |
* errorlevel is the sum of th following number |
| 21 |
* 1: cmbsy5-9, cmcsc8-9, cmex7-9, cmmib5-9 |
| 22 |
* 2: new font: eu??, msam, msbm, wncy??, font_data_file |
| 23 |
* 4: new eufm5-10 |
| 24 |
* 8: unknown eufm |
| 25 |
* 16: old font: msxm, msym, amcsc, mcyr, mcyb, font_data_file |
| 26 |
* 32: old eufm5-10 |
| 27 |
* |
| 28 |
* If errorlevel is larger than 240, |
| 29 |
* 248: error in font_data_file |
| 30 |
* 249: cannot find font_data_file |
| 31 |
* 250: bad parameter |
| 32 |
* 251: old and new eufm |
| 33 |
* 252: bad dvi file |
| 34 |
* 253: error in dvi file |
| 35 |
* 254: not dvi/tfm file or unknown font ID |
| 36 |
* 255: cannot find dvi/tfm/font file |
| 37 |
* |
| 38 |
* |
| 39 |
* 1 point = 65536(=2^(16)) scaled point |
| 40 |
* 1 inch = 72.27 point = 2.54 cm |
| 41 |
* |
| 42 |
*/ |
| 43 |
|
| 44 |
#ifdef WIN32 |
| 45 |
#define MSVC 1 |
| 46 |
#else |
| 47 |
#define UNIX 1 |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <stdio.h> |
| 51 |
#include <stdlib.h> |
| 52 |
#include <string.h> |
| 53 |
#ifndef UNIX |
| 54 |
#include <dos.h> |
| 55 |
#ifdef MSVC |
| 56 |
#include "msvcdir.h" |
| 57 |
#else |
| 58 |
#include <dir.h> |
| 59 |
#endif |
| 60 |
#include <io.h> |
| 61 |
#endif |
| 62 |
|
| 63 |
#ifdef __GNUC__ |
| 64 |
#include <ctype.h> |
| 65 |
#define GCC 1 |
| 66 |
#endif |
| 67 |
|
| 68 |
#include <config.h> |
| 69 |
#ifdef KPATHSEA |
| 70 |
#include <kpathsea/config.h> |
| 71 |
#if defined(WIN32) |
| 72 |
#include <kpathsea/variable.h> |
| 73 |
#endif |
| 74 |
#endif |
| 75 |
|
| 76 |
#include "dd.h" |
| 77 |
#include "common.h" |
| 78 |
|
| 79 |
#if defined(WIN32) && defined(KPATHSEA) |
| 80 |
#undef fopen |
| 81 |
#undef fprintf |
| 82 |
#define fopen fsyscp_fopen |
| 83 |
#define fprintf win32_fprintf |
| 84 |
#endif |
| 85 |
|
| 86 |
#define ID 2 |
| 87 |
#define ID_PTEX 3 |
| 88 |
#define END_DVI 223 |
| 89 |
#define MAX_NAME 16 |
| 90 |
#define MAX_FONT 1024 |
| 91 |
#define BUF_SIZE 1024 |
| 92 |
|
| 93 |
#define HALF_POINT (1L<<8) |
| 94 |
|
| 95 |
#define NEW_FONT 1 |
| 96 |
#define NEW_POINT 2 |
| 97 |
#define NEW_EUFM 4 |
| 98 |
#define BAD_EUFM 8 |
| 99 |
#define OLD_FONT 16 |
| 100 |
#define OLD_EUFM 32 |
| 101 |
|
| 102 |
#define DVI_FILE 0 |
| 103 |
#define TFM_FILE 1 |
| 104 |
#define PXL_FILE 2 |
| 105 |
#define PK_FILE 3 |
| 106 |
#define VF_FILE 4 |
| 107 |
#define VF_FILE_MAP 5 |
| 108 |
|
| 109 |
char buf[BUF_SIZE]; |
| 110 |
char filename[MAXPATH]; |
| 111 |
|
| 112 |
/* |
| 113 |
* eufm: point, checksum old, checksum new |
| 114 |
*/ |
| 115 |
|
| 116 |
struct EUFM { |
| 117 |
int point; /* point number */ |
| 118 |
unsigned int oldd; /* old checksum */ |
| 119 |
unsigned int neww; /* new checksum */ |
| 120 |
}; |
| 121 |
|
| 122 |
/* |
| 123 |
* Multiple lines for a point are allowed. |
| 124 |
* The last line should be 0 point. |
| 125 |
*/ |
| 126 |
struct EUFM eufm[] = |
| 127 |
{ |
| 128 |
5, 0x0891FD38L, 0x246A686BL, |
| 129 |
5, 0x0891FD38L, 0xB8C9AFD4L, |
| 130 |
6, 0x2F8EDF02L, 0x9793B1E1L, |
| 131 |
6, 0x2F8EDF02L, 0x65167BC4L, |
| 132 |
7, 0x37CDA321L, 0x05184980L, |
| 133 |
7, 0x37CDA321L, 0x58ED2602L, |
| 134 |
8, 0x37CCA321L, 0x2564B2F5L, |
| 135 |
8, 0x37CCA321L, 0x5C978225L, |
| 136 |
9, 0x3F977CF3L, 0x1F6C4283L, |
| 137 |
9, 0x3F977CF3L, 0xF833F3AFL, |
| 138 |
10, 0xBF989013L, 0x8F256EB2L, |
| 139 |
0, 0L, 0L |
| 140 |
}; |
| 141 |
|
| 142 |
struct CHKFONT { |
| 143 |
char f_name[MAX_NAME]; /* font name with point */ |
| 144 |
unsigned long oldd; /* old checksum */ |
| 145 |
unsigned long neww; /* new checksum */ |
| 146 |
}; |
| 147 |
|
| 148 |
struct CHKFONT chkfont[MAX_FONT]; |
| 149 |
|
| 150 |
/* |
| 151 |
* old AMS FONTS |
| 152 |
*/ |
| 153 |
|
| 154 |
char *oldfont[] = |
| 155 |
{"msxm", "msym", "amcsc", "mcyr", "mcyb", ""}; |
| 156 |
|
| 157 |
/* |
| 158 |
* add CM fonts, start point, end point |
| 159 |
*/ |
| 160 |
|
| 161 |
struct NEWPOINT { |
| 162 |
char *font_name; /* font name */ |
| 163 |
int top; /* smallest point */ |
| 164 |
int end; /* largest point */ |
| 165 |
}; |
| 166 |
|
| 167 |
struct NEWPOINT newpoint[] = |
| 168 |
{ |
| 169 |
"cmbsy", 5, 9, |
| 170 |
"cmcsc", 8, 9, |
| 171 |
"cmex", 7, 9, |
| 172 |
"cmmib", 5, 9, |
| 173 |
"", 0, 0 |
| 174 |
}; |
| 175 |
|
| 176 |
/* |
| 177 |
* new AMS FONTS |
| 178 |
*/ |
| 179 |
|
| 180 |
char *newfont[] = |
| 181 |
{"euex", "eufb", "eurb", "eurm", "eusb", "eusm", |
| 182 |
"msam", "msbm", |
| 183 |
"wncyb", "wncyi", "wncyr", "wncysc", "wncyss", |
| 184 |
"" |
| 185 |
}; |
| 186 |
|
| 187 |
struct FONT_ATR { |
| 188 |
/* parameters of font_def; See "TeX:The program". */ |
| 189 |
long k, c, s, d; |
| 190 |
int a, l; |
| 191 |
char *n; |
| 192 |
}; |
| 193 |
|
| 194 |
struct VFFONT_ATR { |
| 195 |
/* parameters of font_def; See "TeX:The program". */ |
| 196 |
long k, c, d; |
| 197 |
double s; |
| 198 |
int a, l; |
| 199 |
char *n; |
| 200 |
}; |
| 201 |
|
| 202 |
int mag[] = |
| 203 |
{1095, 1200, 1315, 1440, 1577, 1728, 1893, 2074, 2272, 2488, |
| 204 |
2726, 2986, 3271, 3583, 3925, 4300, 4710, 5160, 32000}; |
| 205 |
|
| 206 |
char *font_ext[] = { |
| 207 |
"gf", "pk", "pxl", "far", "gth", NULL |
| 208 |
}; |
| 209 |
|
| 210 |
#define read_byte(x) (uchar)getc(x) |
| 211 |
|
| 212 |
void usage(void); |
| 213 |
char *name_link(char *, char *); |
| 214 |
void read_post(DVIFILE_INFO *); |
| 215 |
void get_font_list(DVIFILE_INFO *); |
| 216 |
void font_define(int, FILE *); |
| 217 |
void vf_define(int, FILE *); |
| 218 |
int read_uint(FILE *); |
| 219 |
long read_mit(FILE *); |
| 220 |
long read_long(FILE *); |
| 221 |
char *read_str(FILE *, int); |
| 222 |
long read_n(FILE *, int); |
| 223 |
long signed_read_n(FILE *, int); |
| 224 |
void check_font(void); |
| 225 |
void usage(void); |
| 226 |
void show_dvi_data(DVIFILE_INFO *); |
| 227 |
void get_list(char *); |
| 228 |
void type(char *); |
| 229 |
void tfm_define(FILE *); |
| 230 |
void pxl_define(FILE *); |
| 231 |
int chk_font_file(FILE *); |
| 232 |
int check_mag(int); |
| 233 |
long to_long(uchar *); |
| 234 |
|
| 235 |
DVIFILE_INFO dvi_info; |
| 236 |
struct FONT_ATR font; |
| 237 |
struct VFFONT_ATR vffont; |
| 238 |
|
| 239 |
int f_v = -1; /* verbose mode */ |
| 240 |
int f_vv = 0; /* more verbose mode */ |
| 241 |
int f_d; /* ignore default data */ |
| 242 |
int f_t; /* file_type */ |
| 243 |
int n_data; /* number of font_data */ |
| 244 |
uint f_type; |
| 245 |
long pmag; |
| 246 |
long hppp; |
| 247 |
long vppp; |
| 248 |
|
| 249 |
struct FINFO { |
| 250 |
char f_atrib; |
| 251 |
uchar f_time[2]; |
| 252 |
uchar f_date[2]; |
| 253 |
uchar f_size[4]; |
| 254 |
char f_name[14]; |
| 255 |
uchar f_pos[4]; |
| 256 |
}; |
| 257 |
|
| 258 |
struct FARDIR { |
| 259 |
char f_name[10]; |
| 260 |
uchar f_time[4]; |
| 261 |
uchar f_size[4]; |
| 262 |
uchar f_pos[4]; |
| 263 |
}; |
| 264 |
|
| 265 |
uchar gth_buf[sizeof(struct FINFO)]; |
| 266 |
long f_end; |
| 267 |
int f_cont; |
| 268 |
|
| 269 |
int strcmpl(const char *s, const char *t) |
| 270 |
{ |
| 271 |
int i; |
| 272 |
|
| 273 |
i = strlen(t); |
| 274 |
if(strlen(s) < i ) return -1; |
| 275 |
s += strlen(s); |
| 276 |
while(i-- > 0){ |
| 277 |
s--; |
| 278 |
if(toupper(*s) != toupper(t[i])) |
| 279 |
return -1; |
| 280 |
} |
| 281 |
return 0; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
#ifdef UNIX |
| 286 |
char *strlwr(char *p) |
| 287 |
{ |
| 288 |
char *original = p; |
| 289 |
|
| 290 |
while (*p != '\0') { |
| 291 |
*p = tolower(*p); |
| 292 |
++p; |
| 293 |
} |
| 294 |
return original; |
| 295 |
} |
| 296 |
#endif |
| 297 |
|
| 298 |
int main(int argc, char **argv) |
| 299 |
{ |
| 300 |
int i, code; |
| 301 |
char *pt; |
| 302 |
|
| 303 |
if (argc < 2) |
| 304 |
usage(); |
| 305 |
#if defined(WIN32) && defined(KPATHSEA) |
| 306 |
{ |
| 307 |
int ac; |
| 308 |
char **av, *enc; |
| 309 |
|
| 310 |
kpse_set_program_name(argv[0], "chkdvifont"); |
| 311 |
enc = kpse_var_value("command_line_encoding"); |
| 312 |
if (get_command_line_args_utf8(enc, &ac, &av)) { |
| 313 |
argc = ac; |
| 314 |
argv = av; |
| 315 |
} |
| 316 |
} |
| 317 |
#endif |
| 318 |
for (i = 1; i < argc - 1; i++) { |
| 319 |
if (argv[i][0] != '-') |
| 320 |
usage(); |
| 321 |
switch (argv[i][1]) { |
| 322 |
case 'S': |
| 323 |
case 's': |
| 324 |
f_v = 0; |
| 325 |
break; |
| 326 |
case 'c': |
| 327 |
f_v = 1; |
| 328 |
break; |
| 329 |
case 'v': |
| 330 |
f_vv = 1; |
| 331 |
break; |
| 332 |
case 'F': |
| 333 |
f_d = 1; |
| 334 |
case 'f': |
| 335 |
get_list(argv[i] + 2); |
| 336 |
break; |
| 337 |
case 'd': |
| 338 |
f_t = -1; |
| 339 |
break; |
| 340 |
case 't': |
| 341 |
f_t = 1; |
| 342 |
break; |
| 343 |
case 'p': |
| 344 |
f_t = 2; |
| 345 |
break; |
| 346 |
default: |
| 347 |
fprintf(stderr, "Unknown option: %s\n", argv[i]); |
| 348 |
exit(1); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
if(strlen(argv[argc-1]) >= MAXPATH) { |
| 353 |
fprintf(stderr, "Too long filename\n"); |
| 354 |
exit(255); |
| 355 |
} |
| 356 |
|
| 357 |
/* check file extension */ |
| 358 |
if (!f_t){ |
| 359 |
pt = argv[argc-1]; |
| 360 |
i = strlen(pt); |
| 361 |
while(--i > 0){ |
| 362 |
if( pt[i] == '.' ) break; |
| 363 |
if( pt[i] == '\\' || pt[i] == '/' || pt[i] == ':' ){ |
| 364 |
i = 1; |
| 365 |
} |
| 366 |
} |
| 367 |
if (i > 0){ |
| 368 |
pt += i+1; |
| 369 |
if( strcmpl(pt, "dvi") == 0 ) |
| 370 |
f_t = -1; |
| 371 |
else{ |
| 372 |
if( strcmpl(pt, "tfm") == 0 || strcmpl(pt, "ofm") == 0 ) |
| 373 |
f_t = 1; |
| 374 |
else{ |
| 375 |
if( strcmpl(pt, "vf") == 0 ) |
| 376 |
f_t = 2; /* ovf is also included */ |
| 377 |
else{ |
| 378 |
for(i = 0; font_ext[i]; i++){ |
| 379 |
if( strcmpl(pt, font_ext[i]) == 0 ){ |
| 380 |
f_t = 2; |
| 381 |
break; |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
if(f_t == -1) f_t = 0; |
| 390 |
strcpy(filename, dvi_info.file_name = argv[argc - 1]); |
| 391 |
if (f_t != PXL_FILE && strchr(argv[argc - 1], '.') == NULL) |
| 392 |
dvi_info.file_name = name_link(argv[argc - 1], |
| 393 |
(f_t) ? "tfm" : "dvi"); |
| 394 |
if ((dvi_info.file_ptr = fopen(dvi_info.file_name, "rb")) == NULL) { |
| 395 |
fprintf(stderr, "Cannot find %s\n", dvi_info.file_name); |
| 396 |
exit(255); |
| 397 |
} |
| 398 |
if (f_t != DVI_FILE) { |
| 399 |
font.n = dvi_info.file_name; |
| 400 |
if (f_t == TFM_FILE) |
| 401 |
tfm_define(dvi_info.file_ptr); |
| 402 |
else { |
| 403 |
if (chk_font_file(dvi_info.file_ptr)) { |
| 404 |
pxl_define(dvi_info.file_ptr); |
| 405 |
if (f_t == VF_FILE) { |
| 406 |
f_t = VF_FILE_MAP; |
| 407 |
code = read_byte(dvi_info.file_ptr); |
| 408 |
while (code >= FNT_DEF_1 && code < FNT_DEF_1 + 4) { |
| 409 |
vf_define(code, dvi_info.file_ptr); |
| 410 |
check_font(); |
| 411 |
code = read_byte(dvi_info.file_ptr); |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
} |
| 417 |
else { |
| 418 |
read_post(&dvi_info); |
| 419 |
if (f_v) |
| 420 |
show_dvi_data(&dvi_info); |
| 421 |
get_font_list(&dvi_info); |
| 422 |
if (f_v != -1 |
| 423 |
&& (f_type & (OLD_EUFM + NEW_EUFM)) == (OLD_EUFM + NEW_EUFM)) { |
| 424 |
fprintf(stderr, "old and new eufm fonts\n"); |
| 425 |
exit(251); |
| 426 |
} |
| 427 |
} |
| 428 |
if (f_v != -1) { |
| 429 |
if (f_v != 0) |
| 430 |
printf("\n\n"); |
| 431 |
printf("EXIT Code (errorlevel)\t\t= %d\n", f_type); |
| 432 |
if (f_type & OLD_EUFM) |
| 433 |
printf("Old eufm "); |
| 434 |
if (f_type & NEW_EUFM) |
| 435 |
printf("New eufm "); |
| 436 |
if (f_type & OLD_FONT) |
| 437 |
printf("Old font "); |
| 438 |
if (f_type & (NEW_FONT | NEW_POINT)) |
| 439 |
printf("New font"); |
| 440 |
if (f_type == 0) |
| 441 |
printf("No AMS Font"); |
| 442 |
} |
| 443 |
printf("\n"); |
| 444 |
exit(f_type); |
| 445 |
} |
| 446 |
|
| 447 |
int chk_font_file(FILE * fp) |
| 448 |
{ |
| 449 |
int i, f_num; |
| 450 |
long start; |
| 451 |
struct FINFO *finfo; |
| 452 |
struct FARDIR *fardir; |
| 453 |
|
| 454 |
finfo = (struct FINFO *)gth_buf; |
| 455 |
fardir = (struct FARDIR *)gth_buf; |
| 456 |
|
| 457 |
if (fread(gth_buf, sizeof(struct FINFO), 1, fp)<1) goto err; |
| 458 |
|
| 459 |
if (strcmp(gth_buf + 8, "gather") == 0) |
| 460 |
goto gth; |
| 461 |
|
| 462 |
fseek(fp, -8L, SEEK_END); |
| 463 |
f_num = read_uint(fp); |
| 464 |
start = read_long(fp); |
| 465 |
if (read_uint(fp) != (int)('f' + 'o' + 'n' + 't' + 'a' + 'r' + 'c' + 'h' + 'i' + 'v' + 'e')) { |
| 466 |
fseek(fp, 0L, SEEK_SET); |
| 467 |
return (1); |
| 468 |
} |
| 469 |
/* FAR file */ |
| 470 |
if (f_v){ |
| 471 |
f_cont = 1; |
| 472 |
printf("\t\"%s\" is a FAR file which contains...\n", filename); |
| 473 |
} |
| 474 |
while (f_num-- > 0) { |
| 475 |
if (f_v) |
| 476 |
printf("\n"); |
| 477 |
fseek(fp, start, SEEK_SET); |
| 478 |
if (fread((char *)fardir, sizeof(struct FARDIR), 1, fp)<1) goto err; |
| 479 |
|
| 480 |
start = ftell(fp); |
| 481 |
font.n = fardir->f_name; |
| 482 |
f_end = to_long(fardir->f_pos) + to_long(fardir->f_size); |
| 483 |
fseek(fp, to_long(fardir->f_pos), SEEK_SET); |
| 484 |
pxl_define(fp); |
| 485 |
if (f_v) |
| 486 |
printf("\n"); |
| 487 |
} |
| 488 |
return (0); |
| 489 |
|
| 490 |
gth: /* GTH file */ |
| 491 |
if (f_v){ |
| 492 |
f_cont = 1; |
| 493 |
printf("\t\"%s\" is a GTH file which contains...\n", filename); |
| 494 |
} |
| 495 |
start = gth_buf[0] + (gth_buf[1] << 8) + (gth_buf[2] << 16) |
| 496 |
+ (gth_buf[3] << 24); |
| 497 |
f_num = gth_buf[4] + (gth_buf[5]<< 8); |
| 498 |
while (f_num-- > 0) { |
| 499 |
if (f_v) |
| 500 |
printf("\n"); |
| 501 |
fseek(fp, start, SEEK_SET); |
| 502 |
if (fread(gth_buf, sizeof(struct FINFO), 1, fp)<1) goto err; |
| 503 |
|
| 504 |
start = ftell(fp); |
| 505 |
font.n = finfo->f_name; |
| 506 |
printf("%s:%ld(%ld)\n", |
| 507 |
font.n, to_long(finfo->f_pos), to_long(finfo->f_size)); |
| 508 |
f_end = to_long(finfo->f_pos) + to_long(finfo->f_size); |
| 509 |
fseek(fp, to_long(finfo->f_pos), SEEK_SET); |
| 510 |
pxl_define(fp); |
| 511 |
if (f_v) |
| 512 |
printf("\n"); |
| 513 |
} |
| 514 |
return (0); |
| 515 |
|
| 516 |
err: |
| 517 |
fprintf(stderr, "Cannot read data\n"); |
| 518 |
exit(250); |
| 519 |
} |
| 520 |
|
| 521 |
void show_dvi_data(DVIFILE_INFO *dvi) |
| 522 |
{ |
| 523 |
int len, x, y; |
| 524 |
long s_width, s_hight; |
| 525 |
|
| 526 |
#if defined(WIN32) && defined(KPATHSEA) |
| 527 |
fprintf(stdout, "dvi file name\t\t\t= %s\n", dvi->file_name); |
| 528 |
#else |
| 529 |
printf("dvi file name\t\t\t= %s\n", dvi->file_name); |
| 530 |
#endif |
| 531 |
fseek(dvi->file_ptr, 14L, SEEK_SET), |
| 532 |
len = (uchar)read_byte(dvi->file_ptr); |
| 533 |
printf("comment\t\t\t\t=%s\n", read_str(dvi->file_ptr, len)); |
| 534 |
printf("factor converting to 10^{-5}m\t= %ld/%ld\n", |
| 535 |
dvi->num, dvi->den); |
| 536 |
printf("magnification\t\t\t= %ld\n", dvi->mag); |
| 537 |
printf("maximum width\t\t\t= %ld scaled points = %ld points\n", |
| 538 |
dvi->u, (dvi->u + HALF_POINT) >> 16); |
| 539 |
printf("maximum height+depth\t\t= %ld scaled points = %ld points\n", |
| 540 |
dvi->l, (dvi->l + HALF_POINT) >> 16); |
| 541 |
printf("maximum stack depth\t\t= %d\n", dvi->stack_depth); |
| 542 |
printf("number of pages\t\t\t= %d\n", dvi->total_page); |
| 543 |
s_width = ((dvi->u >> 6) * 2540) / 7227; /* scated 2^(-10) mm */ |
| 544 |
s_hight = ((dvi->l >> 6) * 2540) / 7227; /* scaled 2^(-10) mm */ |
| 545 |
x = (s_width + 512) / 1024; |
| 546 |
y = (s_hight + 512) / 1024; |
| 547 |
printf("page size\t\t\t= %2d.%d cm x %2d.%d cm\n", |
| 548 |
x / 10, x % 10, y / 10, y % 10); |
| 549 |
s_width = s_width * dvi->mag / 1000; |
| 550 |
s_hight = s_hight * dvi->mag / 1000; |
| 551 |
x = (s_width + 512) / 1024; |
| 552 |
y = (s_hight + 512) / 1024; |
| 553 |
printf("page size magnificated\t\t= %2d.%d cm x %2d.%d cm", |
| 554 |
x / 10, x % 10, y / 10, y % 10); |
| 555 |
} |
| 556 |
|
| 557 |
int check_mag(int scale) |
| 558 |
{ |
| 559 |
int i; |
| 560 |
|
| 561 |
for (i = 0; scale > mag[i] + 1; i++); |
| 562 |
if (scale + 1 > mag[i]) |
| 563 |
return (i + 1); |
| 564 |
return (-1); |
| 565 |
} |
| 566 |
|
| 567 |
void check_font(void) |
| 568 |
{ |
| 569 |
uchar point; |
| 570 |
char *pt; |
| 571 |
int ratio, cmag; |
| 572 |
int j; |
| 573 |
int f_point; |
| 574 |
|
| 575 |
if (f_v) { |
| 576 |
if (f_t != VF_FILE_MAP) { |
| 577 |
if (f_t == DVI_FILE) |
| 578 |
printf("\n\nFont %ld\n", font.k); |
| 579 |
printf("\tchecksum\t\t= %08lX\n", font.c); |
| 580 |
if (f_t != DVI_FILE) |
| 581 |
printf("\tdesign size\t\t= %ld 2^{-20} points = %ld points", |
| 582 |
font.d, font.d >> 20); |
| 583 |
else |
| 584 |
printf("\tdesign size\t\t=%9ld scaled points =%3ld points", |
| 585 |
font.d, font.d >> 16); |
| 586 |
} |
| 587 |
switch (f_t) { |
| 588 |
|
| 589 |
case (VF_FILE_MAP): |
| 590 |
printf("\n\n\tMapped Font %ld\n", vffont.k); |
| 591 |
// printf("\t\tchecksum\t= %08lX\n", vffont.c); /* always zero, we can't get it without tfm */ |
| 592 |
printf("\t\tfont dsize\t= %ld 2^{-20} points = %ld points", vffont.d, vffont.d/(1<<20)); |
| 593 |
printf("\n\t\tfont at\t\t= %9.6lf", vffont.s/(1<<20)); |
| 594 |
printf("\n\t\tfont name\t= %s", vffont.n); |
| 595 |
break; |
| 596 |
|
| 597 |
case (VF_FILE): |
| 598 |
break; |
| 599 |
|
| 600 |
case (PK_FILE): |
| 601 |
printf("\n\thorizontal\t\t= %ld 2^{-16} dots/point = %ld dpi", |
| 602 |
hppp, ((((hppp >> 4) * 7227) >> 12) + 49) / 100); |
| 603 |
printf("\n\tvertical\t\t= %ld 2^{-16} dots/point " |
| 604 |
"= %ld dpi\n\t\t\t\t", |
| 605 |
vppp, ((((vppp >> 4) * 7227) >> 12) + 49) / 100); |
| 606 |
break; |
| 607 |
|
| 608 |
case (PXL_FILE): |
| 609 |
printf("\n\tmagnification\t\t= %ld (%ld dpi)\n\t\t\t\t", |
| 610 |
pmag, (pmag + 2) / 5); |
| 611 |
break; |
| 612 |
|
| 613 |
case (TFM_FILE): |
| 614 |
printf("\n\t\t\t\t"); |
| 615 |
break; |
| 616 |
|
| 617 |
case (DVI_FILE): |
| 618 |
printf("\n\tspace size\t\t=%9ld scaled points =%3ld points", |
| 619 |
font.s, font.s >> 16); |
| 620 |
ratio = 1000; |
| 621 |
cmag = 0; |
| 622 |
if (font.d > font.s) |
| 623 |
ratio = (font.d * 100L + (font.s / 20L)) / (font.s / 10L); |
| 624 |
else if (font.s > font.d) |
| 625 |
ratio = (font.s * 100L + (font.d / 20L)) / (font.d / 10L); |
| 626 |
if (ratio != 1000) |
| 627 |
cmag = check_mag(ratio); |
| 628 |
if (cmag > 0) { |
| 629 |
printf("\n\tmagnification\t\t= %smagstep%d%s", |
| 630 |
(font.d > font.s) ? "-" : "+", cmag / 2, (cmag & 1) ? ".5" : ""); |
| 631 |
} |
| 632 |
else if (cmag < 0) |
| 633 |
printf("\n\tmagnification\t\t= %d", |
| 634 |
(font.d > font.s) ? ((int)((1000000L + ratio) / ratio)) : ratio); |
| 635 |
printf("\n\tfont name\t\t= %s", font.n); |
| 636 |
break; |
| 637 |
} |
| 638 |
} |
| 639 |
if (f_v == -1) |
| 640 |
return; |
| 641 |
for (j = 0; j < n_data; j++) { |
| 642 |
if (strcmp(chkfont[j].f_name, font.n) == 0) { |
| 643 |
if (chkfont[j].oldd == 0 || chkfont[j].oldd == font.c) { |
| 644 |
type("Old font"); |
| 645 |
f_type |= OLD_FONT; |
| 646 |
return; |
| 647 |
} |
| 648 |
if (chkfont[j].neww == 0 || chkfont[j].neww == font.c) { |
| 649 |
type("New font"); |
| 650 |
f_type |= NEW_FONT; |
| 651 |
return; |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
if (f_d) |
| 656 |
return; |
| 657 |
|
| 658 |
pt = font.n + font.a + font.l - 1; |
| 659 |
while (*pt >= '0' && *pt <= '9') |
| 660 |
pt--; |
| 661 |
point = atoi(++pt); |
| 662 |
*pt = 0; |
| 663 |
|
| 664 |
if (strcmp(font.n, "eufm") == 0) { |
| 665 |
j = f_point = 0; |
| 666 |
while (eufm[j].point != 0) { |
| 667 |
if (eufm[j].point == point) { |
| 668 |
f_point = 1; |
| 669 |
if (eufm[j].oldd == font.c) { |
| 670 |
f_type |= OLD_EUFM; |
| 671 |
type("Old AMSTeX"); |
| 672 |
return; |
| 673 |
} |
| 674 |
else { |
| 675 |
if (eufm[j].neww == font.c) { |
| 676 |
f_type |= NEW_EUFM; |
| 677 |
type("AMSTeX 2.0 or newer"); /* V2.2 is available */ |
| 678 |
return; |
| 679 |
} |
| 680 |
} |
| 681 |
} |
| 682 |
j++; |
| 683 |
} |
| 684 |
f_type |= BAD_EUFM; |
| 685 |
if (f_v) |
| 686 |
type( |
| 687 |
(f_point) ? "unknown checksum" : "unknown point size"); |
| 688 |
return; |
| 689 |
} |
| 690 |
for (j = 0; oldfont[j][0] != 0; j++) { |
| 691 |
if (strcmp(font.n, oldfont[j]) == 0) { |
| 692 |
f_type |= OLD_FONT; |
| 693 |
type("Old AMS Font"); |
| 694 |
return; |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
for (j = 0; newfont[j][0] != 0; j++) { |
| 699 |
if (strcmp(font.n, newfont[j]) == 0) { |
| 700 |
f_type |= NEW_FONT; |
| 701 |
type("New AMS Font"); |
| 702 |
return; |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
for (j = 0; newpoint[j].font_name[0] != 0; j++) { |
| 707 |
if (strcmp(font.n, newpoint[j].font_name) == 0) { |
| 708 |
if (newpoint[j].top <= point && newpoint[j].end >= point) { |
| 709 |
f_type |= NEW_POINT; |
| 710 |
type("New AMS Font"); |
| 711 |
} |
| 712 |
return; |
| 713 |
} |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
char *name_link(char *base, char *ext) |
| 718 |
/* combine basename and extension. */ |
| 719 |
{ |
| 720 |
char *name; |
| 721 |
int base_len; |
| 722 |
|
| 723 |
base_len = strlen(base); |
| 724 |
name = (char *)malloc(base_len + 5); |
| 725 |
strcpy(name, base); |
| 726 |
name[base_len] = '.'; |
| 727 |
strcpy(name + base_len + 1, ext); |
| 728 |
return (name); |
| 729 |
} |
| 730 |
|
| 731 |
void read_post(DVIFILE_INFO *dvi) |
| 732 |
/* read data from POSTAMBLE. */ |
| 733 |
{ |
| 734 |
long endofs; |
| 735 |
int code; |
| 736 |
|
| 737 |
if ((uchar)read_byte(dvi->file_ptr) != PRE || |
| 738 |
(uchar)read_byte(dvi->file_ptr) != ID) { |
| 739 |
err: |
| 740 |
fprintf(stderr, "%s is not correct DVI file\n", dvi->file_name); |
| 741 |
exit(254); |
| 742 |
} |
| 743 |
for (endofs = -3L; fseek(dvi->file_ptr, endofs, SEEK_END), |
| 744 |
(code = (uchar)read_byte(dvi->file_ptr)) != ID; endofs--) |
| 745 |
/* Search id number */ |
| 746 |
if (code == ID_PTEX) { |
| 747 |
printf("This is extended DVI file [ID = 3] for pTeX.\n"); |
| 748 |
break; |
| 749 |
} |
| 750 |
else if (code == EOF || code != END_DVI) |
| 751 |
goto err; |
| 752 |
|
| 753 |
fseek(dvi->file_ptr, endofs - 4L, SEEK_END); |
| 754 |
if ((dvi->post = read_long(dvi->file_ptr)) <= 0) |
| 755 |
goto err; |
| 756 |
/* Read the position of POSTAMBLE */ |
| 757 |
|
| 758 |
fseek(dvi->file_ptr, dvi->post, SEEK_SET); |
| 759 |
/* Set file-ptr at POSTAMBLE */ |
| 760 |
|
| 761 |
if ((uchar)read_byte(dvi->file_ptr) != POST) |
| 762 |
goto err; |
| 763 |
|
| 764 |
if ((dvi->last_bop = read_long(dvi->file_ptr)) <= 0) |
| 765 |
goto err; |
| 766 |
|
| 767 |
dvi->num = read_long(dvi->file_ptr); |
| 768 |
dvi->den = read_long(dvi->file_ptr); |
| 769 |
dvi->mag = read_long(dvi->file_ptr); |
| 770 |
|
| 771 |
dvi->l = (SCALED_PT)read_long(dvi->file_ptr); |
| 772 |
dvi->u = (SCALED_PT)read_long(dvi->file_ptr); |
| 773 |
|
| 774 |
dvi->stack_depth = read_uint(dvi->file_ptr); |
| 775 |
dvi->total_page = read_uint(dvi->file_ptr); |
| 776 |
|
| 777 |
if (dvi->num <= 0 || dvi->den <= 0 || dvi->mag <= 0) |
| 778 |
goto err; |
| 779 |
|
| 780 |
if (dvi->stack_depth < 0 || dvi->total_page <= 0) |
| 781 |
goto err; |
| 782 |
} |
| 783 |
|
| 784 |
void get_font_list(DVIFILE_INFO *dvi) |
| 785 |
{ |
| 786 |
int code, count; |
| 787 |
|
| 788 |
fseek(dvi->file_ptr, dvi->post + 29, SEEK_SET); |
| 789 |
while ((code = getc(dvi->file_ptr)) != POST_POST) |
| 790 |
if (code >= FNT_DEF_1 && code < FNT_DEF_1 + 4) { |
| 791 |
font_define(code, dvi->file_ptr); |
| 792 |
check_font(); |
| 793 |
} |
| 794 |
else if (code != NOP) { |
| 795 |
fprintf(stderr, "Command error code:%d\n", code); |
| 796 |
exit(253); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
void tfm_define(FILE * fp) |
| 801 |
{ |
| 802 |
int i, x, ch, nt, tfmver; /* tfmver = OFM level or JFM version */ |
| 803 |
long lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np, fontdir, sum, size, |
| 804 |
headerlength, topchar, topwidth, topheight, topdepth, topitalic, ncw, nlw, neew, |
| 805 |
nco, npc, nki, nwi, nkf, nwf, nkm, nwm, nkr, nwr, nkg, nwg, nkp, nwp; |
| 806 |
char *s, *t, *u; |
| 807 |
|
| 808 |
font.n[strlen(font.n) - 4] = 0; |
| 809 |
s = font.n + strlen(font.n); |
| 810 |
while (*--s >= '0' && *s <= '9' && s >= font.n); |
| 811 |
t = s; |
| 812 |
while (*s != ':' && *s != '\\' && *s != '/' && s-- > font.n); |
| 813 |
font.n = s + 1; |
| 814 |
font.a = t - s; |
| 815 |
font.l = 0; |
| 816 |
|
| 817 |
/* initialize for standard TFM */ |
| 818 |
ch = 't'; |
| 819 |
u = ""; |
| 820 |
nt = 0; |
| 821 |
tfmver = 0; |
| 822 |
headerlength = 6; |
| 823 |
topchar = 255; |
| 824 |
fontdir = 0; |
| 825 |
nco = npc = nki = nwi = nkf = nwf = nkm = nwm = nkr = nwr = nkg = nwg = nkp = nwp = 0; |
| 826 |
|
| 827 |
if ((i=read_uint(fp)) == 0) { /* (temporary) lf */ |
| 828 |
/* assume OFM */ |
| 829 |
ch = 'o'; |
| 830 |
tfmver = read_uint(fp); |
| 831 |
if (tfmver == 0) |
| 832 |
headerlength = 14; |
| 833 |
else |
| 834 |
headerlength = 29; |
| 835 |
topchar = 1114111L; |
| 836 |
lf = read_long(fp); /* lf */ |
| 837 |
lh = read_long(fp); /* lh */ |
| 838 |
} |
| 839 |
else { |
| 840 |
if (i == 11 || i == 9) { |
| 841 |
/* assume JFM */ |
| 842 |
ch = 'j'; |
| 843 |
if( i == 9 ) u = "(tate)"; |
| 844 |
headerlength = 7; |
| 845 |
nt = read_uint(fp); /* nt */ |
| 846 |
lf = read_uint(fp); /* lf */ |
| 847 |
} |
| 848 |
else { |
| 849 |
/* assume TFM */ |
| 850 |
lf = i; /* lf */ |
| 851 |
} |
| 852 |
lh = read_uint(fp); /* lh */ |
| 853 |
} |
| 854 |
|
| 855 |
/* |
| 856 |
[OFM format] |
| 857 |
Each entry is a 32-bit integer, non-negative and less than 2^31, and |
| 858 |
bc - 1 <= ec <= 1114111L (cf. 65535 in texmf-dist/doc/omega/base/doc-1.8.tex) |
| 859 |
lf = 14 + lh + 2 * (ec - bc + 1) + nw + nh + nd + ni + 2 * nl + nk + 2 * ne + np (for level 0) |
| 860 |
lf = 29 + lh + ncw + nw + nh + nd + ni + 2 * nl + nk + 2 * ne + np |
| 861 |
+ nki + nwi + nkf + nwf + nkm + nwm + nkr + nwr + nkg + nwg + nkp + nwp (for level 1) |
| 862 |
nki + nkf + nkm + nkr + nkg + nkp < 32 (for level 1) |
| 863 |
[JFM format] |
| 864 |
Each entry is a 16-bit integer, non-negative and less than 2^15, and |
| 865 |
0 <= ec <= 255 |
| 866 |
bc = 0 |
| 867 |
lf = 7 + nt + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ng + np |
| 868 |
[TFM format] |
| 869 |
Each entry is a 16-bit integer, non-negative and less than 2^15, and |
| 870 |
bc - 1 <= ec <= 255 |
| 871 |
ne <= 256 |
| 872 |
lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np |
| 873 |
*/ |
| 874 |
if (ch == 'o') { |
| 875 |
bc = read_long(fp); /* bc */ |
| 876 |
ec = read_long(fp); /* ec */ |
| 877 |
nw = read_long(fp); |
| 878 |
nh = read_long(fp); |
| 879 |
nd = read_long(fp); |
| 880 |
ni = read_long(fp); |
| 881 |
nl = read_long(fp); |
| 882 |
nk = read_long(fp); |
| 883 |
ne = read_long(fp); |
| 884 |
np = read_long(fp); |
| 885 |
fontdir = read_long(fp); |
| 886 |
nlw = 2 * nl; |
| 887 |
neew = 2 * ne; |
| 888 |
topchar = 1114111L; |
| 889 |
topwidth = 1114111L; |
| 890 |
topheight = 255; |
| 891 |
topdepth = 255; |
| 892 |
topitalic = 255; |
| 893 |
if (tfmver == 0) { |
| 894 |
ncw = 2 * ( ec - bc + 1 ); |
| 895 |
} |
| 896 |
else { |
| 897 |
nco = read_long(fp); |
| 898 |
ncw = read_long(fp); |
| 899 |
npc = read_long(fp); |
| 900 |
nki = read_long(fp); |
| 901 |
nwi = read_long(fp); |
| 902 |
nkf = read_long(fp); |
| 903 |
nwf = read_long(fp); |
| 904 |
nkm = read_long(fp); |
| 905 |
nwm = read_long(fp); |
| 906 |
nkr = read_long(fp); |
| 907 |
nwr = read_long(fp); |
| 908 |
nkg = read_long(fp); |
| 909 |
nwg = read_long(fp); |
| 910 |
nkp = read_long(fp); |
| 911 |
nwp = read_long(fp); |
| 912 |
} |
| 913 |
} |
| 914 |
else { |
| 915 |
bc = read_uint(fp); /* bc */ |
| 916 |
ec = read_uint(fp); /* ec */ |
| 917 |
nw = read_uint(fp); |
| 918 |
nh = read_uint(fp); |
| 919 |
nd = read_uint(fp); |
| 920 |
ni = read_uint(fp); |
| 921 |
nl = read_uint(fp); |
| 922 |
nk = read_uint(fp); |
| 923 |
ne = read_uint(fp); /* for JFM, this corresponds to ng instead */ |
| 924 |
np = read_uint(fp); |
| 925 |
ncw = ec - bc + 1; |
| 926 |
nlw = nl; |
| 927 |
neew = ne; |
| 928 |
topwidth = 255; |
| 929 |
topheight = 15; |
| 930 |
topdepth = 15; |
| 931 |
topitalic = 63; |
| 932 |
} |
| 933 |
if (lf != (headerlength + nt + lh + ncw + nw + nh + nd + ni + nlw + nk + neew |
| 934 |
+ np + nki + nwi + nkf + nwf + nkm + nwm + nkr + nwr + nkg + nwg + nkp + nwp)) { |
| 935 |
printf("\n\"%s\" is not a %cfm file\n", filename, ch); |
| 936 |
exit(254); |
| 937 |
} |
| 938 |
if (ch == 'j') { |
| 939 |
if (bc != 0 || ec < 0 || ec > topchar) { |
| 940 |
printf("\nThe %cfm file \"%s\" has illegal character code range: %ld -> %ld\n", ch, filename, bc, ec); |
| 941 |
exit(254); |
| 942 |
} |
| 943 |
} |
| 944 |
else { |
| 945 |
if (bc < 0 || bc > ec + 1 || ec > topchar) { |
| 946 |
printf("\nThe %cfm file \"%s\" has illegal character code range: %ld -> %ld\n", ch, filename, bc, ec); |
| 947 |
exit(254); |
| 948 |
} |
| 949 |
} |
| 950 |
#if 0 |
| 951 |
/* more strict check */ |
| 952 |
long ligsize = 800000L; /* set to 800000 for OFM, 32510 for TFM/JFM */ |
| 953 |
if (lh < 2) |
| 954 |
printf("Warning: The header length is only %ld!\n", lh); |
| 955 |
if (nl > ligsize) |
| 956 |
printf("Warning: The lig/kern program is too long!\n"); |
| 957 |
if (nw == 0 || nh == 0 || nd == 0 || ni == 0) |
| 958 |
printf("Warning: Incomplete subfiles for character dimensions!"); |
| 959 |
if (ch != 'j' && ne > topchar + 1) |
| 960 |
printf("Warning: There are %ld extensible recipes!", ne); |
| 961 |
#endif |
| 962 |
|
| 963 |
font.c = read_n(fp,4); /* header[0] */ |
| 964 |
font.d = read_long(fp); /* header[1] */ |
| 965 |
if (ch == 'j') { /* check for new features in Community pTeX / JFM 2.0 */ |
| 966 |
for (i = 2; i < lh; i++) /* the rest of header */ |
| 967 |
read_long(fp); |
| 968 |
for (i = 0; i < nt; i++){ /* char_type */ |
| 969 |
read_n(fp,2); x = read_byte(fp); read_byte(fp); |
| 970 |
if (x>0) tfmver |= 1; /* 3-byte kanji code */ |
| 971 |
} |
| 972 |
for (i = 0; i < ec-bc+1; i++) /* char_info */ |
| 973 |
read_long(fp); |
| 974 |
for (i = 0; i < nw+nh+nd+ni; i++) /* width, height, depth, italic */ |
| 975 |
read_long(fp); |
| 976 |
for (i = 0; i < nl; i++){ /* glue_kern */ |
| 977 |
x = read_byte(fp); read_n(fp,3); |
| 978 |
if (x>0 && x<128) tfmver |= 2; /* SKIP command */ |
| 979 |
if (x>128 && x<=255) tfmver |= 4; /* rearrangement */ |
| 980 |
} |
| 981 |
if (nk>256) tfmver |= 8; /* many kern */ |
| 982 |
if (ne>256) tfmver |= 16; /* many glue */ |
| 983 |
} |
| 984 |
fclose(fp); |
| 985 |
|
| 986 |
if (f_v != 0) { |
| 987 |
if (ch == 'o') { |
| 988 |
printf("\t\"%s\" is a %cfm level %d file :%3ld -> %3ld\n", |
| 989 |
font.n, ch, tfmver, bc, ec); |
| 990 |
} else { |
| 991 |
printf("\t\"%s\" is a %cfm%s file :%3ld -> %3ld\n", |
| 992 |
font.n, ch, u, bc, ec); |
| 993 |
if (ch == 'j' && tfmver > 0) { |
| 994 |
printf("\t\tNew features in Community pTeX / JFM 2.0:\n"); |
| 995 |
if (tfmver & 1) printf("\t\t+ 3-byte kanji code\n"); /* TL18 */ |
| 996 |
if (tfmver & 2) printf("\t\t+ SKIP command in glue_kern\n"); /* TL18 */ |
| 997 |
if (tfmver & 4) printf("\t\t+ rearrangement in glue_kern\n"); /* TL18 */ |
| 998 |
if (tfmver & 8) printf("\t\t+ more than 256 different kern\n"); /* TL24 */ |
| 999 |
if (tfmver & 16) printf("\t\t+ more than 256 different glue\n"); /* TL24 */ |
| 1000 |
} |
| 1001 |
} |
| 1002 |
if (f_vv > 0) { |
| 1003 |
printf("\t\tPARAMETERS:\n"); |
| 1004 |
if (ch == 'j') |
| 1005 |
printf("\t\t nt: %5d\n", nt); |
| 1006 |
printf("\t\t lh: %5ld\n", lh); |
| 1007 |
printf("\t\t bc: %5ld\n", bc); |
| 1008 |
printf("\t\t ec: %5ld\n", ec); |
| 1009 |
printf("\t\t nw: %5ld\n", nw); |
| 1010 |
printf("\t\t nh: %5ld\n", nh); |
| 1011 |
printf("\t\t nd: %5ld\n", nd); |
| 1012 |
printf("\t\t ni: %5ld\n", ni); |
| 1013 |
printf("\t\t nl: %5ld\n", nl); |
| 1014 |
printf("\t\t nk: %5ld\n", nk); |
| 1015 |
if (ch == 'j') |
| 1016 |
printf("\t\t ng: %5ld\n", ne); /* ng */ |
| 1017 |
else |
| 1018 |
printf("\t\t ne: %5ld\n", ne); |
| 1019 |
printf("\t\t np: %5ld\n", np); |
| 1020 |
if (ch == 'o') { |
| 1021 |
printf("\t\t+ FONTDIR: "); |
| 1022 |
switch (fontdir) { |
| 1023 |
case 0: printf("TL (default)"); break; |
| 1024 |
case 1: printf("LT"); break; |
| 1025 |
case 2: printf("TR"); break; |
| 1026 |
case 3: printf("LB"); break; |
| 1027 |
case 4: printf("BL"); break; |
| 1028 |
case 5: printf("RT"); break; |
| 1029 |
case 6: printf("BR"); break; |
| 1030 |
case 7: printf("RB"); break; |
| 1031 |
default: printf("unknown"); |
| 1032 |
} |
| 1033 |
printf("\n"); |
| 1034 |
} |
| 1035 |
} |
| 1036 |
} |
| 1037 |
check_font(); |
| 1038 |
} |
| 1039 |
|
| 1040 |
#define PK_PRE 247 |
| 1041 |
#define PK_ID 89 |
| 1042 |
#define GF_ID 131 |
| 1043 |
#define VF_ID 202 |
| 1044 |
#define PKD_ID ('p'+'k'+'d') |
| 1045 |
#define PK_POST 245 |
| 1046 |
#define GF_POST 223 |
| 1047 |
|
| 1048 |
#define VFW_ID ((PK_PRE<<8)+VF_ID) |
| 1049 |
#define GFW_ID ((PK_PRE<<8)+GF_ID) |
| 1050 |
#define PKW_ID ((PK_PRE<<8)+PK_ID) |
| 1051 |
#define PKDW_ID ((PK_PRE<<8)+PKD_ID) |
| 1052 |
#define JXL4_0_ID (0x0001) |
| 1053 |
#define JXL4_1_ID (0x8B25) |
| 1054 |
|
| 1055 |
void pxl_define(FILE * fp) |
| 1056 |
{ |
| 1057 |
int i, tmp, ch, code; |
| 1058 |
char *type, *s, *t, *u; |
| 1059 |
long endofs; |
| 1060 |
|
| 1061 |
strlwr(font.n); |
| 1062 |
s = u = font.n + strlen(font.n); |
| 1063 |
ch = 0; |
| 1064 |
while (*s != ':' && *s != '\\' && *s != '/' && *s != '.' && |
| 1065 |
s-- >= font.n); |
| 1066 |
if (*s == '.') { |
| 1067 |
ch = *(u = s); |
| 1068 |
*s = 0; |
| 1069 |
} |
| 1070 |
s = font.n + strlen(font.n); |
| 1071 |
while (*--s >= '0' && *s <= '9' && s >= font.n); |
| 1072 |
t = s; |
| 1073 |
while (*s != ':' && *s != '\\' && *s != '/' && s-- > font.n); |
| 1074 |
font.n = s + 1; |
| 1075 |
font.a = t - s; |
| 1076 |
font.l = 0; |
| 1077 |
|
| 1078 |
switch (tmp = read_uint(fp)) { |
| 1079 |
case (0): |
| 1080 |
switch (tmp = read_uint(fp)) { |
| 1081 |
case (1001): |
| 1082 |
type = "PXL1001"; |
| 1083 |
break; |
| 1084 |
|
| 1085 |
case (1002): |
| 1086 |
type = "PXL1002"; |
| 1087 |
break; |
| 1088 |
|
| 1089 |
case (1003): |
| 1090 |
type = "PXL1003"; |
| 1091 |
break; |
| 1092 |
|
| 1093 |
default: |
| 1094 |
printf("\nUnknown id:0000%04X\n", tmp); |
| 1095 |
exit(254); |
| 1096 |
} |
| 1097 |
if (f_end == 0) |
| 1098 |
fseek(fp, -20L, SEEK_END); |
| 1099 |
else |
| 1100 |
fseek(fp, f_end - 20, SEEK_SET); |
| 1101 |
font.c = read_n(fp,4); |
| 1102 |
pmag = read_long(fp); |
| 1103 |
font.d = read_long(fp); |
| 1104 |
break; |
| 1105 |
|
| 1106 |
case (JXL4_0_ID): |
| 1107 |
if (read_long(fp) == JXL4_1_ID) { |
| 1108 |
type = "JXL4"; |
| 1109 |
if (f_end == 0) |
| 1110 |
fseek(fp, -28L, SEEK_END); |
| 1111 |
else |
| 1112 |
fseek(fp, f_end - 28, SEEK_END); |
| 1113 |
font.c = read_n(fp,4); |
| 1114 |
pmag = read_long(fp); |
| 1115 |
font.d = read_long(fp); |
| 1116 |
} |
| 1117 |
else |
| 1118 |
goto id_err; |
| 1119 |
break; |
| 1120 |
|
| 1121 |
case (VFW_ID): |
| 1122 |
type = "VF"; |
| 1123 |
f_t = VF_FILE; |
| 1124 |
code = read_byte(fp); |
| 1125 |
for (i = 0; i < code; i++) |
| 1126 |
read_byte(fp); |
| 1127 |
for (i = 0; i < 4; i++) |
| 1128 |
font.c += read_byte(fp)<<(8*(3-i)); |
| 1129 |
for (i = 0; i < 4; i++) |
| 1130 |
font.d += read_byte(fp)<<(8*(3-i)); |
| 1131 |
break; |
| 1132 |
|
| 1133 |
case (GFW_ID): |
| 1134 |
type = "GF"; |
| 1135 |
for (endofs = -3L; fseek(fp, endofs, SEEK_END), |
| 1136 |
(code = (uchar)read_byte(fp)) == GF_POST; endofs--); |
| 1137 |
/* Search id number */ |
| 1138 |
if (code != GF_ID) { |
| 1139 |
fprintf(stderr, "This is not correct GF file\n"); |
| 1140 |
exit(252); |
| 1141 |
} |
| 1142 |
fseek(fp, endofs - 4, SEEK_END); |
| 1143 |
endofs = read_long(fp); |
| 1144 |
fseek(fp, endofs + 5, SEEK_SET); |
| 1145 |
goto pk3; |
| 1146 |
|
| 1147 |
case (PKDW_ID): |
| 1148 |
type = "PKD"; |
| 1149 |
goto pk2; |
| 1150 |
|
| 1151 |
case (PKW_ID): |
| 1152 |
type = "PK"; |
| 1153 |
pk2:tmp = read_byte(fp); |
| 1154 |
while (tmp--) |
| 1155 |
(void)read_byte(fp); |
| 1156 |
pk3:f_t = PK_FILE; |
| 1157 |
font.d = read_long(fp); |
| 1158 |
font.c = read_n(fp,4); |
| 1159 |
hppp = read_long(fp); |
| 1160 |
vppp = read_long(fp); |
| 1161 |
break; |
| 1162 |
|
| 1163 |
default: |
| 1164 |
id_err: |
| 1165 |
printf("\nUnknown id:%04X\n", tmp); |
| 1166 |
exit(254); |
| 1167 |
} |
| 1168 |
if (f_v != 0) { |
| 1169 |
*u = ch; |
| 1170 |
printf("\t\"%s\" is in %s format\n", font.n, type); |
| 1171 |
*u = 0; |
| 1172 |
} |
| 1173 |
check_font(); |
| 1174 |
} |
| 1175 |
|
| 1176 |
void font_define(int code, FILE * dvifile) |
| 1177 |
{ |
| 1178 |
int i, len, lenm; |
| 1179 |
|
| 1180 |
font.k = read_n(dvifile, code - FNT_DEF_1 + 1); |
| 1181 |
font.c = read_n(dvifile,4); |
| 1182 |
font.s = read_long(dvifile); |
| 1183 |
font.d = read_long(dvifile); |
| 1184 |
font.a = read_byte(dvifile); |
| 1185 |
font.l = read_byte(dvifile); |
| 1186 |
|
| 1187 |
if (font.a == EOF || font.l == EOF) { |
| 1188 |
fprintf(stderr, "Bad DVI file\n"); |
| 1189 |
exit(252); |
| 1190 |
} |
| 1191 |
font.n = read_str(dvifile, font.a + font.l); |
| 1192 |
} |
| 1193 |
|
| 1194 |
void vf_define(int code, FILE * vffile) |
| 1195 |
{ |
| 1196 |
int i, len, lenm; |
| 1197 |
|
| 1198 |
vffont.k = read_n(vffile, code - FNT_DEF_1 + 1); |
| 1199 |
vffont.c = read_n(vffile,4); |
| 1200 |
vffont.s = read_long(vffile); |
| 1201 |
vffont.d = read_long(vffile); |
| 1202 |
vffont.a = read_byte(vffile); |
| 1203 |
vffont.l = read_byte(vffile); |
| 1204 |
|
| 1205 |
if (vffont.a == EOF || vffont.l == EOF) { |
| 1206 |
fprintf(stderr, "Bad VF file\n"); |
| 1207 |
exit(252); |
| 1208 |
} |
| 1209 |
vffont.n = read_str(vffile, vffont.a + vffont.l); |
| 1210 |
} |
| 1211 |
|
| 1212 |
int read_uint(FILE * fp) |
| 1213 |
{ /* read unsigned integer */ |
| 1214 |
int d; |
| 1215 |
|
| 1216 |
d = (uchar)getc(fp); |
| 1217 |
d = (d << 8) | (uchar)getc(fp); |
| 1218 |
return (d); |
| 1219 |
} |
| 1220 |
|
| 1221 |
long read_mit(FILE * fp) |
| 1222 |
{ /* read three bytes as long integer */ |
| 1223 |
long d; |
| 1224 |
|
| 1225 |
d = (uchar)getc(fp); |
| 1226 |
if (d > 127) |
| 1227 |
d -= 256; |
| 1228 |
d = (d << 8) | (uchar)getc(fp); |
| 1229 |
d = (d << 8) | (uchar)getc(fp); |
| 1230 |
return (d); |
| 1231 |
} |
| 1232 |
|
| 1233 |
long read_long(FILE * fp) |
| 1234 |
{ /* read 4 bytes as long integer */ |
| 1235 |
long d; |
| 1236 |
|
| 1237 |
d = (uchar)getc(fp); |
| 1238 |
if (d > 127) |
| 1239 |
d -= 256; |
| 1240 |
d = (d << 8) | (uchar)getc(fp); |
| 1241 |
d = (d << 8) | (uchar)getc(fp); |
| 1242 |
d = (d << 8) | (uchar)getc(fp); |
| 1243 |
return (d); |
| 1244 |
} |
| 1245 |
|
| 1246 |
long to_long(uchar *pt) |
| 1247 |
{ /* read 4 bytes as long integer */ |
| 1248 |
long d; |
| 1249 |
|
| 1250 |
d = (pt[3] << 8) + pt[2]; |
| 1251 |
d = (d << 16) + (pt[1] << 8) + pt[0]; |
| 1252 |
return (d); |
| 1253 |
} |
| 1254 |
|
| 1255 |
|
| 1256 |
char *read_str(FILE * fp, int len) |
| 1257 |
{ |
| 1258 |
char *pt0, *pt; |
| 1259 |
|
| 1260 |
if ((pt = pt0 = (char *)malloc(len + 1)) != NULL) { |
| 1261 |
while (len-- > 0) |
| 1262 |
*pt++ = getc(fp); |
| 1263 |
*pt = '\0'; |
| 1264 |
|
| 1265 |
} |
| 1266 |
return (pt0); |
| 1267 |
} |
| 1268 |
|
| 1269 |
long read_n(FILE * fp, int n) |
| 1270 |
{ /* read 1--4 bytes as unsigned long integer */ |
| 1271 |
ulong d; |
| 1272 |
|
| 1273 |
d = (uchar)getc(fp); |
| 1274 |
|
| 1275 |
switch (n) { |
| 1276 |
case 4: |
| 1277 |
d = (d << 8) | (uchar)getc(fp); |
| 1278 |
case 3: |
| 1279 |
d = (d << 8) | (uchar)getc(fp); |
| 1280 |
case 2: |
| 1281 |
d = (d << 8) | (uchar)getc(fp); |
| 1282 |
} |
| 1283 |
return ((long)d); |
| 1284 |
} |
| 1285 |
|
| 1286 |
long signed_read_n(FILE * fp, int n) |
| 1287 |
{ |
| 1288 |
long d; |
| 1289 |
|
| 1290 |
d = (uchar)getc(fp); |
| 1291 |
if (d > 127) |
| 1292 |
d -= 256; |
| 1293 |
switch (n) { |
| 1294 |
case 4: |
| 1295 |
d = (d << 8) | (uchar)getc(fp); |
| 1296 |
case 3: |
| 1297 |
d = (d << 8) | (uchar)getc(fp); |
| 1298 |
case 2: |
| 1299 |
d = (d << 8) | (uchar)getc(fp); |
| 1300 |
} |
| 1301 |
return (d); |
| 1302 |
} |
| 1303 |
|
| 1304 |
void type(char *s) |
| 1305 |
{ |
| 1306 |
if (f_v) |
| 1307 |
printf(" (%s) ", s); |
| 1308 |
} |
| 1309 |
|
| 1310 |
void get_list(char *fname) |
| 1311 |
{ |
| 1312 |
FILE *fp; |
| 1313 |
|
| 1314 |
if ((fp = fopen(fname, "r")) == NULL) { |
| 1315 |
fprintf(stderr, "Cannot find %s.\n", fname); |
| 1316 |
exit(249); |
| 1317 |
} |
| 1318 |
for (n_data = 0; n_data < MAX_FONT;) { |
| 1319 |
if (fgets(buf, BUF_SIZE, fp) == NULL) |
| 1320 |
return; |
| 1321 |
if (buf[0] == '#' || buf[0] == ';') |
| 1322 |
continue; |
| 1323 |
if (sscanf(buf, "%15s %lX %lX", |
| 1324 |
chkfont[n_data].f_name, |
| 1325 |
&(chkfont[n_data].oldd), |
| 1326 |
&(chkfont[n_data].neww)) != 3) { |
| 1327 |
fprintf(stderr, "error in %s[%s]\n", fname, buf); |
| 1328 |
exit(248); |
| 1329 |
} |
| 1330 |
if (chkfont[n_data].oldd == chkfont[n_data].neww) { |
| 1331 |
fprintf(stderr, "same check sum in %s[%s]\n", fname, buf); |
| 1332 |
exit(248); |
| 1333 |
} |
| 1334 |
n_data++; |
| 1335 |
} |
| 1336 |
if (n_data >= MAX_FONT) { |
| 1337 |
fprintf(stderr, "Too many font data in %s\n", fname); |
| 1338 |
exit(248); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
|
| 1342 |
void usage() |
| 1343 |
{ |
| 1344 |
fprintf(stderr, |
| 1345 |
"\t<<< CHecK DVI/tfm/font file and tell informations of FONTs >>>\n" |
| 1346 |
"\t\t\t\tOriginally written by SHIMA, 1990/1992\n" |
| 1347 |
"\t\t\t\tVer.%s (%s)\n\n", VERSION, TL_VERSION); |
| 1348 |
fprintf(stderr, |
| 1349 |
"Usage: chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-d] dvi_file_name\n" |
| 1350 |
" chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-t] tfm_file_name\n" |
| 1351 |
" chkdvifont [-s] [-c] [-{f|F}<font_data_file>] [-p] font_file_name\n\n" |
| 1352 |
"Option\t -c: check mode\n" |
| 1353 |
"\t -s: silent check mode\n" |
| 1354 |
"\t -v: more verbose (only for TFM/OFM mode)\n" |
| 1355 |
"\t -f: use font_data_file (-F: and ignore default data)\n" |
| 1356 |
"\t -d: force DVI mode\n" |
| 1357 |
"\t -t: force TFM/OFM mode\n" |
| 1358 |
"\t -p: force FONT mode\n" |
| 1359 |
"\t (supported formats: vf/ovf/gf/pk/pkd/pxl/gth/far)\n" |
| 1360 |
"\t By default, mode is guessed from the file extension.\n\n" |
| 1361 |
#if 0 |
| 1362 |
"Input M to see more. Push Return to quit"); |
| 1363 |
switch (getc(stdin)) { |
| 1364 |
case ('M'): |
| 1365 |
case ('m'): |
| 1366 |
goto show; |
| 1367 |
default: |
| 1368 |
exit(250); |
| 1369 |
} |
| 1370 |
exit(1); |
| 1371 |
|
| 1372 |
show: |
| 1373 |
fprintf(stderr, "\n\n" |
| 1374 |
#endif |
| 1375 |
"Errorlevel is the sum of the following number\n" |
| 1376 |
"\t 1: cmbsy5-9, cmcsc8-9, cmex7-9, cmmib5-9\n" |
| 1377 |
"\t 2: new font: eu??, msam, msbm, wncy??, font_data_file\n" |
| 1378 |
"\t 4: new eufm5-10\n" |
| 1379 |
"\t 8: unknown eufm\n" |
| 1380 |
"\t 16: old font: msxm, msym, amcsc, mcyr, mcyb, font_data_file\n" |
| 1381 |
"\t 32: old eufm5-10\n" |
| 1382 |
"If errorlevel is larger than 240,\n" |
| 1383 |
"\t248: error in font_data_file\n" |
| 1384 |
"\t249: cannot find font_data_file\n" |
| 1385 |
"\t250: bad parameter\n" |
| 1386 |
"\t251: old and new eufm\n" |
| 1387 |
"\t252: bad dvi file\n" |
| 1388 |
"\t253: error in dvi file\n" |
| 1389 |
"\t254: not dvi/tfm file or unknown font ID\n" |
| 1390 |
"\t255: cannot find dvi/tfm/font file\n\n" |
| 1391 |
"\t\t<<< Example of font_data_file >>>\n" |
| 1392 |
"# font_name old_check_sum new_check_sum (in HEX, 0 means existence check)\n" |
| 1393 |
"eufm5 0891FD38 246A686B\n" |
| 1394 |
"eufm10 BF989013 8F256EB2\n" |
| 1395 |
"# The line beginning with # or ; is ignored.\n" |
| 1396 |
); |
| 1397 |
fprintf(stderr, "\nEmail bug reports to %s.\n", BUG_ADDRESS); |
| 1398 |
exit(0); |
| 1399 |
} |
| 1400 |
|