home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1838 < prev    next >
Internet Message Format  |  1990-12-28  |  31KB

  1. From: clewis@ecicrl.UUCP (Chris Lewis)
  2. Newsgroups: comp.text.desktop,comp.fonts,alt.sources
  3. Subject: TEX PK to HP SFP font conversion (2 of 2)
  4. Message-ID: <852@ecicrl.UUCP>
  5. Date: 17 Sep 90 16:19:11 GMT
  6.  
  7. Shell archive - cut here -
  8. #!/bin/sh
  9. sed -e 's/^X//' > pk2sfp.c <<\!BLOTTO
  10. X/*    Copyright 1985, 1986, 1987, 1988 90/09/17 Chris Lewis
  11. X        All Rights Reserved
  12. X
  13. X    Permission to copy and further distribute is freely given provided
  14. X    this copyright notice remains intact and that this software is not
  15. X    sold for profit.
  16. X
  17. X    Project:    Generic Troff drivers
  18. X    Module:        pk2sfp.c
  19. X    Author:     Chris Lewis
  20. X    Specs:        Generates SFP's from PK's.
  21. X */
  22. X
  23. X#ifndef    lint
  24. Xstatic char SCCSID[] =
  25. X    "@(#)pk2sfp.c 2.2 Copyright 90/09/17 10:50:03 Chris Lewis";
  26. X#endif
  27. X
  28. X#include "defs.h"
  29. X#include "pk.h"
  30. X
  31. X#define    MAXMAP 256
  32. X
  33. Xstruct fontmap {
  34. X    short from;
  35. X    short to;
  36. X} fontmap[MAXMAP], *flast = fontmap, *fp;
  37. X
  38. Xchar emittedyet[256];
  39. X
  40. X#define    NOTSET    32767
  41. X
  42. Xint symset = NOTSET;
  43. Xint style = NOTSET;
  44. Xint strokeweight = NOTSET;
  45. Xint typeface = NOTSET;
  46. Xint fontid = NOTSET;
  47. Xint verbose = 0;
  48. Xint merge = 0;
  49. Xint symbol = 0;
  50. Xint partial = 0;
  51. Xint permanent = 0;
  52. X
  53. Xchar *progname;
  54. X
  55. X#ifdef    PARTIAL
  56. Xextern struct enctab encNormal[], encSymbol[];
  57. X
  58. Xneedchar(font, character)
  59. Xint font;
  60. Xlong character; {
  61. X    register struct enctab *tab;
  62. X    register char *p;
  63. X
  64. X    if (!partial)
  65. X    return(1);
  66. X
  67. X    if (symbol)
  68. X    tab = encSymbol;
  69. X    else
  70. X    tab = encNormal;
  71. X
  72. X    for(; tab->e_name; tab++) {
  73. X    for (p = tab->e_seq; *p; p++)
  74. X        if (((*p) & 0xff) == character)
  75. X        return(1);
  76. X    }
  77. X
  78. X    return(0);
  79. X}
  80. X#else
  81. Xneedchar(font, character)
  82. Xint font;
  83. Xlong character; {
  84. X    return(1);
  85. X}
  86. X#endif
  87. X
  88. Xmain(argc, argv)
  89. Xint argc;
  90. Xchar **argv; {
  91. X    char buf[512];
  92. X    extern int optind;
  93. X    long totalbytes, numbytes;
  94. X    int totalcodes, numcodes;
  95. X
  96. X    extern char *optarg;
  97. X    int i;
  98. X    int c;
  99. X
  100. X    progname = argv[0];
  101. X
  102. X    while((c = getopt(argc, argv, "D:s:t:w:f:i:vmSpP")) != EOF) {
  103. X    switch(c) {
  104. X        case 'D':
  105. X#ifdef    DEBUG
  106. X        setdebug(optarg, "diagnostics");
  107. X        break;
  108. X#else
  109. X        fprintf(stderr, "%s: DEBUG disabled, recompile\n", progname);
  110. X        exit(1);
  111. X#endif
  112. X        case 'P':
  113. X        permanent = 1;
  114. X        break;
  115. X        case 'S':
  116. X        symbol = 1;
  117. X        break;
  118. X        case 'p':
  119. X        partial = 1;
  120. X        break;
  121. X        case 's':
  122. X        symset = ((optarg[0] - '0') << 5) + optarg[1] - 64;
  123. X        break;
  124. X        case 't':
  125. X        style = atoi(optarg);
  126. X        break;
  127. X        case 'w':
  128. X        strokeweight = atoi(optarg);
  129. X        break;
  130. X        case 'f':
  131. X        typeface = atoi(optarg);
  132. X        break;
  133. X        case 'i':
  134. X        fontid = atoi(optarg);
  135. X        break;
  136. X        case 'v':
  137. X        verbose = 1;
  138. X        break;
  139. X        case 'm':
  140. X        merge = 1;
  141. X        break;
  142. X
  143. X        default:
  144. X        fprintf(stderr, "usage: pk2sfp [-Dopts] [<options>] file...\n");
  145. X        fprintf(stderr, "or   : pk2sfp -m [-Dopts] [<options>]");
  146. X        fprintf(stderr, " map file map file ....\n");
  147. X
  148. X        fprintf(stderr, "\t-sna: symset, eg: -s8U\n");
  149. X        fprintf(stderr, "\t-t0|1: style: 0 upright, 1 italic\n");
  150. X        fprintf(stderr, "\t-wn: stroke weight (-7..7)\n");
  151. X        fprintf(stderr, "\t-fn: typeface, eg: 5 is Times Roman\n");
  152. X        fprintf(stderr, "\t-in: prepend fontid n, auto increments\n");
  153. X        fprintf(stderr, "\t-v: verbose - emit actions to stderr\n");
  154. X        fprintf(stderr, "\t-p: only download chars psroff needs\n");
  155. X        fprintf(stderr, "\t-S: font is used for psroff Symbol font\n");
  156. X        fprintf(stderr, "\t-P: mark font as permanent (needs -in)\n");
  157. X        exit(1);
  158. X    }
  159. X    }
  160. X    if (merge)
  161. X    fprintf(stderr, "MERGING fonts\n");
  162. X
  163. X    numbytes = 0;
  164. X
  165. X    for(;argv[optind];optind++) {
  166. X    register struct pkp *pk;
  167. X    register struct pkc *pc;
  168. X
  169. X    numcodes = 0;
  170. X    numbytes = 0;
  171. X
  172. X    strcpy(buf, argv[optind]);
  173. X
  174. X    if (merge && readmerge(buf))
  175. X        continue;
  176. X
  177. X    /* Read the PK file in-core */
  178. X    pk = pk_read(buf);
  179. X
  180. X    /* Overrides */
  181. X    if (symset != NOTSET)
  182. X        pk->pkp_symset = symset;
  183. X    if (style != NOTSET)
  184. X        pk->pkp_style = style;
  185. X    if (strokeweight != NOTSET)
  186. X        pk->pkp_sw = strokeweight;
  187. X    if (typeface != NOTSET)
  188. X        pk->pkp_typeface = typeface;
  189. X
  190. X    if (verbose)
  191. X        if (merge > 1)
  192. X        fprintf(stderr, "Appending %s: ", buf);
  193. X        else
  194. X        fprintf(stderr, "Emitting %s: ", buf);
  195. X
  196. X    /* you want a font ID select? */
  197. X    if (merge <= 1 && fontid != NOTSET) {
  198. X        if (verbose)
  199. X        fprintf(stderr, "fontid %d\n", fontid);
  200. X        printf("\033*c%dD", fontid);
  201. X    } else
  202. X        if (verbose)
  203. X        fprintf(stderr, "no fontid\n");
  204. X
  205. X    if (merge <= 1 && verbose) {
  206. X        fprintf(stderr, "\tsymset: %d%c\n", pk->pkp_symset >> 5,
  207. X        (pk->pkp_symset & 0x1f) + 64);
  208. X        fprintf(stderr, "\ttype: %s\n", pk->pkp_style?"italic":"upright");
  209. X        fprintf(stderr, "\tstroke weight: %d\n", pk->pkp_sw);
  210. X        fprintf(stderr, "\ttypeface: %d\n", pk->pkp_typeface);
  211. X    }
  212. X
  213. X    if (merge <= 1) {
  214. X        /* Emit the SFP header */
  215. X        epk_desc(pk, stdout);
  216. X        numbytes += 2048;
  217. X        numcodes = 0;
  218. X        if (merge == 1)
  219. X        merge++;
  220. X    }
  221. X
  222. X    /* Emit each character */
  223. X    for (i = 0; i < pk->pkp_num; i++) {
  224. X        pc = pk->pkp_list[i];
  225. X        if (merge) {
  226. X        for (fp = fontmap; fp < flast; fp++)
  227. X            if (pc->pkc_char == fp->from) {
  228. X            pc->pkc_char = fp->to;
  229. X            if (emittedyet[(fp->to)&0xff]) {
  230. X                if (verbose)
  231. X                fprintf(stderr,
  232. X                "Skipping %02x (%c) as %02x (%c) from %s\n",
  233. X                fp->from, pchr(fp->from),
  234. X                fp->to, pchr(fp->to), buf);
  235. X                break;
  236. X            }
  237. X            if (verbose)
  238. X                fprintf(stderr,
  239. X                "Emitting %02x (%c) as %02x (%c) from %s\n",
  240. X                fp->from, pchr(fp->from),
  241. X                fp->to, pchr(fp->to), buf);
  242. X            emittedyet[(fp->to)&0xff] = 1;
  243. X            fp->to = 0x00;
  244. X            numbytes += epkc_desc(pc, stdout);
  245. X            numcodes++;
  246. X            break;
  247. X            }
  248. X        } else {
  249. X        DBP((D_FONT,"Downloading char %02x (%c)\n", pc->pkc_char,
  250. X            pchr(pc->pkc_char)));
  251. X        numbytes += epkc_desc(pc, stdout);
  252. X        numcodes++;
  253. X        }
  254. X    }
  255. X                /* added to make fonts permanent */
  256. X                /* ron@mlfarm 6.1.90 */
  257. X
  258. X    if (fontid != NOTSET && permanent)
  259. X        printf("\033*c%dd5F", fontid);
  260. X
  261. X    if (fontid != NOTSET)
  262. X        fontid++;
  263. X
  264. X    /* Clobber in-core PK */
  265. X    pk_destroy(pk);
  266. X
  267. X    totalbytes += numbytes;
  268. X    totalcodes += numcodes;
  269. X    if (verbose)
  270. X        fprintf(stderr, "%s: %d bytes %d codes\n", buf, numbytes, numcodes);
  271. X
  272. X    }
  273. X    if (merge)
  274. X    checkmissing((char *) NULL);
  275. X    if (verbose)
  276. X    fprintf(stderr, "total: %d bytes %d codes\n", totalbytes, totalcodes);
  277. X    exit(0);
  278. X}
  279. X
  280. X/*    similar to strtol */
  281. Xshort
  282. Xcvt(p)
  283. Xregister char *p; {
  284. X    register short ret = 0;
  285. X    int base = 10;
  286. X
  287. X    if (!isdigit(*p) && !*(p+1))
  288. X    return(*p);
  289. X
  290. X    if (*p == '0')
  291. X    if (*(p+1) == 'x' || *(p+1) == 'X') {
  292. X        base = 16;
  293. X        p += 2;
  294. X    } else
  295. X        base = 8;
  296. X    while(*p)
  297. X    ret = ret * base + ccvt(*p++);
  298. X    return(ret);
  299. X}
  300. X
  301. Xccvt(c)
  302. Xint c; {
  303. X    if (isdigit(c))
  304. X    return(c - '0');
  305. X    else if (isupper(c))
  306. X    return(c - 'A' + 10);
  307. X    else if (islower(c))
  308. X    return(c - 'a' + 10);
  309. X    else {
  310. X    fprintf(stderr, "%s: bad digit %c in map file\n", progname, c);
  311. X    exit(1);
  312. X    }
  313. X}
  314. Xpchr(x)
  315. Xint x; {
  316. X    if (isascii(x) && isprint(x))
  317. X    return(x);
  318. X    else
  319. X    return('?');
  320. X}
  321. X
  322. X/*    Reads merge descriptor.  Returns non-zero if not a merge */
  323. Xreadmerge(name)
  324. Xchar *name; {
  325. X    char from[20], to[20];
  326. X    FILE *f = fopen(name, "r");
  327. X    char buffer[512];
  328. X    register char *p;
  329. X    if (!f) {
  330. X    fprintf(stderr, "%s: Can't open %s\n", progname, name);
  331. X    exit(1);
  332. X    }
  333. X    if (!fgets(buffer, sizeof(buffer), f)) {
  334. X    fprintf(stderr, "%s: Nothing in this file? (%s)\n", progname, name);
  335. X    fclose(f);
  336. X    return(0);
  337. X    }
  338. X    if (buffer[0] == '\033' || (buffer[0] & 0xff) == PK_pre) {
  339. X    fclose(f);
  340. X    return(0);
  341. X    }
  342. X    checkmissing(name);
  343. X    flast = fontmap;
  344. X    do {
  345. X    for(p = buffer; *p && isspace(*p); p++);
  346. X    if (!*p || *p == '\n' || *p == '#')
  347. X        continue;
  348. X    switch(sscanf(p, "%s %s", from, to)) {
  349. X        case 0:
  350. X        continue;
  351. X        case 1:
  352. X        strcpy(to, from);
  353. X        break;
  354. X        case 2:
  355. X        if (strcmp(to, "\"") == 0)
  356. X            strcpy(to, from);
  357. X        break;
  358. X    }
  359. X    if (flast - fontmap >= MAXMAP) {
  360. X        fprintf(stderr, "%s: too many map sequences in %s\n", progname,
  361. X        name);
  362. X        exit(1);
  363. X    }
  364. X
  365. X    flast->from = cvt(from);
  366. X    flast->to = cvt(to);
  367. X    flast++;
  368. X    } while (fgets(buffer, sizeof(buffer), f));
  369. X    fclose(f);
  370. X
  371. X#ifdef    DEBUG
  372. X    if (debug&D_FONT) {
  373. X    DBP((D_FONT, "Map from %s map file\n", name));
  374. X    for (fp = fontmap; fp < flast; fp++)
  375. X        DBP((D_FONT, "  %02x (%c) -> %02x (%c)\n",
  376. X        fp->from, pchr(fp->from),
  377. X        fp->to, pchr(fp->to)));
  378. X    }
  379. X#endif
  380. X    return(1);
  381. X}
  382. X
  383. Xcheckmissing(name)
  384. Xregister char *name; {
  385. X    static char lastmap[512];
  386. X    if (!verbose || flast == fontmap)
  387. X    return;
  388. X    for (fp = fontmap; fp < flast; fp++)
  389. X    if (fp->to)
  390. X        fprintf(stderr, "Didn't remap 0x%02x:0%o:%d (%c) in map file %s\n",
  391. X        fp->from, fp->from, fp->from, pchr(fp->from), lastmap);
  392. X    if (name)
  393. X    strcpy(lastmap, name);
  394. X}
  395. !BLOTTO
  396. sed -e 's/^X//' > pktype.c <<\!BLOTTO
  397. X/*    Copyright 1985, 1986, 1987, 1988 16:49:49 Chris Lewis
  398. X        All Rights Reserved
  399. X
  400. X    Permission to copy and further distribute is freely given provided
  401. X    this copyright notice remains intact and that this software is not
  402. X    sold for profit.
  403. X
  404. X    Project:    Generic Troff drivers
  405. X    Module:        pk2sfp.c
  406. X    Author:     Chris Lewis
  407. X    Specs:        prints header info from PK's and SFP's
  408. X */
  409. X
  410. X#ifndef    lint
  411. Xstatic char SCCSID[] =
  412. X    "@(#)pk2sfp.c 2.1 Copyright 90/07/18 16:49:49 Chris Lewis";
  413. X#endif
  414. X#include "defs.h"
  415. X#include "pk.h"
  416. X
  417. Xint firstchar = 0, lastchar = 0xff;
  418. Xint verbose = 0;
  419. Xchar *progname;
  420. Xextern char *mustmalloc();
  421. Xlong pks_malloc;
  422. X
  423. X/*    Dummied out for pk.c */
  424. Xneedchar(a, b)
  425. Xint a, b; {
  426. X    return(1);
  427. X}
  428. X
  429. Xmain(argc, argv)
  430. Xint argc;
  431. Xchar **argv; {
  432. X    int c;
  433. X    extern int optind, getopt();
  434. X    extern char *optarg;
  435. X    register struct pkp *p;
  436. X    struct pkp *pk_read();
  437. X
  438. X    progname = argv[0];
  439. X    while((c = getopt(argc, argv, "D:vf:l:")) != EOF)
  440. X    switch(c) {
  441. X        case 'D':
  442. X#ifdef    DEBUG
  443. X        setdebug(optarg, "diagnostics");
  444. X        break;
  445. X#else
  446. X        fprintf(stderr, "%s: debug not supported recompile with DEBUG\n",
  447. X            progname);
  448. X        exit(1);
  449. X#endif
  450. X        case 'v':
  451. X        verbose = 1;
  452. X        break;
  453. X        case 'f':
  454. X        firstchar = *optarg;
  455. X        break;
  456. X        case 'l':
  457. X        lastchar = *optarg;
  458. X        break;
  459. X        default:
  460. X        fprintf(stderr, "Usage: %s [-f<ch>] [-l<ch>] pk_files\n", progname);
  461. X        exit(1);
  462. X    }
  463. X#ifdef    DEBUG2
  464. X    {
  465. X    struct pkc p;
  466. X    static int8 raster[] = {
  467. X        0xd9, 0xe2, 0x97, 0x2b, 0x1e, 0x22,
  468. X        0x93, 0x24, 0xe3, 0x97, 0x4e, 0x22,
  469. X        0x93, 0x2c, 0x5e, 0x22, 0x97, 0xd9};
  470. X
  471. X    struct ras *r;
  472. X
  473. X    p.pkc_flag = 0x88;
  474. X    p.pkc_dyn_f = 8;
  475. X    p.pkc_pl = 0x1a;
  476. X    p.pkc_char = 4;
  477. X    p.pkc_tfm = 0x09c61c;
  478. X    p.pkc_dx = 0x19;
  479. X    p.pkc_dy = 0;
  480. X    p.pkc_x_off = 0xFE;
  481. X    p.pkc_y_off = 0;
  482. X    p.pkc_height = 0x1d;
  483. X    p.pkc_width = 0x14;
  484. X    p.pkc_pkr = raster;
  485. X    p.pkc_rlen = sizeof(raster);
  486. X    r = pkrast(&p);
  487. X    dumpr(r, p.pkc_height);
  488. X    }
  489. X#endif
  490. X    for (; optind < argc; optind++) {
  491. X    char *filebuf = mustmalloc(strlen(argv[optind]) + 10);
  492. X    register char *cp;
  493. X
  494. X    cp = strrchr(argv[optind], '/');
  495. X
  496. X    if (cp)
  497. X        strcpy(filebuf, cp+1);
  498. X    else
  499. X        strcpy(filebuf, argv[optind]);
  500. X
  501. X    strcat(filebuf, ".D");
  502. X
  503. X    if (diagFile)
  504. X        fclose(diagFile);
  505. X
  506. X    if (!(diagFile = fopen(filebuf, "w"))) {
  507. X        fprintf(stderr, "%s: cannot open filebuf\n");
  508. X        exit(1);
  509. X    }
  510. X    p = pk_read(argv[optind]);
  511. X    pk_dump(p, argv[optind]);
  512. X    pk_destroy(p);
  513. X    free(filebuf);
  514. X    }
  515. X    exit(0);
  516. X}
  517. X
  518. Xpk_dump(p, file)
  519. Xstruct pkp *p;
  520. Xchar *file; {
  521. X    struct pkc *pc;
  522. X
  523. X    fprintf(diagFile, "**********************************************\n");
  524. X    fprintf(diagFile, "File %s:\n", file);
  525. X    fprintf(diagFile, "  Font file type: %s\n",
  526. X    p->pkp_flags&1 ? "PK" : "SFP");
  527. X    fprintf(diagFile, "  Number of characters: %d\n", p->pkp_num);
  528. X    fprintf(diagFile, "  Approximately %d bytes used\n", pks_malloc);
  529. X    fprintf(diagFile, "  Design size: %ld, Native point size: %ld\n",
  530. X    p->pkp_ds, p->pkp_ds / pow2(20));
  531. X    fprintf(diagFile, "  Pointsize normalized to %d DPI: %ld\n",
  532. X    OUTRES, p->pkp_npts);
  533. X    fprintf(diagFile, "  Checksum: %ld\n", p->pkp_cs);
  534. X    fprintf(diagFile, "  hppp: %ld, vppp: %ld\n", p->pkp_hppp, p->pkp_vppp);
  535. X    fprintf(diagFile, "  hor. pixels/point: %f, ver. pixels/point: %f\n",
  536. X    (double) p->pkp_hppp / pow2(16), (double) p->pkp_vppp / pow2(16));
  537. X    fprintf(diagFile,
  538. X    "  Hor. font resolution: %ld, Ver. font resolution: %ld\n",
  539. X    p->pkp_res, (long) ((p->pkp_vppp * POINT / pow2(16)) + .5));
  540. X    fprintf(diagFile,
  541. X    "  Max y offset: %ld, Max descender: %ld, ", p->pkp_bmax, p->pkp_dmax);
  542. X    fprintf(diagFile, "Max width: %ld, Max X offset: %ld\n",
  543. X    p->pkp_wmax, p->pkp_xomax);
  544. X    fprintf(diagFile,
  545. X    "  Kern high: %ld, Kern low: %ld\n", p->pkp_kh, p->pkp_kl);
  546. X    fprintf(diagFile,
  547. X    "  SFP Info: symset: %d%c, style: %d, stroke: %d, typeface: %d\n",
  548. X    (p->pkp_symset & 0x01e0) >> 5, (p->pkp_symset & 0x1f) + '@',
  549. X    p->pkp_style, p->pkp_sw, p->pkp_typeface);
  550. X
  551. X    for (pc = p->pkp_chars; pc; pc = pc->pkc_next) {
  552. X    register int i;
  553. X    if (pc->pkc_char < firstchar || pc->pkc_char > lastchar)
  554. X        continue;
  555. X    fprintf(diagFile, "\nCharacter: %lx (%c), (0%03o), Packet length: %d\n",
  556. X        pc->pkc_char, (char) (isprint(pc->pkc_char) ? pc->pkc_char : '?'),
  557. X        pc->pkc_char, pc->pkc_pl);
  558. X    fprintf(diagFile, "  Flag byte: %d\n", pc->pkc_flag);
  559. X    fprintf(diagFile, "  Dynamic packing variable: %d\n", pc->pkc_dyn_f);
  560. X    fprintf(diagFile, "  TFM width: %d, dx: %d", pc->pkc_tfm, pc->pkc_dx);
  561. X    if (pc->pkc_dy)
  562. X        fprintf(diagFile, " dy: %d\n", pc->pkc_dy);
  563. X    else
  564. X        putc('\n', diagFile);
  565. X    fprintf(diagFile,
  566. X        "  Height: %d, Width: %d, X-offset: %d, Y-offset: %d\n",
  567. X        pc->pkc_height, pc->pkc_width, pc->pkc_x_off, pc->pkc_y_off);
  568. X    if (pc->pkc_rlen) {
  569. X        fprintf(diagFile,
  570. X        "  Raster length: %d, width in pixels: %ld\n", pc->pkc_rlen,
  571. X        pc->pkc_dx / pow2(16));
  572. X        fprintf(diagFile, "  ");
  573. X        for (i = 0; i < 32; i++)
  574. X        if (i >= pc->pkc_rlen)
  575. X            break;
  576. X        else
  577. X            fprintf(diagFile, "%02x", 0xff & pc->pkc_pkr[i]);
  578. X        putc('\n', diagFile);
  579. X    }
  580. X
  581. X    if (pc->pkc_sfpr)
  582. X        fprintf(diagFile, "  SFP length: %d\n", pc->pkc_sfpr->ras_bytes);
  583. X    if (p->pkp_flags&PK_PK) {
  584. X        if (pc->pkc_dyn_f == 14)
  585. X        fprintf(diagFile, "  Bit map character, ");
  586. X        else
  587. X        fprintf(diagFile, "  Packed character, ");
  588. X        switch(pc->pkc_flag & 0x7) {
  589. X        case 7:
  590. X            fprintf(diagFile, "Long form\n");
  591. X            break;
  592. X        case 4: case 5: case 6:
  593. X            fprintf(diagFile, "Extended short form\n");
  594. X            break;
  595. X        default:
  596. X            fprintf(diagFile, "Short form\n");
  597. X        }
  598. X    }
  599. X    if (verbose)
  600. X        rasterdump(pc);
  601. X    }
  602. X}
  603. X
  604. Xrasterdump(pc)
  605. Xstruct pkc *pc; {
  606. X    struct ras *r;
  607. X    register int x, y;
  608. X    extern struct ras *pkrast();
  609. X    r = pkrast(pc);
  610. X    if (r) {
  611. X    fprintf(diagFile, "Character image:\n");
  612. X    dumpr(r, r->ras_height);
  613. X    free(r->ras_raster);
  614. X    free(r);
  615. X    } else
  616. X    fprintf(diagFile, "NULL character image\n");
  617. X}
  618. !BLOTTO
  619. sed -e 's/^X//' > pk2sfp.1 <<\!BLOTTO
  620. X.\"Copyright 1988 by Chris Lewis 90/07/18
  621. X.TH PK2SFP 1 local
  622. X.SH NAME
  623. Xpk2sfp,pk2ditwid,pktype,pk2ps \- PK/SFP format font file handling utilities
  624. X.SH SYNOPSIS
  625. X.B pk2sfp
  626. X.BI "[-D" opts "]"
  627. X.BI "[" options "]"
  628. Xfonts ...
  629. X.br
  630. X.B pk2sfp
  631. X.B -m
  632. X.BI "[-D" opts "]"
  633. X.BI "[" options "]"
  634. Xmap font map font ...
  635. X.br
  636. X.B pk2ditwid
  637. X.BI "[-D" opts "]"
  638. X.B "[-S]"
  639. X.B "[-s]"
  640. Xfiles...
  641. X.br
  642. X.B pktype
  643. X.BI "[-v]"
  644. X.BI "[-f" char "]"
  645. X.BI "[-l" char "]"
  646. X.BI "[-D" opts "]"
  647. Xfiles...
  648. X.br
  649. X.B pk2ps
  650. X.B "[-f]"
  651. X.B "[-v]"
  652. X.BI "[-D" opts "]"
  653. Xfiles...
  654. X.SH DESCRIPTION
  655. XThese programs allow you to manipulate PK and SFP format font files,
  656. Xwhich
  657. X.B psroff
  658. Xcan use with Hewlett Packard Laserjet (or compatible) printers.
  659. XThese programs are usually found in %%LIBDIR%%.
  660. X.SH "Converting SFP and PK files: pk2sfp"
  661. X.P
  662. X.B pk2sfp
  663. Xreads each of its argument files, and converts them into HPLJ format
  664. Xfonts (HP SFP format), and outputs them to standard output sorted
  665. Xin ascending order of character code.
  666. XThe output does not normally contain "SET FONT ID" sequences.
  667. XThis is how HP distributes their fonts on floppies.
  668. X.P
  669. X.B pk2sfp
  670. Xconcatenates all the conversions of the input files together on standard
  671. Xoutput.
  672. X.P
  673. X.B pk2sfp
  674. Xwith the
  675. X.B "-m"
  676. Xoption allows you to merge font files, at the same time changing the
  677. Xencoding.
  678. XMost of the options for simple font conversions apply to
  679. X.B pk2sfp
  680. Xwith the
  681. X.B "-m"
  682. Xoption, but merging is covered more completely in "Merging SFP and PK
  683. Xfonts" below.
  684. X.P
  685. X.B pk2sfp
  686. Xcan read both PK and SFP format files (the latter effectively being a
  687. X``no-op'' conversion - which can be useful for checking format validity
  688. Xand changing header characteristics, see below).
  689. X.P
  690. X.B pk2sfp
  691. Xattempts to infer certain header characteristics by the basename
  692. Xof the input font file name if the input font is PK format.
  693. XThe
  694. X.B psroff
  695. Xnaming convention is:
  696. X.BR path / troffname . pointsize . "[pk|sfp]"
  697. X.sp
  698. X.in +.5i
  699. X.nf
  700. XAll ROMAN8 encodings unless MATH8.
  701. XAll 0 strokeweight, unless Bold.
  702. XAll upright, unless Italic
  703. XAll Roman typeface, unless otherwise specified
  704. X
  705. XR    : Normal Roman
  706. XI    : Italic
  707. XB    : Bold
  708. XS    : MATH8 Symbol
  709. XX    : Bold italic
  710. X\&.X    : <typeface> Bold italic
  711. X\&.I    : <typeface> Italic
  712. X\&.B    : <typeface> Bold
  713. X\&.R    : <typeface> Normal
  714. XH or H.    : Helvetica typeface
  715. XC or C.    : Courier typeface
  716. X          typefaces should be extended.
  717. X.fi
  718. X.in -.5i
  719. X.P
  720. X.B pk2sfp
  721. Xwill pass through SFP characteristics unchanged, unless you change them
  722. Xexplicitly (see below).
  723. X.P
  724. X.SH "Additional options for pk2sfp"
  725. X.P
  726. XThe
  727. X.BI "-s" na
  728. Xoption will set the symbol set.
  729. XEg:
  730. X.B "-s8U"
  731. Xsets the symbol set to "ROMAN8".
  732. X.P
  733. X.BI "-t" "0|1"
  734. Xsets the orientation to ``upright'' (0) or ``italic'' (1).
  735. X.P
  736. X.BI "-w" n
  737. Xsets the stroke weight, 0 is normal, -7 is very light and 7 is very
  738. Xbold.
  739. X-3 and 3 are traditional values.
  740. X.P
  741. X.BI "-f" n
  742. Xsets the typeface to ``n''.
  743. XFor example, Times Roman is ``5''.
  744. X.P
  745. X.BI "-i" n
  746. Xcauses
  747. X.B pk2sfp
  748. Xto emit fontid sequences in front of each downloaded
  749. Xfont, incrementing the id by one for each font, starting with number
  750. X.IR n .
  751. XFor compatibility with
  752. X.B psroff
  753. Xit is suggested that ``n'' be at least 1000.
  754. X.P
  755. XSpecifying
  756. X.B "-v"
  757. Xrequests pk2sfp to tell you what it's doing on stderr.
  758. X.P
  759. XThe
  760. X.B "-S"
  761. Xtells
  762. X.B pk2sfp
  763. Xthat it's dealing with a font intended for
  764. X.BR psroff "'s"
  765. XS font.
  766. XThis has no effect unless
  767. X.B "-p"
  768. Xis specified.
  769. X.P
  770. XThe
  771. X.B "-p"
  772. X("partial downloading") feature indicates to
  773. X.B pk2sfp
  774. Xthat the fonts are intended for use with
  775. X.B psroff
  776. Xand that characters that aren't used by
  777. X.B psroff
  778. X(eg: half of a ROMAN8 font isn't used) will be dropped from the
  779. Xoutput font.
  780. XThe font being read are assumed to be ROMAN8 fonts and the list of
  781. Xvalid characters will correspond to the characters that
  782. X.B psroff
  783. Xneeds from ROMAN8 sets.
  784. XSpecify
  785. X.B "-S"
  786. Xtoo if you want to do this to MATH8 fonts which are intended for
  787. Xthe characters that
  788. X.B psroff
  789. Xneeds from the MATH8 set.
  790. X.P
  791. XThe
  792. X.B "-P"
  793. Xoption tells pk2sfp to mark the fonts it downloads as permanent,
  794. Xwhich means they are not cleared by a software reset, only explicit
  795. Xdeletions or printer power-offs.
  796. XThis option does not do anything unless
  797. X.BI "-i" n
  798. Xspecified as well.
  799. X.P
  800. XPlease note: the tables used to control
  801. X.B "-p"
  802. Xare compiled into
  803. X.BR pk2sfp .
  804. XIf you change the character translations in lj.c or lj.fonts, you
  805. Xwill have to rebuild
  806. X.BR pk2sfp .
  807. XThe partial option should not be used for auxiliary fonts (fonts
  808. Xwhich supply characters not in ROMAN8 or MATH8).
  809. XUse the
  810. X.B "-m"
  811. X(merge) options for creating specialized reduced size font sets for
  812. Xsuch fonts.
  813. X.P
  814. XThe following example shows how you could preload your laserjet
  815. Xwith fonts (in sizes 8, 9, 10, 11 and 12).
  816. XThis demonstrates the use of
  817. Xthe
  818. X.BR -p "," -P ","
  819. Xand
  820. X.B -S
  821. Xoptions to use up as little Laserjet memory as possible.
  822. X(These fonts should be marked ``b'' (builtin) in
  823. X.IR lj.fonts ")."
  824. X.sp
  825. X.in +.25i
  826. X.nf
  827. X F=%%LJF%%
  828. X pk2sfp -pP -i1000 $F/R.[89].pk $F/R.1[0-2].pk | lp
  829. X pk2sfp -SpP -i1006 $F/S.[89].pk $F/S.1[0-2].pk | lp
  830. X.fi
  831. X.in .-25i
  832. X.sp
  833. X.P
  834. XAll of the preceding options take place on all of the fonts specified in
  835. Xthe command line.
  836. XMost of the options perform no sanity checks on their arguments.
  837. XThe reader is cautioned to read the HP manuals before attempting anything
  838. Xfancy with options that affect header descriptors.
  839. X.SH "Merging PK and SFP fonts: pk2sfp -m"
  840. X.P
  841. XThere are a wealth of fonts and font formats in the world.
  842. XPerforming simple conversions between one format and the other would
  843. Xlead to you having a considerably bigger repertoire of fonts.
  844. XRight?
  845. X.P
  846. XWell, not always.
  847. XNot only to the formats change from one font format to another, but
  848. X.B encodings
  849. Xdo too.
  850. XIf you simply converted Knuth's fonts in PK format to SFP and used them
  851. Xon your Laserjet you're bound to be disappointed, because a character in
  852. XKnuth's font isn't necessarily in the same place in standard SFP fonts.
  853. XEg: If you used the hex code 0x7B to print a left brace-bracket (that's
  854. Xwhat it is in ASCII and ROMAN8 fonts right?), you'd find that in Knuth's
  855. XCMR font you'll get a "ff" ligature instead.
  856. XWorse, other ASCII/ROMAN8 characters don't exist in CMR at all.
  857. X.P
  858. XSo, font conversion often needs more than simple format translation
  859. Xto work out the way you want.
  860. X.P
  861. XThe
  862. X.B "-m"
  863. Xoption to
  864. X.B pk2sfp
  865. Xis intended to do just that: take characters from a combination of
  866. Xfonts, change encodings as necessary, and create one output font.
  867. X.BR Psroff "'s"
  868. XHP Laserjet S font is created in this way from four separate PK fonts.
  869. X.P
  870. XThe
  871. X.B "-m"
  872. Xoption to
  873. X.B pk2sfp
  874. Xindicates that preceding each font file specified a map file will be
  875. Xgiven.
  876. XEach font file will be appended together (with only one SFP header)
  877. Xwith the translations specified by the map files and copied to
  878. Xstandard output.
  879. XAny character not mentioned in a map file is not copied.
  880. XThe map file applies to the font files following until overridden
  881. Xby the next map file.
  882. XThe map file specifies the translations with lines of the following format:
  883. X.sp
  884. X.in +.5i
  885. X.nf
  886. Xfrom  to  description
  887. X.fi
  888. X.in -.5i
  889. X.sp
  890. X.P
  891. X.I From
  892. Xspecifies the character in the font file to be selected.
  893. XAny character that doesn't match a ``from'' line will not be
  894. Xcopied to the output.
  895. X.I To
  896. Xspecifies what character number the ``from'' character should be
  897. Xchanged to.
  898. XIf ``to'' is omitted, it is assumed to be the same as ``from''.
  899. XThe description is free form text and is ignored.
  900. XFrom, to and description are separated by white space.
  901. XEmpty lines or lines beginning with "#" are comments.
  902. X.P
  903. X``From'' and ``to'' can be specified in any of the following formats:
  904. Xa single non-numeric character other than ``#'',
  905. Xa decimal number starting with a non-zero digit,
  906. Xan octal number consisting of a zero digit followed by numeric digits,
  907. Xor hexadecimal consisting of a zero digit, followed by 'x' or 'X', followed
  908. Xby digits and upper or lower case 'a' through 'f'.
  909. XIf the ``to'' string is a single double quote ("), it is duplicated
  910. Xfrom the ``from'' string.
  911. XThe error checking isn't very exhaustive, so it is recommended that you
  912. Xuse the
  913. X.B -v
  914. Xoption to check things.
  915. XThe
  916. X.B -v
  917. Xoption will also give you a very verbose description of what characters
  918. Xits translating and what characters it couldn't find.
  919. X.P
  920. XThere are some examples of this in the source tree for
  921. X.B psroff ,
  922. Xthat generate a ROMAN8 and MATH8 SFP in 10 points.
  923. XLook in utils/Makefile for ``testmerge'', utils/maps contains some
  924. Xuseful translation maps, and utils/fonts contains a few PK files for
  925. Xyour experimentation.
  926. X.B Psroff
  927. Xis shipped with PK format font files that were created by use of this
  928. Xutility.
  929. X.SH "Creating width tables: pk2ditwid"
  930. X.P
  931. X.B pk2ditwid
  932. Xis used to generate a ditroff format width table file (used by
  933. X.B psroff
  934. Xwidth table installation via
  935. X.B gfnttab
  936. Xand
  937. X.BR dit2catwid )
  938. Xfrom PK or SFP font files.
  939. XThe output files are generated in the current directory with the
  940. Xsame name as the basename of the input files, with a ".WID"
  941. Xsuffix.
  942. X.P
  943. XThe
  944. X.B -S
  945. Xoption indicates to
  946. X.B pk2ditwid
  947. Xthat the font file is a
  948. XPK or SFP used for the symbol font, otherwise
  949. X.B pk2ditwid
  950. Xassumes that it is a normal font.
  951. X.P
  952. XThe
  953. X.B -s
  954. Xoption tells
  955. X.B pk2ditwid
  956. Xto shut up and do the best it can.
  957. XOrdinarily
  958. X.B pk2ditwid
  959. Xis extremely chatty about which characters it could find etc.,
  960. Xwhich is rarely of major interest to the user.
  961. XWhich is why
  962. X.BR psroff "'s"
  963. Xinstallation script puts
  964. X.BR pk2ditwid "'s"
  965. Xoutput in log files and makes no attempt to show them to the user.
  966. X.P
  967. X.BR pk2ditwid "'s"
  968. Xexact operation is somewhat bizarre, the following is a simplified
  969. Xdescription:
  970. X.P
  971. XNormally,
  972. X.B psroff
  973. Xworks with pure ROMAN8 and MATH8
  974. Xencoded fonts for normal and symbol font sets respectively.
  975. X(ROMAN8 and MATH8 are two of HP's standard "char-to-glyph" mapping tables).
  976. XHowever,
  977. XThe MATH8 and ROMAN8 encodings do not exactly reflect CAT
  978. X.BI troff 's
  979. Xdivisions of characters.
  980. XIn
  981. X.BR troff2ps 's
  982. Xbackend drivers, there are tables that correspond to CAT normal and symbol,
  983. Xwhich are indexed by CAT code to select which HP font and character sequence
  984. Xshould be emitted by the backend to print a specific CAT character.
  985. X.P
  986. XMost CAT codes are single HP characters, but a few are done by concatenation
  987. X(for example \e(34 may be) or overstrike
  988. X(\e(co may be).
  989. X.P
  990. X.B pk2ditwid
  991. Xuses the backend tables and reads each of the font files given as arguments.
  992. XIt then generates a ditroff-like width table that contains width information
  993. Xfor each sequence of HP characters needed to generate a CAT character.
  994. XThe width tables are fairly simple, and contain three fields of principle
  995. Xinterest:
  996. X.P
  997. XColumn one is the CAT
  998. X.B troff
  999. Xcharacter name.
  1000. XSingle characters are themselves, dual characters are prefixed by "\e("
  1001. Xin
  1002. X.BR troff .
  1003. X.P
  1004. XThe second column indicates the width of that character in 1/300th's of an
  1005. Xinch when the character is printed at 10 points.
  1006. X(Which are the default
  1007. X.BR gfnttab / dit2catwid
  1008. Xsettings)
  1009. X.P
  1010. XThe third column is the kerning information, and is a number formed
  1011. Xby or'ing a 1 and/or 2 together.
  1012. XA ``1'' denotes an descender (eg: ``g''),
  1013. Xand a ``2'' denotes a character with an ascender (eg: ``k'').
  1014. X.P
  1015. XPlease note this is only ditroff-\f3like\fP \(em the output is not
  1016. Xintended to go through real
  1017. X.B makedev
  1018. Xwhich will probably complain about multiple-character emit sequences and
  1019. Xmissing directives.
  1020. X.P
  1021. XThe wierdness comes from the fact that it's possible to override the
  1022. XCAT character to HP sequence translation by adding directives to the
  1023. X.I lj.fonts
  1024. Xfile but the sequences are built-in (so I'm lazy...) to
  1025. X.BR pk2ditwid .
  1026. XIf you choose to add in translation overrides to
  1027. X.IR lj.fonts ,
  1028. Xyou will have to recompile
  1029. X.B pk2ditwid
  1030. Xand rerun the width table build and install procedures
  1031. Xto recompute and install the new width tables.
  1032. XThe Makefile uses the
  1033. X.B troff2ps
  1034. Xbinary to generate a compileable table of translation sequences, using
  1035. Xboth the built-in backend map plus the
  1036. X.I lj.fonts
  1037. Xoverride you've specified,
  1038. Xplus the mkenctab shell script to generate the pk2ditwid tables.
  1039. XThis is so durn complicated, that I simply automated it all:
  1040. Xin the
  1041. X.B psroff
  1042. Xsource directory area, change
  1043. X.B lib/lj.fonts
  1044. Xto reflect the translations you need,
  1045. Xand rebuild and reinstall
  1046. X.BR psroff .
  1047. X.P
  1048. XIf you're just adding new fonts to
  1049. X.BR psroff 's
  1050. Xrepertoire, this isn't all necessary, just install the fonts into
  1051. X%%LJF%% (using the proper naming convention),
  1052. Xupdate
  1053. X.IR lj.fonts ,
  1054. Xand go into the widths source directory and type ``make ljwidths widths''
  1055. Xthen su to root and ``make installwidths''.
  1056. X.P
  1057. X.B pk2ditwid
  1058. Xneed only be run on one font in each family, and by default, the build
  1059. Xprocedure runs
  1060. X.B pk2ditwid
  1061. Xonce each font (in the size closest to 10) that it finds in the
  1062. X%%LJF%% directory.
  1063. X.SH "Examining PK and SFP font files: pktype"
  1064. X.P
  1065. X.B pktype
  1066. Xreads PK and SFP format files and generates files suffixed with ".D"
  1067. Xwhich contain a description of the font and each character.
  1068. XIf the
  1069. X.B "-v"
  1070. Xoption is specified, an approximation of the character image is displayed
  1071. Xtoo.
  1072. XThe
  1073. X.BI "-f" char
  1074. Xand
  1075. X.BI "-l" char
  1076. Xoptions allow you to specify a range of characters to print, where
  1077. Xthe
  1078. X.B -f
  1079. Xspecifies the first character, and
  1080. X.B -l
  1081. Xspecifies the last character.
  1082. X.SH "Displaying PK and SFP font files: pk2ps"
  1083. X.P
  1084. X.B pk2ps
  1085. Xtakes each of the specified files and generates bitmap Postscript
  1086. Xfonts and appends to each commands to draw a table.
  1087. XThe table contains each character in the font, and below it are
  1088. Xdecimal, hexidecimal and octal numbers representing the character code.
  1089. XThe output of
  1090. X.B pk2ps
  1091. Xis on standard output.
  1092. X.P
  1093. XThe
  1094. X.B -f
  1095. Xoption causes
  1096. X.B pk2ps
  1097. Xto omit the table printing commands and some of the extra Postscript, leaving
  1098. Xonly the Postscript font definition.
  1099. XThe resultant output can then be used as a Postscript font (via inclusion
  1100. Xin ps.lib etc.).
  1101. XThe font is named for the basename of the filename.
  1102. X``<path>/cmr10.358pk'' will be called ``cmr10''.
  1103. XThe font is supposedly properly scaled, so Postscript ``scalefont'' will
  1104. Xwork normally and generate the size font you expect.
  1105. XWarning: this uses bitmapped fonts: displaying these characters at
  1106. Xconsiderably
  1107. Xlarger sizes or at odd multiples of the ``true'' size (the size of the
  1108. Xexample is actually 10 * 358 / 300) may lead to some objectionable
  1109. Xjaggies.
  1110. X.P
  1111. XIn all four utilities, the
  1112. X.BI "-D" opts
  1113. Xoption allows you to turn on debugging.
  1114. XSee
  1115. X.BR troff2ps (1)
  1116. Xfor further information.
  1117. XNote: if DEBUG compiled out, this will not be available.
  1118. X.SH FILES
  1119. X.if t .ta 2.5i
  1120. X.if n .ta 3.5i
  1121. X%%LJF%%    troff2ps LJ font directory.
  1122. X.br
  1123. X%%LIBDIR%%/lib/lj.fonts    LJ font definitions and translation overrides.
  1124. X    not read by pk2sfp/pktype/pk2ditwid
  1125. X.SH "BUGS"
  1126. X.B pk2sfp
  1127. Xshould really have multiple output files when requested by an option.
  1128. X.B pk2ditwid
  1129. Xand
  1130. X.B pk2sfp
  1131. Xshould be able to read the
  1132. X.I lj.fonts
  1133. Xfile instead of being recompiled.
  1134. X.B pk2ditwid
  1135. Xonly understands backspace or character concatenation sequences
  1136. X(eg: "a\010b" or "ab"),
  1137. Xany translation that contains any other escape sequence will not be
  1138. Xparsed properly and may generate bizarre widths, though it will
  1139. Xbe moderately sane if all of the characters in the escape sequence
  1140. Xare nonprintable (or not in the font file).
  1141. XSuch escape sequences may also affect operation of
  1142. X.B pk2sfp "'s"
  1143. Xpartial downloading feature (by including characters that you don't
  1144. Xreally need - which is harmless).
  1145. X.SH "SEE ALSO"
  1146. Xtroff2ps(1L), \fIlj.fonts\fP,
  1147. XHewlett Packard's HP Laserjet Reference Manuals.
  1148. X.SH AUTHOR
  1149. XWritten by Chris Lewis
  1150. !BLOTTO
  1151. -- 
  1152. Chris Lewis, Phone: (416)-294-9253
  1153. UUCP: uunet!utai!lsuc!ecicrl!clewis
  1154. Moderator of the Ferret Mailing List (ferret-request@eci386)
  1155. Psroff mailing list (psroff-request@eci386)
  1156.