| 1 |
/* |
| 2 |
* NAME |
| 3 |
* ps2pk - creates a PK font from a type1 PostScript font |
| 4 |
* SYNOPSIS: |
| 5 |
* ps2pk [options] type1 [pkname] |
| 6 |
* DESCRIPTION |
| 7 |
* This program renders a given type1 PostScript font at a given |
| 8 |
* pointsize (default 10.0 points) and resolution (default 300dpi) |
| 9 |
* into a TeX PK font. |
| 10 |
* |
| 11 |
* To generate the PK font ps2pk needs a valid type1 fontname (for |
| 12 |
* example Utopia-Regular.pfa) and its corresponding AFMfile |
| 13 |
* (Utopia-Regular.afm). The program accepts both the MSDOS binary |
| 14 |
* type1 format (Utopia-Regula.pfb) and its UNIX ASCII equivalent |
| 15 |
* (Utopia-Regula.pfa). The resulting PK font does contain all |
| 16 |
* characters for which the C-code is non negative. This can be |
| 17 |
* overruled by specifying an explicit <encoding> via the -e<encoding> |
| 18 |
* option. Character codes in AFM files are specified as integer values |
| 19 |
* after the C, for example Utopia-Regular.afm provides: |
| 20 |
* C 251 ; WX 601 ; N germandbls ; B 22 -12 573 742 ; |
| 21 |
* C -1 ; WX 380 ; N onesuperior ; B 81 272 307 680 ; |
| 22 |
* |
| 23 |
* The `germandbls' has code 251 and `onesuperior' -1 which means |
| 24 |
* that this character is not part of the default AdobeStandard- |
| 25 |
* Encoding scheme. To get this `onesuperior' you have to add it to |
| 26 |
* an encoding vector as described in the PostScript manuals. But of |
| 27 |
* course it is better to use standard encodings, like the one provided |
| 28 |
* with the new psfonts. This `TeXBase1Encoding' encoding does contain |
| 29 |
* all names of characters as defined in the 256 character TeX fonts. |
| 30 |
* |
| 31 |
* The location of files for ps2pk, since version 1.5, has been |
| 32 |
* improved using PostScript resource databases. These databases |
| 33 |
* can be created using Adobe's mkpsres(1) utility. On UNIX the |
| 34 |
* default name is PSres.upr and can be found in directories like |
| 35 |
* /usr/lib/DPS depending on the machine you are using. The |
| 36 |
* following example of an UPR file contains three resources |
| 37 |
* PS-Resources-1.0 |
| 38 |
* Encoding |
| 39 |
* FontAFM |
| 40 |
* FontOutline |
| 41 |
* . |
| 42 |
* //usr/local/tex/fonts/type1faces |
| 43 |
* Encoding |
| 44 |
* ECEncoding=EC.enc |
| 45 |
* . |
| 46 |
* FontAFM |
| 47 |
* Courier=ResidentFonts/Courier.pfa |
| 48 |
* . |
| 49 |
* FontOutline |
| 50 |
* Courier=ResidentFonts/Courier.afm |
| 51 |
* . |
| 52 |
* |
| 53 |
* When this UPR is in the PSRESOURCEPATH ps2pk can make an EC encoded |
| 54 |
* PK font for Courier with: |
| 55 |
* |
| 56 |
* ps2pk -eECEncoding Courier |
| 57 |
* |
| 58 |
* It is also possible without the UPR file but then you have to |
| 59 |
* set T1INPUTS to the directories containing the files you need, |
| 60 |
* for example: |
| 61 |
* |
| 62 |
* setenv T1INPUTS /usr/local/tex/fonts/type1faces// |
| 63 |
* |
| 64 |
* and to run ps2pk by providing the proper filenames: |
| 65 |
* |
| 66 |
* ps2pk -eEC.enc Courier.pfa |
| 67 |
* |
| 68 |
* In both cases the result will be the PK font Courier10.300pk. |
| 69 |
* |
| 70 |
* PostScript resource databases eliminate the need for recursive |
| 71 |
* directory search, this is done by mkpsres(1) instead. And all |
| 72 |
* resources can be stored in one directory per computer keeping |
| 73 |
* maintenance easy. Another advantage is the mapping of internal |
| 74 |
* PostScript names, which are case sensitive and not restricted to |
| 75 |
* MSDOS limitations, to external platform dependant filenames in |
| 76 |
* a very natural way. On a MSDOS computer psres.dpr (the equivalent |
| 77 |
* of PSres.upr) could be: |
| 78 |
* PS-Resources-1.0 |
| 79 |
* Encoding |
| 80 |
* FontAFM |
| 81 |
* FontOutline |
| 82 |
* . |
| 83 |
* Encoding |
| 84 |
* TeXBase1Encoding=c:\emtex\dvips\8r.enc |
| 85 |
* . |
| 86 |
* FontAFM |
| 87 |
* Courier=c:\psfonts\com_____.pfb |
| 88 |
* . |
| 89 |
* FontOutline |
| 90 |
* Courier=c:\psfonts\afm\com_____.afm |
| 91 |
* . |
| 92 |
* |
| 93 |
* Given this psres.dpr resource database |
| 94 |
* |
| 95 |
* ps2pk -eTeXBase1Encoding Courier |
| 96 |
* |
| 97 |
* will create Courier10.300pk. Unfortunately MSDOS will abbreviate |
| 98 |
* this name to COURIER1.300. Mkpsres(1) is an improved version |
| 99 |
* of Adobe's makepsres(1) that runs on UNIX and MSDOS. This program |
| 100 |
* will treat PFB fonts and PFM fonts correctly and recognize |
| 101 |
* filenames ending with ".enc" as encoding vectors. |
| 102 |
* |
| 103 |
* If the name of <type1font> does not contain an explicit extension |
| 104 |
* or directory separator it is considered as the name of a resource. |
| 105 |
* Otherwise as a filename. You can not mix up resource names and file- |
| 106 |
* names. Filenames must have an extension! |
| 107 |
* |
| 108 |
* OPTIONS AND ARGUMENTS |
| 109 |
* -a<AFM> The name of the AFM resource or file can be |
| 110 |
* overruled with this option. |
| 111 |
* -e<encoding> The encoding scheme (default the encoding from the |
| 112 |
* AFM file is used). |
| 113 |
* -E<extension> The extension factor (real value, default 1.0). |
| 114 |
* -O Create old checksums (for compatibility) |
| 115 |
* -P<pointsize> The desired pointsize (real value, default 10.0 |
| 116 |
* points). PK fonts created with a value different |
| 117 |
* to 10.0 will cause dvips warnings `dvips: Design |
| 118 |
* size mismatch in font ...'. |
| 119 |
* -R<baseres> The base resolution (integer value, default 300 |
| 120 |
* dpi). Only used for creating METAFONT compatible |
| 121 |
* identification strings in PK postamble. |
| 122 |
* -S<slant> The slant (real value, default 0.0). |
| 123 |
* -X<xres> The resolution (integer value) in the X direction |
| 124 |
* (default 300 dpi). |
| 125 |
* -Y<yres> The resolution (integer value) in the Y direction |
| 126 |
* (defaults to the value of <xres>). |
| 127 |
* -d Debug stat() calls during recursive path searching |
| 128 |
* -v Verbose flag. (Tells what the program is doing.) |
| 129 |
* |
| 130 |
* type1font The name of the PostScript type 1 font. When no |
| 131 |
* explicit AFMfile is given via the -a option the |
| 132 |
* name of the AFMfile will be constructed from this |
| 133 |
* name by removing the extension (if supplied) and |
| 134 |
* adding ".afm". |
| 135 |
* [pkname] The name of the resulting PK font can be overruled |
| 136 |
* with this name. The default name of the PK font is |
| 137 |
* derived from the basename of the type1 font, the |
| 138 |
* pointsize and <xres>. For example: |
| 139 |
* ps2pk -P17.28 Utopia-Regular |
| 140 |
* will result in: |
| 141 |
* Utopia-Regular17.300pk |
| 142 |
* |
| 143 |
* ENVIRONMENTS |
| 144 |
* |
| 145 |
* PSRESOURCEPATH |
| 146 |
* The path used for locating PS resource database files (PSres.upr |
| 147 |
* on UNIX and psres.dpr on MSDOS). The default of the path will be |
| 148 |
* shown by running ps2pk with the -v flag and a non-existant resource |
| 149 |
* name. |
| 150 |
* |
| 151 |
* T1INPUTS |
| 152 |
* The path used for locating PS type1 fonts, their AFM files and |
| 153 |
* encoding vectors. Path may contain '//' (UNIX) or '!!' (MSDOS) to |
| 154 |
* force ps2pk to look into subdirectories. Using PSRESOURCEPATH |
| 155 |
* instead of T1INPUTS avoids recursion. The default of the path will |
| 156 |
* be shown by running ps2pk with the -v flag and a non-existant |
| 157 |
* filename. |
| 158 |
* |
| 159 |
* ACKNOWLEDGEMENTS |
| 160 |
* This program uses the type1 hinting and rendering software IBM |
| 161 |
* has donated to the X-consortium. |
| 162 |
* |
| 163 |
* Since version 1.5 the lookup of PS resources as described in |
| 164 |
* `Programming the Display PostScript System with X (Appendix A: |
| 165 |
* Locating PostScript Resources)' from Adobe Systems is used. |
| 166 |
* SEE ALSO |
| 167 |
* ``METAFONT: The Program'', Donald Knuth. |
| 168 |
* ``The GFtoPK processor'', belonging to the METAFONTware. |
| 169 |
* afm2tfm(1) |
| 170 |
* mkpsres(1) |
| 171 |
* mtpk(1) |
| 172 |
* pk2bm(1) |
| 173 |
* pkfonts(1) |
| 174 |
* AUTHOR |
| 175 |
* Piet Tutelaers |
| 176 |
*/ |
| 177 |
|
| 178 |
#include "basics.h" /* basic definitions and fatal() */ |
| 179 |
#include <ctype.h> |
| 180 |
#include <stdio.h> |
| 181 |
#include <stdlib.h> |
| 182 |
#include <string.h> |
| 183 |
/* PostScript Resource lookup functions */ |
| 184 |
/* |
| 185 |
#include "PSres.h" |
| 186 |
*/ |
| 187 |
#include "filenames.h" /* newname(), extension(), ps_resource() */ |
| 188 |
#include "psearch.h" /* path search functions */ |
| 189 |
#include "pkout.h" /* PK output functions */ |
| 190 |
|
| 191 |
/* begin interface to type 1 software */ |
| 192 |
#include "ffilest.h" |
| 193 |
|
| 194 |
#include "objects.h" |
| 195 |
#include "spaces.h" |
| 196 |
#include "paths.h" |
| 197 |
#include "regions.h" |
| 198 |
#include "t1stdio.h" |
| 199 |
#include "util.h" |
| 200 |
#include "fontfcn.h" |
| 201 |
|
| 202 |
FontScalableRec vals; |
| 203 |
FontEntryRec entry; |
| 204 |
#define Succesful 85 |
| 205 |
/* end interface to type 1 software */ |
| 206 |
|
| 207 |
char *encfile = NULL, *afmfile; |
| 208 |
|
| 209 |
char ps2pk_args[MAXSTRLEN] = "none"; /* essential ps2pk arguments */ |
| 210 |
|
| 211 |
#define POINTSPERINCH 72.27 |
| 212 |
#define DEFAULTRES 300 |
| 213 |
#define DEFAULTPOINTSIZE 10.0 |
| 214 |
|
| 215 |
double pointsize = 0.0; /* wanted pointsize */ |
| 216 |
int W, H, /* width and height of character glyph */ |
| 217 |
base_resolution = DEFAULTRES, |
| 218 |
x_resolution = 0, |
| 219 |
y_resolution = 0; |
| 220 |
|
| 221 |
int verbose = 0, debug = 0; |
| 222 |
|
| 223 |
/* Provide old (-O flag) and new (default) checksum function */ |
| 224 |
static uint32_t checksum(encoding, int [256]); |
| 225 |
static uint32_t old_checksum(encoding, int [256]); |
| 226 |
uint32_t (*pchecksum)(encoding, int [256]) = checksum; |
| 227 |
|
| 228 |
/* Prototypes */ |
| 229 |
static int next_pixel(void); |
| 230 |
#if 0 |
| 231 |
static void print_pixmap(void); |
| 232 |
#endif |
| 233 |
static void first_pixel(CharInfoRec *); |
| 234 |
static int32_t TFMwidth(int); |
| 235 |
static int h_escapement(int); |
| 236 |
static void add_option(const char *, const char *); |
| 237 |
|
| 238 |
int main(int argc, char *argv[]) |
| 239 |
{ |
| 240 |
char c; |
| 241 |
int done, i; |
| 242 |
const char *myname = "ps2pk"; |
| 243 |
char *psname, *psbasename, *afmname = NULL, |
| 244 |
*encname = NULL, *psfile = NULL, *psfilebn, pkname[80], |
| 245 |
*AFM_fontname = NULL, |
| 246 |
*encodingscheme = NULL; |
| 247 |
|
| 248 |
FontPtr fontptr; |
| 249 |
unsigned char glyphcode[1]; /* must be an array */ |
| 250 |
CharInfoRec *glyphs[1]; |
| 251 |
unsigned int count; |
| 252 |
int charcode, rc = -1, charno; |
| 253 |
char comment[256]; |
| 254 |
long cs; |
| 255 |
encoding ev; |
| 256 |
int WX[256]; |
| 257 |
|
| 258 |
float efactor = 1.0, slant = 0.0; |
| 259 |
|
| 260 |
#ifdef KPATHSEA |
| 261 |
kpse_set_program_name(argv[0], "ps2pk"); |
| 262 |
#endif |
| 263 |
|
| 264 |
while (--argc > 0 && (*++argv)[0] == '-') { |
| 265 |
done=0; |
| 266 |
while ((!done) && (c = *++argv[0])) /* allow -bcK like options */ |
| 267 |
switch (c) { |
| 268 |
case 'a': |
| 269 |
if (*++argv[0] == '\0') { |
| 270 |
argc--; argv++; |
| 271 |
} |
| 272 |
if (argv[0] == NULL) goto invalid; |
| 273 |
afmname = argv[0]; |
| 274 |
done = 1; |
| 275 |
break; |
| 276 |
case 'd': |
| 277 |
debug = 1; |
| 278 |
break; |
| 279 |
case 'e': |
| 280 |
if (*++argv[0] == '\0') { |
| 281 |
argc--; argv++; |
| 282 |
} |
| 283 |
if (argv[0] == NULL) goto invalid; |
| 284 |
encname = argv[0]; |
| 285 |
add_option("-e", encname); |
| 286 |
done = 1; |
| 287 |
break; |
| 288 |
case 'E': |
| 289 |
if (*++argv[0] == '\0') { |
| 290 |
argc--; argv++; |
| 291 |
} |
| 292 |
if (argv[0] == NULL) goto invalid; |
| 293 |
efactor = atof(argv[0]); |
| 294 |
add_option("-E", argv[0]); |
| 295 |
done = 1; |
| 296 |
break; |
| 297 |
case 'O': |
| 298 |
pchecksum = old_checksum; |
| 299 |
add_option("-O", ""); |
| 300 |
break; |
| 301 |
case 'P': |
| 302 |
if (*++argv[0] == '\0') { |
| 303 |
argc--; argv++; |
| 304 |
} |
| 305 |
if (argv[0] == NULL) goto invalid; |
| 306 |
pointsize = atof(argv[0]); |
| 307 |
add_option("-P", argv[0]); |
| 308 |
done = 1; |
| 309 |
break; |
| 310 |
case 'R': |
| 311 |
if (*++argv[0] == '\0') { |
| 312 |
argc--; argv++; |
| 313 |
} |
| 314 |
if (argv[0] == NULL) goto invalid; |
| 315 |
base_resolution = atoi(argv[0]); |
| 316 |
add_option("-R", argv[0]); |
| 317 |
done = 1; |
| 318 |
break; |
| 319 |
case 'S': |
| 320 |
if (*++argv[0] == '\0') { |
| 321 |
argc--; argv++; |
| 322 |
} |
| 323 |
if (argv[0] == NULL) goto invalid; |
| 324 |
slant = atof(argv[0]); |
| 325 |
add_option("-S", argv[0]); |
| 326 |
done = 1; |
| 327 |
break; |
| 328 |
case 'X': |
| 329 |
if (*++argv[0] == '\0') { |
| 330 |
argc--; argv++; |
| 331 |
} |
| 332 |
if (argv[0] == NULL) goto invalid; |
| 333 |
x_resolution = atoi(argv[0]); done = 1; |
| 334 |
if (y_resolution == 0) y_resolution = x_resolution; |
| 335 |
add_option("-X", argv[0]); |
| 336 |
break; |
| 337 |
case 'Y': |
| 338 |
if (*++argv[0] == '\0') { |
| 339 |
argc--; argv++; |
| 340 |
} |
| 341 |
if (argv[0] == NULL) goto invalid; |
| 342 |
y_resolution = atoi(argv[0]); done = 1; |
| 343 |
if (x_resolution == 0) x_resolution = y_resolution; |
| 344 |
add_option("-Y", argv[0]); |
| 345 |
break; |
| 346 |
case 'v': |
| 347 |
verbose = 1; |
| 348 |
break; |
| 349 |
invalid: |
| 350 |
default: |
| 351 |
fatal("%s: %c invalid option\n", myname, c); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
if (argc < 1 || argc >2) { |
| 356 |
msg ("ps2pk version " PACKAGE_VERSION " (" TL_VERSION ")\n"); |
| 357 |
msg ("Usage: %s [options] type1font [pkname]\n", myname); |
| 358 |
msg ("options: -d -v -e<enc> -X<xres> -E<expansion> -S<slant>\n"); |
| 359 |
msg ("options: -O -P<pointsize> -Y<yres> -a<AFM> -R<baseres>\n"); |
| 360 |
fatal("\nEmail bug reports to %s.\n", PACKAGE_BUGREPORT); |
| 361 |
} |
| 362 |
|
| 363 |
psname = argv[0]; argc--; argv++; |
| 364 |
|
| 365 |
#ifndef KPATHSEA |
| 366 |
if (ps_resource(psname)) { |
| 367 |
/* if psname does neither contain a DIRSEP or `.' character |
| 368 |
* then find the filename of this resource in one of the PS |
| 369 |
* resource database(s) available in PSRESOURCEPATH. |
| 370 |
*/ |
| 371 |
char **names, **files; int i, count; |
| 372 |
|
| 373 |
psrespath = path(PSRESOURCEPATH, getenv("PSRESOURCEPATH")); |
| 374 |
if (verbose) msg("PSRESOURCEPATH := %s\n", psrespath); |
| 375 |
|
| 376 |
count = ListPSResourceFiles(psrespath, NULL, |
| 377 |
"FontOutline", psname, &names, &files); |
| 378 |
if (count == 0) |
| 379 |
fatal("No FontOutline resource found for %s\n", psname); |
| 380 |
if (verbose && count > 1) { |
| 381 |
msg("More than one FontOutline resource for %s\n", psname); |
| 382 |
for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]); |
| 383 |
} |
| 384 |
psfile = files[0]; |
| 385 |
if (verbose) msg("Resource <%s>\n", psfile); |
| 386 |
psbasename = psname; |
| 387 |
} |
| 388 |
|
| 389 |
if (psfile != NULL) { |
| 390 |
char **names, **files; int count; |
| 391 |
|
| 392 |
if (afmname == NULL || ps_resource(afmname)) { |
| 393 |
if (afmname == NULL) afmname = psname; |
| 394 |
count = ListPSResourceFiles(psrespath, NULL, |
| 395 |
"FontAFM", afmname, &names, &files); |
| 396 |
if (count == 0) |
| 397 |
fatal("No FontAFM resource found for %s\n", afmname); |
| 398 |
if (verbose && count > 1) { |
| 399 |
msg("More than one FontAFM resource for %s\n", afmname); |
| 400 |
for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]); |
| 401 |
} |
| 402 |
afmfile = files[0]; |
| 403 |
if (verbose) msg("Resource <%s>\n", afmfile); |
| 404 |
} |
| 405 |
else fatal("%s: invalid resource name\n", afmname); |
| 406 |
|
| 407 |
if (encname != NULL) { |
| 408 |
if (!ps_resource(encname)) |
| 409 |
fatal("%s: invalid Encoding resource\n", encname); |
| 410 |
count = ListPSResourceFiles(psrespath, NULL, |
| 411 |
"Encoding", encname, &names, &files); |
| 412 |
if (count == 0) |
| 413 |
fatal("No Encoding resource found for %s\n", encname); |
| 414 |
if (verbose && count > 1) { |
| 415 |
msg("More than one Encoding resource for %s\n", encname); |
| 416 |
for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]); |
| 417 |
} |
| 418 |
encfile = files[0]; |
| 419 |
if (verbose) msg("Resource <%s>\n", encfile); |
| 420 |
} |
| 421 |
} |
| 422 |
else { /* No PS resource database or no resource for type1font */ |
| 423 |
#endif |
| 424 |
#ifdef KPATHSEA |
| 425 |
psfile = kpse_find_file(psname,kpse_type1_format,0); |
| 426 |
if (!psfile) { |
| 427 |
/* kpse_find_file does not look for alternate suffixes */ |
| 428 |
char *altname = newname(psname, ".pfb"); |
| 429 |
psfile = kpse_find_file(altname, kpse_type1_format, 0); |
| 430 |
free(altname); |
| 431 |
} |
| 432 |
if (!psfile) |
| 433 |
fatal("%s: PS file %s not found!\n", kpse_invocation_name, |
| 434 |
psname); |
| 435 |
if (afmname == NULL) |
| 436 |
afmname = newname(psname, ".afm"); |
| 437 |
afmfile = kpse_find_file(afmname,kpse_afm_format,0); |
| 438 |
if (!afmfile) |
| 439 |
fatal("%s: AFM file %s not found!\n", kpse_invocation_name, |
| 440 |
afmname); |
| 441 |
|
| 442 |
if (encname) { |
| 443 |
encfile = kpse_find_file(encname,kpse_enc_format,0); |
| 444 |
if (!encfile) |
| 445 |
fatal("%s: enc file %s not found!\n", kpse_invocation_name, |
| 446 |
encname); |
| 447 |
} |
| 448 |
else |
| 449 |
encfile = NULL; |
| 450 |
printf("psfile = %s\n", psfile); |
| 451 |
printf("afmfile = %s\n", afmfile); |
| 452 |
if (encfile) printf("encfile = %s\n", encfile); |
| 453 |
#else |
| 454 |
t1inputs = path(T1INPUTS, getenv("T1INPUTS")); |
| 455 |
if (verbose) msg("T1INPUTS := %s\n", t1inputs); |
| 456 |
|
| 457 |
psfile = search_file(t1inputs, psname, FATAL); |
| 458 |
if (verbose) msg("Font file <%s>\n", psfile); |
| 459 |
|
| 460 |
if (afmname == NULL) afmname = newname(psfile, ".afm"); |
| 461 |
afmfile = search_file(t1inputs, afmname, FATAL); |
| 462 |
if (verbose) msg("AFM file <%s>\n", afmfile); |
| 463 |
|
| 464 |
/* get encoding when -e<enc> provided */ |
| 465 |
if (encname) { |
| 466 |
encfile = search_file(t1inputs, encname, FATAL); |
| 467 |
if (verbose) msg("Encoding file <%s>\n", encfile); |
| 468 |
} |
| 469 |
#endif |
| 470 |
psbasename = basename(psname, extension(psname)); |
| 471 |
#ifndef KPATHSEA |
| 472 |
} |
| 473 |
#endif |
| 474 |
psfilebn = basename(psfile, NULL); |
| 475 |
|
| 476 |
if (pointsize == 0.0) pointsize = DEFAULTPOINTSIZE; |
| 477 |
if (x_resolution == 0) x_resolution = DEFAULTRES; |
| 478 |
if (y_resolution == 0) y_resolution = x_resolution; |
| 479 |
if (verbose) |
| 480 |
msg("Loading encoding vector from %s ...", |
| 481 |
encname? encname: basename(afmfile, NULL)); |
| 482 |
getenc(&AFM_fontname, &encodingscheme, ev, WX); |
| 483 |
if (efactor != 1.0) |
| 484 |
for (i=0; i < 256; i++) { |
| 485 |
if (ev[i] == NULL) continue; |
| 486 |
WX[i] = WX[i] * efactor + 0.5; |
| 487 |
} |
| 488 |
if (verbose) msg(" done\n"); |
| 489 |
|
| 490 |
if (argc == 1) strcpy(pkname, argv[0]); |
| 491 |
else |
| 492 |
sprintf(pkname, "%s%d.%dpk", psbasename, |
| 493 |
(int) (pointsize + 0.5), x_resolution); |
| 494 |
|
| 495 |
/* next values are needed! */ |
| 496 |
vals.x = x_resolution; |
| 497 |
vals.y = y_resolution; |
| 498 |
vals.point = 10.0 * pointsize + 0.5; /* DECIPOINTS */ |
| 499 |
vals.pixel = pointsize * y_resolution / POINTSPERINCH + 0.5; |
| 500 |
|
| 501 |
if (verbose) msg("Checking type1 font %s ...", psfilebn); |
| 502 |
Type1RegisterFontFileFunctions(); |
| 503 |
if (verbose) msg(" done\n"); |
| 504 |
|
| 505 |
/* next line prevents UNIX core dumps */ |
| 506 |
entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1"; |
| 507 |
if (verbose) |
| 508 |
msg("Creating character glyphs for %s ...", psfilebn); |
| 509 |
rc = Type1OpenScalable(ev, &fontptr, 0, &entry, |
| 510 |
psfile, &vals, 0, 0, efactor, slant); |
| 511 |
if (rc != Succesful) |
| 512 |
fatal("Type1OpenScalable error (result: %d) on %s \n", rc, psfile); |
| 513 |
if (verbose) msg(" done\n"); |
| 514 |
|
| 515 |
pk_open(pkname); |
| 516 |
sprintf(comment, "%s rendered at %f points", psbasename, pointsize); |
| 517 |
cs = pchecksum(ev, WX); |
| 518 |
pk_preamble(comment, pointsize, cs, x_resolution, y_resolution); |
| 519 |
charno = 0; |
| 520 |
if (verbose) msg("Creating %s from %s\n", pkname, psfilebn); |
| 521 |
for (charcode = 0; charcode < 256; charcode++) { |
| 522 |
if (ev[charcode] == NULL) continue; |
| 523 |
glyphcode[0] = charcode; |
| 524 |
(fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs); |
| 525 |
if (count > 0) { |
| 526 |
if (debug) { |
| 527 |
msg("'%03o ", charcode); charno++; |
| 528 |
if (charno == 8) { |
| 529 |
msg("%c", '\n'); charno = 0; |
| 530 |
} |
| 531 |
} |
| 532 |
first_pixel(glyphs[0]); /* assigns W and H */ |
| 533 |
pk_char(charcode, /* charcode */ |
| 534 |
TFMwidth(WX[charcode]), /* TFMwidth */ |
| 535 |
h_escapement(WX[charcode]), /* h_escapement */ |
| 536 |
W, H, /* width and height */ |
| 537 |
- glyphs[0]->metrics.leftSideBearing, /* h_offset */ |
| 538 |
glyphs[0]->metrics.ascent, /* v_offset */ |
| 539 |
next_pixel); /* pixel generator */ |
| 540 |
} |
| 541 |
} |
| 542 |
if (debug) msg("%c", '\n'); |
| 543 |
ps2pk_postamble(psbasename, encodingscheme, |
| 544 |
base_resolution, x_resolution, y_resolution, pointsize, |
| 545 |
ps2pk_args); |
| 546 |
pk_close(); |
| 547 |
exit(0); |
| 548 |
} |
| 549 |
|
| 550 |
/* |
| 551 |
* The checksum should garantee that our PK file belongs to the correct TFM |
| 552 |
* file! Exactly the same as the afm2tfm (dvips5487) calculation. |
| 553 |
*/ |
| 554 |
static uint32_t old_checksum(encoding ev, int width[256]) |
| 555 |
{ |
| 556 |
int i; |
| 557 |
uint32_t s1 = 0, s2 = 0; |
| 558 |
char *p ; |
| 559 |
|
| 560 |
for (i=0; i<256; i++) { |
| 561 |
if (ev[i] == NULL) continue; |
| 562 |
s1 = (s1<<1) ^ width[i]; /* left shift */ |
| 563 |
for (p=ev[i]; *p; p++) |
| 564 |
s2 = s2 * 3 + *p ; |
| 565 |
} |
| 566 |
return (s1<<1) ^ s2 ; |
| 567 |
} |
| 568 |
|
| 569 |
/* |
| 570 |
* The new checksum algorithm. |
| 571 |
*/ |
| 572 |
static uint32_t checksum(encoding ev, int width[256]) |
| 573 |
{ |
| 574 |
int i; |
| 575 |
uint32_t s1 = 0, s2 = 0; |
| 576 |
char *p ; |
| 577 |
|
| 578 |
for (i=0; i<256; i++) { |
| 579 |
if (ev[i] == NULL) continue; |
| 580 |
s1 = ((s1<<1) ^ (s1>>31)) ^ width[i]; /* cyclic left shift */ |
| 581 |
for (p=ev[i]; *p; p++) |
| 582 |
s2 = s2 * 3 + *p ; |
| 583 |
} |
| 584 |
return (s1<<1) ^ s2 ; |
| 585 |
} |
| 586 |
|
| 587 |
static int row, col; |
| 588 |
static int data, bitno; |
| 589 |
static unsigned char *p_data; |
| 590 |
|
| 591 |
static int |
| 592 |
next_pixel(void) |
| 593 |
{ |
| 594 |
int pixel; |
| 595 |
|
| 596 |
while (row < H) { |
| 597 |
if (col++ < W) { |
| 598 |
if (bitno == 0) { data = *p_data++; bitno = 8; } |
| 599 |
pixel = data & 0x80? BLACK: WHITE; |
| 600 |
data <<= 1; bitno--; return pixel; |
| 601 |
} |
| 602 |
col = 0; row++; bitno = 0; |
| 603 |
} |
| 604 |
fatal("Not that many pixels!\n"); |
| 605 |
} |
| 606 |
|
| 607 |
static void |
| 608 |
first_pixel(CharInfoRec *G) |
| 609 |
{ |
| 610 |
row = col = 0; |
| 611 |
p_data = (unsigned char *) G->bits; |
| 612 |
W = G->metrics.rightSideBearing - G->metrics.leftSideBearing; |
| 613 |
H = G->metrics.ascent + G->metrics.descent; |
| 614 |
bitno = 0; |
| 615 |
} |
| 616 |
|
| 617 |
#if 0 |
| 618 |
static void |
| 619 |
print_pixmap(void) |
| 620 |
{ |
| 621 |
int c, r; |
| 622 |
unsigned char *save_p_data; |
| 623 |
|
| 624 |
save_p_data = p_data; |
| 625 |
if (W*H == 0) return; /* easy */ |
| 626 |
for (r = 0; r < H; r++) { |
| 627 |
for (c = 0; c < W; c++) |
| 628 |
if (next_pixel() == BLACK) msg("%c", 'X'); |
| 629 |
else msg("%c", '.'); |
| 630 |
msg("%c", '\n'); |
| 631 |
} |
| 632 |
/* reset data for scanning pixmap */ |
| 633 |
p_data = save_p_data; |
| 634 |
bitno = 0; row = 0; col = 0; |
| 635 |
} |
| 636 |
#endif |
| 637 |
|
| 638 |
/* Next function computes the width as a fix_word. A fix_word is |
| 639 |
an integer representation for fractions. The decimal point is |
| 640 |
left from bit 20. (The method is `stolen' from afm2tfm.) */ |
| 641 |
|
| 642 |
static int32_t |
| 643 |
TFMwidth(int wx) |
| 644 |
{ |
| 645 |
return (((wx / 1000) << 20) + |
| 646 |
(((wx % 1000) << 20) + 500) / 1000) ; |
| 647 |
} |
| 648 |
|
| 649 |
static float HXU = -1.0; /* horizontal pixels per design unit */ |
| 650 |
|
| 651 |
/* the horizontal escapent is the number of pixels to next origin */ |
| 652 |
static int |
| 653 |
h_escapement(int wx) |
| 654 |
{ |
| 655 |
if (HXU == -1.0) |
| 656 |
HXU = (pointsize * x_resolution) / 72270.0; |
| 657 |
return wx * HXU + 0.5; |
| 658 |
} |
| 659 |
|
| 660 |
/* add ps2pk option to string */ |
| 661 |
static void |
| 662 |
add_option(const char *option, const char *value) |
| 663 |
{ |
| 664 |
static char *p_args = NULL; |
| 665 |
|
| 666 |
if (p_args == NULL) { |
| 667 |
p_args = ps2pk_args; |
| 668 |
sprintf(p_args, "%s%s", option, value); |
| 669 |
} |
| 670 |
else |
| 671 |
sprintf(p_args, " %s%s", option, value); |
| 672 |
p_args+= strlen(p_args); |
| 673 |
} |
| 674 |
|
| 675 |
/* Next stuff is needed by type1 rendering functions */ |
| 676 |
|
| 677 |
int CheckFSFormat(int format, int fmask, int *bit, int *Byte, int *scan, |
| 678 |
int *glyph, int *image) |
| 679 |
{ |
| 680 |
*bit = *Byte = 1; |
| 681 |
*glyph = *scan = *image = 1; |
| 682 |
return Successful; |
| 683 |
|
| 684 |
} |
| 685 |
|
| 686 |
intptr_t MakeAtom(const char *p, unsigned int len, int foo) |
| 687 |
{ |
| 688 |
return (intptr_t)p; |
| 689 |
} |
| 690 |
|
| 691 |
#if 0 |
| 692 |
void GetClientResolutions(int *resP) |
| 693 |
{ |
| 694 |
*resP = 0; |
| 695 |
} |
| 696 |
#endif |
| 697 |
|
| 698 |
void *Xalloc(size_t size) |
| 699 |
{ |
| 700 |
void *p; |
| 701 |
p = malloc(size); |
| 702 |
if (p == NULL) fatal("Out of memory\n"); |
| 703 |
return p; |
| 704 |
} |
| 705 |
|
| 706 |
void Xfree(void *p) |
| 707 |
{ |
| 708 |
free(p); |
| 709 |
} |