home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume19 / dvi / part03 < prev    next >
Encoding:
Text File  |  1991-05-14  |  44.0 KB  |  1,814 lines

  1. Newsgroups: comp.sources.misc
  2. From: Parag Patel <parag@hpsdeb.sde.hp.com>
  3. Subject:  v19i066:  dvi - C++ DVI filter for HP LaserJets, Part03/03
  4. Message-ID: <1991May14.182326.14349@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: c63465dae9cfa0208ce45f0719ca45f9
  6. Date: Tue, 14 May 1991 18:23:26 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Parag Patel <parag@hpsdeb.sde.hp.com>
  10. Posting-number: Volume 19, Issue 66
  11. Archive-name: dvi/part03
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 03 of dvi
  16. # ============= pkfont.C ==============
  17. if test -f 'pkfont.C' -a X"$1" != X"-c"; then
  18.     echo 'x - skipping pkfont.C (File already exists)'
  19. else
  20. echo 'x - extracting pkfont.C (Text)'
  21. sed 's/^X//' << 'SHAR_EOF' > 'pkfont.C' &&
  22. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  23. static const char rcsid[] = "$Header: pkfont.C,v 1.21 91/02/22 15:58:17 hmgr Exp $";
  24. X
  25. // read font data from the METAFONT PK (packed font) files
  26. //
  27. // by Parag Patel
  28. X
  29. #include "defs.h"
  30. X
  31. X
  32. // these are for "drawing" an image of a character in a font
  33. const int WHITE = FALSE;
  34. const int BLACK = TRUE;
  35. X
  36. X
  37. // return a string containing the magnification sub-directory for the
  38. // requested magnification
  39. // 
  40. char *pkmagdir(Dirlist &dirlist, long mag)
  41. {
  42. X    // look for the closest resolution value to the one desired
  43. X    int ent = -1;
  44. X    long diff = MAXLONG;
  45. X
  46. X    for (int i = 0; i < dirlist.size(); i++)
  47. X    {
  48. X    long magval = dirlist[i].val;
  49. X    if (strchr(dirlist[i].name, '.') == NULL)
  50. X    {
  51. X        magval *= 1000;
  52. X        magval /= RESOLUTION;
  53. X    }
  54. X
  55. X    long d = mag - magval;
  56. X    long newdiff = d < 0 ? -d : d;    // absolute value
  57. X    if (newdiff < diff)
  58. X    {
  59. X        diff = newdiff;
  60. X        ent = i;
  61. X    }
  62. X    }
  63. X    debug(7, "PK dir ent=%s  diff=%ld  mag=%ld",
  64. X        ent < 0 ? "" : dirlist[ent].name, diff, mag);
  65. X
  66. X    // we should be within 1/32 (~3%) of the desired mag value
  67. X    if (ent < 0 || diff > (mag >> 5))
  68. X    return "";
  69. X
  70. X    // return the new value as a string, if there was one
  71. X    return dirlist[ent].name;
  72. }
  73. X
  74. X
  75. // setup a PK font file in memory
  76. //
  77. void setuppkfont(font &f, FILE *fp)
  78. {
  79. X    // skip the comment
  80. X    int len = (unsigned)getuval(1, fp);
  81. X    while (len-- > 0)
  82. X    (void)getuval(1, fp);
  83. X
  84. X    // get and verify that the design size is ok - the PK file stores
  85. X    // this value as a "fix_word" value while the DVI file keeps it as
  86. X    // a "scaled-point" value - also note that the "basename" pointer
  87. X    // is NULL only for the "dumpfont" main program
  88. X
  89. X    long dsize = getsval(4, fp);
  90. X    debug(4, "PK designsize=%ld", dsize);
  91. X    if (f.basename != NULL && dsize >> 4 != f.designsize)
  92. X    if (dochecksum && dsize != 0 && f.designsize != 0)
  93. X        quit("Designsize in DVI and PK file %s does not match", f.path);
  94. X    else
  95. X        warn("Designsize in DVI and PK file %s does not match", f.path);
  96. X
  97. X    // check the checksum
  98. X    long check = getuval(4, fp);
  99. X    debug(5, "PK checksum=%ld", check);
  100. X    if (f.basename != NULL && check != f.checksum)
  101. X    if (dochecksum && check != 0 && f.checksum != 0)
  102. X        quit("Checksums in DVI and PK file %s do not match", f.path);
  103. X    else
  104. X        warn("Checksums in DVI and PK file %s do not match", f.path);
  105. X
  106. X    // get the horizontal and vertical pixels per point values
  107. X    f.hppp = getuval(4, fp);
  108. X    f.vppp = getuval(4, fp);
  109. X
  110. X    debug(3, "mag=%ld  hppp=%ld vppp=%ld", f.mag, f.hppp, f.vppp);
  111. X
  112. X    f.minm = MAXLONG;
  113. X    f.maxm = -MAXLONG;
  114. X    f.minn = MAXLONG;
  115. X    f.maxn = -MAXLONG;
  116. X
  117. X    // now initialize the info for each character in this font
  118. X    int op;
  119. X    while ((op = (int)getuval(1, fp)) != PKPOST)
  120. X    {
  121. X    switch (op)
  122. X    {
  123. X        // special opcodes - just ignore for now
  124. X    case PKXXX1:
  125. X        skipbytes(getuval(1, fp), fp);
  126. X        continue;
  127. X    case PKXXX2:
  128. X        skipbytes(getuval(2, fp), fp);
  129. X        continue;
  130. X    case PKXXX3:
  131. X        skipbytes(getuval(3, fp), fp);
  132. X        continue;
  133. X    case PKXXX4:
  134. X        skipbytes(getuval(4, fp), fp);
  135. X        continue;
  136. X
  137. X        // special numeric opcode - also ignored
  138. X    case PKYYY:
  139. X        (void)getuval(4, fp);
  140. X        continue;
  141. X
  142. X    case PKNOOP:
  143. X        continue;
  144. X    default:
  145. X        ;
  146. X    }
  147. X
  148. X    // save the location of this character in the file
  149. X    long floc = ftell(fp) - 1;
  150. X
  151. X    if (op > PKCHAR)
  152. X        quit("Illegal opcode %d in PK file %s", op, f.path);
  153. X
  154. X    int flag = op;
  155. X    int size = (flag & 0x04) ? 2 : 1;
  156. X    int addtolen = flag & 0x03;
  157. X    if ((flag & 0x07) == 0x07)
  158. X        size = 4;
  159. X
  160. X    long packetlen, charcode;
  161. X
  162. X    switch (size)
  163. X    {
  164. X    Case 1:
  165. X        packetlen = getuval(1, fp) + (addtolen << 8);
  166. X        charcode = getuval(1, fp);
  167. X
  168. X    Case 2:
  169. X        packetlen = getuval(2, fp) + (addtolen << 16);
  170. X        charcode = getuval(1, fp);
  171. X
  172. X    Case 4:
  173. X        packetlen = getuval(4, fp);
  174. X        charcode = getuval(4, fp);
  175. X
  176. X    Default:
  177. X        quit("?!?Eh?  Internal error - size must be 1, 2, or 4.");
  178. X    }
  179. X
  180. X    if (charcode >= MAXCHARS)
  181. X        quit("Char %ld too big in PF file %s", charcode, f.path);
  182. X    fontchar & g = f.chr[charcode];
  183. X
  184. X    // save the location of the character data in the file
  185. X    g.floc = floc;
  186. X
  187. X    double tfmwidth;
  188. X    long width, height, hoff, voff;
  189. X
  190. X    switch (size)
  191. X    {
  192. X    Case 1:
  193. X        tfmwidth = Getuval(3, fp);
  194. X        g.dx = getuval(1, fp) << 16;
  195. X        g.dy = 0;
  196. X        width = getuval(1, fp);
  197. X        height = getuval(1, fp);
  198. X        hoff = getsval(1, fp);
  199. X        voff = getsval(1, fp);
  200. X        packetlen -= 8;
  201. X
  202. X    Case 2:
  203. X        tfmwidth = Getuval(3, fp);
  204. X        g.dx = getuval(2, fp) << 16;
  205. X        g.dy = 0;
  206. X        width = getuval(2, fp);
  207. X        height = getuval(2, fp);
  208. X        hoff = getsval(2, fp);
  209. X        voff = getsval(2, fp);
  210. X        packetlen -= 13;
  211. X
  212. X    Case 4:
  213. X        tfmwidth = Getsval(4, fp);
  214. X        g.dx = getuval(4, fp);
  215. X        g.dy = getuval(4, fp);
  216. X        width = getuval(4, fp);
  217. X        height = getuval(4, fp);
  218. X        hoff = getsval(4, fp);
  219. X        voff = getsval(4, fp);
  220. X        packetlen -= 28;
  221. X
  222. X    Default:
  223. X        quit("?!?Eh?  Internal error - size must be 1, 2, or 4.");
  224. X    }
  225. X
  226. X    // calculate character min/max boundaries
  227. X    g.minm = -hoff;
  228. X    g.maxm = width - hoff;
  229. X    g.minn = voff - height + 1;
  230. X    g.maxn = voff;
  231. X
  232. X    // set the size limits of the characters in this font
  233. X    if (g.minm < f.minm)
  234. X        f.minm = g.minm;
  235. X    if (g.maxm > f.maxm)
  236. X        f.maxm = g.maxm;
  237. X    if (g.minn < f.minn)
  238. X        f.minn = g.minn;
  239. X    if (g.maxn > f.maxn)
  240. X        f.maxn = g.maxn;
  241. X
  242. X    // calculate the scaled points width from the pixel width
  243. X    g.width = (double)tfmwidth / (double)16 * (double)f.designsize /
  244. X    (double)65536L * (double)f.mag / 1000.0;
  245. X
  246. X    // skip the character data and go to the next char
  247. X    if (fseek(fp, packetlen, SEEK_CUR) < 0)
  248. X        quit("Cannot seek past character data in %s", f.path);
  249. X    }
  250. }
  251. X
  252. X
  253. static long packetlen = 0;
  254. X
  255. X
  256. // return a nybble (4-bit value) from a file - reset ourselves
  257. // if we are called with a NULL file - return the upper nybble
  258. // of a byte first and then the lower - as a side-effect, we decrement
  259. // the packetlen count for every byte read from the file
  260. //
  261. static int getnyb(FILE *fp)
  262. {
  263. X    static boolean nybsave = FALSE;
  264. X    static int nybdata = 0;
  265. X
  266. X    packetlen--;
  267. X    if (fp == NULL || nybsave)
  268. X    {
  269. X    nybsave = FALSE;
  270. X    return nybdata & 0x0F;
  271. X    }
  272. X    nybsave = TRUE;
  273. X    nybdata = (unsigned)getuval(1, fp);
  274. X    return nybdata >> 4;
  275. }
  276. X
  277. X
  278. X
  279. static int dynf = 0;
  280. static int repeat = 0;
  281. X
  282. X
  283. // get a packed run-count value from a file using getnyb() above - 
  284. // assumes that dynf above is initialized to a reasonable value
  285. //
  286. static int getpacked(FILE *fp)
  287. {
  288. X    int i = getnyb(fp);
  289. X    if (i == 0)
  290. X    {
  291. X    if (packetlen <= 0)
  292. X        return 0;
  293. X    int j;
  294. X    do
  295. X    {
  296. X        j = getnyb(fp);
  297. X        i++;
  298. X    } while (j == 0);
  299. X    while (i-- > 0)
  300. X        j = (j << 4) + getnyb(fp);
  301. X    return j - 15 + ((13 - dynf) << 4) + dynf;
  302. X    }
  303. X    if (i <= dynf)
  304. X    return i;
  305. X    if (i < 14)
  306. X    return ((i - dynf - 1) << 4) + getnyb(fp) + dynf + 1;
  307. X    if (i == 14)
  308. X    repeat = getpacked(fp);
  309. X    else
  310. X    repeat = 1;
  311. X    return getpacked(fp);
  312. }
  313. X
  314. X
  315. X
  316. // load the specified character "ch" from the PK file - we read this
  317. // character's PK commands to build a bitmap of the character in memory
  318. // 
  319. void getpkchar(font &f, fontchar &g, int ch)
  320. {
  321. X    // go to the file where this character is defined
  322. X    if (fseek(f.fp, g.floc, SEEK_SET) < 0)
  323. X    quit("Cannot fseek to start of font in %s", f.path);
  324. X    FILE *fp = f.fp;
  325. X
  326. X    // reset our get-nybble function
  327. X    (void)getnyb(NULL);
  328. X
  329. X    int flag = (unsigned)getuval(1, fp);
  330. X    if (flag > PKCHAR)
  331. X    quit("Illegal flag value %d in PK file %s", flag, f.path);
  332. X
  333. X    // set up globals for getpacked() above
  334. X    dynf = flag >> 4;
  335. X
  336. X    int size = (flag & 0x04) ? 2 : 1;
  337. X    long addtolen = flag & 0x03;
  338. X    if ((flag & 0x07) == 0x07)
  339. X    size = 4;
  340. X
  341. X    long charcode;
  342. X
  343. X    switch (size)
  344. X    {
  345. X    Case 1:
  346. X    packetlen = getuval(1, fp) + (addtolen << 8);
  347. X    charcode = getuval(1, fp);
  348. X
  349. X    Case 2:
  350. X    packetlen = getuval(2, fp) + (addtolen << 16);
  351. X    charcode = getuval(1, fp);
  352. X
  353. X    Case 4:
  354. X    packetlen = getuval(4, fp);
  355. X    charcode = getuval(4, fp);
  356. X
  357. X    Default:
  358. X    quit("?!?Eh?  Internal error - size must be 1, 2, or 4");
  359. X    }
  360. X
  361. X    if (charcode != ch)
  362. X    quit("?!?Eh?  Internal error - expected charcode for %d here", ch);
  363. X
  364. X    long dx, dy, tfmwidth, width, height, hoff, voff;
  365. X
  366. X    switch (size)
  367. X    {
  368. X    Case 1:
  369. X    tfmwidth = getuval(3, fp);
  370. X    dx = getuval(1, fp) << 16;
  371. X    dy = 0;
  372. X    width = getuval(1, fp);
  373. X    height = getuval(1, fp);
  374. X    hoff = getsval(1, fp);
  375. X    voff = getsval(1, fp);
  376. X    packetlen -= 8;
  377. X
  378. X    Case 2:
  379. X    tfmwidth = getuval(3, fp);
  380. X    dx = getuval(2, fp) << 16;
  381. X    dy = 0;
  382. X    width = getuval(2, fp);
  383. X    height = getuval(2, fp);
  384. X    hoff = getsval(2, fp);
  385. X    voff = getsval(2, fp);
  386. X    packetlen -= 13;
  387. X
  388. X    Case 4:
  389. X    tfmwidth = getuval(4, fp);
  390. X    dx = getuval(4, fp);
  391. X    dy = getuval(4, fp);
  392. X    width = getuval(4, fp);
  393. X    height = getuval(4, fp);
  394. X    hoff = getsval(4, fp);
  395. X    voff = getsval(4, fp);
  396. X    packetlen -= 28;
  397. X
  398. X    Default:
  399. X    quit("?!?Eh?  Internal error - size must be 1, 2, or 4.");
  400. X    }
  401. X    {
  402. X    int len;
  403. X    const char *x = dev_char2dev(ch, len);
  404. X    debug(5, "char=%d(%s)  minm=%ld maxm=%ld  minn=%ld maxn=%ld",
  405. X        ch, x, g.minm, g.maxm, g.minn, g.maxn);
  406. X    debug(5, "    dx=%ld dy=%ld  dx/=%ld dy/=%ld  width=%ld/%f  height=%ld",
  407. X        dx, dy, dx >> 16, dy >> 16, width, g.width, height);
  408. X    debug(5, "    hoff=%ld voff=%ld  len=%ld  flag=%d  dyn_f=%d",
  409. X        hoff, voff, packetlen, flag, dynf);
  410. X    }
  411. X
  412. X    if (dynf < 0 || dynf > 14)
  413. X    quit("?!?Eh?  dyn_f value must be 0-14 inclusive - not %d", dynf);
  414. X
  415. X    // initialize the character painting variables
  416. X    register long m = 0;
  417. X    register long n = height - 1;
  418. X    int p = (flag & 0x08) ? BLACK : WHITE;
  419. X
  420. X    // clear the global fontbits for the bitmap
  421. X    for (long d = n; d >= 0; d--)
  422. X    fontbits[d]->clear();
  423. X
  424. X    // paint the fontbits to build this character
  425. X    if (dynf < 14)
  426. X    {
  427. X    // packed data
  428. X    repeat = 0;
  429. X    packetlen <<= 1;
  430. X    while (packetlen > 0)
  431. X    {
  432. X        int count = getpacked(fp);
  433. X        while (count-- > 0)
  434. X        {
  435. X        if (p)
  436. X            *fontbits[n] += m;
  437. X        if (++m >= width)
  438. X        {
  439. X            long r = n--;
  440. X            n -= repeat;
  441. X            m = 0;
  442. X            for (; repeat > 0; repeat--)
  443. X            *fontbits[r - repeat] = *fontbits[r];
  444. X            repeat = 0;
  445. X        }
  446. X        }
  447. X        p = !p;
  448. X    }
  449. X    for (; repeat > 0; repeat--)
  450. X        *fontbits[n - repeat] = *fontbits[n];
  451. X    }
  452. X    else
  453. X    {
  454. X    // straight bit-map
  455. X    while (packetlen-- > 0)
  456. X    {
  457. X        int byte = (unsigned)getuval(1, fp);
  458. X        for (int mask = 0x0080; mask != 0; mask >>= 1)
  459. X        {
  460. X        if (byte & mask)
  461. X            *fontbits[n] += m;
  462. X        if (++m >= width)
  463. X        {
  464. X            n--;
  465. X            m = 0;
  466. X        }
  467. X        }
  468. X    }
  469. X    }
  470. }
  471. SHAR_EOF
  472. chmod 0444 pkfont.C ||
  473. echo 'restore of pkfont.C failed'
  474. Wc_c="`wc -c < 'pkfont.C'`"
  475. test 10380 -eq "$Wc_c" ||
  476.     echo 'pkfont.C: original size 10380, current size' "$Wc_c"
  477. fi
  478. # ============= bitvec.C ==============
  479. if test -f 'bitvec.C' -a X"$1" != X"-c"; then
  480.     echo 'x - skipping bitvec.C (File already exists)'
  481. else
  482. echo 'x - extracting bitvec.C (Text)'
  483. sed 's/^X//' << 'SHAR_EOF' > 'bitvec.C' &&
  484. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  485. static const char rcsid[] = "$Header: bitvec.C,v 1.5 91/02/22 15:58:31 hmgr Exp $";
  486. X
  487. // An array of bits
  488. //
  489. // By  Parag Patel
  490. X
  491. #include <stdio.h>
  492. #include "bitvec.h"
  493. X
  494. X
  495. // the following are machine-dependant - change them if necessary
  496. // sizeof long == 32 bits == 2**5 --> 5, therefore ...
  497. const int NUM = 32;
  498. const int SHIFT = 5;
  499. const int MASK = 0x1F;
  500. const unsigned long EMPTY = 0L;
  501. X
  502. X
  503. // generic minimum function
  504. inline long MIN(long i1, long i2)
  505. {
  506. X    return i1 < i2 ? i1 : i2;
  507. }
  508. X
  509. // this determines which particular "long" in the array has this element
  510. inline long ELT(long e)
  511. {
  512. X    return e >> SHIFT;
  513. }
  514. X
  515. // this gets the bit position in a "long" for this vec element
  516. inline unsigned long BIT(long e)
  517. {
  518. X    return ((unsigned long)(1L << (e & MASK)));
  519. }
  520. X
  521. // this adds an element to an array of longs
  522. inline void ADD(unsigned long *elts, long e)
  523. {
  524. X    elts[ELT(e)] |= BIT(e);
  525. }
  526. X
  527. X
  528. // return a new vec of elts - clear it
  529. static unsigned long *newelts(long largest)
  530. {
  531. X    register unsigned long *elts = new unsigned long[ELT(largest) + 1];
  532. X
  533. X    for (register long i = ELT(largest); i >= 0; i--)
  534. X    elts[i] = EMPTY;
  535. X    return elts;
  536. }
  537. X
  538. // bump the size of a vec
  539. void Bitvec::bumpsize(long largest)
  540. {
  541. X    if (largest <= num)
  542. X    return;
  543. X
  544. X    // only re-allocate our array if we are out of ELTs
  545. X    if (ELT(largest) != ELT(num))
  546. X    {
  547. X    register unsigned long *ne = newelts(largest);
  548. X    for (register long i = ELT(num); i >= 0; i--)
  549. X        ne[i] = elts[i];
  550. X    delete elts;
  551. X    elts = ne;
  552. X    }
  553. X    num = largest;
  554. }
  555. X
  556. // various constructors:
  557. X
  558. // make a new vec of the specified size
  559. Bitvec::Bitvec(long size)
  560. {
  561. X    if (size <= 1)
  562. X        size = 1;
  563. X    elts = newelts(num = size - 1);
  564. }
  565. X
  566. // dup a vec
  567. Bitvec::Bitvec(const Bitvec &s)
  568. {
  569. X    elts = newelts(num = s.num);
  570. X    for (register long i = ELT(s.num); i >= 0; i--)
  571. X    elts[i] = s.elts[i];
  572. }
  573. X
  574. // assign a vec to a vec - also a dup
  575. Bitvec &Bitvec::operator=(const Bitvec &s)
  576. {
  577. X    register long i, t;
  578. X
  579. X    BUMPSIZE(s.num);
  580. X    for (i = t = ELT(s.num); i >= 0; i--)
  581. X    elts[i] = s.elts[i];
  582. X    for (i = ELT(num); i > t; i--)
  583. X    elts[i] = EMPTY;
  584. X    return *this;
  585. }
  586. X
  587. X
  588. // add an element to a vec
  589. Bitvec &Bitvec::add(long elt)
  590. {
  591. X    if (elt < 0)
  592. X    return *this;
  593. X    BUMPSIZE(elt);
  594. X    elts[ELT(elt)] |= BIT(elt);
  595. X    return *this;
  596. }
  597. X
  598. // delete an element from a vec
  599. Bitvec &Bitvec::remove(long elt)
  600. {
  601. X    if (elt < 0)
  602. X    return *this;
  603. X    elts[ELT(elt)] &= ~BIT(elt);
  604. X    return *this;
  605. }
  606. X
  607. // is vec same as s?
  608. boolean Bitvec::operator==(const Bitvec &s) const
  609. {
  610. X    register long i = MIN(num, s.num);
  611. X
  612. X    for (i = ELT(i); i >= 0; i--)
  613. X    if (elts[i] != s.elts[i])
  614. X        return FALSE;
  615. X    if (num == s.num)
  616. X    return TRUE;
  617. X
  618. X    register long t;
  619. X    if (num < s.num)
  620. X    {
  621. X    for (t = ELT(num), i = ELT(s.num); i > t; i--)
  622. X        if (s.elts[i])
  623. X        return FALSE;
  624. X    }
  625. X    else
  626. X    {
  627. X    for (t = ELT(s.num), i = ELT(num); i > t; i--)
  628. X        if (elts[i])
  629. X        return FALSE;
  630. X    }
  631. X    return TRUE;
  632. }
  633. X
  634. X
  635. // return the number of elements in the vec (cardinality)
  636. long Bitvec::size() const
  637. {
  638. X    register long n = 0;
  639. X
  640. X    for (register long i = ELT(num); i >= 0; i--)
  641. X    for (register unsigned long m = 1; m; m <<= 1)
  642. X        if (elts[i] & m)
  643. X        n++;
  644. X    return n;
  645. }
  646. X
  647. // clear the vec of all elements
  648. void Bitvec::clear()
  649. {
  650. X    for (register long i = ELT(num); i >= 0; i--)
  651. X    elts[i] = EMPTY;
  652. }
  653. SHAR_EOF
  654. chmod 0444 bitvec.C ||
  655. echo 'restore of bitvec.C failed'
  656. Wc_c="`wc -c < 'bitvec.C'`"
  657. test 3331 -eq "$Wc_c" ||
  658.     echo 'bitvec.C: original size 3331, current size' "$Wc_c"
  659. fi
  660. # ============= hp2684.h ==============
  661. if test -f 'hp2684.h' -a X"$1" != X"-c"; then
  662.     echo 'x - skipping hp2684.h (File already exists)'
  663. else
  664. echo 'x - extracting hp2684.h (Text)'
  665. sed 's/^X//' << 'SHAR_EOF' > 'hp2684.h' &&
  666. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  667. // $Header: hp2684.h,v 1.10 91/02/22 15:58:37 hmgr Exp $
  668. X
  669. // HP2684 LaserJet 2000 device-specific definitions.
  670. // The LaserJet 2000 Reference Manual should be consulted for more
  671. // information on the various constants.
  672. //
  673. // by Parag Patel
  674. X
  675. X
  676. class HP2684 : public HP33447
  677. {
  678. protected:
  679. X    HP2684(int maxf, int maxc, int maxpg, int maxld, int res,
  680. X            int ho, int vo, int fhmn, int fhmx, int fvmn,
  681. X            int fvmx, int fwd, int fhg, char *deffp) :
  682. X        HP33447(maxf, maxc, maxpg, maxld, res, ho, vo,
  683. X        fhmn, fhmx, fvmn, fvmx, fwd, fhg, deffp) { }
  684. public:
  685. X    HP2684();
  686. };
  687. SHAR_EOF
  688. chmod 0444 hp2684.h ||
  689. echo 'restore of hp2684.h failed'
  690. Wc_c="`wc -c < 'hp2684.h'`"
  691. test 632 -eq "$Wc_c" ||
  692.     echo 'hp2684.h: original size 632, current size' "$Wc_c"
  693. fi
  694. # ============= hp33440.h ==============
  695. if test -f 'hp33440.h' -a X"$1" != X"-c"; then
  696.     echo 'x - skipping hp33440.h (File already exists)'
  697. else
  698. echo 'x - extracting hp33440.h (Text)'
  699. sed 's/^X//' << 'SHAR_EOF' > 'hp33440.h' &&
  700. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  701. // $Header: hp33440.h,v 1.8 91/02/22 15:58:41 hmgr Exp $
  702. X
  703. // LaserJetII series device-specific definitions.
  704. // The LaserJetII Reference Manual should be consulted for more
  705. // information on the various constants.
  706. //
  707. // by Parag Patel
  708. X
  709. X
  710. // LaserJetII
  711. //
  712. class HP33440 : public HP2686
  713. {
  714. protected:
  715. X    HP33440(int maxf, int maxc, int maxpg, int maxld, int res,
  716. X            int ho, int vo, int fhmn, int fhmx, int fvmn, int fvmx,
  717. X            int fwd, int fhg, char *deffp) :
  718. X    HP2686(maxf, maxc, maxpg, maxld, res, ho, vo,
  719. X        fhmn, fhmx, fvmn, fvmx, fwd, fhg, deffp) { }
  720. public:
  721. X    HP33440();
  722. };
  723. X
  724. X
  725. // LaserJetIID - does double-sided but is otherwise identical to the II
  726. //
  727. class HP33447 : public HP33440
  728. {
  729. protected:
  730. X    HP33447(int maxf, int maxc, int maxpg, int maxld, int res,
  731. X            int ho, int vo, int fhmn, int fhmx, int fvmn,
  732. X            int fvmx, int fwd, int fhg, char *deffp);
  733. public:
  734. X    HP33447();
  735. X    ~HP33447();
  736. X    void newpage(boolean odd, boolean first);
  737. };
  738. SHAR_EOF
  739. chmod 0444 hp33440.h ||
  740. echo 'restore of hp33440.h failed'
  741. Wc_c="`wc -c < 'hp33440.h'`"
  742. test 1015 -eq "$Wc_c" ||
  743.     echo 'hp33440.h: original size 1015, current size' "$Wc_c"
  744. fi
  745. # ============= hp2686.h ==============
  746. if test -f 'hp2686.h' -a X"$1" != X"-c"; then
  747.     echo 'x - skipping hp2686.h (File already exists)'
  748. else
  749. echo 'x - extracting hp2686.h (Text)'
  750. sed 's/^X//' << 'SHAR_EOF' > 'hp2686.h' &&
  751. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  752. // $Header: hp2686.h,v 1.13 91/02/22 15:58:47 hmgr Exp $
  753. X
  754. // HP2686 LaserJet+ device-specific definitions.
  755. // The LaserJet+ Reference Manual should be consulted for more
  756. // information on the various constants.
  757. //
  758. // by Parag Patel
  759. X
  760. X
  761. class HP2686 : public Device
  762. {
  763. protected:
  764. X    HP2686(int maxf, int maxc, int maxpg, int maxld, int res,
  765. X            int ho, int vo, int fhmn, int fhmx, int fvmn, int fvmx,
  766. X            int fwd, int fhg, char *deffp);
  767. X    void downljchar(font &f, fontchar &g, int ch);
  768. public:
  769. X    HP2686();
  770. X    ~HP2686();
  771. X
  772. X    const char *char2dev(int ch, int &len);
  773. X    long sp2dev(double sp);
  774. X    double dev2sp(long pix);
  775. X
  776. X    void newpage(boolean odd, boolean first);
  777. X    void downchar(font &f, fontchar &g, int ch);
  778. X    void bigchar(font &f, fontchar &g, int ch);
  779. X    void movehv(long h, long v);
  780. X    void moveh(long);
  781. X    void movev(long);
  782. X    void push();
  783. X    void pop();
  784. X    void delfont(font &);
  785. X    void newfont(font &);
  786. X    void usefont(font &);
  787. X    void rule(double v, double h);
  788. };
  789. X
  790. #define HP2686_FPATH "/usr/lib/tex/fontbits/laser:/usr/lib/tex/fnt:/usr/local/tex/fontbits/laser"
  791. X
  792. // about 1 inch from both margins - tweaked until TeX test comes out right
  793. // when printed to a LaserJet - lots of fun with unprintable regions!
  794. #define HP2686_HOFFSET 245
  795. #define HP2686_VOFFSET 300
  796. SHAR_EOF
  797. chmod 0444 hp2686.h ||
  798. echo 'restore of hp2686.h failed'
  799. Wc_c="`wc -c < 'hp2686.h'`"
  800. test 1357 -eq "$Wc_c" ||
  801.     echo 'hp2686.h: original size 1357, current size' "$Wc_c"
  802. fi
  803. # ============= defs.h ==============
  804. if test -f 'defs.h' -a X"$1" != X"-c"; then
  805.     echo 'x - skipping defs.h (File already exists)'
  806. else
  807. echo 'x - extracting defs.h (Text)'
  808. sed 's/^X//' << 'SHAR_EOF' > 'defs.h' &&
  809. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  810. // $Header: defs.h,v 1.22 91/02/22 15:58:55 hmgr Exp $
  811. X
  812. // Header file for a C++ TeX DVI filter.
  813. // Strangely enough, this file should be device-INdependent.
  814. // 
  815. // by Parag Patel
  816. X
  817. X
  818. // This program takes as input the DVI file generated by TeX or LaTeX
  819. // and converts it to a device-specific format that is used to actually
  820. // typeset (print) the document.  The device-specific info should be in
  821. // the files "dev.h" and "dev.c".  The HP2686 LaserJet+ is currently
  822. // supported, but others should be fairly easy to add, unless the code
  823. // isn't as device-indenpendent as it was intended to be.
  824. //
  825. // The DVI file format is described in the book "TeX: The Program" by
  826. // Donald E. Knuth (of course) pp. 234-243.  This program also uses the
  827. // GF (Generic Font) format files to determine what to download to the
  828. // device/printer. This format is described in the book
  829. // "METAFONT: The Program" by Donald E. Knuth pp. 484-489.  Both these
  830. // books should be used to determine exactly what the code is supposed
  831. // to be doing.  The various number formats are also described in
  832. // these books.
  833. X
  834. X
  835. // some standard include files
  836. #include <stdio.h>
  837. #include <stdlib.h>
  838. #include <ctype.h>
  839. #include <string.h>
  840. #include <math.h>
  841. #include <sys/types.h>
  842. #ifndef __ZTC__
  843. #   include <sys/param.h>
  844. #   include <unistd.h>
  845. #endif
  846. #if !defined(BSD) && !defined(__ZTC__)
  847. #   include <values.h>
  848. #endif
  849. X
  850. #ifdef __ZTC__
  851. X    extern "C" int getopt(int, const char**, const char*);
  852. #   define    NUMOPENFILES 7
  853. #endif
  854. X
  855. #ifdef MSDOS
  856. #   define    PATHSEP    ';'
  857. #   define    F_READ    "rb"
  858. #endif
  859. #ifndef PATHSEP
  860. #    define    PATHSEP    ':'
  861. #endif
  862. X
  863. #ifndef    NUMOPENFILES
  864. #   define    NUMOPENFILES 5
  865. #endif
  866. #ifndef MAXLONG
  867. #   define MAXLONG 0x7FFFFFFFL
  868. #endif
  869. #ifndef MAXPATHLEN
  870. #   define MAXPATHLEN 64
  871. #endif
  872. #ifndef SEEK_SET
  873. #   define SEEK_SET 0
  874. #   define SEEK_CUR 1
  875. #   define SEEK_END 2
  876. #endif
  877. #ifndef _NFILE
  878. #   define _NFILE 20
  879. #endif
  880. #ifndef F_READ
  881. // for fopen(), because of POS-ICKS adding "rb" instead of "rt"
  882. #   define    F_READ    "r"
  883. #endif
  884. X
  885. // handy macros for large switch statements
  886. #define Case break;case
  887. #define Default break;default
  888. X
  889. X
  890. // DVI-file specific id and tail filler bytes
  891. const int ID = 2;
  892. const int FILLER = 223;
  893. X
  894. // DVI file opcodes - thoroughly described in "TeX: The Program"
  895. enum opcodes
  896. {
  897. X    SET0 = 0,        // typeset range of characters
  898. X    SET127 = 127,
  899. X
  900. X    SET1 = 128,        // typeset char and move cursor
  901. X    SET2 = 129,
  902. X    SET3 = 130,
  903. X    SET4 = 131,
  904. X    SETRULE = 132,        // typeset a rule & move cursor
  905. X
  906. X    PUT1 = 133,        // just typeset a character
  907. X    PUT2 = 134,
  908. X    PUT3 = 135,
  909. X    PUT4 = 136,
  910. X    PUTRULE = 137,        // typeset rule
  911. X
  912. X    NOOP = 138,
  913. X
  914. X    BOP = 139,        // Beginning Of Page
  915. X    EOP = 140,        // End Of Page
  916. X    PUSH = 141,        // push internal DVI stack
  917. X    POP = 142,        // pop DVI stack
  918. X
  919. X    RIGHT1 = 143,        // move cursor right/left
  920. X    RIGHT2 = 144,
  921. X    RIGHT3 = 145,
  922. X    RIGHT4 = 146,
  923. X
  924. X    W0 = 147,        // move right/left using W DVI var
  925. X    W1 = 148,
  926. X    W2 = 149,
  927. X    W3 = 150,
  928. X    W4 = 151,
  929. X
  930. X    X0 = 152,        // move right/left using X var
  931. X    X1 = 153,
  932. X    X2 = 154,
  933. X    X3 = 155,
  934. X    X4 = 156,
  935. X
  936. X    DOWN1 = 157,        // move cursor down/up
  937. X    DOWN2 = 158,
  938. X    DOWN3 = 159,
  939. X    DOWN4 = 160,
  940. X
  941. X    Y0 = 161,        // move down/up using Y var
  942. X    Y1 = 162,
  943. X    Y2 = 163,
  944. X    Y3 = 164,
  945. X    Y4 = 165,
  946. X
  947. X    Z0 = 166,        // move down/up using Z var
  948. X    Z1 = 167,
  949. X    Z2 = 168,
  950. X    Z3 = 169,
  951. X    Z4 = 170,
  952. X
  953. X    FONT0 = 171,        // use a new font - range version
  954. X    FONT63 = 234,
  955. X
  956. X    FNT1 = 235,        // use a new font
  957. X    FNT2 = 236,
  958. X    FNT3 = 237,
  959. X    FNT4 = 238,
  960. X
  961. X    XXX1 = 239,        // special - user defined
  962. X    XXX2 = 240,
  963. X    XXX3 = 241,
  964. X    XXX4 = 242,
  965. X
  966. X    FNTDEF1 = 243,        // define a font
  967. X    FNTDEF2 = 244,
  968. X    FNTDEF3 = 245,
  969. X    FNTDEF4 = 246,
  970. X
  971. X    PRE = 247,        // preamble
  972. X    POST = 248,        // start of postamble
  973. X    POSTPOST = 249,        // end of postamble
  974. };
  975. X
  976. X
  977. // this describes which pages exist in the DVI file
  978. struct pageinfo
  979. {
  980. X    long page;
  981. X    long section;
  982. X    long loc;
  983. };
  984. X
  985. // this describes which pages (or page ranges) that we wish to print
  986. struct pagespec
  987. {
  988. X    long page, endpage;
  989. X    long section, endsection;
  990. };
  991. X
  992. X
  993. // other include files for this program
  994. #include "boolean.h"
  995. #include "bitvec.h"
  996. #include "darray.h"
  997. #include "dev.h"
  998. #include "font.h"
  999. #include "dirs.h"
  1000. X
  1001. // all other misc externs are here to keep 'em together
  1002. #include "extern.h"
  1003. SHAR_EOF
  1004. chmod 0444 defs.h ||
  1005. echo 'restore of defs.h failed'
  1006. Wc_c="`wc -c < 'defs.h'`"
  1007. test 4214 -eq "$Wc_c" ||
  1008.     echo 'defs.h: original size 4214, current size' "$Wc_c"
  1009. fi
  1010. # ============= extern.h ==============
  1011. if test -f 'extern.h' -a X"$1" != X"-c"; then
  1012.     echo 'x - skipping extern.h (File already exists)'
  1013. else
  1014. echo 'x - extracting extern.h (Text)'
  1015. sed 's/^X//' << 'SHAR_EOF' > 'extern.h' &&
  1016. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1017. // $Header: extern.h,v 1.24 91/02/22 15:59:02 hmgr Exp $
  1018. X
  1019. // externs for various LaserJet+ DVI filter functions
  1020. //
  1021. // by Parag Patel
  1022. X
  1023. // misc. dynamic array types
  1024. declare_array(Pageinfo, pageinfo);
  1025. declare_array(Pagespec, pagespec);
  1026. X
  1027. class fontptr
  1028. {
  1029. public:
  1030. X    font *ptr;
  1031. X    fontptr() { ptr = NULL; }
  1032. X    operator font*() { return ptr; }
  1033. X    font *operator->() { return ptr; }
  1034. X    font *operator=(font *p) { return ptr = p; }
  1035. };
  1036. declare_array(Fontlist, fontptr);
  1037. X
  1038. // globals.C
  1039. extern char *fontpath;
  1040. extern char *dviinput;
  1041. extern int debuglevel;
  1042. extern boolean verbose;
  1043. extern boolean dochecksum;
  1044. extern char *devname;
  1045. extern boolean reverse;
  1046. extern boolean landscape;
  1047. extern boolean duplexv;
  1048. extern boolean duplexh;
  1049. extern boolean duparg;
  1050. extern long usermag;
  1051. extern font *currfont;
  1052. extern Fontlist fontlist;
  1053. extern Bitvec **fontbits;
  1054. extern double H, V, W, X, Y, Z;
  1055. extern void init_globals();
  1056. extern void fini_globals();
  1057. X
  1058. // util.C
  1059. extern void debug(int, char *, ...);
  1060. extern void mesg(char *, ...);
  1061. extern void warn(char *, ...);
  1062. extern void error(char *, ...);
  1063. extern void quit(char *, ...);
  1064. extern long getuval(int, FILE *);
  1065. extern long getsval(int, FILE *);
  1066. extern void skipbytes(long num, FILE *fp);
  1067. extern FILE *fopenp(char *path, char *file, char *type);
  1068. X
  1069. // stack.C
  1070. extern void pushdvi();
  1071. extern void popdvi();
  1072. extern void cleardvi();
  1073. X
  1074. // fonts.C
  1075. extern void clearfonts();
  1076. extern void definefont(FILE*, long, long);
  1077. extern void newfont(long);
  1078. extern void makecurrent(boolean force = FALSE);
  1079. extern void special(FILE*, long);
  1080. extern void typeset(long, boolean, double);
  1081. extern void typerule(FILE*, boolean, double);
  1082. X
  1083. // dirs.C
  1084. extern Pathlist pathlist;
  1085. extern void setupdirs(char *path);
  1086. X
  1087. // readfont.C
  1088. extern void setupfont(font &);
  1089. extern void downchar(int ch, boolean toomany);
  1090. extern void dumpbits(int);
  1091. X
  1092. // gffont.C
  1093. extern void setupgffont(font &f, FILE *fp);
  1094. extern void getgfchar(font &f, fontchar &g, int);
  1095. extern char *gfmagdir(Dirlist &, long mag);
  1096. X
  1097. // pkfont.C
  1098. extern void setuppkfont(font &f, FILE *fp);
  1099. extern void getpkchar(font &f, fontchar &g, int);
  1100. extern char *pkmagdir(Dirlist &, long mag);
  1101. X
  1102. // dvi.C
  1103. extern void dodvi(FILE *, Pagespec&);
  1104. X
  1105. X
  1106. // convienient inlines - these would otherwise would have to go elsewhere
  1107. X
  1108. inline char *strnew(size_t len) { return (char*)malloc(len + 1); }
  1109. inline void  strfree(char *s) { if (s != NULL) free((void *)s); }
  1110. inline char *strdup(const char *s)
  1111. X    { return s != NULL ? strcpy((char*)malloc(strlen(s) + 1), s) : NULL; }
  1112. inline boolean streq(const char *s1, const char *s2)
  1113. X    { return (strcmp(s1, s2) == 0) ? TRUE: FALSE; }
  1114. X
  1115. inline double Getsval(int n, FILE *fp)
  1116. {
  1117. X    return double(getsval(n, fp));
  1118. }
  1119. X
  1120. inline double Getuval(int n, FILE *fp)
  1121. {
  1122. X    return double(getuval(n, fp));
  1123. }
  1124. X
  1125. inline void movedown(double m)
  1126. {
  1127. X    V += m;
  1128. }
  1129. X
  1130. inline void moveright(double m)
  1131. {
  1132. X    H += m;
  1133. }
  1134. SHAR_EOF
  1135. chmod 0444 extern.h ||
  1136. echo 'restore of extern.h failed'
  1137. Wc_c="`wc -c < 'extern.h'`"
  1138. test 2904 -eq "$Wc_c" ||
  1139.     echo 'extern.h: original size 2904, current size' "$Wc_c"
  1140. fi
  1141. # ============= dirs.h ==============
  1142. if test -f 'dirs.h' -a X"$1" != X"-c"; then
  1143.     echo 'x - skipping dirs.h (File already exists)'
  1144. else
  1145. echo 'x - extracting dirs.h (Text)'
  1146. sed 's/^X//' << 'SHAR_EOF' > 'dirs.h' &&
  1147. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1148. // $Header: dirs.h,v 1.6 91/02/22 15:59:05 hmgr Exp $
  1149. X
  1150. // for reading font directory names into memory for fast traversal
  1151. //
  1152. // by Parag Patel
  1153. X
  1154. #ifndef    _D_I_R_S_
  1155. #define    _D_I_R_S_
  1156. X
  1157. X
  1158. struct Dirent
  1159. {
  1160. X    char *name;
  1161. X    long val;
  1162. X
  1163. X    Dirent();
  1164. };
  1165. declare_array(Dirlist, Dirent);
  1166. X
  1167. X
  1168. struct Pathent
  1169. {
  1170. X    char *path;
  1171. X    Dirlist dirs;
  1172. X
  1173. X    Pathent();
  1174. X    Pathent &operator=(Pathent &x);
  1175. };
  1176. declare_array(Pathlist, Pathent);
  1177. X
  1178. X
  1179. X
  1180. #endif /* _D_I_R_S_ */
  1181. SHAR_EOF
  1182. chmod 0444 dirs.h ||
  1183. echo 'restore of dirs.h failed'
  1184. Wc_c="`wc -c < 'dirs.h'`"
  1185. test 506 -eq "$Wc_c" ||
  1186.     echo 'dirs.h: original size 506, current size' "$Wc_c"
  1187. fi
  1188. # ============= font.h ==============
  1189. if test -f 'font.h' -a X"$1" != X"-c"; then
  1190.     echo 'x - skipping font.h (File already exists)'
  1191. else
  1192. echo 'x - extracting font.h (Text)'
  1193. sed 's/^X//' << 'SHAR_EOF' > 'font.h' &&
  1194. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1195. // $Header: font.h,v 1.13 91/02/22 15:59:11 hmgr Exp $
  1196. X
  1197. // describe fonts
  1198. //
  1199. // by Parag Patel
  1200. X
  1201. X
  1202. // X and Y are cartesian coordinates
  1203. // sp == scaled points == points * 2^16
  1204. // si == scaled integer == num * 2^16
  1205. // spx == scaled pixels == pixels * 2^16
  1206. // pix == pixels (whatever they are for a device)
  1207. X
  1208. X
  1209. // This is what a character in a METAFONT file should look like.
  1210. // 
  1211. class fontchar
  1212. {
  1213. public:
  1214. X    boolean downloaded;        // is char currently in printer?
  1215. X    boolean charbig;        // is char too big for printer?
  1216. X    long dx;            // X spx displacement for typesetting
  1217. X    long dy;            // Y spx delta
  1218. X    double width;        // sp width to move after typesetting
  1219. X    long minm;            // start X pix coord for char
  1220. X    long maxm;            // end X   - these describe the box
  1221. X    long minn;            // start Y - that this character should
  1222. X    long maxn;            // end Y   - fit within
  1223. X    long floc;            // file pointer to start of char data
  1224. };
  1225. X
  1226. X
  1227. // this describes a particular font that TeX wishes to use - it is
  1228. // information from the DVI file and the GF file
  1229. // 
  1230. class font
  1231. {
  1232. public:
  1233. X    int type;            // GF or PK ID value
  1234. X    long checksum;        // in both DVI and font files
  1235. X    long scaledsize;        // scaled font size in sp
  1236. X    long designsize;        // design size in sp (DVI & font)
  1237. X    long mag;            // magnification calculated from above
  1238. X    char *path;            // path name to font file
  1239. X    char *basename;        // basename of above for messages
  1240. X    boolean onpage;        // is font on the current page?
  1241. X    boolean toomany;        // too many fonts on page - reload this one
  1242. X    boolean downloaded;        // is font currently downloaded?
  1243. X    boolean setup;        // is font setup in memory?
  1244. X    long use;            // use count - least recently used 
  1245. X    long num;            // number of this font
  1246. X    long hppp;            // horizontal pixels per point (si)
  1247. X    long vppp;            // vertical pixels per point
  1248. X    long minm;            // smallest X in this font
  1249. X    long maxm;            // largest X  - used to for gross char sizing
  1250. X    long minn;            // smallest Y - when allocating memory for
  1251. X    long maxn;            // largest Y  - building bitmap images
  1252. X    FILE *fp;
  1253. X    fontchar *chr;
  1254. X
  1255. X    font();
  1256. X    ~font();
  1257. };
  1258. X
  1259. X
  1260. // current GF ID byte and FILLER byte values
  1261. const int GFID        = 131;
  1262. const int GFILLER    = 223;
  1263. X
  1264. // opcodes in a GF file
  1265. // 
  1266. enum gfcodes
  1267. {
  1268. X    PAINT0 = 0,        // range of paint commands
  1269. X    PAINT63 = 63,
  1270. X
  1271. X    PAINT1 = 64,        // paint a row of pixels
  1272. X    PAINT2 = 65,
  1273. X    PAINT3 = 66,
  1274. X
  1275. X    BOC = 67,        // Beginning Of a Character description
  1276. X    BOC1 = 68,
  1277. X    EOC = 69,        // End Of Character
  1278. X
  1279. X    SKIP0 = 70,        // vertical skip
  1280. X    SKIP1 = 71,
  1281. X    SKIP2 = 72,
  1282. X    SKIP3 = 73,
  1283. X
  1284. X    NEWROW0 = 74,        // another vertical skip (range)
  1285. X    NEWROW164 = 238,
  1286. X
  1287. X    FXXX1 = 239,        // special (user definable)
  1288. X    FXXX2 = 240,
  1289. X    FXXX3 = 241,
  1290. X    FXXX4 = 242,
  1291. X
  1292. X    YYY = 243,        // also special
  1293. X
  1294. X    FNOOP = 244,        // noop!
  1295. X
  1296. X    CHARLOC = 245,        // character locators
  1297. X    CHARLOC0 = 246,
  1298. X
  1299. X    FPRE = 247,        // preamble
  1300. X    FPOST = 248,        // start of postamble
  1301. X    FPOSTPOST = 249,    // end of postamble
  1302. };
  1303. X
  1304. X
  1305. // current PK identification byte value
  1306. const int PKID    = 89;
  1307. X
  1308. // PK font file opcodes & special values
  1309. enum pkcodes
  1310. {
  1311. X    PKCHAR = 239,
  1312. X
  1313. X    PKXXX1 = 240,
  1314. X    PKXXX2 = 241,
  1315. X    PKXXX3 = 242,
  1316. X    PKXXX4 = 243,
  1317. X    PKYYY = 244,
  1318. X    PKPOST = 245,
  1319. X    PKNOOP = 246,
  1320. X    PKPRE = 247,
  1321. X
  1322. X    PKREPEAT = 14,
  1323. X    PKREPEAT1 = 15,
  1324. X    PKRUNLARGE = 0,
  1325. X    PKRUNBEGIN = 1,
  1326. X    PKRUNEND = 13,
  1327. };
  1328. SHAR_EOF
  1329. chmod 0444 font.h ||
  1330. echo 'restore of font.h failed'
  1331. Wc_c="`wc -c < 'font.h'`"
  1332. test 3299 -eq "$Wc_c" ||
  1333.     echo 'font.h: original size 3299, current size' "$Wc_c"
  1334. fi
  1335. # ============= dev.h ==============
  1336. if test -f 'dev.h' -a X"$1" != X"-c"; then
  1337.     echo 'x - skipping dev.h (File already exists)'
  1338. else
  1339. echo 'x - extracting dev.h (Text)'
  1340. sed 's/^X//' << 'SHAR_EOF' > 'dev.h' &&
  1341. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1342. // $Header: dev.h,v 1.17 91/02/22 15:59:17 hmgr Exp $
  1343. X
  1344. // Base device class definition.  Specific devices should derive a
  1345. // class from this base class, and overload every virtual function.
  1346. //
  1347. // by Parag Patel
  1348. X
  1349. X
  1350. class font;
  1351. class fontchar;
  1352. X
  1353. class Device
  1354. {
  1355. public: 
  1356. X    const int maxfonts;
  1357. X    const int maxchars;
  1358. X    const int maxonpage;
  1359. X    const int maxloaded;
  1360. X    const int resolution;
  1361. X    const int hoff;
  1362. X    const int voff;
  1363. X    const int fhmin;
  1364. X    const int fhmax;
  1365. X    const int fvmin;
  1366. X    const int fvmax;
  1367. X    const int fwidth;
  1368. X    const int fheight;
  1369. X    char *deffontpath;
  1370. X
  1371. protected: 
  1372. X    // a Device may only be created by a derived class and is never
  1373. X    // directly used
  1374. X    Device(int maxf, int maxc, int maxpg, int maxld, int res,
  1375. X    int ho, int vo, int fhmn, int fhmx, int fvmn, int fvmx,
  1376. X    int fwd, int fhg, char *deffp);
  1377. X
  1378. public:
  1379. X    virtual ~Device();
  1380. X
  1381. X    //virtual void color(long red, long green, long blue);
  1382. X
  1383. X    // the following are pure virtual functions and MUST be overridden
  1384. X    // by a derived class since the are NOT defined
  1385. X    //
  1386. X    virtual const char *char2dev(int ch, int &len) = 0;
  1387. X    virtual long sp2dev(double sp) = 0;
  1388. X    virtual double dev2sp(long pix) = 0;
  1389. X    virtual void newpage(boolean odd, boolean first) = 0;
  1390. X    virtual void downchar(font & f, fontchar & g, int ch) = 0;
  1391. X    virtual void bigchar(font & f, fontchar & g, int ch) = 0;
  1392. X    virtual void movehv(long h, long v) = 0;
  1393. X    virtual void moveh(long n) = 0;
  1394. X    virtual void movev(long n) = 0;
  1395. X    virtual void push() = 0;
  1396. X    virtual void pop() = 0;
  1397. X    virtual void delfont(font & f) = 0;
  1398. X    virtual void newfont(font & f) = 0;
  1399. X    virtual void usefont(font & f) = 0;
  1400. X    virtual void rule(double v, double h) = 0;
  1401. };
  1402. X
  1403. X
  1404. // The following macros are for backward compatibility with the older
  1405. // code in this program.  It was originally C code that was upgraded to
  1406. // C++.  Since there may only be a single "device" per invocation,
  1407. // there's little need to change all the old code.  Yet.
  1408. X
  1409. extern Device *device;
  1410. X
  1411. #define MAXFONTS    device->maxfonts
  1412. #define MAXCHARS    device->maxchars
  1413. X
  1414. #define MAXONPAGE    device->maxonpage
  1415. #define MAXLOADED    device->maxloaded
  1416. X
  1417. #define RESOLUTION    device->resolution
  1418. X
  1419. #define HOFF        device->hoff
  1420. #define VOFF        device->voff
  1421. X
  1422. #define FHMIN        device->fhmin
  1423. #define FHMAX        device->fhmax
  1424. #define FVMIN        device->fvmin
  1425. #define FVMAX        device->fvmax
  1426. #define FWIDTH        device->fwidth
  1427. #define FHEIGHT        device->fheight
  1428. X
  1429. #define DEFFONTPATH    device->deffontpath
  1430. X
  1431. #define dev_char2dev    device->char2dev
  1432. #define dev_sp2dev    device->sp2dev
  1433. #define dev_dev2sp    device->dev2sp
  1434. #define dev_newpage    device->newpage
  1435. #define dev_downchar    device->downchar
  1436. #define dev_bigchar    device->bigchar
  1437. #define dev_movehv    device->movehv
  1438. #define dev_moveh    device->moveh
  1439. #define dev_movev    device->movev
  1440. #define dev_push    device->push
  1441. #define dev_pop        device->pop
  1442. #define dev_delfont    device->delfont
  1443. #define dev_newfont    device->newfont
  1444. #define dev_usefont    device->usefont
  1445. #define dev_rule    device->rule
  1446. #define dev_color    device->color
  1447. SHAR_EOF
  1448. chmod 0444 dev.h ||
  1449. echo 'restore of dev.h failed'
  1450. Wc_c="`wc -c < 'dev.h'`"
  1451. test 3077 -eq "$Wc_c" ||
  1452.     echo 'dev.h: original size 3077, current size' "$Wc_c"
  1453. fi
  1454. # ============= darray.h ==============
  1455. if test -f 'darray.h' -a X"$1" != X"-c"; then
  1456.     echo 'x - skipping darray.h (File already exists)'
  1457. else
  1458. echo 'x - extracting darray.h (Text)'
  1459. sed 's/^X//' << 'SHAR_EOF' > 'darray.h' &&
  1460. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1461. // $Header: darray.h,v 1.3 91/02/22 15:59:22 hmgr Exp $
  1462. X
  1463. // Handle simple dynamic arrays of arbitrary type and range.
  1464. // They are automatically grown to fit any array-like reference.
  1465. // by Parag Patel
  1466. X
  1467. #ifndef __DARRAY_H_
  1468. #define __DARRAY_H_
  1469. X
  1470. X
  1471. // this is used to create an ARRAY of a TYPE
  1472. #define declare_array(ARRAY, TYPE) \
  1473. class ARRAY \
  1474. { \
  1475. X    long len; \
  1476. X    long max; \
  1477. X    TYPE *arr; \
  1478. X    TYPE &bumpsize(long); \
  1479. public: \
  1480. X    ARRAY() { arr = 0; max = len = 0; } \
  1481. X    ARRAY(long siz) \
  1482. X        { arr = 0; max = len = 0; if (siz > 0) bumpsize(siz-1); } \
  1483. X    ARRAY(const ARRAY &); \
  1484. X    ~ARRAY() { delete[max] arr; } \
  1485. X    ARRAY &operator=(const ARRAY &); \
  1486. X    long size() const { return len; } \
  1487. X    void reset(long l = 0) { bumpsize(l); len = l; } \
  1488. X    TYPE &operator[](long e) \
  1489. X        { if (e < len) return arr[e]; else return bumpsize(e); } \
  1490. };
  1491. X
  1492. // this implements an ARRAY of a TYPE
  1493. #define implement_array(ARRAY, TYPE) \
  1494. TYPE &ARRAY::bumpsize(long elt) \
  1495. { \
  1496. X    if (elt < 0) \
  1497. X        elt = 0; \
  1498. X    if (elt >= max) \
  1499. X    { \
  1500. X        long omax = max; \
  1501. X        if (max <= 0) \
  1502. X            max = 1; \
  1503. X        TYPE *narr = new TYPE[max = elt + (max > 1024 ? 1024 : max)]; \
  1504. X        for (long i = 0; i < len; i++) \
  1505. X            narr[i] = arr[i]; \
  1506. X        delete[omax] arr; \
  1507. X        arr = narr; \
  1508. X    } \
  1509. X    if (elt >= len) \
  1510. X        len = elt + 1; \
  1511. X    return arr[elt]; \
  1512. } \
  1513. ARRAY &ARRAY::operator=(const ARRAY &a) \
  1514. { \
  1515. X    if (&a == this) \
  1516. X        return *this; \
  1517. X    if (a.len > len) \
  1518. X        bumpsize(a.len); \
  1519. X    len = a.len; \
  1520. X    for (long i = 0; i < len; i++) \
  1521. X        arr[i] = a.arr[i]; \
  1522. X    return *this; \
  1523. } \
  1524. ARRAY::ARRAY(const ARRAY &t) \
  1525. { \
  1526. X    arr = 0; \
  1527. X    max = len = 0; \
  1528. X    *this = t; \
  1529. }
  1530. X
  1531. #endif /* __DARRAY_H_ */
  1532. SHAR_EOF
  1533. chmod 0444 darray.h ||
  1534. echo 'restore of darray.h failed'
  1535. Wc_c="`wc -c < 'darray.h'`"
  1536. test 1656 -eq "$Wc_c" ||
  1537.     echo 'darray.h: original size 1656, current size' "$Wc_c"
  1538. fi
  1539. # ============= boolean.h ==============
  1540. if test -f 'boolean.h' -a X"$1" != X"-c"; then
  1541.     echo 'x - skipping boolean.h (File already exists)'
  1542. else
  1543. echo 'x - extracting boolean.h (Text)'
  1544. sed 's/^X//' << 'SHAR_EOF' > 'boolean.h' &&
  1545. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1546. // $Header: boolean.h,v 1.3 91/02/22 15:59:28 hmgr Exp $
  1547. X
  1548. #ifndef __BOOLEAN_H_
  1549. #define __BOOLEAN_H_
  1550. X
  1551. typedef int boolean;
  1552. const boolean FALSE = 0;
  1553. const boolean TRUE = 1;
  1554. X
  1555. #endif /* __BOOLEAN_H_ */
  1556. SHAR_EOF
  1557. chmod 0444 boolean.h ||
  1558. echo 'restore of boolean.h failed'
  1559. Wc_c="`wc -c < 'boolean.h'`"
  1560. test 258 -eq "$Wc_c" ||
  1561.     echo 'boolean.h: original size 258, current size' "$Wc_c"
  1562. fi
  1563. # ============= bitvec.h ==============
  1564. if test -f 'bitvec.h' -a X"$1" != X"-c"; then
  1565.     echo 'x - skipping bitvec.h (File already exists)'
  1566. else
  1567. echo 'x - extracting bitvec.h (Text)'
  1568. sed 's/^X//' << 'SHAR_EOF' > 'bitvec.h' &&
  1569. // Copyright (c) 1991 by Parag Patel.  All Rights Reserved.
  1570. // $Header: bitvec.h,v 1.4 91/02/22 15:59:36 hmgr Exp $
  1571. X
  1572. #ifndef __BITVEC_H_
  1573. #define __BITVEC_H_
  1574. X
  1575. #include "boolean.h"
  1576. X
  1577. // BUG: machine dependent macros: sizeof (unsigned long) must == 32 bits
  1578. #define __B_V_BIT(n) ((unsigned long)(1L << (n & 0x1F)))
  1579. #define __B_V_ELT(n) (n >> 5)
  1580. X
  1581. // a set of longs (esp. enums) - also an array of bits
  1582. class Bitvec
  1583. {
  1584. X    long num;
  1585. X    unsigned long *elts;
  1586. X
  1587. X    void bumpsize(long);        // grow the Bitvec
  1588. X    // inline for speed
  1589. X    void BUMPSIZE(long largest) { if (num < largest) bumpsize(largest); }
  1590. X
  1591. public: 
  1592. X    Bitvec(long);        // new size
  1593. X    Bitvec(Bitvec const &);    // new Bitvec
  1594. X    Bitvec() { elts = new unsigned long; num = 0; elts[0] = 0L; }
  1595. X    ~Bitvec() { delete elts; }    // destructor
  1596. X
  1597. X    Bitvec& operator=(Bitvec const &);   // dup
  1598. X
  1599. X    Bitvec& add(long);        // add to
  1600. X    Bitvec& remove(long);    // delete from
  1601. X    Bitvec& operator+=(long e) { return add(e); }
  1602. X    Bitvec& operator-=(long e) { return remove(e); }
  1603. X
  1604. X    long size() const;            // number of elements in Bitvec
  1605. X    boolean isin(long bit) const
  1606. X    { return bit >= 0 && bit <= num &&
  1607. X        (elts[__B_V_ELT(bit)] & __B_V_BIT(bit)); }
  1608. X    void clear();        // clear the set
  1609. X
  1610. X    long get(long elt) const
  1611. X        { return (elt >= 0 && elt <= num &&
  1612. X            (elts[__B_V_ELT(elt)] & __B_V_BIT(elt))) ? 1 : 0; }
  1613. X    long operator[](long elt) const { return get(elt); }
  1614. X    unsigned long *getelts() { return elts; }
  1615. X
  1616. X    // equality testing:
  1617. X    boolean operator==(Bitvec const &s) const;
  1618. X    boolean operator!=(Bitvec const &s) const { return !(s == *this); }
  1619. };
  1620. X
  1621. #undef __B_V_ELT
  1622. #undef __B_V_BIT
  1623. X
  1624. #endif /* __BITVEC_H_ */
  1625. SHAR_EOF
  1626. chmod 0444 bitvec.h ||
  1627. echo 'restore of bitvec.h failed'
  1628. Wc_c="`wc -c < 'bitvec.h'`"
  1629. test 1665 -eq "$Wc_c" ||
  1630.     echo 'bitvec.h: original size 1665, current size' "$Wc_c"
  1631. fi
  1632. # ============= ljdump.c ==============
  1633. if test -f 'ljdump.c' -a X"$1" != X"-c"; then
  1634.     echo 'x - skipping ljdump.c (File already exists)'
  1635. else
  1636. echo 'x - extracting ljdump.c (Text)'
  1637. sed 's/^X//' << 'SHAR_EOF' > 'ljdump.c' &&
  1638. /* Copyright (c) 1991 by Parag Patel.  All Rights Reserved. */
  1639. static char rcsid[] = "$Header: ljdump.c,v 1.8 91/02/22 15:59:49 hmgr Exp $";
  1640. X
  1641. /*
  1642. X   NOT written by me. The real author refuses to stick his name in
  1643. X   here, but he can't stop me from adding this note!  -- Parag
  1644. X
  1645. X   BTW - This is C code - NOT C++!
  1646. X */
  1647. X
  1648. #include <stdio.h>
  1649. #include <ctype.h>
  1650. X
  1651. #define SAME(a,b) (strcmp(a,b)==0)
  1652. #define SEQ(s,c,x) (x[strlen(x)-1]==c && strncmp(s,x,strlen(s))==0)
  1653. X
  1654. int
  1655. getnum(cp)
  1656. char *cp;
  1657. {
  1658. X    cp = &cp[strlen(cp)] - 2;
  1659. X    while (isdigit(*cp))
  1660. X    cp--;
  1661. X    return atoi(cp + 1);
  1662. }
  1663. X
  1664. void
  1665. dump_data(nbytes)
  1666. int nbytes;
  1667. {
  1668. X    int max = 32;
  1669. X    int ch;
  1670. X
  1671. X    printf("\t");
  1672. X    while (nbytes-- > 0)
  1673. X    {
  1674. X    ch = getchar();
  1675. X    if (max > 0)
  1676. X        printf("%.2X", ch);
  1677. X
  1678. X    if (max-- == 0)
  1679. X        printf("->");
  1680. X    }
  1681. X    putchar('\n');
  1682. }
  1683. X
  1684. void
  1685. do_esc(seq)
  1686. char *seq;
  1687. {
  1688. X    typedef char byte;
  1689. X    typedef unsigned char ubyte;
  1690. X    typedef short word;
  1691. X    typedef unsigned short uword;
  1692. X    struct
  1693. X    {
  1694. X    uword size;
  1695. X    byte dummy0;
  1696. X    byte is_eightbit;
  1697. X    word dummy1;
  1698. X    uword baseline;
  1699. X    uword cell_width;
  1700. X    uword cell_height;
  1701. X    byte is_landscape;
  1702. X    byte is_proportional;
  1703. X    uword symbol_set;
  1704. X    uword pitch;
  1705. X    uword height;
  1706. X    word dummy2;
  1707. X    byte dummy3;
  1708. X    byte is_italic;
  1709. X    byte stroke_weight;
  1710. X    ubyte typeface;
  1711. X    } fontdesc;
  1712. X    struct
  1713. X    {
  1714. X    word dummy0;
  1715. X    word dummy1;
  1716. X    byte is_landscape;
  1717. X    byte dymmy2;
  1718. X    word left_offset;
  1719. X    word top_offset;
  1720. X    uword width;
  1721. X    uword height;
  1722. X    word deltax;
  1723. X    } chardesc;
  1724. X
  1725. X    printf("^[%s", seq);
  1726. X    if (SEQ(")s", 'W', seq))
  1727. X    {
  1728. X    fread(&fontdesc, sizeof fontdesc, 1, stdin);
  1729. X    printf("\n\t");
  1730. X    if (fontdesc.is_proportional)
  1731. X        printf("proportional ");
  1732. X    else
  1733. X        printf("fixed ");
  1734. X    if (fontdesc.is_landscape)
  1735. X        printf("landscape ");
  1736. X    else
  1737. X        printf("portrait ");
  1738. X    if (fontdesc.is_italic)
  1739. X        printf("italic ");
  1740. X    printf("%d-bit chars, symbol set: %d%c\n",
  1741. X        fontdesc.is_eightbit + 7,
  1742. X        fontdesc.symbol_set >> 5,
  1743. X        (fontdesc.symbol_set & 0x1F) + 64);
  1744. X    printf("\tbaseline: %d dots\n", fontdesc.baseline);
  1745. X    printf("\tcell height: %d dots  width: %d dots\n",
  1746. X        fontdesc.cell_height, fontdesc.cell_width);
  1747. X    printf("\tpitch: %.1f dots\n", fontdesc.pitch / 4.0);
  1748. X    printf("\theight: %.1f dots\n", fontdesc.height / 4.0);
  1749. X    printf("\tstroke weight: %d, typeface: %d\n",
  1750. X        fontdesc.stroke_weight, fontdesc.typeface);
  1751. X    }
  1752. X    else if (SEQ("(s", 'W', seq))
  1753. X    {
  1754. X    fread(&chardesc, sizeof chardesc, 1, stdin);
  1755. X    if (chardesc.is_landscape)
  1756. X        printf("\n\tlandscape");
  1757. X    printf("\n\ttop offset: %d dots, left offset: %d dots\n",
  1758. X        chardesc.top_offset, chardesc.left_offset);
  1759. X    printf("\theight: %d dots, width: %d dots\n",
  1760. X        chardesc.height, chardesc.width);
  1761. X    printf("\tdelta X: %.1f dots\n", chardesc.deltax / 4.0);
  1762. X    dump_data(getnum(seq) - sizeof chardesc);
  1763. X    }
  1764. X    else if (SEQ("*b", 'W', seq))
  1765. X    {
  1766. X    dump_data(getnum(seq));
  1767. X    }
  1768. X    else if (SEQ("*c", 'E', seq) && isprint(getnum(seq)))
  1769. X    printf(" ('%c')\n", getnum(seq));
  1770. X    else
  1771. X    putchar('\n');
  1772. }
  1773. X
  1774. main()
  1775. {
  1776. X    int ch;
  1777. X    char *cp;
  1778. X    char seq[100];
  1779. X
  1780. X    while ((ch = getchar()) != EOF)
  1781. X    {
  1782. X    switch (ch)
  1783. X    {
  1784. X    case '\033':
  1785. X        for (cp = seq; !isupper((ch = getchar())); *cp++ = ch)
  1786. X        ;
  1787. X        *cp++ = ch;
  1788. X        *cp = '\0';
  1789. X        do_esc(seq);
  1790. X        break;
  1791. X    default:
  1792. X        printf("'%c' (%d) (0x%X) (0%o)\n", ch, ch, ch, ch);
  1793. X        break;
  1794. X    }
  1795. X    }
  1796. X
  1797. X    exit(0);
  1798. }
  1799. SHAR_EOF
  1800. chmod 0444 ljdump.c ||
  1801. echo 'restore of ljdump.c failed'
  1802. Wc_c="`wc -c < 'ljdump.c'`"
  1803. test 3296 -eq "$Wc_c" ||
  1804.     echo 'ljdump.c: original size 3296, current size' "$Wc_c"
  1805. fi
  1806. exit 0
  1807.  
  1808. exit 0 # Just in case...
  1809. -- 
  1810. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1811. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1812. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1813. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1814.