| 1 |
/* |
| 2 |
* T1part.c version 1.59 beta Copyright (C)1994, 1996 |
| 3 |
* by Sergey Lesenko |
| 4 |
* [email protected] |
| 5 |
* |
| 6 |
* It is distributed with no warranty of any kind. |
| 7 |
* You may modify and use this program. It can be included |
| 8 |
* in any distribution, commercial or otherwise, so long as |
| 9 |
* copyright notice be preserved on all copies. |
| 10 |
*/ |
| 11 |
#ifndef XDVIPSK |
| 12 |
#include "dvips.h" |
| 13 |
#else |
| 14 |
#include "xdvips.h" /* The copyright notice in that file is included too! */ |
| 15 |
#endif /* XDVIPSK */ |
| 16 |
#include "t1part.h" |
| 17 |
#ifndef SEEK_SET |
| 18 |
#define SEEK_SET (0) |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifdef BORLANDC |
| 22 |
void huge *UniGetMem(size) |
| 23 |
ub4 size; |
| 24 |
{ |
| 25 |
void huge *tmp; |
| 26 |
if ((tmp =(void huge*) farcalloc(1L, size)) == NULL) |
| 27 |
{ |
| 28 |
fprintf(stderr,"Error allocating far memory\n"); |
| 29 |
exit(1); |
| 30 |
} |
| 31 |
return tmp; |
| 32 |
} |
| 33 |
#else |
| 34 |
#define UniGetMem getmem |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifdef WIN32 |
| 38 |
/* CHAR is typedef'd by <windows.h> -- [email protected]. */ |
| 39 |
#define CHAR CHARACTER |
| 40 |
#endif |
| 41 |
|
| 42 |
typedef struct Char |
| 43 |
{ |
| 44 |
unsigned char *name; |
| 45 |
int length; |
| 46 |
int num; |
| 47 |
int choose; |
| 48 |
struct Char *NextChar; |
| 49 |
} |
| 50 |
CHAR; |
| 51 |
|
| 52 |
typedef struct String |
| 53 |
{ |
| 54 |
unsigned char *name; |
| 55 |
int num; |
| 56 |
struct String *NextStr; |
| 57 |
} |
| 58 |
STRING; |
| 59 |
|
| 60 |
static STRING *FirstStr; |
| 61 |
static STRING *RevStr; |
| 62 |
|
| 63 |
static CHAR *FirstChar; |
| 64 |
static CHAR *FirstCharA; |
| 65 |
CHAR *FirstCharB; |
| 66 |
static CHAR *FirstCharW; |
| 67 |
|
| 68 |
int CharCount; |
| 69 |
int GridCount; |
| 70 |
int ind_ref; |
| 71 |
|
| 72 |
static unsigned char CDeCrypt(unsigned char, unsigned int *); |
| 73 |
static void CorrectGrid(void); |
| 74 |
static void OutHEX(FILE *); |
| 75 |
static int Afm(void); |
| 76 |
static int LoadVector(int, CHAR *); |
| 77 |
static int ChooseVect(CHAR *); |
| 78 |
#ifndef XDVIPSK |
| 79 |
static void ErrorOfScan(int err); |
| 80 |
static void NameOfProgram(void); |
| 81 |
#else |
| 82 |
static void NameOfProgram(char **buf); |
| 83 |
static void ErrorOfScan(int err, char **buf); |
| 84 |
#endif /* XDVIPSK */ |
| 85 |
|
| 86 |
typedef struct |
| 87 |
{ |
| 88 |
int num[4]; |
| 89 |
int select; |
| 90 |
} |
| 91 |
def_ref; |
| 92 |
|
| 93 |
def_ref refer[10]; |
| 94 |
|
| 95 |
#ifndef min |
| 96 |
#define min(a, b) ((a) < (b) ? (a) : (b)) |
| 97 |
#endif |
| 98 |
|
| 99 |
#ifndef max |
| 100 |
#define max(a, b) ((a) > (b) ? (a) : (b)) |
| 101 |
#endif |
| 102 |
|
| 103 |
|
| 104 |
#define PFA 1 |
| 105 |
#define PFB 2 |
| 106 |
|
| 107 |
|
| 108 |
#define NOTHING 0 |
| 109 |
#define FLG_ASCII 1 |
| 110 |
#define FLG_BINARY 2 |
| 111 |
#define FLG_EOF 3 |
| 112 |
#define FLG_ZERO_LINE 4 |
| 113 |
|
| 114 |
#define FLG_OUT_STR (-1) |
| 115 |
#define CHAR_NOT_DEF (-1) |
| 116 |
#define SEAC_NOT_END (-2) |
| 117 |
|
| 118 |
#define FLG_LOAD_BASE (1) |
| 119 |
|
| 120 |
#define STANDARD_ENC (1) |
| 121 |
#define SPECIAL_ENC (2) |
| 122 |
#define AFM_ENC (4) |
| 123 |
|
| 124 |
|
| 125 |
#define FLG_REENCODE (4) |
| 126 |
|
| 127 |
|
| 128 |
#define BYTES_PER_LINE 32 |
| 129 |
|
| 130 |
#ifndef KPATHSEA_TYPES_H |
| 131 |
#define TRUE 1 |
| 132 |
#define FALSE 0 |
| 133 |
#endif /* not KPATHSEA_TYPES_H */ |
| 134 |
|
| 135 |
#define LENIV 0 |
| 136 |
#define SUBRS 1 |
| 137 |
#define CHARSTRINGS 2 |
| 138 |
|
| 139 |
#define ERR_FIRST_NUM (-1) |
| 140 |
#define ERR_SECOND_NUM (-2) |
| 141 |
#define ERR_FIRST_TOK (-3) |
| 142 |
#define ERR_SECOND_TOK (-4) |
| 143 |
#define ERR_STACK (-5) |
| 144 |
#define ERR_NUM_CHAR (-6) |
| 145 |
#define ERR_NAME_CHAR (-7) |
| 146 |
|
| 147 |
#define SUBR_STR 1 |
| 148 |
#define CHAR_STR -1 |
| 149 |
#define CHAR_SEAC -2 |
| 150 |
#define SKIP_ON_DUP 3 |
| 151 |
|
| 152 |
#define C1 52845 |
| 153 |
#define C2 22719 |
| 154 |
#define EDR 55665 |
| 155 |
#define EER 55665 |
| 156 |
#define CDR 4330 |
| 157 |
|
| 158 |
#define MAX_ESCAPE 33 |
| 159 |
|
| 160 |
#define HSTEM 1 |
| 161 |
#define VSTEM 3 |
| 162 |
#define VMOVETO 4 |
| 163 |
#define CHARS_RLINETO 5 |
| 164 |
#define HLINETO 6 |
| 165 |
#define VLINETO 7 |
| 166 |
#define RRCURVETO 8 |
| 167 |
#define CHARS_CLOSEPATH 9 |
| 168 |
#define CALLSUBR 10 |
| 169 |
#define RETURN 11 |
| 170 |
#define ESCAPE 12 |
| 171 |
#define HSBW 13 |
| 172 |
#define ENDCHAR 14 |
| 173 |
#define CHARS_RMOVETO 21 |
| 174 |
#define HMOVETO 22 |
| 175 |
#define VHCURVETO 30 |
| 176 |
#define HVCURVETO 31 |
| 177 |
|
| 178 |
#define DOTSECTION 0 |
| 179 |
#define VSTEM3 1 |
| 180 |
#define HSTEM3 2 |
| 181 |
#define SEAC 6 |
| 182 |
#define SBW 7 |
| 183 |
#define CHARS_DIV 12 |
| 184 |
#define CALLOTHERSUBR 16 |
| 185 |
#define POP 17 |
| 186 |
#define SETCURRENTPOINT 33 |
| 187 |
|
| 188 |
typetemp BORLAND_HUGE *temp; |
| 189 |
typetemp BORLAND_HUGE *begin_of_scan; |
| 190 |
typetemp BORLAND_HUGE *end_of_scan; |
| 191 |
unsigned char *line; |
| 192 |
unsigned char *tmpline; |
| 193 |
unsigned char token[64]; |
| 194 |
unsigned char notdef[]="/.notdef"; |
| 195 |
unsigned char grid[256]; |
| 196 |
unsigned char tmpgrid[256]; |
| 197 |
unsigned char psfontfile[500]; /* really should dynamically allocate */ |
| 198 |
unsigned char psvectfile[500]; |
| 199 |
unsigned char basevect[]="ad.enc"; |
| 200 |
unsigned char version[] = "v1.59 beta (c)1994, 1996"; |
| 201 |
unsigned char tmp_token[64]; |
| 202 |
/* static int j = 0; */ |
| 203 |
static int stack[128]; |
| 204 |
|
| 205 |
ub1 buf[BUFSIZ]; |
| 206 |
|
| 207 |
int loadbase = 0; |
| 208 |
static int encode; |
| 209 |
static int reencode; |
| 210 |
|
| 211 |
int find_encod; |
| 212 |
int lastpart=0; |
| 213 |
int keep_flg=0; |
| 214 |
int keep_num=0; |
| 215 |
|
| 216 |
int number; |
| 217 |
int offset; |
| 218 |
long value; |
| 219 |
int lenIV = 4; |
| 220 |
|
| 221 |
static int grow=0; |
| 222 |
static int level; |
| 223 |
static int flg_seac=0; |
| 224 |
|
| 225 |
typedef struct |
| 226 |
{ |
| 227 |
const char *command; |
| 228 |
int code; |
| 229 |
} |
| 230 |
tablecommand; |
| 231 |
|
| 232 |
tablecommand TableCommand[] = |
| 233 |
{ |
| 234 |
{"callsubr", CALLSUBR}, {"callothersubr", CALLOTHERSUBR}, |
| 235 |
{"pop", POP }, {"seac", SEAC}, {""} |
| 236 |
}; |
| 237 |
|
| 238 |
typedef struct |
| 239 |
{ |
| 240 |
const char *extension; |
| 241 |
int num; |
| 242 |
} |
| 243 |
typefonts; |
| 244 |
|
| 245 |
|
| 246 |
typefonts TypeFonts[] = |
| 247 |
{ |
| 248 |
{".pfa", PFA}, {".pfb", PFB}, |
| 249 |
{".PFA", PFA}, {".PFB", PFB}, {""} |
| 250 |
}; |
| 251 |
|
| 252 |
static char Dup[]="dup"; |
| 253 |
|
| 254 |
typedef struct |
| 255 |
{ |
| 256 |
typetemp BORLAND_HUGE *begin; |
| 257 |
int length; |
| 258 |
int type; |
| 259 |
int offset; |
| 260 |
int oldnum; |
| 261 |
int newnum; |
| 262 |
} |
| 263 |
def_key; |
| 264 |
|
| 265 |
def_key keyword[6]; |
| 266 |
|
| 267 |
int FirstKey, current; |
| 268 |
|
| 269 |
int subrs, char_str; |
| 270 |
|
| 271 |
|
| 272 |
typedef struct |
| 273 |
{ |
| 274 |
const char *name; |
| 275 |
int num; |
| 276 |
} |
| 277 |
type_key; |
| 278 |
|
| 279 |
|
| 280 |
type_key Key[] = |
| 281 |
{ |
| 282 |
{"/LenIV", LENIV}, {"/Subrs", SUBRS}, {"/CharStrings", CHARSTRINGS}, {""} |
| 283 |
}; |
| 284 |
|
| 285 |
|
| 286 |
struct def_label |
| 287 |
{ |
| 288 |
typetemp BORLAND_HUGE *begin; |
| 289 |
unsigned char skip; |
| 290 |
int length; |
| 291 |
short select; |
| 292 |
int num; |
| 293 |
}; |
| 294 |
|
| 295 |
struct def_label label[NUM_LABEL]; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
static int |
| 300 |
DefTypeFont(unsigned char *name) |
| 301 |
{ |
| 302 |
int i; |
| 303 |
|
| 304 |
for(i=0;*TypeFonts[i].extension;i++) |
| 305 |
{ |
| 306 |
if(strstr((char *)name,TypeFonts[i].extension)!=0) |
| 307 |
return(TypeFonts[i].num); |
| 308 |
} |
| 309 |
return -1; |
| 310 |
} |
| 311 |
|
| 312 |
static int |
| 313 |
GetZeroLine(unsigned char *str) |
| 314 |
{ |
| 315 |
int token_type=0; |
| 316 |
if(*str!='0') |
| 317 |
{ |
| 318 |
return (token_type=0); |
| 319 |
} |
| 320 |
while(*str=='0') |
| 321 |
{ |
| 322 |
str++; |
| 323 |
} |
| 324 |
|
| 325 |
if(*str=='\n' || *str=='\r') |
| 326 |
token_type= -1; |
| 327 |
else |
| 328 |
token_type=0; |
| 329 |
return(token_type); |
| 330 |
} |
| 331 |
|
| 332 |
/* We get token type and its content for ASCII code */ |
| 333 |
|
| 334 |
static int |
| 335 |
GetWord(unsigned char *mem) |
| 336 |
{ |
| 337 |
int token_type=0; |
| 338 |
register unsigned char *tmp; |
| 339 |
tmp=mem; |
| 340 |
*tmp= *line; |
| 341 |
while((*line!='\0')&&(*line!='%')) |
| 342 |
{ |
| 343 |
if(*line=='-') |
| 344 |
{ |
| 345 |
*tmp++= *line++; |
| 346 |
} |
| 347 |
|
| 348 |
if(isdigit(*line)) |
| 349 |
{ |
| 350 |
while(isdigit(*line)) |
| 351 |
{ |
| 352 |
*tmp++= *line++; |
| 353 |
} |
| 354 |
*tmp = '\0'; |
| 355 |
return 5; |
| 356 |
} |
| 357 |
|
| 358 |
if(*line=='/') |
| 359 |
{ |
| 360 |
*tmp++= *line++; token_type=1; |
| 361 |
} |
| 362 |
if(*line=='.') |
| 363 |
{ |
| 364 |
*tmp++= *line++; |
| 365 |
|
| 366 |
if(token_type==1) |
| 367 |
{ |
| 368 |
if(*line==' ') |
| 369 |
{ |
| 370 |
*tmp = '\0'; |
| 371 |
return(token_type=token_type+2); |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
if(isalpha(*line)) |
| 376 |
{ |
| 377 |
*tmp++ = *line++; |
| 378 |
while(!isspace(*line) && *line != '/') |
| 379 |
*tmp++= *line++; |
| 380 |
*tmp = '\0'; |
| 381 |
return(token_type=token_type+2); |
| 382 |
} |
| 383 |
|
| 384 |
token_type=0; |
| 385 |
tmp=mem; |
| 386 |
line++; |
| 387 |
} |
| 388 |
return(token_type= -1); |
| 389 |
} |
| 390 |
|
| 391 |
/* We get token type and its content for BINARY code */ |
| 392 |
|
| 393 |
static int |
| 394 |
GetToken(void) |
| 395 |
{ |
| 396 |
register unsigned char *tmp; |
| 397 |
int token_type=0; |
| 398 |
|
| 399 |
tmp=token; |
| 400 |
|
| 401 |
*tmp= *temp; |
| 402 |
while(temp<end_of_scan) |
| 403 |
{ |
| 404 |
if(*temp=='/') |
| 405 |
{ |
| 406 |
*tmp++= *temp++; token_type=1; |
| 407 |
} |
| 408 |
|
| 409 |
if(*temp=='.') |
| 410 |
{ |
| 411 |
*tmp++= *temp++; |
| 412 |
token_type++; |
| 413 |
} |
| 414 |
|
| 415 |
if(isalpha(*temp)) |
| 416 |
{ |
| 417 |
while(isalnum(*temp) || *temp == '.') |
| 418 |
*tmp++= *temp++; |
| 419 |
|
| 420 |
*tmp = '\0'; |
| 421 |
|
| 422 |
return(token_type=token_type+2); |
| 423 |
} |
| 424 |
token_type=0; |
| 425 |
tmp=token; |
| 426 |
temp++; |
| 427 |
} |
| 428 |
return(token_type= -1); |
| 429 |
} |
| 430 |
|
| 431 |
static int |
| 432 |
GetNum(void) |
| 433 |
{ |
| 434 |
unsigned char *tmp; |
| 435 |
tmp=token; |
| 436 |
*tmp= *temp; |
| 437 |
|
| 438 |
while(temp<end_of_scan) |
| 439 |
{ |
| 440 |
if(isdigit(*temp)) |
| 441 |
{ |
| 442 |
while(isdigit(*temp)) |
| 443 |
*tmp++= *temp++; |
| 444 |
*tmp = '\0'; |
| 445 |
return(atoi((char *)token)); |
| 446 |
} |
| 447 |
temp++; |
| 448 |
} |
| 449 |
|
| 450 |
return -1; |
| 451 |
} |
| 452 |
|
| 453 |
/* We pass token without definition its type, it's for speed */ |
| 454 |
|
| 455 |
static int |
| 456 |
PassToken(void) |
| 457 |
{ |
| 458 |
while(temp < end_of_scan) |
| 459 |
{ |
| 460 |
if(!isspace(*temp)) |
| 461 |
{ |
| 462 |
while(!isspace(*temp)) |
| 463 |
temp++; |
| 464 |
return 1; |
| 465 |
} |
| 466 |
temp++; |
| 467 |
} |
| 468 |
return -1; |
| 469 |
} |
| 470 |
|
| 471 |
/* */ |
| 472 |
/* Simple pass off without charstring decrypting */ |
| 473 |
/* */ |
| 474 |
|
| 475 |
static int |
| 476 |
PassString(unsigned char flg) |
| 477 |
{ |
| 478 |
int len_str; |
| 479 |
|
| 480 |
len_str=GetNum(); |
| 481 |
if(len_str<0) |
| 482 |
{ |
| 483 |
return ERR_SECOND_NUM; |
| 484 |
} |
| 485 |
|
| 486 |
if(PassToken()<0) |
| 487 |
return ERR_FIRST_TOK; |
| 488 |
|
| 489 |
|
| 490 |
if(flg==1) |
| 491 |
{ |
| 492 |
label[number].length = len_str; |
| 493 |
label[number].skip = temp - label[number].begin; |
| 494 |
} |
| 495 |
|
| 496 |
temp= temp+1+len_str; |
| 497 |
|
| 498 |
if(PassToken()<0) |
| 499 |
return ERR_SECOND_TOK; |
| 500 |
return 1; |
| 501 |
} |
| 502 |
|
| 503 |
void * |
| 504 |
getmem(unsigned size) |
| 505 |
{ |
| 506 |
void *tmp; |
| 507 |
if ((tmp = calloc(1, size)) == NULL) |
| 508 |
{ |
| 509 |
#ifndef XDVIPSK |
| 510 |
fprintf(stderr,"Error allocating memory\n"); |
| 511 |
exit(1); |
| 512 |
#else |
| 513 |
error("! Error allocating memory"); |
| 514 |
dvips_exit(1); |
| 515 |
#endif /* XDVIPSK */ |
| 516 |
} |
| 517 |
return tmp; |
| 518 |
} |
| 519 |
|
| 520 |
static CHAR * |
| 521 |
AddChar(CHAR *TmpChar, unsigned char *CharName, int num) |
| 522 |
{ |
| 523 |
int length; |
| 524 |
|
| 525 |
CHAR *ThisChar = (CHAR*) getmem(sizeof(CHAR)); |
| 526 |
length = strlen((char *) CharName); |
| 527 |
ThisChar->name = (unsigned char *) getmem(length+1); |
| 528 |
strcpy((char *) ThisChar->name, (char *) CharName); |
| 529 |
ThisChar->length= length; |
| 530 |
ThisChar->num=num; |
| 531 |
ThisChar->NextChar = TmpChar; |
| 532 |
TmpChar = ThisChar; |
| 533 |
return TmpChar; |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
static void |
| 538 |
AddStr(unsigned char *name, int num) |
| 539 |
{ |
| 540 |
int length; |
| 541 |
|
| 542 |
STRING *ThisStr = (STRING *) getmem(sizeof(STRING)); |
| 543 |
length = strlen((char *) name); |
| 544 |
ThisStr->name = (unsigned char *) getmem(length+1); |
| 545 |
strcpy((char *) ThisStr->name, (char *) name); |
| 546 |
ThisStr->num=num; |
| 547 |
|
| 548 |
ThisStr->NextStr = FirstStr; |
| 549 |
FirstStr = ThisStr; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
/* We prepare own encoding vector for output */ |
| 554 |
|
| 555 |
static void |
| 556 |
RevChar(CHAR *TmpChar) |
| 557 |
{ |
| 558 |
int i; |
| 559 |
CHAR *ThisChar = TmpChar; |
| 560 |
|
| 561 |
while (ThisChar != NULL) |
| 562 |
{ |
| 563 |
for(i=keyword[char_str].offset-1; i < number; i++) |
| 564 |
{ |
| 565 |
if(ThisChar->num == label[i].num) |
| 566 |
{ |
| 567 |
if (label[i].select==FLG_BINARY) |
| 568 |
{ |
| 569 |
CHAR *Rev_Char = (CHAR *) getmem(sizeof(CHAR)); |
| 570 |
Rev_Char->name = ThisChar->name; |
| 571 |
Rev_Char->num = ThisChar->num; |
| 572 |
|
| 573 |
Rev_Char->NextChar = FirstCharW; |
| 574 |
FirstCharW = Rev_Char; |
| 575 |
break; |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
ThisChar = ThisChar->NextChar; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
/* And here we produce own resulting encoding vector for partial font */ |
| 584 |
|
| 585 |
static void |
| 586 |
OutChar(CHAR *TmpChar, FILE *fout) |
| 587 |
{ |
| 588 |
|
| 589 |
CHAR *ThisChar = TmpChar; |
| 590 |
|
| 591 |
while (ThisChar != NULL) |
| 592 |
{ |
| 593 |
CHAR *tm = ThisChar; |
| 594 |
if (ThisChar->num >= 0) |
| 595 |
#ifdef SHIFTLOWCHARS |
| 596 |
fprintf(fout, "dup %d %s put\n",T1Char(ThisChar->num),ThisChar->name); |
| 597 |
#else |
| 598 |
fprintf(fout, "dup %d %s put\n",ThisChar->num,ThisChar->name); |
| 599 |
#endif |
| 600 |
ThisChar = ThisChar->NextChar; |
| 601 |
free(tm); |
| 602 |
} |
| 603 |
|
| 604 |
FirstCharW = NULL; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
/* We prepare strings list for output */ |
| 611 |
|
| 612 |
static void |
| 613 |
Reeverse(STRING *TmpStr) |
| 614 |
{ |
| 615 |
|
| 616 |
int tmp; |
| 617 |
|
| 618 |
if(encode==AFM_ENC) |
| 619 |
tmp = -2; |
| 620 |
else |
| 621 |
tmp=0; |
| 622 |
|
| 623 |
|
| 624 |
while (TmpStr != NULL) |
| 625 |
{ |
| 626 |
|
| 627 |
if(TmpStr->num < tmp) |
| 628 |
{ |
| 629 |
STRING *ThisStr = (STRING *) getmem(sizeof(STRING)); |
| 630 |
ThisStr->name = TmpStr->name; |
| 631 |
|
| 632 |
ThisStr->NextStr = RevStr; |
| 633 |
RevStr = ThisStr; |
| 634 |
} |
| 635 |
TmpStr = TmpStr->NextStr; |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
/* And here we post strings to out */ |
| 641 |
|
| 642 |
static void |
| 643 |
OutStr(STRING *TmpStr, FILE *fout) |
| 644 |
{ |
| 645 |
STRING *ThisStr = TmpStr; |
| 646 |
if(encode==AFM_ENC) |
| 647 |
fprintf(fout, "readonly def\n"); |
| 648 |
while (ThisStr != NULL) |
| 649 |
{ |
| 650 |
STRING *tm = ThisStr; |
| 651 |
fprintf(fout, "%s",ThisStr->name); |
| 652 |
ThisStr = ThisStr->NextStr; |
| 653 |
free(tm); |
| 654 |
} |
| 655 |
RevStr = NULL; |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
static void |
| 664 |
PrintChar(CHAR *TmpChar) |
| 665 |
{ |
| 666 |
CHAR *ThisChar = TmpChar; |
| 667 |
while (ThisChar != NULL) |
| 668 |
{ |
| 669 |
if(ThisChar->choose==1) |
| 670 |
{ |
| 671 |
fprintf_str(stderr, " Debug: Char %d '%s'\n", |
| 672 |
ThisChar->num,ThisChar->name); |
| 673 |
} |
| 674 |
ThisChar = ThisChar->NextChar; |
| 675 |
} |
| 676 |
|
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
static int |
| 681 |
ClearB(void) |
| 682 |
{ |
| 683 |
CHAR *ThisChar = FirstCharB; |
| 684 |
while (ThisChar != NULL) |
| 685 |
{ |
| 686 |
ThisChar->choose=0; |
| 687 |
ThisChar = ThisChar->NextChar; |
| 688 |
} |
| 689 |
return 1; |
| 690 |
} |
| 691 |
|
| 692 |
/* We mark chars in encoding vector thanks same names from |
| 693 |
reencoding vector */ |
| 694 |
|
| 695 |
static int |
| 696 |
ChooseChar(unsigned char *name, CHAR *TmpChar) |
| 697 |
{ |
| 698 |
int length; |
| 699 |
CHAR *ThisChar = TmpChar; |
| 700 |
length=strlen((char *) name); |
| 701 |
while (ThisChar != NULL) |
| 702 |
{ |
| 703 |
CHAR *NextChar = ThisChar->NextChar; |
| 704 |
if(ThisChar->length==length) |
| 705 |
{ |
| 706 |
if (strcmp((char *) name, (char *) ThisChar->name) == 0) |
| 707 |
{ |
| 708 |
ThisChar->choose=1; |
| 709 |
return 1; |
| 710 |
} |
| 711 |
} |
| 712 |
/* |
| 713 |
* If we couldn't find it, NextChar is NULL here. We fake up an entry |
| 714 |
* (assuming it really does exist in the font). Fix is from Melissa |
| 715 |
* O'Neill; bugs in application of fix due to me. |
| 716 |
*/ |
| 717 |
if (NextChar == 0) { |
| 718 |
NextChar = (CHAR *) getmem(sizeof(CHAR)); |
| 719 |
NextChar->name = (unsigned char *) getmem(length + 1); |
| 720 |
strcpy((char *) NextChar->name, (char *) name); |
| 721 |
NextChar->length = length; |
| 722 |
NextChar->num = -1; |
| 723 |
NextChar->NextChar = 0; |
| 724 |
NextChar->choose = 1; |
| 725 |
ThisChar->NextChar = NextChar; |
| 726 |
} |
| 727 |
ThisChar = NextChar; |
| 728 |
} |
| 729 |
/* |
| 730 |
* Can't ever get here. |
| 731 |
*/ |
| 732 |
return -1; |
| 733 |
} |
| 734 |
|
| 735 |
/* We find index in label array for char, wich is required |
| 736 |
for compose char, if it uses SEAC command */ |
| 737 |
|
| 738 |
static int |
| 739 |
FindSeac(int num) |
| 740 |
{ |
| 741 |
int i; |
| 742 |
|
| 743 |
for(i=keyword[char_str].offset-1; i < number; i++) |
| 744 |
{ |
| 745 |
if(label[i].num==num) |
| 746 |
{ |
| 747 |
return i; |
| 748 |
} |
| 749 |
} |
| 750 |
return -1; |
| 751 |
} |
| 752 |
|
| 753 |
|
| 754 |
static void ClearCW(CHAR *); |
| 755 |
|
| 756 |
static int |
| 757 |
FindCharW(unsigned char *name, int length) |
| 758 |
{ |
| 759 |
CHAR *ThisChar = FirstCharW; |
| 760 |
|
| 761 |
int find = 0; |
| 762 |
int keep_char = 0; |
| 763 |
int tmp = 0; |
| 764 |
int tmp_num = 0; |
| 765 |
|
| 766 |
int ddd = 0; |
| 767 |
|
| 768 |
#ifdef DEBUG |
| 769 |
if(dd(D_VIEW_VECTOR)) |
| 770 |
{ |
| 771 |
ddd = 1; |
| 772 |
} |
| 773 |
#endif |
| 774 |
|
| 775 |
while (ThisChar != NULL) |
| 776 |
{ |
| 777 |
/* since ClearCW may free ThisChar, follow the pointer now. */ |
| 778 |
CHAR *NextChar = ThisChar->NextChar; |
| 779 |
|
| 780 |
if(ThisChar->length==length) |
| 781 |
{ |
| 782 |
if (strcmp((char *) name, (char *) ThisChar->name) == 0) |
| 783 |
{ |
| 784 |
if(ThisChar->choose==1) |
| 785 |
{ |
| 786 |
if(find !=2) |
| 787 |
{ |
| 788 |
find = 2; |
| 789 |
tmp=FLG_BINARY; |
| 790 |
label[number].num=ThisChar->num; |
| 791 |
} |
| 792 |
} |
| 793 |
else |
| 794 |
{ |
| 795 |
keep_char = 0; |
| 796 |
if(find != 2) |
| 797 |
{ |
| 798 |
find = 1; |
| 799 |
tmp_num = ThisChar->num; |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
if(keep_char == 0) |
| 805 |
{ |
| 806 |
ClearCW(ThisChar); |
| 807 |
} |
| 808 |
|
| 809 |
if((find == 2)&&(ddd == 1)) |
| 810 |
keep_char = 1; |
| 811 |
} |
| 812 |
} |
| 813 |
ThisChar = NextChar; |
| 814 |
} |
| 815 |
|
| 816 |
if(find == 1) |
| 817 |
{ |
| 818 |
tmp=NOTHING; |
| 819 |
label[number].num=tmp_num; |
| 820 |
} |
| 821 |
return tmp; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
static void |
| 826 |
ClearCW(CHAR *ThisChar) |
| 827 |
{ |
| 828 |
|
| 829 |
if (ThisChar == FirstCharW) |
| 830 |
FirstCharW = ThisChar->NextChar; |
| 831 |
else |
| 832 |
{ |
| 833 |
CHAR *tm = FirstCharW; |
| 834 |
while (tm != NULL) |
| 835 |
{ |
| 836 |
if (ThisChar == tm->NextChar) |
| 837 |
{ |
| 838 |
tm->NextChar = ThisChar->NextChar; |
| 839 |
break; |
| 840 |
} |
| 841 |
tm = tm->NextChar; |
| 842 |
} |
| 843 |
} |
| 844 |
free(ThisChar); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
/* We build temporary 'work' encoding vector only for searching |
| 849 |
needed chars */ |
| 850 |
|
| 851 |
static int |
| 852 |
WorkVect(CHAR *TmpChar) |
| 853 |
{ |
| 854 |
while (TmpChar != NULL) { |
| 855 |
{ |
| 856 |
CHAR *ThisChar = (CHAR *) getmem(sizeof(CHAR)); |
| 857 |
ThisChar->name = TmpChar->name; |
| 858 |
ThisChar->length = TmpChar->length; |
| 859 |
ThisChar->num = TmpChar->num; |
| 860 |
ThisChar->choose = TmpChar->choose; |
| 861 |
|
| 862 |
ThisChar->NextChar = FirstCharW; |
| 863 |
FirstCharW = ThisChar; |
| 864 |
} |
| 865 |
TmpChar = TmpChar->NextChar; |
| 866 |
} |
| 867 |
return 0; |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
static void |
| 872 |
UnDefineCharsW(void) |
| 873 |
{ |
| 874 |
CHAR *ThisChar = FirstCharW; |
| 875 |
while (ThisChar != NULL) |
| 876 |
{ |
| 877 |
CHAR *tm = ThisChar; |
| 878 |
ThisChar = ThisChar->NextChar; |
| 879 |
free(tm); |
| 880 |
} |
| 881 |
FirstCharW = NULL; |
| 882 |
CharCount = 0; |
| 883 |
} |
| 884 |
|
| 885 |
CHAR * |
| 886 |
UnDefineChars(CHAR *TmpChar) |
| 887 |
{ |
| 888 |
CHAR *ThisChar = TmpChar; |
| 889 |
while (ThisChar != NULL) |
| 890 |
{ |
| 891 |
CHAR *tm = ThisChar; |
| 892 |
free(ThisChar->name); |
| 893 |
ThisChar = ThisChar->NextChar; |
| 894 |
free(tm); |
| 895 |
} |
| 896 |
TmpChar = NULL; |
| 897 |
CharCount = 0; |
| 898 |
return TmpChar; |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
static void |
| 904 |
UnDefineStr(void) |
| 905 |
{ |
| 906 |
STRING *ThisStr = FirstStr; |
| 907 |
while (ThisStr != NULL) |
| 908 |
{ |
| 909 |
STRING *tm = ThisStr; |
| 910 |
free(ThisStr->name); |
| 911 |
ThisStr = ThisStr->NextStr; |
| 912 |
free(tm); |
| 913 |
} |
| 914 |
FirstStr = NULL; |
| 915 |
} |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
/* */ |
| 920 |
/* We mark subroutines without charstring decrypting */ |
| 921 |
/* */ |
| 922 |
|
| 923 |
static void |
| 924 |
ScanSubrs(int i) |
| 925 |
{ |
| 926 |
#ifdef XDVIPSK |
| 927 |
char *buf, err_buf[1024]; |
| 928 |
#endif /* XDVIPSK */ |
| 929 |
int err_num; |
| 930 |
int word_type = 0; |
| 931 |
int len_dup; |
| 932 |
int num_err=0; |
| 933 |
int test=0; |
| 934 |
|
| 935 |
len_dup = strlen(Dup); |
| 936 |
|
| 937 |
for(; number < keyword[i].oldnum + keyword[i].offset;) |
| 938 |
{ |
| 939 |
if((word_type=GetToken())>0) |
| 940 |
{ |
| 941 |
if(word_type==2) |
| 942 |
{ |
| 943 |
if(!strcmp((char *) token,Dup)) |
| 944 |
{ |
| 945 |
if(test==0) |
| 946 |
test=1; |
| 947 |
label[number].begin = temp-len_dup; |
| 948 |
|
| 949 |
err_num=GetNum(); |
| 950 |
if(err_num<0) |
| 951 |
; |
| 952 |
else |
| 953 |
{ |
| 954 |
if(err_num<4) |
| 955 |
{ |
| 956 |
label[number].select=FLG_BINARY; |
| 957 |
keyword[i].newnum++; |
| 958 |
|
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
label[number].num=err_num; |
| 963 |
|
| 964 |
num_err=PassString(1); |
| 965 |
|
| 966 |
if(num_err<0) |
| 967 |
{ |
| 968 |
#ifndef XDVIPSK |
| 969 |
ErrorOfScan(num_err); |
| 970 |
fprintf(stderr,"in %d Subr string", number - 1); |
| 971 |
exit(1); |
| 972 |
#else |
| 973 |
ErrorOfScan(num_err, &buf); |
| 974 |
sprintf(err_buf, "! %sin %d Subr string", buf, number - 1); |
| 975 |
free(buf); |
| 976 |
error(err_buf); |
| 977 |
dvips_exit(1); |
| 978 |
#endif /* XDVIPSK */ |
| 979 |
} |
| 980 |
if(test>1) |
| 981 |
PassToken(); |
| 982 |
|
| 983 |
number++; |
| 984 |
} |
| 985 |
else |
| 986 |
{ |
| 987 |
if(test>=1) |
| 988 |
test++; |
| 989 |
} |
| 990 |
} |
| 991 |
} |
| 992 |
else |
| 993 |
{ |
| 994 |
#ifndef XDVIPSK |
| 995 |
ErrorOfScan(0); |
| 996 |
fprintf(stderr, |
| 997 |
"Token 'def' not found in %d Subr string ", number - 1); |
| 998 |
exit(1); |
| 999 |
#else |
| 1000 |
ErrorOfScan(0, &buf); |
| 1001 |
sprintf(err_buf, |
| 1002 |
"! %sToken 'def' not found in %d Subr string ", buf, number - 1); |
| 1003 |
free(buf); |
| 1004 |
error(err_buf); |
| 1005 |
dvips_exit(1); |
| 1006 |
#endif /* XDVIPSK */ |
| 1007 |
} |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
static void |
| 1012 |
ViewReturnCall(int num_err, int top, int *pstack, |
| 1013 |
int j, int depth) |
| 1014 |
{ |
| 1015 |
int k,m; |
| 1016 |
#ifdef XDVIPSK |
| 1017 |
char *buf, err_buf[1024]; |
| 1018 |
int x; |
| 1019 |
#endif /* XDVIPSK */ |
| 1020 |
|
| 1021 |
#ifdef DEBUG |
| 1022 |
if((dd(D_CALL_SUBR))&&(num_err>0)) |
| 1023 |
{ |
| 1024 |
if(grow==1) |
| 1025 |
{ |
| 1026 |
grow=0; |
| 1027 |
fprintf(stderr, "\n Top: "); |
| 1028 |
} |
| 1029 |
else |
| 1030 |
fprintf(stderr, " Back: "); |
| 1031 |
} |
| 1032 |
|
| 1033 |
#endif |
| 1034 |
|
| 1035 |
#ifdef XDVIPSK |
| 1036 |
x = 0; |
| 1037 |
#endif /* XDVIPSK */ |
| 1038 |
if(num_err<0) |
| 1039 |
{ |
| 1040 |
if(grow==1) |
| 1041 |
{ |
| 1042 |
grow=0; |
| 1043 |
fprintf(stderr, "\n ERROR: "); |
| 1044 |
#ifndef XDVIPSK |
| 1045 |
ErrorOfScan(num_err); |
| 1046 |
#else |
| 1047 |
ErrorOfScan(num_err, &buf); |
| 1048 |
x = 1; |
| 1049 |
#endif /* XDVIPSK */ |
| 1050 |
} |
| 1051 |
else |
| 1052 |
fprintf(stderr, " Back: "); |
| 1053 |
} |
| 1054 |
|
| 1055 |
#ifndef XDVIPSK |
| 1056 |
fprintf(stderr, " %d Subr \n", top); |
| 1057 |
#else |
| 1058 |
if (x) { |
| 1059 |
sprintf(err_buf, "! %s %d Subr", buf, top); |
| 1060 |
free(buf); |
| 1061 |
error(err_buf); |
| 1062 |
} |
| 1063 |
else |
| 1064 |
fprintf(stderr, " %d Subr \n", top); |
| 1065 |
#endif /* XDVIPSK */ |
| 1066 |
|
| 1067 |
fprintf(stderr," %dth level> STACK: ", level); |
| 1068 |
|
| 1069 |
for(m=0; m < j; m++, pstack++) |
| 1070 |
{ |
| 1071 |
if(depth>(j-(m+1))) |
| 1072 |
{ |
| 1073 |
for(k=0; |
| 1074 |
TableCommand[k].command; |
| 1075 |
k++) |
| 1076 |
{ |
| 1077 |
if(TableCommand[k].code==*pstack) |
| 1078 |
{ |
| 1079 |
fprintf_str(stderr," %s", |
| 1080 |
TableCommand[k].command); |
| 1081 |
k=0; |
| 1082 |
break; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
if(k!=0) |
| 1086 |
fprintf(stderr," (%d)", *pstack); |
| 1087 |
} |
| 1088 |
else |
| 1089 |
fprintf(stderr, " %d", *pstack); |
| 1090 |
} |
| 1091 |
fprintf(stderr, " \n"); |
| 1092 |
} |
| 1093 |
|
| 1094 |
/* */ |
| 1095 |
/* We decrypt charstring with recursive descent */ |
| 1096 |
/* */ |
| 1097 |
|
| 1098 |
static int |
| 1099 |
DeCodeStr(int num, int numseac) |
| 1100 |
{ |
| 1101 |
#ifdef XDVIPSK |
| 1102 |
char err_buf[1024]; |
| 1103 |
#endif /* XDVIPSK */ |
| 1104 |
unsigned int loccr; |
| 1105 |
unsigned char byte; |
| 1106 |
static int j; |
| 1107 |
int i; |
| 1108 |
unsigned char jj,k; |
| 1109 |
int tmpnum; |
| 1110 |
int depth = 0; |
| 1111 |
int num_err = 0; |
| 1112 |
int len_str; |
| 1113 |
typetemp BORLAND_HUGE *loc; |
| 1114 |
typetemp BORLAND_HUGE *end_str; |
| 1115 |
int pstack[64]; |
| 1116 |
int last_subr; |
| 1117 |
|
| 1118 |
if(num > CHAR_STR) |
| 1119 |
{ |
| 1120 |
last_subr=keyword[subrs].offset+keyword[subrs].oldnum; |
| 1121 |
|
| 1122 |
for(tmpnum=keyword[subrs].offset; tmpnum<last_subr; tmpnum++) |
| 1123 |
{ |
| 1124 |
if(label[tmpnum].num==num) |
| 1125 |
break; |
| 1126 |
} |
| 1127 |
|
| 1128 |
if(tmpnum==last_subr) |
| 1129 |
{ |
| 1130 |
#ifndef XDVIPSK |
| 1131 |
fprintf(stderr, " Error: %d Subr not found \n", num); |
| 1132 |
exit(1); |
| 1133 |
#else |
| 1134 |
sprintf(err_buf, "! %d Subr not found", num); |
| 1135 |
error(err_buf); |
| 1136 |
dvips_exit(1); |
| 1137 |
#endif /* XDVIPSK */ |
| 1138 |
} |
| 1139 |
if(label[tmpnum].select==FLG_BINARY) |
| 1140 |
{ |
| 1141 |
if(j==0) |
| 1142 |
return 1; |
| 1143 |
} |
| 1144 |
else |
| 1145 |
{ |
| 1146 |
label[tmpnum].select=FLG_BINARY; |
| 1147 |
if(num+1 > keyword[subrs].newnum ) /* max num of subr */ |
| 1148 |
keyword[subrs].newnum = num+1; |
| 1149 |
} |
| 1150 |
loc = label[tmpnum].begin + label[tmpnum].skip; |
| 1151 |
len_str=label[tmpnum].length; |
| 1152 |
} |
| 1153 |
else |
| 1154 |
{ |
| 1155 |
j=0; |
| 1156 |
|
| 1157 |
if(num == CHAR_SEAC) |
| 1158 |
{ |
| 1159 |
if(label[numseac].select!=FLG_BINARY) |
| 1160 |
{ |
| 1161 |
label[numseac].select=FLG_BINARY; |
| 1162 |
keyword[char_str].newnum++; |
| 1163 |
temp = label[numseac].begin; |
| 1164 |
} |
| 1165 |
else return 1; |
| 1166 |
} |
| 1167 |
len_str=GetNum(); |
| 1168 |
|
| 1169 |
if(len_str < 0) |
| 1170 |
{ |
| 1171 |
return ERR_SECOND_NUM; |
| 1172 |
} |
| 1173 |
num_err = PassToken(); |
| 1174 |
if(num_err < 0) |
| 1175 |
{ |
| 1176 |
return ERR_FIRST_TOK; |
| 1177 |
} |
| 1178 |
loc=temp; |
| 1179 |
} |
| 1180 |
loc++; |
| 1181 |
|
| 1182 |
end_str=loc+len_str; |
| 1183 |
|
| 1184 |
loccr = CDR; |
| 1185 |
|
| 1186 |
for (i = 0; i < lenIV; i++,loc++) |
| 1187 |
{ |
| 1188 |
byte = CDeCrypt(*loc, &loccr); |
| 1189 |
} |
| 1190 |
for (; loc < end_str;) |
| 1191 |
{ |
| 1192 |
byte = CDeCrypt(*loc++, &loccr); |
| 1193 |
if (byte == RETURN) |
| 1194 |
{ |
| 1195 |
j=0; |
| 1196 |
break; |
| 1197 |
} |
| 1198 |
else if (byte == ESCAPE) |
| 1199 |
{ |
| 1200 |
byte = CDeCrypt(*loc++, &loccr); |
| 1201 |
#ifndef XDVIPSK |
| 1202 |
if (byte > MAX_ESCAPE) |
| 1203 |
fprintf_str(stderr, |
| 1204 |
"Error: not_defined_e%d in %s", byte, psfontfile); |
| 1205 |
#else |
| 1206 |
if (byte > MAX_ESCAPE) { |
| 1207 |
sprintf(err_buf, |
| 1208 |
"! not_defined_e%d in %s", byte, psfontfile); |
| 1209 |
error(errbuf); |
| 1210 |
} |
| 1211 |
#endif /* XDVIPSK */ |
| 1212 |
else |
| 1213 |
{ |
| 1214 |
switch(byte) |
| 1215 |
{ |
| 1216 |
case DOTSECTION : j=0; break; |
| 1217 |
case VSTEM3 : j=0; break; |
| 1218 |
case HSTEM3 : j=0; break; |
| 1219 |
case SEAC : |
| 1220 |
stack[j++]=byte; |
| 1221 |
grow=1; |
| 1222 |
level++; |
| 1223 |
jj=j; |
| 1224 |
for(k=0;k<jj;k++) |
| 1225 |
pstack[k]=stack[k]; |
| 1226 |
num_err=FindSeac(pstack[jj-3]); |
| 1227 |
if(num_err<0) |
| 1228 |
{ |
| 1229 |
flg_seac=1; |
| 1230 |
CharCount++; |
| 1231 |
keyword[char_str].newnum--; |
| 1232 |
if(flg_seac > -3) |
| 1233 |
label[number].select=SEAC_NOT_END; |
| 1234 |
grow=0; |
| 1235 |
level=0; |
| 1236 |
j=0; |
| 1237 |
break; |
| 1238 |
} |
| 1239 |
|
| 1240 |
num_err=DeCodeStr(CHAR_SEAC, num_err); |
| 1241 |
level--; |
| 1242 |
|
| 1243 |
#ifdef DEBUG |
| 1244 |
if((num_err<0)||(dd(D_CALL_SUBR))) |
| 1245 |
#else |
| 1246 |
if(num_err<0) |
| 1247 |
#endif |
| 1248 |
ViewReturnCall |
| 1249 |
(num_err, pstack[jj-3],pstack,jj,1); |
| 1250 |
grow=1; |
| 1251 |
level++; |
| 1252 |
num_err=FindSeac(pstack[jj-2]); |
| 1253 |
if(num_err<0) |
| 1254 |
{ |
| 1255 |
flg_seac=1; |
| 1256 |
CharCount++; |
| 1257 |
keyword[char_str].newnum--; |
| 1258 |
keyword[char_str].newnum--; |
| 1259 |
if(flg_seac > -3) |
| 1260 |
label[number].select=SEAC_NOT_END; |
| 1261 |
grow=0; |
| 1262 |
level=0; |
| 1263 |
j=0; |
| 1264 |
break; |
| 1265 |
} |
| 1266 |
num_err=DeCodeStr(CHAR_SEAC, num_err); |
| 1267 |
level--; |
| 1268 |
#ifdef DEBUG |
| 1269 |
if((num_err<0)||(dd(D_CALL_SUBR))) |
| 1270 |
#else |
| 1271 |
if(num_err<0) |
| 1272 |
#endif |
| 1273 |
|
| 1274 |
ViewReturnCall |
| 1275 |
(num_err, pstack[jj-2],pstack,jj,1); |
| 1276 |
|
| 1277 |
if(num_err<0) |
| 1278 |
return ERR_STACK; |
| 1279 |
j=0; break; |
| 1280 |
case SBW : j=0; break; |
| 1281 |
case CHARS_DIV : j=0; break; |
| 1282 |
case CALLOTHERSUBR : stack[j++]=byte; |
| 1283 |
depth=depth+2; |
| 1284 |
break; |
| 1285 |
case POP : stack[j++]=byte; |
| 1286 |
depth=depth+2; |
| 1287 |
break; |
| 1288 |
case SETCURRENTPOINT : j=0; break; |
| 1289 |
} |
| 1290 |
} |
| 1291 |
continue; |
| 1292 |
} |
| 1293 |
else if (byte < 32) |
| 1294 |
{ |
| 1295 |
switch(byte) |
| 1296 |
{ |
| 1297 |
case HSTEM : j=0; break; |
| 1298 |
case VSTEM : j=0; break; |
| 1299 |
case VMOVETO : j=0; break; |
| 1300 |
case CHARS_RLINETO : j=0; break; |
| 1301 |
case HLINETO : j=0; break; |
| 1302 |
case VLINETO : j=0; break; |
| 1303 |
case RRCURVETO : j=0; break; |
| 1304 |
case CHARS_CLOSEPATH : j=0; break; |
| 1305 |
case CALLSUBR : stack[j++]=byte; |
| 1306 |
depth=depth+2; |
| 1307 |
level++; |
| 1308 |
grow=1; |
| 1309 |
jj=j; |
| 1310 |
j=j-depth; |
| 1311 |
for(k=0;k<jj;k++) |
| 1312 |
pstack[k]=stack[k]; |
| 1313 |
|
| 1314 |
num_err = DeCodeStr(stack[j],0); |
| 1315 |
|
| 1316 |
level--; |
| 1317 |
#ifdef DEBUG |
| 1318 |
if((num_err<0)||(dd(D_CALL_SUBR))) |
| 1319 |
#else |
| 1320 |
if(num_err<0) |
| 1321 |
#endif |
| 1322 |
ViewReturnCall |
| 1323 |
(num_err, pstack[jj-depth], pstack,jj,depth/2); |
| 1324 |
|
| 1325 |
if(num_err<0) |
| 1326 |
return ERR_STACK; |
| 1327 |
else |
| 1328 |
{ |
| 1329 |
depth=0; |
| 1330 |
break; |
| 1331 |
} |
| 1332 |
case RETURN : j=0; break; |
| 1333 |
case ESCAPE : break; |
| 1334 |
case HSBW : j=0; break; |
| 1335 |
case ENDCHAR : j=0; break; |
| 1336 |
case CHARS_RMOVETO : j=0; break; |
| 1337 |
case HMOVETO : j=0; break; |
| 1338 |
case VHCURVETO : j=0; break; |
| 1339 |
case HVCURVETO : j=0; break; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
if (byte >= 32) |
| 1343 |
{ |
| 1344 |
if (byte <= 246) |
| 1345 |
{ |
| 1346 |
value= byte - 139; |
| 1347 |
stack[j++]=value; |
| 1348 |
} |
| 1349 |
else if ((byte >= 247) && (byte <= 250)) |
| 1350 |
{ |
| 1351 |
value= (byte - 247) * 256 + CDeCrypt(*loc++, &loccr) + 108; |
| 1352 |
stack[j++]=value; |
| 1353 |
} |
| 1354 |
else if ((byte >= 251) && (byte <= 254)) |
| 1355 |
{ |
| 1356 |
value= -(byte - 251) * 256 - CDeCrypt(*loc++, &loccr) - 108; |
| 1357 |
stack[j++]=value; |
| 1358 |
} |
| 1359 |
else if (byte == 255) |
| 1360 |
{ |
| 1361 |
value = CDeCrypt(*loc++, &loccr); |
| 1362 |
value <<= 8; |
| 1363 |
value += CDeCrypt(*loc++, &loccr); |
| 1364 |
value <<= 8; |
| 1365 |
value += CDeCrypt(*loc++, &loccr); |
| 1366 |
value <<= 8; |
| 1367 |
value += CDeCrypt(*loc++, &loccr); |
| 1368 |
stack[j++]=value; |
| 1369 |
} |
| 1370 |
} |
| 1371 |
} |
| 1372 |
if(num == CHAR_STR) |
| 1373 |
{ |
| 1374 |
temp=loc; |
| 1375 |
num_err = PassToken(); |
| 1376 |
if(num_err<0) |
| 1377 |
{ |
| 1378 |
return ERR_SECOND_TOK; |
| 1379 |
} |
| 1380 |
} |
| 1381 |
return 1; |
| 1382 |
} |
| 1383 |
|
| 1384 |
/* */ |
| 1385 |
/* We mark only necessary charstring */ |
| 1386 |
/* */ |
| 1387 |
|
| 1388 |
|
| 1389 |
static void |
| 1390 |
ScanChars(int i) |
| 1391 |
{ |
| 1392 |
|
| 1393 |
#ifdef XDVIPSK |
| 1394 |
char *buf, err_buf[1024]; |
| 1395 |
#endif /* XDVIPSK */ |
| 1396 |
int word_type=0; |
| 1397 |
int found; |
| 1398 |
int str_len; |
| 1399 |
int max_num; |
| 1400 |
int counter; |
| 1401 |
int num_err = 0; |
| 1402 |
typetemp BORLAND_HUGE *tmptemp; |
| 1403 |
|
| 1404 |
|
| 1405 |
CharCount++; |
| 1406 |
counter=number; |
| 1407 |
max_num = keyword[i].offset+keyword[i].oldnum; |
| 1408 |
|
| 1409 |
while( number < max_num ) |
| 1410 |
{ |
| 1411 |
if((word_type=GetToken())>0) |
| 1412 |
{ |
| 1413 |
if(word_type>=3) |
| 1414 |
{ |
| 1415 |
strcpy((char *) tmp_token, (char *) token); |
| 1416 |
str_len = strlen((char *) token); |
| 1417 |
|
| 1418 |
|
| 1419 |
if(CharCount!=0) |
| 1420 |
{ |
| 1421 |
|
| 1422 |
num_err=FindCharW(token, str_len); |
| 1423 |
|
| 1424 |
if(num_err==FLG_BINARY) |
| 1425 |
{ |
| 1426 |
CharCount--; |
| 1427 |
found=num_err; |
| 1428 |
keyword[i].newnum++; |
| 1429 |
} |
| 1430 |
else |
| 1431 |
{ |
| 1432 |
#ifdef DEBUG |
| 1433 |
|
| 1434 |
if(dd(D_VIEW_VECTOR)&&(num_err==-1)) |
| 1435 |
{ |
| 1436 |
fprintf_str(stderr, |
| 1437 |
" Debug: Char '%s' not used in WorkVector\n", token); |
| 1438 |
|
| 1439 |
} |
| 1440 |
#endif |
| 1441 |
if(word_type>3) |
| 1442 |
{ |
| 1443 |
if(strstr((char *) token, (char *) notdef)!=NULL) |
| 1444 |
{ |
| 1445 |
CharCount--; |
| 1446 |
label[number].num = -2; |
| 1447 |
found=FLG_BINARY; |
| 1448 |
keyword[i].newnum++; |
| 1449 |
} |
| 1450 |
else |
| 1451 |
found=NOTHING; |
| 1452 |
} |
| 1453 |
else |
| 1454 |
found=NOTHING; |
| 1455 |
} |
| 1456 |
} |
| 1457 |
else |
| 1458 |
{ |
| 1459 |
found=NOTHING; |
| 1460 |
} |
| 1461 |
|
| 1462 |
label[number].begin = temp-str_len; |
| 1463 |
label[number].select = found; |
| 1464 |
|
| 1465 |
switch(found) |
| 1466 |
{ |
| 1467 |
case FLG_BINARY: |
| 1468 |
tmptemp=temp; |
| 1469 |
for(subrs=FirstKey; subrs<char_str; subrs++) |
| 1470 |
{ |
| 1471 |
level=0; |
| 1472 |
if(subrs!=FirstKey) |
| 1473 |
{ |
| 1474 |
temp=tmptemp; |
| 1475 |
} |
| 1476 |
|
| 1477 |
num_err=DeCodeStr(CHAR_STR,0); |
| 1478 |
|
| 1479 |
} |
| 1480 |
#ifdef DEBUG |
| 1481 |
if(dd(D_CALL_SUBR)) |
| 1482 |
{ |
| 1483 |
if(num_err>0) |
| 1484 |
fprintf_str(stderr, |
| 1485 |
" Debug for Char '%s'\n", tmp_token); |
| 1486 |
} |
| 1487 |
#endif |
| 1488 |
break; |
| 1489 |
case NOTHING: |
| 1490 |
|
| 1491 |
num_err=PassString(0); |
| 1492 |
break; |
| 1493 |
} |
| 1494 |
|
| 1495 |
if(num_err<0) |
| 1496 |
{ |
| 1497 |
#ifndef XDVIPSK |
| 1498 |
ErrorOfScan(num_err); |
| 1499 |
fprintf_str(stderr,"in Char string of '%s'", tmp_token); |
| 1500 |
exit(1); |
| 1501 |
#else |
| 1502 |
ErrorOfScan(num_err, &buf); |
| 1503 |
sprintf(err_buf, "! %sin Char string of '%s'", buf, tmp_token); |
| 1504 |
free(buf); |
| 1505 |
error(err_buf); |
| 1506 |
dvips_exit(1); |
| 1507 |
#endif /* XDVIPSK */ |
| 1508 |
} |
| 1509 |
number++; |
| 1510 |
} |
| 1511 |
} |
| 1512 |
else |
| 1513 |
{ |
| 1514 |
#ifndef XDVIPSK |
| 1515 |
fprintf_str(stderr, |
| 1516 |
"\n File <%s> ended before all chars have been found.", psfontfile); |
| 1517 |
#else |
| 1518 |
sprintf(err_buf, |
| 1519 |
"! File <%s> ended before all chars have been found.", psfontfile); |
| 1520 |
error(err_buf); |
| 1521 |
#endif /* XDVIPSK */ |
| 1522 |
|
| 1523 |
fprintf(stderr, |
| 1524 |
"\n We scan %d Chars from %d", |
| 1525 |
counter - (2 + keyword[subrs].oldnum), |
| 1526 |
keyword[i].oldnum); |
| 1527 |
|
| 1528 |
if(tmp_token!=NULL) |
| 1529 |
{ |
| 1530 |
fprintf_str(stderr, "\n Last seen token was '%s'\n", tmp_token); |
| 1531 |
} |
| 1532 |
#ifndef XDVIPSK |
| 1533 |
exit(1); |
| 1534 |
#else |
| 1535 |
dvips_exit(1); |
| 1536 |
#endif /* XDVIPSK */ |
| 1537 |
} |
| 1538 |
} |
| 1539 |
|
| 1540 |
if(flg_seac!=0) |
| 1541 |
{ |
| 1542 |
tmptemp=temp; |
| 1543 |
flg_seac--; |
| 1544 |
for(; counter<max_num; counter++) |
| 1545 |
{ |
| 1546 |
if((int) label[counter].select==SEAC_NOT_END) |
| 1547 |
{ |
| 1548 |
for(subrs=FirstKey; subrs<char_str; subrs++) |
| 1549 |
{ |
| 1550 |
level=0; |
| 1551 |
temp=label[counter].begin; |
| 1552 |
num_err=DeCodeStr(CHAR_STR,0); |
| 1553 |
} |
| 1554 |
if(num_err<0) |
| 1555 |
{ |
| 1556 |
#ifndef XDVIPSK |
| 1557 |
fprintf(stderr," Warning: %d char not choose during SEAC\n", |
| 1558 |
label[counter].num); |
| 1559 |
#else |
| 1560 |
sprintf(err_buf, "Warning: %d char not choose during SEAC", |
| 1561 |
label[counter].num); |
| 1562 |
error(err_buf); |
| 1563 |
#endif /* XDVIPSK */ |
| 1564 |
} |
| 1565 |
else |
| 1566 |
{ |
| 1567 |
CharCount--; |
| 1568 |
label[counter].select=FLG_BINARY; |
| 1569 |
if(CharCount==0) |
| 1570 |
break; |
| 1571 |
} |
| 1572 |
} |
| 1573 |
} |
| 1574 |
|
| 1575 |
temp=tmptemp; |
| 1576 |
} |
| 1577 |
|
| 1578 |
if(CharCount!=0) |
| 1579 |
{ |
| 1580 |
#ifndef XDVIPSK |
| 1581 |
fprintf(stderr," WARNING: Not all chars found."); |
| 1582 |
#else |
| 1583 |
sprintf(err_buf, "WARNING: Not all chars found."); |
| 1584 |
error(err_buf); |
| 1585 |
#endif /* XDVIPSK */ |
| 1586 |
PrintChar(FirstCharW); |
| 1587 |
|
| 1588 |
} |
| 1589 |
} |
| 1590 |
|
| 1591 |
static void |
| 1592 |
LastLook(void) |
| 1593 |
{ |
| 1594 |
label[number].begin = temp; |
| 1595 |
label[number].select = FLG_BINARY; |
| 1596 |
number++; |
| 1597 |
} |
| 1598 |
|
| 1599 |
static int |
| 1600 |
FindKeyWord(int First_Key, int lastkey) |
| 1601 |
{ |
| 1602 |
#ifdef XDVIPSK |
| 1603 |
char err_buf[1024]; |
| 1604 |
#endif /* XDVIPSK */ |
| 1605 |
int word_type=0; |
| 1606 |
int i; |
| 1607 |
int tmp_num=0; |
| 1608 |
|
| 1609 |
for(;;) |
| 1610 |
{ |
| 1611 |
if((word_type=GetToken())>0) |
| 1612 |
{ |
| 1613 |
if(word_type==3) |
| 1614 |
{ |
| 1615 |
for(i=First_Key; i<=lastkey; i++) |
| 1616 |
{ |
| 1617 |
if(!strcmp((char *) token, Key[i].name)) |
| 1618 |
{ |
| 1619 |
tmp_num = GetNum(); |
| 1620 |
if(tmp_num<0) |
| 1621 |
{ |
| 1622 |
#ifndef XDVIPSK |
| 1623 |
fprintf_str(stderr, |
| 1624 |
"\n ERROR: Number not found for '%s' in <%s>", |
| 1625 |
Key[i].name, psfontfile); |
| 1626 |
exit(1); |
| 1627 |
#else |
| 1628 |
sprintf(err_buf, |
| 1629 |
"! Number not found for '%s' in <%s>", |
| 1630 |
Key[i].name, psfontfile); |
| 1631 |
error(err_buf); |
| 1632 |
dvips_exit(1); |
| 1633 |
#endif /* XDVIPSK */ |
| 1634 |
} |
| 1635 |
keyword[current].oldnum = tmp_num; |
| 1636 |
keyword[current].length=strlen((char *) token); |
| 1637 |
keyword[current].begin=temp - keyword[current].length; |
| 1638 |
return i; |
| 1639 |
} |
| 1640 |
} |
| 1641 |
} |
| 1642 |
} |
| 1643 |
else |
| 1644 |
{ |
| 1645 |
#ifndef XDVIPSK |
| 1646 |
fprintf_str(stderr, |
| 1647 |
"\n ERROR: In <%s> keyword not found:", psfontfile); |
| 1648 |
#else |
| 1649 |
sprintf(err_buf, |
| 1650 |
"! In <%s> keyword not found:", psfontfile); |
| 1651 |
error(err_buf); |
| 1652 |
#endif /* XDVIPSK */ |
| 1653 |
|
| 1654 |
for(i=First_Key; i<=lastkey; i++) |
| 1655 |
fprintf_str(stderr,"\n %dth > '%s' ",i,Key[i].name); |
| 1656 |
#ifndef XDVIPSK |
| 1657 |
exit(1); |
| 1658 |
#else |
| 1659 |
dvips_exit(1); |
| 1660 |
#endif /* XDVIPSK */ |
| 1661 |
} |
| 1662 |
} |
| 1663 |
} |
| 1664 |
|
| 1665 |
/* To increase scan speed we use dynamic range of keywords */ |
| 1666 |
|
| 1667 |
static int |
| 1668 |
ScanBinary(void) |
| 1669 |
{ |
| 1670 |
int i; |
| 1671 |
int firstnum, lastnum; |
| 1672 |
firstnum= LENIV; |
| 1673 |
lastnum=SUBRS; |
| 1674 |
|
| 1675 |
number=0; |
| 1676 |
label[number].begin = begin_of_scan; |
| 1677 |
temp = label[number].begin; |
| 1678 |
label[number].select = FLG_BINARY; |
| 1679 |
offset= ++number; |
| 1680 |
|
| 1681 |
for (current=0, FirstKey=current;; current++) |
| 1682 |
{ |
| 1683 |
i=FindKeyWord(firstnum,lastnum); |
| 1684 |
switch(i) |
| 1685 |
{ |
| 1686 |
case LENIV: |
| 1687 |
FirstKey++; |
| 1688 |
firstnum=SUBRS; |
| 1689 |
lastnum=SUBRS; |
| 1690 |
lenIV=keyword[current].oldnum; |
| 1691 |
keyword[current].type=Key[0].num; |
| 1692 |
break; |
| 1693 |
case SUBRS: |
| 1694 |
firstnum=SUBRS; |
| 1695 |
lastnum= CHARSTRINGS; |
| 1696 |
keyword[current].offset=number; |
| 1697 |
keyword[current].newnum=0; |
| 1698 |
keyword[current].type=Key[1].num; |
| 1699 |
ScanSubrs(current); |
| 1700 |
LastLook(); |
| 1701 |
break; |
| 1702 |
case CHARSTRINGS: |
| 1703 |
char_str=current; |
| 1704 |
keyword[current].offset=number; |
| 1705 |
keyword[current].newnum=0; |
| 1706 |
keyword[current].type=Key[2].num; |
| 1707 |
ScanChars(current); |
| 1708 |
LastLook(); |
| 1709 |
#ifdef DEBUG |
| 1710 |
if(dd(D_CALL_SUBR)) |
| 1711 |
{ |
| 1712 |
for(i=0;i<=2;i++) |
| 1713 |
{ |
| 1714 |
if(keyword[i].oldnum!=0) |
| 1715 |
fprintf_str(stderr, " Result for <%s>: %s %d (instead %d) \n", |
| 1716 |
psfontfile, Key[keyword[i].type].name,keyword[i].newnum, keyword[i].oldnum); |
| 1717 |
} |
| 1718 |
|
| 1719 |
} |
| 1720 |
#endif |
| 1721 |
return 1; |
| 1722 |
} |
| 1723 |
} |
| 1724 |
} |
| 1725 |
|
| 1726 |
static unsigned char * |
| 1727 |
itoasp(int n, unsigned char *s, int len) |
| 1728 |
{ |
| 1729 |
static int i, j; |
| 1730 |
|
| 1731 |
j++; |
| 1732 |
if(n/10) |
| 1733 |
itoasp(n/10,s,len); |
| 1734 |
else |
| 1735 |
i=0; |
| 1736 |
s[i++]=abs(n)%10+'0'; |
| 1737 |
j--; |
| 1738 |
if(j==0) |
| 1739 |
{ |
| 1740 |
for(; i<len;) |
| 1741 |
s[i++]=' '; |
| 1742 |
s[i]='\0'; |
| 1743 |
return s; |
| 1744 |
} |
| 1745 |
return NULL; |
| 1746 |
} |
| 1747 |
|
| 1748 |
static void |
| 1749 |
SubstNum(void) |
| 1750 |
{ |
| 1751 |
int i, j; |
| 1752 |
|
| 1753 |
for(i=FirstKey;i<=char_str;i++) |
| 1754 |
{ |
| 1755 |
itoasp(keyword[i].newnum,token,keyword[i].length); |
| 1756 |
temp=keyword[i].begin; |
| 1757 |
for(j=0;token[j];++j,++temp) |
| 1758 |
{ |
| 1759 |
*temp=token[j]; |
| 1760 |
} |
| 1761 |
temp=keyword[i].begin; |
| 1762 |
} |
| 1763 |
} |
| 1764 |
|
| 1765 |
static ub4 |
| 1766 |
little4(ub1 *buff) |
| 1767 |
{ |
| 1768 |
return (ub4) buff[0] + |
| 1769 |
((ub4) buff[1] << 8) + |
| 1770 |
((ub4) buff[2] << 16) + |
| 1771 |
((ub4) buff[3] << 24); |
| 1772 |
} |
| 1773 |
|
| 1774 |
unsigned short int c1 = C1, c2 = C2; |
| 1775 |
unsigned short int edr; |
| 1776 |
|
| 1777 |
|
| 1778 |
static unsigned char |
| 1779 |
CDeCrypt(unsigned char cipher, unsigned int *lcdr) |
| 1780 |
{ |
| 1781 |
register unsigned char plain; |
| 1782 |
|
| 1783 |
plain = (cipher ^ (*lcdr >> 8)); |
| 1784 |
*lcdr = (cipher + *lcdr) * c1 + c2; |
| 1785 |
return plain; |
| 1786 |
} |
| 1787 |
|
| 1788 |
unsigned short int eer; |
| 1789 |
|
| 1790 |
/* We find end of own vector with non StandardEncoding, |
| 1791 |
|
| 1792 |
|
| 1793 |
*/ |
| 1794 |
|
| 1795 |
|
| 1796 |
static int |
| 1797 |
EndOfEncoding(int err_num) |
| 1798 |
{ |
| 1799 |
|
| 1800 |
int j; |
| 1801 |
int i = 0; |
| 1802 |
int flg_get_word=0; |
| 1803 |
|
| 1804 |
|
| 1805 |
static const char *RefKey[] = |
| 1806 |
{ |
| 1807 |
"readonly", |
| 1808 |
"getinterval", |
| 1809 |
"exch", |
| 1810 |
"def", |
| 1811 |
"" |
| 1812 |
}; |
| 1813 |
|
| 1814 |
for(;;) |
| 1815 |
{ |
| 1816 |
if(flg_get_word==0) |
| 1817 |
flg_get_word = 1; |
| 1818 |
else |
| 1819 |
{ |
| 1820 |
err_num=GetWord(token); |
| 1821 |
|
| 1822 |
} |
| 1823 |
|
| 1824 |
if(err_num <= 0) |
| 1825 |
return -1; |
| 1826 |
|
| 1827 |
if(err_num==5) |
| 1828 |
refer[ind_ref].num[i++]=atoi((char *) token); |
| 1829 |
else |
| 1830 |
{ |
| 1831 |
for(j=0; *RefKey[j]; j++) |
| 1832 |
{ |
| 1833 |
if(strcmp((char *) token, RefKey[j]) ==0) |
| 1834 |
break; |
| 1835 |
} |
| 1836 |
switch(j) |
| 1837 |
{ |
| 1838 |
case 0: |
| 1839 |
case 3: |
| 1840 |
find_encod=1; |
| 1841 |
keep_num = -2; |
| 1842 |
if(ind_ref!=0) |
| 1843 |
{ |
| 1844 |
CorrectGrid(); |
| 1845 |
} |
| 1846 |
return 1; |
| 1847 |
|
| 1848 |
case 1: |
| 1849 |
break; |
| 1850 |
|
| 1851 |
case 2: |
| 1852 |
if(i==1) |
| 1853 |
{ |
| 1854 |
refer[ind_ref].num[1] = 1; |
| 1855 |
refer[ind_ref].num[2] = refer[ind_ref].num[0]; |
| 1856 |
GetWord(token); |
| 1857 |
refer[ind_ref].num[0]= atoi((char *) token); |
| 1858 |
} |
| 1859 |
i=0; |
| 1860 |
refer[ind_ref].select=1; |
| 1861 |
ind_ref++; |
| 1862 |
break; |
| 1863 |
default: |
| 1864 |
break; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
} |
| 1868 |
|
| 1869 |
} |
| 1870 |
|
| 1871 |
/* We rebuild grid for case |
| 1872 |
"dup dup 161 10 getinterval 0 exch putinterval |
| 1873 |
dup dup 173 23 getinterval 10 exch putinterval |
| 1874 |
dup dup 127 exch 196 get put readonly def" |
| 1875 |
in non StandardEncoding */ |
| 1876 |
|
| 1877 |
|
| 1878 |
static void |
| 1879 |
CorrectGrid(void) |
| 1880 |
{ |
| 1881 |
int i, j, k, imax; |
| 1882 |
|
| 1883 |
|
| 1884 |
for(j=0; j<=ind_ref; j++){ |
| 1885 |
if(refer[j].select==1){ |
| 1886 |
imax= refer[j].num[1] + refer[j].num[2]; |
| 1887 |
|
| 1888 |
for(k=0, i=refer[j].num[2]; i< imax; k++,i++){ |
| 1889 |
if(grid[i]==1){ |
| 1890 |
grid[i]=0; |
| 1891 |
grid[k+refer[j].num[0]]=1; |
| 1892 |
} |
| 1893 |
} |
| 1894 |
} |
| 1895 |
} |
| 1896 |
} |
| 1897 |
/* We build vector for non StandardEncoding */ |
| 1898 |
|
| 1899 |
static int |
| 1900 |
CharEncoding(void) |
| 1901 |
{ |
| 1902 |
int err_token=0; |
| 1903 |
int num=0; |
| 1904 |
int seen = 0; |
| 1905 |
|
| 1906 |
while (1) { |
| 1907 |
err_token=GetWord(token); |
| 1908 |
|
| 1909 |
if(err_token==2) |
| 1910 |
{ |
| 1911 |
if(strcmp((char *) token, Dup) ==0) |
| 1912 |
{ |
| 1913 |
err_token=GetWord(token); |
| 1914 |
if(err_token<0) |
| 1915 |
return ERR_NUM_CHAR; |
| 1916 |
|
| 1917 |
if(err_token!=2) /* define "dup word" */ |
| 1918 |
{ |
| 1919 |
num=atoi((char *) token); |
| 1920 |
|
| 1921 |
err_token=GetWord(token); |
| 1922 |
if(err_token<0) |
| 1923 |
{ |
| 1924 |
return ERR_NAME_CHAR; |
| 1925 |
} |
| 1926 |
FirstChar=AddChar(FirstChar,token, num); |
| 1927 |
keep_num=num; |
| 1928 |
keep_flg=1; |
| 1929 |
seen++; |
| 1930 |
err_token = GetWord(token); |
| 1931 |
} |
| 1932 |
} else { |
| 1933 |
|
| 1934 |
if(keep_flg==1) |
| 1935 |
{ |
| 1936 |
keep_num=FLG_OUT_STR; |
| 1937 |
|
| 1938 |
if(EndOfEncoding(err_token)<0) |
| 1939 |
{ |
| 1940 |
return -1; |
| 1941 |
} |
| 1942 |
} |
| 1943 |
} |
| 1944 |
} else |
| 1945 |
return seen; |
| 1946 |
} |
| 1947 |
} |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
static void |
| 1952 |
FindEncoding(void) |
| 1953 |
{ |
| 1954 |
#ifdef XDVIPSK |
| 1955 |
char *buf, err_buf[1024]; |
| 1956 |
#endif /* XDVIPSK */ |
| 1957 |
int num_err=0; |
| 1958 |
int tmpnum; |
| 1959 |
|
| 1960 |
line=tmpline; |
| 1961 |
|
| 1962 |
if(encode==0) |
| 1963 |
{ |
| 1964 |
|
| 1965 |
while((num_err=GetWord(token))>=0) |
| 1966 |
{ |
| 1967 |
if(num_err==3) |
| 1968 |
{ |
| 1969 |
if (strcmp((char *) token,"/Encoding") == 0) |
| 1970 |
{ |
| 1971 |
|
| 1972 |
tmpnum=GetWord(token); |
| 1973 |
|
| 1974 |
if(tmpnum==5) |
| 1975 |
{ |
| 1976 |
encode=SPECIAL_ENC; |
| 1977 |
} |
| 1978 |
|
| 1979 |
else |
| 1980 |
{ |
| 1981 |
find_encod=1; |
| 1982 |
encode=STANDARD_ENC; |
| 1983 |
} |
| 1984 |
return; |
| 1985 |
} |
| 1986 |
} |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
else |
| 1991 |
{ |
| 1992 |
num_err= CharEncoding(); |
| 1993 |
if(num_err<0) |
| 1994 |
{ |
| 1995 |
#ifndef XDVIPSK |
| 1996 |
ErrorOfScan(num_err); |
| 1997 |
fprintf_str(stderr, |
| 1998 |
"\n ERROR in encoding vector in <%s>", psfontfile); |
| 1999 |
exit(1); |
| 2000 |
#else |
| 2001 |
ErrorOfScan(num_err, &buf); |
| 2002 |
sprintf(err_buf, |
| 2003 |
"! %sin encoding vector in <%s>", buf, psfontfile); |
| 2004 |
free(buf); |
| 2005 |
error(err_buf); |
| 2006 |
dvips_exit(1); |
| 2007 |
#endif /* XDVIPSK */ |
| 2008 |
} |
| 2009 |
} |
| 2010 |
} |
| 2011 |
|
| 2012 |
/* Before parse in BINARY portion of font we should mark needed chars, |
| 2013 |
reencode them if there is reencoding vector for this case and |
| 2014 |
build work vector */ |
| 2015 |
|
| 2016 |
static void |
| 2017 |
CheckChoosing(void) |
| 2018 |
{ |
| 2019 |
|
| 2020 |
#ifdef XDVIPSK |
| 2021 |
char err_buf[1024]; |
| 2022 |
#endif /* XDVIPSK */ |
| 2023 |
CHAR *TmpChar; |
| 2024 |
int err_num, i; |
| 2025 |
|
| 2026 |
if(encode==STANDARD_ENC) |
| 2027 |
{ |
| 2028 |
TmpChar = FirstCharB; |
| 2029 |
} |
| 2030 |
else |
| 2031 |
{ |
| 2032 |
if(encode==SPECIAL_ENC) |
| 2033 |
{ |
| 2034 |
TmpChar = FirstChar; |
| 2035 |
} |
| 2036 |
else |
| 2037 |
{ |
| 2038 |
#ifndef XDVIPSK |
| 2039 |
fprintf_str(stderr, |
| 2040 |
"WARNING: '/Encoding' not found in <%s>\n", psfontfile); |
| 2041 |
exit(1); |
| 2042 |
#else |
| 2043 |
sprintf(err_buf, |
| 2044 |
"WARNING: '/Encoding' not found in <%s>\n", psfontfile); |
| 2045 |
error(err_buf); |
| 2046 |
dvips_exit(1); |
| 2047 |
#endif /* XDVIPSK */ |
| 2048 |
} |
| 2049 |
} |
| 2050 |
|
| 2051 |
if(reencode==FLG_REENCODE) |
| 2052 |
err_num=LoadVector(reencode, TmpChar); |
| 2053 |
else |
| 2054 |
err_num=ChooseVect(TmpChar); |
| 2055 |
|
| 2056 |
if(err_num<0) |
| 2057 |
{ |
| 2058 |
Afm(); |
| 2059 |
encode=AFM_ENC; |
| 2060 |
|
| 2061 |
TmpChar = FirstCharA; |
| 2062 |
|
| 2063 |
for(i=0;i<=255;i++) |
| 2064 |
grid[i]=tmpgrid[i]; |
| 2065 |
|
| 2066 |
|
| 2067 |
if(reencode==FLG_REENCODE) |
| 2068 |
err_num=LoadVector(reencode, TmpChar); |
| 2069 |
else |
| 2070 |
err_num=ChooseVect(TmpChar); |
| 2071 |
|
| 2072 |
if(err_num<0) |
| 2073 |
{ |
| 2074 |
#ifdef XDVIPSK |
| 2075 |
sprintf(err_buf, |
| 2076 |
"Warning: after loading AFM file only %d chars found instead %d for <%s>", |
| 2077 |
CharCount, GridCount, psfontfile); |
| 2078 |
error(err_buf); |
| 2079 |
#else |
| 2080 |
fprintf(stderr, |
| 2081 |
"\n Warning: after loading AFM file \n"); |
| 2082 |
|
| 2083 |
fprintf_str(stderr, |
| 2084 |
" only %d chars found instead %d for <%s>\n", |
| 2085 |
CharCount, GridCount, psfontfile); |
| 2086 |
#endif /* XDVIPSK */ |
| 2087 |
} |
| 2088 |
|
| 2089 |
} |
| 2090 |
WorkVect(TmpChar); |
| 2091 |
|
| 2092 |
#ifdef DEBUG |
| 2093 |
|
| 2094 |
if(dd(D_VIEW_VECTOR)) |
| 2095 |
{ |
| 2096 |
fprintf(stderr, "\n"); |
| 2097 |
if(encode==1) |
| 2098 |
fprintf(stderr, " Encoding: standard \n"); |
| 2099 |
else |
| 2100 |
fprintf(stderr, " Encoding: not standard \n"); |
| 2101 |
|
| 2102 |
if(reencode==FLG_REENCODE) |
| 2103 |
fprintf_str(stderr, " with reencode vector <%s>\n", psvectfile); |
| 2104 |
|
| 2105 |
PrintChar(FirstCharW); |
| 2106 |
} |
| 2107 |
#endif |
| 2108 |
|
| 2109 |
} |
| 2110 |
|
| 2111 |
/* |
| 2112 |
* As we write the output file, we search for /UniqueID, and if we find |
| 2113 |
* such, we munge it. We need to do this because the font is only partial, |
| 2114 |
* and if we send out a valid UniqueID, this well may mess up future jobs |
| 2115 |
* that use this font, but characters that we do not include. We munge |
| 2116 |
* the string from /UniqueID to /UniqueXX just to make it more clear |
| 2117 |
* what we've done. |
| 2118 |
*/ |
| 2119 |
|
| 2120 |
static char * |
| 2121 |
KillUnique(char *s) |
| 2122 |
{ |
| 2123 |
char *r = strstr(s, "/UniqueID"); |
| 2124 |
if (r) { |
| 2125 |
r[7] = 'X'; |
| 2126 |
r[8] = 'X'; |
| 2127 |
} |
| 2128 |
return s; |
| 2129 |
} |
| 2130 |
|
| 2131 |
static void |
| 2132 |
OutASCII(FILE *fout, ub1 *buff, ub4 len) |
| 2133 |
{ |
| 2134 |
ub4 i; |
| 2135 |
|
| 2136 |
for (i = 0; i < len; i++) |
| 2137 |
{ |
| 2138 |
if ((*buff == 10)||(*buff == 13)) |
| 2139 |
{ |
| 2140 |
buff++; |
| 2141 |
*line++='\n'; |
| 2142 |
*line='\0'; |
| 2143 |
|
| 2144 |
if((find_encod==0)&&(lastpart==0)) |
| 2145 |
{ |
| 2146 |
FindEncoding(); |
| 2147 |
} |
| 2148 |
|
| 2149 |
line=(unsigned char *) KillUnique((char *) tmpline); |
| 2150 |
|
| 2151 |
if(keep_flg==0) |
| 2152 |
fprintf(fout,"%s", line); |
| 2153 |
else |
| 2154 |
{ |
| 2155 |
if(keep_num<0) |
| 2156 |
{ |
| 2157 |
AddStr(line,keep_num); |
| 2158 |
if(keep_num==-2) |
| 2159 |
keep_num = -3; |
| 2160 |
} |
| 2161 |
|
| 2162 |
} |
| 2163 |
} |
| 2164 |
else |
| 2165 |
{ |
| 2166 |
*line++ = *buff++; |
| 2167 |
} |
| 2168 |
} |
| 2169 |
} |
| 2170 |
|
| 2171 |
/* It's eexec decription for PFB format */ |
| 2172 |
|
| 2173 |
static void |
| 2174 |
BinEDeCrypt(ub1 *buff, ub4 len) |
| 2175 |
{ |
| 2176 |
ub4 i; |
| 2177 |
|
| 2178 |
for (i = 0; i < len; i++, temp++, buff++) |
| 2179 |
{ |
| 2180 |
*temp = (*buff ^ (edr >> 8)); |
| 2181 |
edr = (*buff + edr) * c1 + c2; |
| 2182 |
} |
| 2183 |
} |
| 2184 |
|
| 2185 |
/* And it's eexec decription for PFA format */ |
| 2186 |
|
| 2187 |
|
| 2188 |
static void |
| 2189 |
HexEDeCrypt(unsigned char *mem) |
| 2190 |
{ |
| 2191 |
int ch1, ch2, cipher; |
| 2192 |
|
| 2193 |
|
| 2194 |
for(;*mem!='\n' && *mem!='\r'; temp++) |
| 2195 |
{ |
| 2196 |
ch1= *mem++; |
| 2197 |
ch2= *mem++; |
| 2198 |
|
| 2199 |
if ('A' <= ch1 && ch1 <= 'F') |
| 2200 |
ch1 -= 'A' - 10; |
| 2201 |
else if ('a' <= ch1 && ch1 <= 'f') |
| 2202 |
ch1 -= 'a' - 10; |
| 2203 |
else |
| 2204 |
ch1 -= '0'; |
| 2205 |
ch1<<=4; |
| 2206 |
|
| 2207 |
if ('A' <= ch2 && ch2 <= 'F') |
| 2208 |
ch2 -= 'A' - 10; |
| 2209 |
else if ('a' <= ch2 && ch2 <= 'f') |
| 2210 |
ch2 -= 'a' - 10; |
| 2211 |
else |
| 2212 |
ch2 -= '0'; |
| 2213 |
|
| 2214 |
cipher = ch1 + ch2; |
| 2215 |
|
| 2216 |
*temp = (cipher ^ (edr >> 8)); |
| 2217 |
edr = (cipher + edr) * c1 + c2; |
| 2218 |
|
| 2219 |
} |
| 2220 |
} |
| 2221 |
|
| 2222 |
static int |
| 2223 |
PartialPFA(FILE *fin, FILE *fout) |
| 2224 |
{ |
| 2225 |
ub1 type; |
| 2226 |
ub4 memory, addmemory, length, add_of_len; |
| 2227 |
unsigned char *mem = tmpline; |
| 2228 |
int check_vect=0; |
| 2229 |
|
| 2230 |
tmpline=buf; |
| 2231 |
edr = EDR; |
| 2232 |
type = FLG_ASCII; |
| 2233 |
memory = BASE_MEM; |
| 2234 |
addmemory= ADD_MEM; |
| 2235 |
length=0; |
| 2236 |
temp=(typetemp *) UniGetMem(memory); |
| 2237 |
begin_of_scan=temp; |
| 2238 |
|
| 2239 |
for(;;) |
| 2240 |
{ |
| 2241 |
if(fgets((char *)buf,BUFSIZ,fin)==NULL) |
| 2242 |
break; |
| 2243 |
switch (type) |
| 2244 |
{ |
| 2245 |
case FLG_ASCII: |
| 2246 |
if(strstr((char *)buf,"currentfile eexec") != NULL) |
| 2247 |
{ |
| 2248 |
type=FLG_BINARY; |
| 2249 |
} |
| 2250 |
|
| 2251 |
if((find_encod==0)&&(lastpart==0)) |
| 2252 |
{ |
| 2253 |
FindEncoding(); |
| 2254 |
} |
| 2255 |
|
| 2256 |
if(keep_flg==0) |
| 2257 |
fprintf(fout,"%s", KillUnique((char *)buf)); |
| 2258 |
else |
| 2259 |
{ |
| 2260 |
AddStr(buf,keep_num); |
| 2261 |
} |
| 2262 |
break; |
| 2263 |
|
| 2264 |
case FLG_BINARY: |
| 2265 |
if(check_vect==0) |
| 2266 |
{ |
| 2267 |
tmpline=mem; |
| 2268 |
CheckChoosing(); |
| 2269 |
check_vect=1; |
| 2270 |
} |
| 2271 |
|
| 2272 |
if(GetZeroLine(buf)<0) |
| 2273 |
{ |
| 2274 |
type = FLG_ZERO_LINE; |
| 2275 |
end_of_scan=temp; |
| 2276 |
ScanBinary(); |
| 2277 |
SubstNum(); |
| 2278 |
if(keep_flg==1) |
| 2279 |
{ |
| 2280 |
keep_flg=0; |
| 2281 |
lastpart=1; |
| 2282 |
if(encode!=1) |
| 2283 |
{ |
| 2284 |
UnDefineCharsW(); |
| 2285 |
if(encode==4) |
| 2286 |
RevChar(FirstCharA); |
| 2287 |
else |
| 2288 |
RevChar(FirstChar); |
| 2289 |
|
| 2290 |
OutChar(FirstCharW, fout); |
| 2291 |
} |
| 2292 |
Reeverse(FirstStr); |
| 2293 |
OutStr(RevStr, fout); |
| 2294 |
} |
| 2295 |
|
| 2296 |
OutHEX(fout); |
| 2297 |
UniFree(begin_of_scan); |
| 2298 |
fprintf(fout, "%s", KillUnique((char*) buf)); |
| 2299 |
break; |
| 2300 |
} |
| 2301 |
|
| 2302 |
add_of_len=strlen((char *) buf)/2; |
| 2303 |
length=length + add_of_len; |
| 2304 |
|
| 2305 |
if(length>memory) |
| 2306 |
{ |
| 2307 |
memory = memory + addmemory; |
| 2308 |
/* Using "memory = length;" retains minimum */ |
| 2309 |
/* of memory but it will be more slowly */ |
| 2310 |
begin_of_scan = (typetemp*) UniRealloc(begin_of_scan, memory); |
| 2311 |
temp = begin_of_scan + length - add_of_len; |
| 2312 |
} |
| 2313 |
HexEDeCrypt(buf); |
| 2314 |
break; |
| 2315 |
case FLG_ZERO_LINE: |
| 2316 |
fprintf(fout, "%s", buf); |
| 2317 |
break; |
| 2318 |
} |
| 2319 |
} |
| 2320 |
if(type == FLG_ZERO_LINE) |
| 2321 |
return TRUE; |
| 2322 |
else return FALSE; |
| 2323 |
} |
| 2324 |
|
| 2325 |
#define FIRST_ASCII 1 |
| 2326 |
#define FIRST_BINARY 2 |
| 2327 |
#define NEXT_BINARY 3 |
| 2328 |
#define NEXT_ASCII 4 |
| 2329 |
|
| 2330 |
static int |
| 2331 |
PartialPFB(FILE *fin, FILE *fout) |
| 2332 |
{ |
| 2333 |
ub1 type; |
| 2334 |
ub4 t_length, length, nread; |
| 2335 |
int nbytes, rc; |
| 2336 |
int check_vect = 0; |
| 2337 |
int sub_type = FIRST_ASCII; |
| 2338 |
|
| 2339 |
line=tmpline; |
| 2340 |
edr = EDR; |
| 2341 |
|
| 2342 |
/* To find summary length of multiple binary parts we prescan font file */ |
| 2343 |
|
| 2344 |
t_length = 0L; |
| 2345 |
|
| 2346 |
for (;;) |
| 2347 |
{ |
| 2348 |
if ((rc = fread((char *) buf, 1, 6, fin)) < 2) |
| 2349 |
{ |
| 2350 |
return FALSE; |
| 2351 |
} |
| 2352 |
|
| 2353 |
if (buf[0] != 128) |
| 2354 |
return FALSE; |
| 2355 |
|
| 2356 |
type = buf[1]; |
| 2357 |
|
| 2358 |
if (type == FLG_EOF) |
| 2359 |
{ |
| 2360 |
break; |
| 2361 |
} |
| 2362 |
|
| 2363 |
if (rc != 6) |
| 2364 |
return FALSE; |
| 2365 |
|
| 2366 |
length = little4(&buf[2]); |
| 2367 |
|
| 2368 |
if(type==FLG_BINARY) |
| 2369 |
{ |
| 2370 |
t_length = (ub4)(length + t_length); |
| 2371 |
} |
| 2372 |
fseek(fin, ftell(fin) + length, SEEK_SET); |
| 2373 |
} |
| 2374 |
|
| 2375 |
/* Here we start real parsing */ |
| 2376 |
|
| 2377 |
sub_type = FIRST_BINARY; |
| 2378 |
|
| 2379 |
fseek(fin, 0L, SEEK_SET); |
| 2380 |
|
| 2381 |
for (;;) |
| 2382 |
{ |
| 2383 |
if ((rc = fread((char *) buf, 1, 6, fin)) < 2) |
| 2384 |
{ |
| 2385 |
return FALSE; |
| 2386 |
} |
| 2387 |
if (buf[0] != 128) |
| 2388 |
return FALSE; |
| 2389 |
|
| 2390 |
type = buf[1]; |
| 2391 |
|
| 2392 |
if (type == FLG_EOF) |
| 2393 |
{ |
| 2394 |
return TRUE; |
| 2395 |
} |
| 2396 |
|
| 2397 |
if (rc != 6) |
| 2398 |
return FALSE; |
| 2399 |
|
| 2400 |
length = little4(&buf[2]); |
| 2401 |
|
| 2402 |
if(type==FLG_BINARY) |
| 2403 |
{ |
| 2404 |
if(sub_type == FIRST_BINARY) |
| 2405 |
{ |
| 2406 |
sub_type = NEXT_BINARY; |
| 2407 |
temp=(typetemp*) UniGetMem(t_length); |
| 2408 |
begin_of_scan=temp; |
| 2409 |
} |
| 2410 |
} |
| 2411 |
else |
| 2412 |
{ |
| 2413 |
if( sub_type == NEXT_BINARY) |
| 2414 |
{ |
| 2415 |
sub_type = NEXT_ASCII; |
| 2416 |
end_of_scan=temp; |
| 2417 |
ScanBinary(); |
| 2418 |
SubstNum(); |
| 2419 |
if(keep_flg==1) |
| 2420 |
{ |
| 2421 |
keep_flg=0; |
| 2422 |
lastpart=1; |
| 2423 |
if(encode!=1) |
| 2424 |
{ |
| 2425 |
UnDefineCharsW(); |
| 2426 |
if(encode==4) |
| 2427 |
RevChar(FirstCharA); |
| 2428 |
else |
| 2429 |
RevChar(FirstChar); |
| 2430 |
|
| 2431 |
OutChar(FirstCharW, fout); |
| 2432 |
} |
| 2433 |
|
| 2434 |
Reeverse(FirstStr); |
| 2435 |
OutStr(RevStr, fout); |
| 2436 |
} |
| 2437 |
OutHEX(fout); |
| 2438 |
UniFree(begin_of_scan); |
| 2439 |
} |
| 2440 |
} |
| 2441 |
|
| 2442 |
for (nread = 0; nread < length; nread += rc) |
| 2443 |
{ |
| 2444 |
nbytes = min(BUFSIZ, length - nread); |
| 2445 |
|
| 2446 |
if ((rc = fread((char *) buf, 1, nbytes, fin)) == 0) |
| 2447 |
{ |
| 2448 |
return FALSE; |
| 2449 |
} |
| 2450 |
switch (type) |
| 2451 |
{ |
| 2452 |
case FLG_ASCII: |
| 2453 |
OutASCII(fout, buf, (ub4) rc); |
| 2454 |
break; |
| 2455 |
case FLG_BINARY: |
| 2456 |
if(check_vect==0) |
| 2457 |
{ |
| 2458 |
CheckChoosing(); |
| 2459 |
check_vect=1; |
| 2460 |
} |
| 2461 |
BinEDeCrypt(buf, (ub4) rc); |
| 2462 |
break; |
| 2463 |
default: |
| 2464 |
return FALSE; |
| 2465 |
} |
| 2466 |
} |
| 2467 |
} |
| 2468 |
} |
| 2469 |
|
| 2470 |
static void |
| 2471 |
OutHEX(FILE *fout) |
| 2472 |
{ |
| 2473 |
int i=0; |
| 2474 |
int num; |
| 2475 |
static const char *hexstr = "0123456789abcdef"; |
| 2476 |
int bin; |
| 2477 |
|
| 2478 |
line=tmpline; |
| 2479 |
eer = EER; |
| 2480 |
label[number].begin = end_of_scan; |
| 2481 |
label[number].select = NOTHING; |
| 2482 |
number++; |
| 2483 |
|
| 2484 |
for(num=0; num < number; num++) |
| 2485 |
{ |
| 2486 |
switch(label[num].select) |
| 2487 |
{ |
| 2488 |
case NOTHING: |
| 2489 |
break; |
| 2490 |
case FLG_BINARY: |
| 2491 |
label[num].select=NOTHING; |
| 2492 |
for(temp=label[num].begin; temp<label[num+1].begin; temp++,i++) |
| 2493 |
{ |
| 2494 |
bin = (*temp ^ (eer >> 8)); /* Eexec encryption */ |
| 2495 |
eer = ((bin + eer) * c1 + c2); |
| 2496 |
|
| 2497 |
*line++= hexstr[(bin&0xf0)>>4]; |
| 2498 |
*line++= hexstr[bin&0xf]; |
| 2499 |
|
| 2500 |
if (!((i + 1) % BYTES_PER_LINE)) |
| 2501 |
{ |
| 2502 |
*line++='\0'; |
| 2503 |
line =tmpline; |
| 2504 |
fprintf(fout, "%s\n",line); |
| 2505 |
} |
| 2506 |
} |
| 2507 |
break; |
| 2508 |
} |
| 2509 |
} |
| 2510 |
if (i % BYTES_PER_LINE) |
| 2511 |
{ |
| 2512 |
*line++='\0'; |
| 2513 |
line =tmpline; |
| 2514 |
fprintf(fout, "%s\n",line); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
|
| 2518 |
/* We parse AFM file only if we've received errors after |
| 2519 |
parsing of own vector */ |
| 2520 |
|
| 2521 |
static int |
| 2522 |
Afm(void) |
| 2523 |
{ |
| 2524 |
#ifdef XDVIPSK |
| 2525 |
char *buf, err_buf[1024]; |
| 2526 |
#endif /* XDVIPSK */ |
| 2527 |
unsigned char afmfile[100]; |
| 2528 |
FILE *fafm; |
| 2529 |
int err_num=0; |
| 2530 |
int i,j,k,num=0; |
| 2531 |
unsigned char name[40]; |
| 2532 |
|
| 2533 |
static const char *AfmKey[] = |
| 2534 |
{ |
| 2535 |
"StartCharMetrics", |
| 2536 |
"EndCharMetrics", |
| 2537 |
"" |
| 2538 |
}; |
| 2539 |
|
| 2540 |
static const char *InfoKey[] = |
| 2541 |
{ |
| 2542 |
"C", |
| 2543 |
"N", |
| 2544 |
"" |
| 2545 |
}; |
| 2546 |
|
| 2547 |
for(i=0; psfontfile[i]; i++) |
| 2548 |
{ |
| 2549 |
if(psfontfile[i] == '.') |
| 2550 |
break; |
| 2551 |
else |
| 2552 |
afmfile[i]=psfontfile[i]; |
| 2553 |
} |
| 2554 |
|
| 2555 |
afmfile[i]='\0'; |
| 2556 |
strcat((char *) afmfile,".afm"); |
| 2557 |
fprintf_str(stderr, "<%s>", afmfile); |
| 2558 |
|
| 2559 |
if ((fafm = psfopen((char *) afmfile, "r")) == NULL) |
| 2560 |
{ |
| 2561 |
#ifndef XDVIPSK |
| 2562 |
NameOfProgram(); |
| 2563 |
perror((char *) afmfile); |
| 2564 |
return -1; |
| 2565 |
#else |
| 2566 |
NameOfProgram(&buf); |
| 2567 |
sprintf(err_buf, "! %s: Open error", buf); |
| 2568 |
free(buf); |
| 2569 |
error_with_perror(err_buf, (char *)afmfile); |
| 2570 |
dvips_exit(-1); |
| 2571 |
#endif /* XDVIPSK */ |
| 2572 |
} |
| 2573 |
|
| 2574 |
for(j=0;;) |
| 2575 |
{ |
| 2576 |
line = tmpline; |
| 2577 |
|
| 2578 |
if(fgets((char *) line,BUFSIZ,fafm)==NULL) |
| 2579 |
break; |
| 2580 |
|
| 2581 |
if(strstr((char *) line, AfmKey[j])!=NULL) |
| 2582 |
{ |
| 2583 |
if(j==0) |
| 2584 |
{ |
| 2585 |
j++; |
| 2586 |
continue; |
| 2587 |
} |
| 2588 |
else |
| 2589 |
{ |
| 2590 |
fclose(fafm); |
| 2591 |
return 1; |
| 2592 |
} |
| 2593 |
} |
| 2594 |
|
| 2595 |
if(j==1) |
| 2596 |
{ |
| 2597 |
for(k=0; err_num>=0; ) |
| 2598 |
{ |
| 2599 |
err_num=GetWord(token); |
| 2600 |
if(err_num==2) |
| 2601 |
{ |
| 2602 |
if(strcmp((char *) token,InfoKey[k])==0) |
| 2603 |
{ |
| 2604 |
if(k==0) |
| 2605 |
{ |
| 2606 |
err_num=GetWord(token); |
| 2607 |
num=atoi((char *) token); |
| 2608 |
k=1; |
| 2609 |
continue; |
| 2610 |
} |
| 2611 |
else |
| 2612 |
{ |
| 2613 |
err_num=GetWord(token); |
| 2614 |
name[0]='/'; |
| 2615 |
name[1]='\0'; |
| 2616 |
strcat((char *) name, (char *) token); |
| 2617 |
if(num>=0) |
| 2618 |
FirstCharA=AddChar(FirstCharA, name, num); |
| 2619 |
break; |
| 2620 |
} |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
} |
| 2625 |
} |
| 2626 |
} |
| 2627 |
return -2; |
| 2628 |
} |
| 2629 |
|
| 2630 |
int |
| 2631 |
FontPart(FILE *fout, unsigned char *fontfile, |
| 2632 |
unsigned char *vectfile) |
| 2633 |
{ |
| 2634 |
#ifdef XDVIPSK |
| 2635 |
char *buf, err_buf[1024]; |
| 2636 |
#endif /* XDVIPSK */ |
| 2637 |
FILE *fin=0; |
| 2638 |
int num; |
| 2639 |
int rc; |
| 2640 |
int i; |
| 2641 |
|
| 2642 |
ind_ref=0; |
| 2643 |
reencode=0; |
| 2644 |
encode=0; |
| 2645 |
lastpart=0; |
| 2646 |
keep_flg=0; |
| 2647 |
flg_seac=0; |
| 2648 |
strcpy((char *) psfontfile, (char *) fontfile); |
| 2649 |
find_encod=0; |
| 2650 |
CharCount=0; |
| 2651 |
|
| 2652 |
if(loadbase != 1) |
| 2653 |
{ |
| 2654 |
for(i=offset; i < NUM_LABEL; i++) |
| 2655 |
label[i].num=CHAR_NOT_DEF; |
| 2656 |
|
| 2657 |
|
| 2658 |
strcpy((char *) psvectfile, (char *) basevect); |
| 2659 |
|
| 2660 |
#ifdef DEBUG |
| 2661 |
if(dd(D_VIEW_VECTOR)) |
| 2662 |
fprintf_str(stderr, " Base vector <%s>.", basevect); |
| 2663 |
#endif |
| 2664 |
|
| 2665 |
if(LoadVector(1, FirstCharB)==1) |
| 2666 |
{ |
| 2667 |
loadbase = FLG_LOAD_BASE; |
| 2668 |
|
| 2669 |
} |
| 2670 |
else |
| 2671 |
#ifndef XDVIPSK |
| 2672 |
exit(1); |
| 2673 |
#else |
| 2674 |
dvips_exit(1); |
| 2675 |
#endif /* XDVIPSK */ |
| 2676 |
} |
| 2677 |
|
| 2678 |
if(vectfile) |
| 2679 |
{ |
| 2680 |
reencode=FLG_REENCODE; |
| 2681 |
strcpy((char *) psvectfile, (char *) vectfile); |
| 2682 |
} |
| 2683 |
|
| 2684 |
for(num=0;num<NUM_LABEL;num++) |
| 2685 |
label[num].select = NOTHING; |
| 2686 |
|
| 2687 |
switch(DefTypeFont(fontfile)) |
| 2688 |
{ |
| 2689 |
case PFA: |
| 2690 |
if ((fin = psfopen((char *) fontfile, "r"))==NULL) |
| 2691 |
{ |
| 2692 |
#ifndef XDVIPSK |
| 2693 |
NameOfProgram(); |
| 2694 |
perror((char *) fontfile); |
| 2695 |
return -1; |
| 2696 |
#else |
| 2697 |
NameOfProgram(&buf); |
| 2698 |
sprintf(err_buf, "! %s: Open error", buf); |
| 2699 |
free(buf); |
| 2700 |
error_with_perror(err_buf, (char *)fontfile); |
| 2701 |
dvips_exit(-1); |
| 2702 |
#endif /* XDVIPSK */ |
| 2703 |
} |
| 2704 |
rc = PartialPFA(fin,fout); |
| 2705 |
if (rc == FALSE) |
| 2706 |
{ |
| 2707 |
#ifndef XDVIPSK |
| 2708 |
NameOfProgram(); |
| 2709 |
(void) fprintf_str(stderr, |
| 2710 |
"Error: %s is not a valid PFA file\n", fontfile); |
| 2711 |
return -1; |
| 2712 |
#else |
| 2713 |
NameOfProgram(&buf); |
| 2714 |
sprintf(err_buf, "! %s: is not a valid PFA file", buf); |
| 2715 |
free(buf); |
| 2716 |
error_with_perror(err_buf, (char *)fontfile); |
| 2717 |
dvips_exit(-1); |
| 2718 |
#endif /* XDVIPSK */ |
| 2719 |
} |
| 2720 |
|
| 2721 |
break; |
| 2722 |
case PFB: |
| 2723 |
if ((fin = psfopen((char *) fontfile, OPEN_READ_BINARY))==NULL) |
| 2724 |
{ |
| 2725 |
#ifndef XDVIPSK |
| 2726 |
NameOfProgram(); |
| 2727 |
perror((char *) fontfile); |
| 2728 |
return -1; |
| 2729 |
#else |
| 2730 |
NameOfProgram(&buf); |
| 2731 |
sprintf(err_buf, "! %s: Open error", buf); |
| 2732 |
free(buf); |
| 2733 |
error_with_perror(err_buf, (char *)fontfile); |
| 2734 |
dvips_exit(-1); |
| 2735 |
#endif /* XDVIPSK */ |
| 2736 |
} |
| 2737 |
rc = PartialPFB(fin,fout); |
| 2738 |
if (rc==FALSE) |
| 2739 |
{ |
| 2740 |
#ifndef XDVIPSK |
| 2741 |
NameOfProgram(); |
| 2742 |
(void) fprintf_str(stderr, |
| 2743 |
"Error: %s is not a valid PFB file\n", fontfile); |
| 2744 |
return -1; |
| 2745 |
#else |
| 2746 |
NameOfProgram(&buf); |
| 2747 |
sprintf(err_buf, "! %s: is not a valid PFB file", buf); |
| 2748 |
free(buf); |
| 2749 |
error_with_perror(err_buf, (char *)fontfile); |
| 2750 |
dvips_exit(-1); |
| 2751 |
#endif /* XDVIPSK */ |
| 2752 |
} |
| 2753 |
break; |
| 2754 |
case -1: |
| 2755 |
#ifndef XDVIPSK |
| 2756 |
NameOfProgram(); |
| 2757 |
fprintf_str(stderr, |
| 2758 |
"Error: %s has neither PFA nor PFB extension", fontfile); |
| 2759 |
return -1; |
| 2760 |
#else |
| 2761 |
NameOfProgram(&buf); |
| 2762 |
sprintf(err_buf, |
| 2763 |
"! %s: %s has neither PFA nor PFB extension", buf, fontfile); |
| 2764 |
free(buf); |
| 2765 |
error(err_buf); |
| 2766 |
dvips_exit(-1); |
| 2767 |
#endif /* XDVIPSK */ |
| 2768 |
} |
| 2769 |
|
| 2770 |
UnDefineCharsW(); |
| 2771 |
|
| 2772 |
if(encode==AFM_ENC) |
| 2773 |
FirstCharA=UnDefineChars(FirstCharA); |
| 2774 |
|
| 2775 |
if(encode!=1) |
| 2776 |
{ |
| 2777 |
UnDefineStr(); |
| 2778 |
} |
| 2779 |
|
| 2780 |
FirstChar=UnDefineChars(FirstChar); |
| 2781 |
|
| 2782 |
fclose(fin); |
| 2783 |
|
| 2784 |
for(i=0; i < number; i++) |
| 2785 |
label[i].num=CHAR_NOT_DEF; |
| 2786 |
|
| 2787 |
ClearB(); |
| 2788 |
return 1; |
| 2789 |
} |
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
static int |
| 2794 |
LoadVector(int num, CHAR *TmpChar) |
| 2795 |
{ |
| 2796 |
|
| 2797 |
#ifdef XDVIPSK |
| 2798 |
char *buf, err_buf[1024]; |
| 2799 |
#endif /* XDVIPSK */ |
| 2800 |
FILE *fvect; |
| 2801 |
int i = 0; |
| 2802 |
int j = 0; |
| 2803 |
int end_vect=0; |
| 2804 |
int index_grid = 0; |
| 2805 |
|
| 2806 |
CharCount = 0; |
| 2807 |
|
| 2808 |
if ((fvect = psfopen((char *) psvectfile, "r")) == NULL) |
| 2809 |
{ |
| 2810 |
#ifndef XDVIPSK |
| 2811 |
NameOfProgram(); |
| 2812 |
perror((char *) psvectfile); |
| 2813 |
return -1; |
| 2814 |
#else |
| 2815 |
NameOfProgram(&buf); |
| 2816 |
sprintf(err_buf, "! %s: Open error", buf); |
| 2817 |
free(buf); |
| 2818 |
error_with_perror(err_buf, (char *)psvectfile); |
| 2819 |
dvips_exit(-1); |
| 2820 |
#endif /* XDVIPSK */ |
| 2821 |
} |
| 2822 |
|
| 2823 |
for(;;) |
| 2824 |
{ |
| 2825 |
line = tmpline; |
| 2826 |
|
| 2827 |
if((fgets((char*)line,BUFSIZ,fvect)==NULL)||(end_vect!=0)) |
| 2828 |
break; |
| 2829 |
|
| 2830 |
for(;;) |
| 2831 |
{ |
| 2832 |
j=GetWord(token); |
| 2833 |
if(j==3) |
| 2834 |
{ |
| 2835 |
if(i==0) |
| 2836 |
{ |
| 2837 |
i++; |
| 2838 |
continue; |
| 2839 |
} |
| 2840 |
|
| 2841 |
if(num==4) |
| 2842 |
{ |
| 2843 |
if(grid[index_grid]==1) |
| 2844 |
{ |
| 2845 |
if(ChooseChar(token, TmpChar)> 0) |
| 2846 |
CharCount++; |
| 2847 |
else |
| 2848 |
{ |
| 2849 |
fprintf_str(stderr, |
| 2850 |
"Error: '%s' not found in reencoding vector <%s> for <%s>\n", |
| 2851 |
token,psvectfile, psfontfile); |
| 2852 |
} |
| 2853 |
} |
| 2854 |
index_grid++; |
| 2855 |
} |
| 2856 |
else |
| 2857 |
{ |
| 2858 |
if(num==1) /* Build base vector */ |
| 2859 |
{ |
| 2860 |
FirstCharB=AddChar(FirstCharB,token, CharCount); |
| 2861 |
CharCount++; |
| 2862 |
} |
| 2863 |
} |
| 2864 |
continue; |
| 2865 |
} |
| 2866 |
if(j== -1) |
| 2867 |
break; |
| 2868 |
if(j==2) |
| 2869 |
{ |
| 2870 |
i=0; |
| 2871 |
end_vect = 1; |
| 2872 |
break; |
| 2873 |
} |
| 2874 |
} |
| 2875 |
} |
| 2876 |
|
| 2877 |
if(j==2) |
| 2878 |
{ |
| 2879 |
if((index_grid!=256)&&(CharCount!=256)) |
| 2880 |
{ |
| 2881 |
fclose(fvect); |
| 2882 |
#ifndef XDVIPSK |
| 2883 |
fprintf_str(stderr,"Error during Load Vector in <%s> \n", |
| 2884 |
psvectfile); |
| 2885 |
fprintf(stderr, |
| 2886 |
"Found %d chars instead 256\n", max(index_grid,CharCount)); |
| 2887 |
#else |
| 2888 |
sprintf(err_buf, "! Error during Load Vector in <%s>. Found %d chars instead 256", |
| 2889 |
psvectfile, max(index_grid, CharCount)); |
| 2890 |
error(err_buf); |
| 2891 |
#endif /* XDVIPSK */ |
| 2892 |
return -3; |
| 2893 |
} |
| 2894 |
|
| 2895 |
if(CharCount>0) |
| 2896 |
{ |
| 2897 |
fclose(fvect); |
| 2898 |
return 1; |
| 2899 |
} |
| 2900 |
else |
| 2901 |
{ |
| 2902 |
fclose(fvect); |
| 2903 |
#ifndef XDVIPSK |
| 2904 |
fprintf_str(stderr, |
| 2905 |
"\n Warning: Vector from <%s> for <%s> doesn't load\n", |
| 2906 |
psvectfile, psfontfile); |
| 2907 |
#else |
| 2908 |
sprintf(err_buf, |
| 2909 |
"Warning: Vector from <%s> for <%s> doesn't load\n", |
| 2910 |
psvectfile, psfontfile); |
| 2911 |
error(err_buf); |
| 2912 |
#endif /* XDVIPSK */ |
| 2913 |
return -1; |
| 2914 |
} |
| 2915 |
} |
| 2916 |
else |
| 2917 |
{ |
| 2918 |
#ifndef XDVIPSK |
| 2919 |
fprintf_str(stderr,"\n Error: ending token 'def' not found in <%s> \n", |
| 2920 |
psvectfile); |
| 2921 |
#else |
| 2922 |
sprintf(err_buf, "! ending token 'def' not found in <%s> \n", |
| 2923 |
psvectfile); |
| 2924 |
error(err_buf); |
| 2925 |
#endif /* XDVIPSK */ |
| 2926 |
return -2; |
| 2927 |
} |
| 2928 |
} |
| 2929 |
|
| 2930 |
static int |
| 2931 |
ChooseVect(CHAR *tmpChar) |
| 2932 |
{ |
| 2933 |
CHAR *ThisChar = tmpChar; |
| 2934 |
|
| 2935 |
CharCount=0; |
| 2936 |
while (ThisChar != NULL) |
| 2937 |
{ |
| 2938 |
ThisChar->choose= grid[ThisChar->num]; |
| 2939 |
if(grid[ThisChar->num]==1) |
| 2940 |
{ |
| 2941 |
CharCount++; |
| 2942 |
} |
| 2943 |
ThisChar = ThisChar->NextChar; |
| 2944 |
} |
| 2945 |
|
| 2946 |
if(CharCount<GridCount) |
| 2947 |
return -1; |
| 2948 |
else |
| 2949 |
return 1; |
| 2950 |
|
| 2951 |
} |
| 2952 |
|
| 2953 |
static void |
| 2954 |
#ifndef XDVIPSK |
| 2955 |
ErrorOfScan(int err) |
| 2956 |
#else |
| 2957 |
ErrorOfScan(int err, char **buf) |
| 2958 |
#endif /* XDVIPSK */ |
| 2959 |
{ |
| 2960 |
#ifdef XDVIPSK |
| 2961 |
*buf = mymalloc(64); |
| 2962 |
memset(*buf, 0, 64); |
| 2963 |
#endif /* XDVIPSK */ |
| 2964 |
switch(err) |
| 2965 |
{ |
| 2966 |
|
| 2967 |
case 0: break; |
| 2968 |
|
| 2969 |
case ERR_FIRST_NUM: |
| 2970 |
#ifndef XDVIPSK |
| 2971 |
fprintf(stderr, " First number not found "); |
| 2972 |
#else |
| 2973 |
strcpy(*buf, " First number not found "); |
| 2974 |
#endif /* XDVIPSK */ |
| 2975 |
break; |
| 2976 |
case ERR_SECOND_NUM: |
| 2977 |
#ifndef XDVIPSK |
| 2978 |
fprintf(stderr, " Second number not found "); |
| 2979 |
#else |
| 2980 |
strcpy(*buf, " Second number not found "); |
| 2981 |
#endif /* XDVIPSK */ |
| 2982 |
break; |
| 2983 |
|
| 2984 |
case ERR_FIRST_TOK: |
| 2985 |
#ifndef XDVIPSK |
| 2986 |
fprintf(stderr, " First token not found "); |
| 2987 |
#else |
| 2988 |
strcpy(*buf, " First token not found "); |
| 2989 |
#endif /* XDVIPSK */ |
| 2990 |
break; |
| 2991 |
|
| 2992 |
case ERR_SECOND_TOK: |
| 2993 |
#ifndef XDVIPSK |
| 2994 |
fprintf(stderr, " Second token not found "); |
| 2995 |
#else |
| 2996 |
strcpy(*buf, " Second token not found "); |
| 2997 |
#endif /* XDVIPSK */ |
| 2998 |
break; |
| 2999 |
|
| 3000 |
case ERR_STACK: |
| 3001 |
#ifndef XDVIPSK |
| 3002 |
fprintf(stderr, " End of stack "); |
| 3003 |
#else |
| 3004 |
strcpy(*buf, " End of stack "); |
| 3005 |
#endif /* XDVIPSK */ |
| 3006 |
break; |
| 3007 |
|
| 3008 |
case ERR_NUM_CHAR: |
| 3009 |
#ifndef XDVIPSK |
| 3010 |
fprintf(stderr, " Number of char not found "); |
| 3011 |
#else |
| 3012 |
strcpy(*buf, " Number of char not found "); |
| 3013 |
#endif /* XDVIPSK */ |
| 3014 |
break; |
| 3015 |
|
| 3016 |
case ERR_NAME_CHAR: |
| 3017 |
#ifndef XDVIPSK |
| 3018 |
fprintf(stderr, " Name of char not found "); |
| 3019 |
#else |
| 3020 |
strcpy(*buf, " Name of char not found "); |
| 3021 |
#endif /* XDVIPSK */ |
| 3022 |
break; |
| 3023 |
} |
| 3024 |
} |
| 3025 |
|
| 3026 |
static void |
| 3027 |
#ifndef XDVIPSK |
| 3028 |
NameOfProgram(void) |
| 3029 |
#else |
| 3030 |
NameOfProgram(char **buf) |
| 3031 |
#endif /* XDVIPSK */ |
| 3032 |
{ |
| 3033 |
#ifdef DVIPS |
| 3034 |
#ifndef XDVIPSK |
| 3035 |
fprintf(stderr,"This is DVIPS, t1part module \n"); |
| 3036 |
#else |
| 3037 |
*buf = mymalloc(64); |
| 3038 |
strcpy(*buf,"This is DVIPS, t1part module "); |
| 3039 |
#endif /* XDVIPSK */ |
| 3040 |
#else |
| 3041 |
#ifndef XDVIPSK |
| 3042 |
fprintf(stderr,"This is t1part, %s by Sergey Lesenko\n", version); |
| 3043 |
#else |
| 3044 |
*buf = mymalloc(64); |
| 3045 |
sprintf(*buf, "This is t1part, %s by Sergey Lesenko\n", version); |
| 3046 |
#endif /* XDVIPSK */ |
| 3047 |
#endif |
| 3048 |
} |
| 3049 |
|
| 3050 |
|