| 1 |
/* |
| 2 |
* Code to download a font definition at the beginning of a section. |
| 3 |
* hacked by SPQR 8.95 to allow for non-partial downloading |
| 4 |
* |
| 5 |
*/ |
| 6 |
#ifndef XDVIPSK |
| 7 |
#include "dvips.h" /* The copyright notice in that file is included too! */ |
| 8 |
#else |
| 9 |
#include "xdvips.h" /* The copyright notice in that file is included too! */ |
| 10 |
#endif /* XDVIPSK */ |
| 11 |
#ifndef DOWNLOAD_USING_PDFTEX |
| 12 |
#define DOWNLOAD_USING_PDFTEX |
| 13 |
#endif |
| 14 |
#ifndef DOWNLOAD_USING_PDFTEX |
| 15 |
#include "t1part.h" |
| 16 |
#endif |
| 17 |
#define DVIPS |
| 18 |
/* |
| 19 |
* The external declarations: |
| 20 |
*/ |
| 21 |
#include "protos.h" |
| 22 |
|
| 23 |
static unsigned char dummyend[8] = { 252 }; |
| 24 |
|
| 25 |
/* |
| 26 |
* We have a routine that downloads an individual character. |
| 27 |
*/ |
| 28 |
static int lastccout; |
| 29 |
quarterword *unpack_bb(chardesctype *c, integer *cwidth, integer *cheight, |
| 30 |
integer *xoff, integer *yoff) { |
| 31 |
#ifdef XDVIPSK |
| 32 |
assert(c); |
| 33 |
#endif /* XDVIPSK */ |
| 34 |
quarterword *p = c->packptr; |
| 35 |
halfword cmd = *p++; |
| 36 |
if (cmd & 4) { |
| 37 |
if ((cmd & 7) == 7) { |
| 38 |
*cwidth = getlong(p); |
| 39 |
*cheight = getlong(p + 4); |
| 40 |
*xoff = getlong(p + 8); |
| 41 |
*yoff = getlong(p + 12); |
| 42 |
p += 16; |
| 43 |
} else { |
| 44 |
*cwidth = p[0] * 256 + p[1]; |
| 45 |
*cheight = p[2] * 256 + p[3]; |
| 46 |
*xoff = p[4] * 256 + p[5]; |
| 47 |
if (*xoff > 32767) |
| 48 |
*xoff -= 65536 ; |
| 49 |
*yoff = p[6] * 256 + p[7]; |
| 50 |
if (*xoff > 32767) |
| 51 |
*xoff -= 65536 ; |
| 52 |
p += 8; |
| 53 |
} |
| 54 |
} else { |
| 55 |
*cwidth = *p++; |
| 56 |
*cheight = *p++; |
| 57 |
*xoff = *p++; |
| 58 |
*yoff = *p++; |
| 59 |
if (*xoff > 127) |
| 60 |
*xoff -= 256; |
| 61 |
if (*yoff > 127) |
| 62 |
*yoff -= 256; |
| 63 |
} |
| 64 |
return p ; |
| 65 |
} |
| 66 |
static void |
| 67 |
downchar(chardesctype *c, shalfword cc) |
| 68 |
{ |
| 69 |
register long i, j; |
| 70 |
integer cheight, cwidth; |
| 71 |
register long k; |
| 72 |
register quarterword *p; |
| 73 |
register halfword cmd; |
| 74 |
integer xoff, yoff; |
| 75 |
halfword wwidth = 0; |
| 76 |
register long len; |
| 77 |
int smallchar; |
| 78 |
|
| 79 |
#ifdef XDVIPSK |
| 80 |
assert(c); |
| 81 |
#endif /* XDVIPSK */ |
| 82 |
cmd = *(c->packptr) ; |
| 83 |
p = unpack_bb(c, &cwidth, &cheight, &xoff, &yoff) ; |
| 84 |
if (c->flags & BIGCHAR) |
| 85 |
smallchar = 0; |
| 86 |
else |
| 87 |
smallchar = 5; |
| 88 |
if (compressed) { |
| 89 |
len = getlong(p); |
| 90 |
p += 4; |
| 91 |
} else { |
| 92 |
wwidth = (cwidth + 15) / 16; |
| 93 |
i = 2 * cheight * (long)wwidth; |
| 94 |
if (i <= 0) |
| 95 |
i = 2; |
| 96 |
i += smallchar; |
| 97 |
if (mbytesleft < i) { |
| 98 |
if (mbytesleft >= RASTERCHUNK) |
| 99 |
(void) free((char *) mraster); |
| 100 |
if (RASTERCHUNK > i) { |
| 101 |
mraster = (quarterword *)mymalloc((integer)RASTERCHUNK); |
| 102 |
mbytesleft = RASTERCHUNK; |
| 103 |
} else { |
| 104 |
k = i + i / 4; |
| 105 |
mraster = (quarterword *)mymalloc((integer)k); |
| 106 |
mbytesleft = k; |
| 107 |
} |
| 108 |
} |
| 109 |
k = i; |
| 110 |
while (k > 0) |
| 111 |
mraster[--k] = 0; |
| 112 |
unpack(p, (halfword *)mraster, cwidth, cheight, cmd); |
| 113 |
p = mraster; |
| 114 |
len = i - smallchar; |
| 115 |
} |
| 116 |
if (cheight == 0 || cwidth == 0 || len == 0) { |
| 117 |
cwidth = 1; |
| 118 |
cheight = 1; |
| 119 |
wwidth = 1; |
| 120 |
len = 2; |
| 121 |
if (compressed) |
| 122 |
p = dummyend; /* CMD(END); see repack.c */ |
| 123 |
else |
| 124 |
mraster[0] = 0; |
| 125 |
} |
| 126 |
if (smallchar) { |
| 127 |
p[len] = cwidth; |
| 128 |
p[len + 1] = cheight; |
| 129 |
p[len + 2] = xoff + 128; |
| 130 |
p[len + 3] = yoff + 128; |
| 131 |
p[len + 4] = c->pixelwidth; |
| 132 |
} else |
| 133 |
/* |
| 134 |
* Now we actually send out the data. |
| 135 |
*/ |
| 136 |
specialout('['); |
| 137 |
if (compressed) { |
| 138 |
specialout('<'); |
| 139 |
mhexout(p, len + smallchar); |
| 140 |
specialout('>'); |
| 141 |
} else { |
| 142 |
i = (cwidth + 7) / 8; |
| 143 |
if (i * cheight > 65520) { |
| 144 |
long bc = 0; |
| 145 |
specialout('<'); |
| 146 |
for (j=0; j<cheight; j++) { |
| 147 |
if (bc + i > 65520) { |
| 148 |
specialout('>'); |
| 149 |
specialout('<'); |
| 150 |
bc = 0; |
| 151 |
} |
| 152 |
mhexout(p, i); |
| 153 |
bc += i; |
| 154 |
p += 2*wwidth; |
| 155 |
} |
| 156 |
specialout('>'); |
| 157 |
} else { |
| 158 |
specialout('<'); |
| 159 |
if (2 * wwidth == i) |
| 160 |
mhexout(p, ((long)cheight) * i + smallchar); |
| 161 |
else { |
| 162 |
for (j=0; j<cheight; j++) { |
| 163 |
mhexout(p, i); |
| 164 |
p += 2*wwidth; |
| 165 |
} |
| 166 |
if (smallchar) |
| 167 |
mhexout(p, (long)smallchar); |
| 168 |
} |
| 169 |
specialout('>'); |
| 170 |
} |
| 171 |
} |
| 172 |
if (smallchar == 0) { |
| 173 |
numout((integer)cwidth); |
| 174 |
numout((integer)cheight); |
| 175 |
numout((integer)xoff + 128); /* not all these casts needed. */ |
| 176 |
numout((integer)yoff + 128); |
| 177 |
numout((integer)(c->pixelwidth)); |
| 178 |
} |
| 179 |
if (lastccout + 1 == cc) { |
| 180 |
cmdout("I"); |
| 181 |
} else { |
| 182 |
numout((integer)cc); |
| 183 |
cmdout("D"); |
| 184 |
} |
| 185 |
lastccout = cc; |
| 186 |
} |
| 187 |
/* |
| 188 |
* Output the literal name of the font change command with PostScript index n |
| 189 |
*/ |
| 190 |
static char goodnames[] = |
| 191 |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 192 |
void |
| 193 |
makepsname(register char *s, register int n) |
| 194 |
{ |
| 195 |
n--; |
| 196 |
*s++ = 'F' + n / (sizeof(goodnames)-1); |
| 197 |
*s++ = goodnames[n % (sizeof(goodnames)-1)]; |
| 198 |
*s++ = 0; |
| 199 |
} |
| 200 |
void |
| 201 |
lfontout(int n) |
| 202 |
{ |
| 203 |
char buf[10]; |
| 204 |
char *b = buf; |
| 205 |
*b++ = '/'; |
| 206 |
makepsname(b, n); |
| 207 |
cmdout(buf); |
| 208 |
} |
| 209 |
|
| 210 |
/* |
| 211 |
* And the download procedure. |
| 212 |
*/ |
| 213 |
void |
| 214 |
#ifndef XDVIPSK |
| 215 |
download(charusetype *p, int psfont) |
| 216 |
#else |
| 217 |
download(charusetype *p) |
| 218 |
#endif /* XDVIPSK */ |
| 219 |
{ |
| 220 |
double scale; |
| 221 |
int seq; |
| 222 |
register int b, i; |
| 223 |
register halfword bit; |
| 224 |
register chardesctype *c; |
| 225 |
int cc, maxcc = -1, numcc; |
| 226 |
double fontscale; |
| 227 |
char name[10]; |
| 228 |
lastccout = -5; |
| 229 |
name[0] = '/'; |
| 230 |
#ifndef XDVIPSK |
| 231 |
makepsname(name + 1, psfont); |
| 232 |
#else |
| 233 |
static chardesctype ctmp; |
| 234 |
name[1] = 0; |
| 235 |
makepsname(name + 1, p->fd->psname); |
| 236 |
#endif /* XDVIPSK */ |
| 237 |
curfnt = p->fd; |
| 238 |
#ifndef XDVIPSK |
| 239 |
curfnt->psname = psfont; |
| 240 |
#endif /* XDVIPSK */ |
| 241 |
if (curfnt->resfont) { |
| 242 |
struct resfont *rf = curfnt->resfont; |
| 243 |
int non_empty=0; |
| 244 |
#ifdef XDVIPSK |
| 245 |
if (rf->otftype) { |
| 246 |
cmdout(name); |
| 247 |
if (rf->specialinstructions[0] == '{') |
| 248 |
cmdout(rf->specialinstructions); |
| 249 |
else { |
| 250 |
char *p = strstr(rf->specialinstructions,"{"); |
| 251 |
if (p) |
| 252 |
cmdout(p); |
| 253 |
} |
| 254 |
fontscale = curfnt->scaledsize * conv; |
| 255 |
sprintf(nextstring, "%g", fontscale); |
| 256 |
cmdout(nextstring); |
| 257 |
strcpy(nextstring, "/CID+"); |
| 258 |
strcat(nextstring, rf->PSname); |
| 259 |
cmdout(nextstring); |
| 260 |
cmdout("ct_cid"); |
| 261 |
rf->sent = 1; |
| 262 |
return; |
| 263 |
} |
| 264 |
#endif /* XDVIPSK */ |
| 265 |
for (b=0; b<16; b++) |
| 266 |
if(p->bitmap[b] !=0) |
| 267 |
non_empty =1; |
| 268 |
if(non_empty==0 && curfnt->iswide == 0 && curfnt->codewidth==1) |
| 269 |
return; |
| 270 |
cmdout(name); |
| 271 |
/* following code re-arranged - Rob Hutchings 1992Apr02 */ |
| 272 |
#ifndef XDVIPSK |
| 273 |
c = curfnt->chardesc + 255; |
| 274 |
cc = 255; |
| 275 |
#else |
| 276 |
cc = 255; |
| 277 |
c = find_chardesc(curfnt, cc); |
| 278 |
if (!c) |
| 279 |
{ |
| 280 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 281 |
c = &ctmp; |
| 282 |
} |
| 283 |
#endif /* XDVIPSK */ |
| 284 |
numcc = 0; |
| 285 |
i = 0; |
| 286 |
for (b=15; b>=0; b--) { |
| 287 |
for (bit=1; bit; bit<<=1) { |
| 288 |
if (p->bitmap[b] & bit) { |
| 289 |
if (i > 0) { |
| 290 |
numout((integer)i); |
| 291 |
specialout('['); |
| 292 |
i = 0; |
| 293 |
} |
| 294 |
numout((integer)c->pixelwidth); |
| 295 |
c->flags |= EXISTS; |
| 296 |
numcc++; |
| 297 |
} else { |
| 298 |
i++; |
| 299 |
c->flags &= ~EXISTS; |
| 300 |
} |
| 301 |
#ifndef XDVIPSK |
| 302 |
c--; |
| 303 |
cc--; |
| 304 |
#else |
| 305 |
cc--; |
| 306 |
c = find_chardesc(curfnt, cc); |
| 307 |
if ((!c) && (cc >= 0) && (cc < 256)) |
| 308 |
{ |
| 309 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 310 |
c = &ctmp; |
| 311 |
} |
| 312 |
#endif /* XDVIPSK */ |
| 313 |
} |
| 314 |
} |
| 315 |
if (i > 0) { |
| 316 |
numout((integer)i); |
| 317 |
specialout('['); |
| 318 |
} |
| 319 |
specialout ('{'); |
| 320 |
if (rf->specialinstructions) |
| 321 |
cmdout(rf->specialinstructions); |
| 322 |
specialout ('}'); |
| 323 |
numout((integer)numcc); |
| 324 |
/* |
| 325 |
* This code has been bogus for a long time. The fix is |
| 326 |
* straightforward. The input, curfnt->scaledsize, is the |
| 327 |
* desired size of the font in dvi units. The output is the |
| 328 |
* fontscale, which is the height of the font in output units |
| 329 |
* which are simply pixels. Thus, all we need to do is multiply |
| 330 |
* by the default generic conv, which properly takes into |
| 331 |
* account magnification, num/den, output resolution, and so on. |
| 332 |
* Sorry this bug has been in here so long. -tgr |
| 333 |
*/ |
| 334 |
fontscale = curfnt->scaledsize * conv; |
| 335 |
sprintf(nextstring, "%g", fontscale); |
| 336 |
cmdout(nextstring); |
| 337 |
strcpy(nextstring, "/"); |
| 338 |
strcat(nextstring, rf->PSname); |
| 339 |
cmdout(nextstring); |
| 340 |
/* end of changed section - Rob */ |
| 341 |
cmdout("rf"); |
| 342 |
rf->sent = 1; |
| 343 |
return; |
| 344 |
} |
| 345 |
/* |
| 346 |
* Here we calculate the largest character actually used, and |
| 347 |
* send it as a parameter to df. |
| 348 |
*/ |
| 349 |
cc = 0; |
| 350 |
numcc = 0; |
| 351 |
for (b=0; b<16; b++) { |
| 352 |
for (bit=32768; bit!=0; bit>>=1) { |
| 353 |
if (p->bitmap[b] & bit) { |
| 354 |
maxcc = cc; |
| 355 |
numcc++; |
| 356 |
} |
| 357 |
cc++; |
| 358 |
} |
| 359 |
} |
| 360 |
if (numcc <= 0) |
| 361 |
return; |
| 362 |
fontscale = ((double)(curfnt->scaledsize)) / 65536.0; |
| 363 |
fontscale *= (mag/1000.0); |
| 364 |
newline(); |
| 365 |
fprintf(bitfile, "%%DVIPSBitmapFont: %s %s %g %d\n", name+1, curfnt->name, |
| 366 |
fontscale, numcc); |
| 367 |
scale = fontscale * DPI / 72.0 ; |
| 368 |
seq = -1 ; |
| 369 |
if (encodetype3) |
| 370 |
seq = downloadbmencoding(curfnt->name, scale, curfnt) ; |
| 371 |
cmdout(name); |
| 372 |
numout((integer)numcc); |
| 373 |
numout((integer)maxcc + 1); |
| 374 |
/* |
| 375 |
* If we need to scale the font, we say so by using dfs |
| 376 |
* instead of df, and we give it a scale factor. We also |
| 377 |
* scale the character widths; this is ugly, but scaling |
| 378 |
* fonts is ugly, and this is the best we can probably do. |
| 379 |
*/ |
| 380 |
if (curfnt->dpi != curfnt->loadeddpi) { |
| 381 |
numout((integer)curfnt->dpi); |
| 382 |
numout((integer)curfnt->loadeddpi); |
| 383 |
if (curfnt->alreadyscaled == 0) { |
| 384 |
#ifndef XDVIPSK |
| 385 |
for (b=0, c=curfnt->chardesc; b<256; b++, c++) |
| 386 |
c->pixelwidth = (c->pixelwidth * |
| 387 |
(long)curfnt->dpi * 2 + curfnt->loadeddpi) / (2 * curfnt->loadeddpi); |
| 388 |
#else |
| 389 |
for (b = 0; b<256; b++) { |
| 390 |
c = find_chardesc(curfnt, b); |
| 391 |
if (!c) |
| 392 |
{ |
| 393 |
PRINTF_PR("Error: character %d not found in the font %s\n", b, curfnt->name); |
| 394 |
} |
| 395 |
else |
| 396 |
c->pixelwidth = (c->pixelwidth * |
| 397 |
(long)curfnt->dpi * 2 + curfnt->loadeddpi) / (2 * curfnt->loadeddpi); |
| 398 |
} |
| 399 |
#endif /* XDVIPSK */ |
| 400 |
curfnt->alreadyscaled = 1; |
| 401 |
} |
| 402 |
cmdout("dfs"); |
| 403 |
} else |
| 404 |
cmdout("df"); |
| 405 |
#ifndef XDVIPSK |
| 406 |
c = curfnt->chardesc; |
| 407 |
#endif /* XDVIPSK */ |
| 408 |
cc = 0; |
| 409 |
for (b=0; b<16; b++) { |
| 410 |
for (bit=32768; bit; bit>>=1) { |
| 411 |
#ifdef XDVIPSK |
| 412 |
c = find_chardesc(curfnt, cc); |
| 413 |
if ((!c) && (cc < 256)) |
| 414 |
{ |
| 415 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 416 |
c = &ctmp; |
| 417 |
} |
| 418 |
#endif /* XDVIPSK */ |
| 419 |
if (p->bitmap[b] & bit) { |
| 420 |
downchar(c, (shalfword)cc); |
| 421 |
c->flags |= EXISTS; |
| 422 |
} else |
| 423 |
c->flags &= ~EXISTS; |
| 424 |
c++; |
| 425 |
cc++; |
| 426 |
} |
| 427 |
} |
| 428 |
cmdout("E"); |
| 429 |
newline() ; |
| 430 |
if (seq >= 0) |
| 431 |
finishbitmapencoding(name, scale) ; |
| 432 |
fprintf(bitfile, "%%EndDVIPSBitmapFont\n"); |
| 433 |
} |
| 434 |
|
| 435 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 436 |
/* |
| 437 |
* Magic code to deal with PostScript font partial downloading. |
| 438 |
* We track the encodings we've seen so far and keep them in these |
| 439 |
* structures. We rely on writet1 to load the encodings for us. |
| 440 |
*/ |
| 441 |
static struct seenEncodings { |
| 442 |
struct seenEncodings *next; |
| 443 |
const char *name; |
| 444 |
char **glyphs; |
| 445 |
} *seenEncodings; |
| 446 |
|
| 447 |
/* |
| 448 |
* Load a new encoding and return the array of glyphs as a vector. |
| 449 |
* Linear search. |
| 450 |
*/ |
| 451 |
#ifdef XDVIPSK |
| 452 |
char **getEncoding(char *encoding, char **builtin) { |
| 453 |
int ii; |
| 454 |
#else |
| 455 |
static char **getEncoding(char *encoding) { |
| 456 |
#endif /* XDVIPSK */ |
| 457 |
struct seenEncodings *p = seenEncodings; |
| 458 |
while (p != 0) |
| 459 |
if (strcmp(encoding, p->name) == 0) |
| 460 |
break; |
| 461 |
else |
| 462 |
p = p->next; |
| 463 |
if (p == 0) { |
| 464 |
p = (struct seenEncodings *)mymalloc(sizeof(struct seenEncodings)); |
| 465 |
p->next = seenEncodings; |
| 466 |
seenEncodings = p; |
| 467 |
p->name = xstrdup(encoding); |
| 468 |
#ifdef XDVIPSK |
| 469 |
if (builtin) |
| 470 |
{ |
| 471 |
p->glyphs = (char**)mymalloc(256 * sizeof(char*)); |
| 472 |
assert(p->glyphs); |
| 473 |
for (ii = 0; ii < 256; ii++) |
| 474 |
p->glyphs[ii] = xstrdup(builtin[ii]); |
| 475 |
} |
| 476 |
else |
| 477 |
#endif /* XDVIPSK */ |
| 478 |
p->glyphs = load_enc_file(encoding); |
| 479 |
} |
| 480 |
return p->glyphs; |
| 481 |
} |
| 482 |
/* |
| 483 |
* When partially downloading a type 1 font, sometimes the font uses |
| 484 |
* the built-in encoding (which we don't know at this point) so we want |
| 485 |
* to subset it by character code. Sometimes the font uses a different |
| 486 |
* encoding, so we want to subset it by glyph. These routines manage |
| 487 |
* accumulating all the glyph names for a particular font from all |
| 488 |
* the various uses into a single, slash-delimited string for writet1(). |
| 489 |
* |
| 490 |
* If no glyphs have been added, extraGlyphs is null. In all cases, |
| 491 |
* the memory allocated for this is in extraGlyphSpace. |
| 492 |
*/ |
| 493 |
static char *extraGlyphs = 0; |
| 494 |
static char *extraGlyphSpace = 0; |
| 495 |
static int extraGlyphSize = 0; |
| 496 |
static int glyphSizeUsed = 0; |
| 497 |
/* |
| 498 |
* We want to make sure we pass in null or "/" but never "". |
| 499 |
*/ |
| 500 |
static void clearExtraGlyphList(void) { |
| 501 |
glyphSizeUsed = 0; |
| 502 |
extraGlyphs = 0; |
| 503 |
} |
| 504 |
/* |
| 505 |
* Add the glyph name; make sure it hasn't been added already. |
| 506 |
* We do this by adding it, so we can get the // around it, |
| 507 |
* and *then* see if it's already there and if it is un-add it. |
| 508 |
*/ |
| 509 |
static void addGlyph(const char *glyphName) { |
| 510 |
int len = strlen(glyphName); |
| 511 |
char *startOfAdd = 0; |
| 512 |
if (len + glyphSizeUsed + 3 > extraGlyphSize) { |
| 513 |
extraGlyphSize = 2 * (extraGlyphSize + len + 100); |
| 514 |
extraGlyphSpace = (char *) xrealloc(extraGlyphSpace, extraGlyphSize); |
| 515 |
} |
| 516 |
extraGlyphs = extraGlyphSpace; |
| 517 |
if (glyphSizeUsed == 0) { |
| 518 |
startOfAdd = extraGlyphs + glyphSizeUsed; |
| 519 |
extraGlyphs[glyphSizeUsed++] = '/'; /* leading / */ |
| 520 |
} else { |
| 521 |
startOfAdd = extraGlyphs + glyphSizeUsed - 1; |
| 522 |
} |
| 523 |
strcpy(extraGlyphs + glyphSizeUsed, glyphName); |
| 524 |
glyphSizeUsed += len; |
| 525 |
extraGlyphs[glyphSizeUsed++] = '/'; /* trailing / */ |
| 526 |
extraGlyphs[glyphSizeUsed] = 0; |
| 527 |
if (strstr(extraGlyphs, startOfAdd) != startOfAdd) { /* already there! */ |
| 528 |
glyphSizeUsed = startOfAdd - extraGlyphs + 1; /* kill the second copy */ |
| 529 |
extraGlyphs[glyphSizeUsed] = 0; |
| 530 |
} |
| 531 |
} |
| 532 |
#endif |
| 533 |
|
| 534 |
/* |
| 535 |
* Download a PostScript font, using partial font downloading if |
| 536 |
* necessary. |
| 537 |
*/ |
| 538 |
static void |
| 539 |
downpsfont(charusetype *p, charusetype *all) |
| 540 |
{ |
| 541 |
static unsigned char grid[256]; |
| 542 |
int GridCount; |
| 543 |
register int b; |
| 544 |
register halfword bit; |
| 545 |
register chardesctype *c; |
| 546 |
struct resfont *rf; |
| 547 |
int cc; |
| 548 |
int j; |
| 549 |
#ifdef XDVIPSK |
| 550 |
luacharmap *map; |
| 551 |
charusetype *all_gl = all; |
| 552 |
#endif /* XDVIPSK */ |
| 553 |
|
| 554 |
curfnt = p->fd; |
| 555 |
rf = curfnt->resfont; |
| 556 |
if (rf == 0 || rf->Fontfile == NULL) |
| 557 |
return; |
| 558 |
for (; all->fd; all++) |
| 559 |
#ifndef XDVIPSK |
| 560 |
if (all->fd->resfont && |
| 561 |
strcmp(rf->PSname, all->fd->resfont->PSname) == 0) |
| 562 |
break; |
| 563 |
#else |
| 564 |
if (rf->otftype) { |
| 565 |
if (all->fd->resfont && all->fd->resfont->otftype && |
| 566 |
(strcmp(rf->PSname, all->fd->resfont->PSname) == 0)) |
| 567 |
break; |
| 568 |
} |
| 569 |
else { |
| 570 |
if (all->fd->resfont && (!all->fd->resfont->otftype) && |
| 571 |
(strcmp(rf->PSname, all->fd->resfont->PSname) == 0)) |
| 572 |
break; |
| 573 |
} |
| 574 |
#endif /* XDVIPSK */ |
| 575 |
if (all != p) |
| 576 |
return; |
| 577 |
if (rf->sent == 2) /* sent as header, from a PS file */ |
| 578 |
return; |
| 579 |
for (j=0; downloadedpsnames[j] && j < unused_top_of_psnames; j++) { |
| 580 |
if (strcmp (downloadedpsnames[j], rf->PSname) == 0) |
| 581 |
return; |
| 582 |
} |
| 583 |
if (all->fd == 0) |
| 584 |
error("! internal error in downpsfont"); |
| 585 |
#ifdef XDVIPSK |
| 586 |
if (rf->otftype) { |
| 587 |
map = (luacharmap *)mymalloc((integer)sizeof(luacharmap)); |
| 588 |
map->luamap_idx = rf->luamap_idx; |
| 589 |
map->next = NULL; |
| 590 |
p->map_chain = map; |
| 591 |
all++; |
| 592 |
for (; all->fd; all++) { |
| 593 |
if (all->fd->resfont && all->fd->resfont->otftype && |
| 594 |
(strcmp(rf->PSname, all->fd->resfont->PSname) == 0)) { |
| 595 |
for (j = 0; j < USED_CHARS_BUF_SIZE; j++) |
| 596 |
p->bitmap[j] |= all->bitmap[j]; |
| 597 |
map = (luacharmap *)mymalloc((integer)sizeof(luacharmap)); |
| 598 |
map->luamap_idx = all->fd->resfont->luamap_idx; |
| 599 |
map->next = p->map_chain; |
| 600 |
p->map_chain = map; |
| 601 |
} |
| 602 |
} |
| 603 |
newline(); |
| 604 |
if (!disablecomments) |
| 605 |
fprintf(bitfile, "%%%%BeginFont: %s\n", rf->PSname); |
| 606 |
writecid(p); |
| 607 |
if (!quiet) { |
| 608 |
if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) { |
| 609 |
fprintf(stderr, "\n"); |
| 610 |
prettycolumn = 0; |
| 611 |
} |
| 612 |
fprintf(stderr, "<%s>", realnameoffile); |
| 613 |
prettycolumn += strlen(realnameoffile) + 2; |
| 614 |
} |
| 615 |
if (!disablecomments) |
| 616 |
fprintf(bitfile, "%%%%EndFont \n"); |
| 617 |
return; |
| 618 |
} |
| 619 |
#endif /* XDVIPSK */ |
| 620 |
#ifndef XDVIPSK |
| 621 |
if (!partialdownload) { |
| 622 |
infont = all->fd->resfont->PSname; |
| 623 |
copyfile(all->fd->resfont->Fontfile); |
| 624 |
infont = 0; |
| 625 |
#else |
| 626 |
if (!t1_partialdownload || !rf->partialdownload) { |
| 627 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 628 |
for (cc = 0; cc<256; cc++) |
| 629 |
grid[cc] = 1; |
| 630 |
newline(); |
| 631 |
if (!disablecomments) |
| 632 |
fprintf(bitfile, "%%%%BeginFont: %s\n", rf->PSname); |
| 633 |
if (!t1_write_full(rf->Fontfile, grid)) |
| 634 |
dvips_exit(1); |
| 635 |
// exit(1); |
| 636 |
if (!quiet) { |
| 637 |
if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) { |
| 638 |
fprintf(stderr, "\n"); |
| 639 |
prettycolumn = 0; |
| 640 |
} |
| 641 |
fprintf(stderr, "<%s>", realnameoffile); |
| 642 |
prettycolumn += strlen(realnameoffile) + 2; |
| 643 |
} |
| 644 |
if (!disablecomments) |
| 645 |
fprintf(bitfile, "%%%%EndFont \n"); |
| 646 |
#else |
| 647 |
infont = all->fd->resfont->PSname; |
| 648 |
copyfile(all->fd->resfont->Fontfile); |
| 649 |
infont = 0; |
| 650 |
#endif |
| 651 |
#endif /* XDVIPSK */ |
| 652 |
return; |
| 653 |
} |
| 654 |
for (cc=0; cc<256; cc++) |
| 655 |
grid[cc] = 0; |
| 656 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 657 |
clearExtraGlyphList(); |
| 658 |
#endif |
| 659 |
for (; all->fd; all++) { |
| 660 |
#ifndef XDVIPSK |
| 661 |
if (all->fd->resfont == 0 || |
| 662 |
#else |
| 663 |
if ((all->fd->resfont == 0) || all->fd->resfont->otftype || |
| 664 |
#endif /* XDVIPSK */ |
| 665 |
strcmp(rf->PSname, all->fd->resfont->PSname)) |
| 666 |
continue; |
| 667 |
curfnt = all->fd; |
| 668 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 669 |
if (curfnt->resfont->Vectfile) { |
| 670 |
#ifndef XDVIPSK |
| 671 |
char **glyphs = getEncoding(curfnt->resfont->Vectfile); |
| 672 |
c = curfnt->chardesc + 255; |
| 673 |
#else /* XDVIPSK */ |
| 674 |
char **glyphs = getEncoding(curfnt->resfont->Vectfile, NULL); |
| 675 |
#endif /* XDVIPSK */ |
| 676 |
cc = 255; |
| 677 |
#ifdef XDVIPSK |
| 678 |
c = find_chardesc(curfnt, cc); |
| 679 |
if (!c) |
| 680 |
{ |
| 681 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 682 |
} |
| 683 |
#endif /* XDVIPSK */ |
| 684 |
for (b=15; b>=0; b--) { |
| 685 |
for (bit=1; bit; bit<<=1) { |
| 686 |
if (all->bitmap[b] & bit) { |
| 687 |
addGlyph(glyphs[cc]); |
| 688 |
} |
| 689 |
#ifndef XDVIPSK |
| 690 |
c--; |
| 691 |
cc--; |
| 692 |
#else /* XDVIPSK */ |
| 693 |
cc--; |
| 694 |
c = find_chardesc(curfnt, cc); |
| 695 |
if ((!c) && (cc >= 0)) |
| 696 |
{ |
| 697 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 698 |
} |
| 699 |
#endif /* XDVIPSK */ |
| 700 |
} |
| 701 |
} |
| 702 |
} else { |
| 703 |
#endif |
| 704 |
#ifndef XDVIPSK |
| 705 |
c = curfnt->chardesc + 255; |
| 706 |
#else /* XDVIPSK */ |
| 707 |
c = find_chardesc(curfnt, cc); |
| 708 |
if ((!c) && (cc >= 0) && (cc < 256)) |
| 709 |
{ |
| 710 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 711 |
} |
| 712 |
#endif /* XDVIPSK */ |
| 713 |
cc = 255; |
| 714 |
for (b=15; b>=0; b--) { |
| 715 |
for (bit=1; bit; bit<<=1) { |
| 716 |
if (all->bitmap[b] & bit) { |
| 717 |
grid[cc]=1; |
| 718 |
} |
| 719 |
#ifndef XDVIPSK |
| 720 |
c--; |
| 721 |
cc--; |
| 722 |
#else /* XDVIPSK */ |
| 723 |
cc--; |
| 724 |
c = find_chardesc(curfnt, cc); |
| 725 |
if ((!c) && (cc >= 0)) |
| 726 |
{ |
| 727 |
PRINTF_PR("Error: character %d not found in the font %s\n", cc, curfnt->name); |
| 728 |
} |
| 729 |
#endif /* XDVIPSK */ |
| 730 |
} |
| 731 |
} |
| 732 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 733 |
} |
| 734 |
#endif |
| 735 |
} |
| 736 |
|
| 737 |
for (GridCount=0,cc=0; cc<256; cc++) { |
| 738 |
/* tmpgrid[cc]=grid[cc]; */ |
| 739 |
if(grid[cc] ==1) { |
| 740 |
GridCount++; |
| 741 |
} |
| 742 |
} |
| 743 |
if(GridCount!=0 |
| 744 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 745 |
|| extraGlyphs |
| 746 |
#endif |
| 747 |
) { |
| 748 |
newline(); |
| 749 |
if (! disablecomments) |
| 750 |
fprintf(bitfile, "%%%%BeginFont: %s\n", rf->PSname); |
| 751 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 752 |
if (!t1_subset_2(rf->Fontfile, grid, extraGlyphs)) |
| 753 |
#else |
| 754 |
if(FontPart(bitfile, rf->Fontfile, rf->Vectfile) < 0) |
| 755 |
#endif |
| 756 |
#ifndef XDVIPSK |
| 757 |
exit(1); |
| 758 |
#else /* XDVIPSK */ |
| 759 |
dvips_exit(1); |
| 760 |
#endif /* XDVIPSK */ |
| 761 |
if (!quiet) { |
| 762 |
if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) { |
| 763 |
fprintf(stderr, "\n"); |
| 764 |
prettycolumn = 0; |
| 765 |
} |
| 766 |
fprintf_str(stderr, "<%s>", realnameoffile); |
| 767 |
prettycolumn += strlen(realnameoffile) + 2; |
| 768 |
} |
| 769 |
if (! disablecomments) |
| 770 |
fprintf(bitfile, "%%%%EndFont \n"); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
void |
| 775 |
dopsfont(sectiontype *fs) |
| 776 |
{ |
| 777 |
charusetype *cu; |
| 778 |
#ifdef XDVIPSK |
| 779 |
int psfont; |
| 780 |
#endif /* XDVIPSK */ |
| 781 |
|
| 782 |
cu = (charusetype *) (fs + 1); |
| 783 |
#ifdef XDVIPSK |
| 784 |
psfont = 1; |
| 785 |
#endif /* XDVIPSK */ |
| 786 |
#ifdef DOWNLOAD_USING_PDFTEX |
| 787 |
while (cu->fd) { |
| 788 |
if (cu->psfused) |
| 789 |
cu->fd->psflag = EXISTS; |
| 790 |
#ifdef XDVIPSK |
| 791 |
cu->fd->psname = psfont; |
| 792 |
psfont++; |
| 793 |
#endif /* XDVIPSK */ |
| 794 |
downpsfont(cu++, (charusetype *)(fs + 1)); |
| 795 |
} |
| 796 |
#else |
| 797 |
line = getmem(BUFSIZ); |
| 798 |
tmpline=line; |
| 799 |
while (cu->fd) { |
| 800 |
if (cu->psfused) |
| 801 |
cu->fd->psflag = EXISTS; |
| 802 |
#ifdef XDVIPSK |
| 803 |
cu->fd->psname = psfont; |
| 804 |
psfont++; |
| 805 |
#endif /* XDVIPSK */ |
| 806 |
downpsfont(cu++, (charusetype *)(fs + 1)); |
| 807 |
} |
| 808 |
loadbase = ~FLG_LOAD_BASE; |
| 809 |
FirstCharB=UnDefineChars(FirstCharB); |
| 810 |
free(tmpline); |
| 811 |
#endif |
| 812 |
} |