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

  1. From: hot@integow.uucp (Roland van Hout)
  2. Newsgroups: alt.sources
  3. Subject: PD plot(4) librarys (and hercules driver for interactive 386) part 4 of 9
  4. Message-ID: <1392@integow.uucp>
  5. Date: 28 Oct 90 03:55:33 GMT
  6.  
  7.  
  8.  
  9. #!/bin/sh
  10. # This is part 04 of a multipart archive
  11. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  12.  then TOUCH=touch
  13.  else TOUCH=true
  14. fi
  15. # ============= libplot/lp/ib_map.c ==============
  16. echo "x - extracting libplot/lp/ib_map.c (Text)"
  17. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/ib_map.c &&
  18. X/*
  19. X * ib_map.c
  20. X *
  21. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  22. X */
  23. X
  24. X#include <stdio.h>
  25. X#include "const.h"
  26. X#include "fillcnst.h"
  27. X
  28. X#ifdef TESTVER
  29. X#include <signal.h>
  30. X#include "dbgvars.h"
  31. X#endif
  32. X
  33. X#define XLIM 94            /* 47 for 1/2 pg output, 94 for full page
  34. X                 * output */
  35. X#define YLIM 480        /* 240/480 for half/full pg output, mode K... */
  36. X /* ...480/960 for half/full pg output, mode L */
  37. X#define MODE 'Z'        /* 'K' / 'L': 60 dots per in / 120 dots per
  38. X                 * in 'Z' quad density 240 dots per in */
  39. X
  40. X#define LEFT_CUTOFF  0
  41. X
  42. X/*
  43. X * Constants
  44. X * SCALEX and SCALEY have been changed to vars, set in init_map,
  45. X * to simplify quick changes of scale, depending on XLIM, YLIM
  46. X */
  47. X
  48. X#define ROUNDER 0.0
  49. X
  50. X#ifndef TESTVER
  51. X#define PUT_BIT(x,y)    map[(x >> 3) + (XLIM * y)] |= BITS[x & 7]
  52. X#endif
  53. X
  54. X#define ABS(x) ((x) > 0.0 ? (x) : -(x))
  55. X
  56. Xlong    MAP_MAX;
  57. Xdouble  SCALEX,
  58. X        SCALEY;            /* <<<<<<<<<<<< */
  59. Xchar    BITS[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  60. Xextern char map[];        /* in maps.c */
  61. X
  62. X
  63. X/*******************************
  64. X * catch(), catchi() were here *
  65. X *******************************/
  66. X
  67. X#ifdef TESTVER
  68. XPUT_BIT(x, y)
  69. X    int     x,
  70. X            y;
  71. X{
  72. X    int     offset;
  73. X
  74. X    offset = ((x >> 3) + (XLIM * y));
  75. X    if ((offset >= (MAP_MAX)) || (offset < 0)) {
  76. X    fprintf(stderr,
  77. X        "PUTBIT offset overflow: %d;  x: %d;  y: %d\n", offset, x, y);
  78. X    fprintf(errfp,
  79. X        "PUTBIT offset overflow: %d;  x: %d;  y: %d\n", offset, x, y);
  80. X    fclose(errfp);
  81. X    dump_map(TRUE);
  82. X    exit(1);
  83. X    }
  84. X    map[offset] |= BITS[x & 7];
  85. X}
  86. X
  87. X#endif
  88. X
  89. X
  90. Xib_put_seg(p1, p2)
  91. X    POINT   p1,
  92. X            p2;
  93. X{
  94. X    double  diffx,
  95. X            diffy,
  96. X            change_ratio;
  97. X    register int x,
  98. X            y;
  99. X    register int inc;
  100. X
  101. X#if 0
  102. X    signal(SIGSEGV, catch);
  103. X    signal(SIGINT, catchi);
  104. X#endif
  105. X
  106. X#ifdef TESTVER
  107. X    if (debug2 || debug2x) {
  108. X    fprintf(errfp, "p1 ( %d, %d );   p2 ( %d, %d )\n",
  109. X        p1.x, p1.y, p2.x, p2.y);
  110. X    }
  111. X#endif
  112. X
  113. X    p1.x = SCALEX * (double) p1.x + ROUNDER;
  114. X    p2.x = SCALEX * (double) p2.x + ROUNDER;
  115. X    p1.y = SCALEY * (double) p1.y + ROUNDER;
  116. X    p2.y = SCALEY * (double) p2.y + ROUNDER;
  117. X
  118. X    diffx = p2.x - p1.x;
  119. X    diffy = p2.y - p1.y;
  120. X
  121. X    if (diffx != 0.0 && diffy != 0.0) {    /* neither horiz nor vert */
  122. X    if (ABS(diffx) > ABS(diffy)) {    /* closer to horizontal */
  123. X        inc = (diffx < 0) ? -1 : 1;
  124. X        change_ratio = diffy / diffx;
  125. X        for (x = p1.x; x != p2.x; x += inc) {
  126. X        y = (x - p1.x) * change_ratio + p1.y + ROUNDER;
  127. X        PUT_BIT(x, y);
  128. X        }
  129. X        PUT_BIT(p2.x, p2.y);
  130. X    } else {        /* closer to vertical */
  131. X        inc = (diffy < 0) ? -1 : 1;
  132. X        change_ratio = diffx / diffy;
  133. X        for (y = p1.y; y != p2.y; y += inc) {
  134. X        x = (y - p1.y) * change_ratio + p1.x + ROUNDER;
  135. X        PUT_BIT(x, y);
  136. X        }
  137. X        PUT_BIT(p2.x, p2.y);
  138. X    }
  139. X    } else {
  140. X    if (diffx) {        /* horizontal line */
  141. X        y = p1.y;
  142. X        inc = (diffx < 0) ? -1 : 1;
  143. X        for (x = p1.x; x != p2.x; x += inc) {
  144. X        PUT_BIT(x, y);
  145. X        }
  146. X        PUT_BIT(p2.x, y);
  147. X    } else {        /* vert. line */
  148. X        x = p1.x;
  149. X        inc = (diffy < 0) ? -1 : 1;
  150. X        for (y = p1.y; y != p2.y; y += inc) {
  151. X        PUT_BIT(x, y);
  152. X        }
  153. X        PUT_BIT(x, p2.y);
  154. X    }
  155. X    }
  156. X}
  157. X
  158. X
  159. Xib_dump_map(to_printer)
  160. X    int     to_printer;
  161. X{
  162. X    int     i;
  163. X    register int j;
  164. X    char    ch;
  165. X    char    hdr[5];
  166. X
  167. X    if (to_printer) {
  168. X    hdr[0] = ESC;
  169. X    hdr[1] = '3';
  170. X    hdr[2] = 24;        /* Line spacing for graphics: 24/216 inch */
  171. X    write(1, hdr, 3);
  172. X    hdr[1] = MODE;        /* 'K'/'L': 480/960 bit image graphics */
  173. X    hdr[2] = (YLIM - LEFT_CUTOFF) & 0xff;    /* n1 = YLIM mod 256 */
  174. X    hdr[3] = ((YLIM - LEFT_CUTOFF) >> 8) & 0xff;    /* n2 = YLIM / 256 */
  175. X
  176. X    for (i = 0; i < XLIM; i++) {
  177. X        write(1, hdr, 4);
  178. X        for (j = LEFT_CUTOFF * XLIM; j < MAP_MAX; j += XLIM) {
  179. X        ch = map[i + j];
  180. X        if (ch == 26)
  181. X            ch = 18;    /* bug in proprinter graphics */
  182. X        if (ch == '\n')
  183. X            ch = 8;    /* prevent add'n of \r to \n */
  184. X        write(1, &ch, 1);
  185. X#ifdef TESTVER
  186. X        if (debug5)
  187. X            fprintf(errfp, "%4d", ch);
  188. X#endif
  189. X        }
  190. X#ifdef TESTVER
  191. X        if (debug5)
  192. X        fprintf(errfp, "%3d*\n", i);
  193. X#endif
  194. X        putchar('\n');    /* LF and CR to end line */
  195. X        putchar('\r');
  196. X        fflush(stdout);
  197. X    }
  198. X
  199. X    /* putchar( '\f' ); *//* form feed */
  200. X#ifdef TESTVER
  201. X    fclose(errfp);
  202. X#endif
  203. X
  204. X    }                /* end if ( to_printer )... */
  205. X}
  206. X
  207. X
  208. Xib_init_map()
  209. X{
  210. X#ifdef TRUESOLID
  211. X    extern double PUs_per_dot;    /* declared in file filltype.c */
  212. X
  213. X#endif
  214. X    register int k;
  215. X    register char *mp;
  216. X
  217. X    MAP_MAX = XLIM * YLIM;
  218. X    SCALEX = (double) (XLIM * 8) / 10366;
  219. X    SCALEY = (double) (YLIM) / 7963;
  220. X
  221. X#ifdef TRUESOLID
  222. X    PUs_per_dot = 1.0 / SCALEX;    /* used by fix_fill() in file filltype.c */
  223. X#endif
  224. X
  225. X    mp = map;
  226. X    for (k = 0; k < MAP_MAX; k++)
  227. X    *mp++ = 0;
  228. X}
  229. SHAR_EOF
  230. $TOUCH -am 0214090289 libplot/lp/ib_map.c &&
  231. chmod 0644 libplot/lp/ib_map.c ||
  232. echo "restore of libplot/lp/ib_map.c failed"
  233. set `wc -c libplot/lp/ib_map.c`;Wc_c=$1
  234. if test "$Wc_c" != "4616"; then
  235.     echo original size 4616, current size $Wc_c
  236. fi
  237. # ============= libplot/lp/itoa.h ==============
  238. echo "x - extracting libplot/lp/itoa.h (Text)"
  239. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/itoa.h &&
  240. X/********************************************************************
  241. X ***** itoa -- Konvertieren Zahlen in ASCII String              *****
  242. X ********************************************************************/
  243. X/* Setzt Zahlen in ASCII String um. Die Umwandlung erfolgt
  244. X   in umgekehrter Reihenfolge. Danach wird der String vertauscht.
  245. X
  246. X   Beispiele:
  247. X    int n;
  248. X    char scrtext[100];
  249. X
  250. X    itoa(n,scrtext);
  251. X        printf("String: %s",&scrtext[0]);
  252. X*/
  253. X
  254. Xitoa(n,scrtext)
  255. Xint n;
  256. Xchar scrtext[];
  257. X{
  258. Xint i,sign,c,j;
  259. X/* 
  260. X    Vorzeichen merken 
  261. X*/
  262. Xif ((sign = n) <0)
  263. X  n= -n;
  264. X/* 
  265. X    Umwandeln 
  266. X*/
  267. Xi=0;
  268. Xdo
  269. X  {
  270. X  scrtext[i++]= n % 10 +'0';
  271. X  }
  272. Xwhile (( n/= 10)>0);
  273. X/* 
  274. X    Vorzeichen setzen 
  275. X*/
  276. Xif (sign <0)
  277. X  scrtext[i++]='-';
  278. Xscrtext[i]='\0';
  279. X/* 
  280. X    Nun Umdrehen 
  281. X*/
  282. Xj= i-1;
  283. Xif (j>0);
  284. X  {
  285. X  for (i=0 ; i<j ; i++ , j--)
  286. X    {
  287. X    c=scrtext[i];
  288. X    scrtext[i]=scrtext[j];
  289. X    scrtext[j]=c;
  290. X    }
  291. X  }
  292. X}
  293. X
  294. X    
  295. SHAR_EOF
  296. $TOUCH -am 1007125888 libplot/lp/itoa.h &&
  297. chmod 0644 libplot/lp/itoa.h ||
  298. echo "restore of libplot/lp/itoa.h failed"
  299. set `wc -c libplot/lp/itoa.h`;Wc_c=$1
  300. if test "$Wc_c" != "879"; then
  301.     echo original size 879, current size $Wc_c
  302. fi
  303. # ============= libplot/lp/label.c ==============
  304. echo "x - extracting libplot/lp/label.c (Text)"
  305. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/label.c &&
  306. X/*
  307. X * do_lb.c
  308. X *
  309. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  310. X */
  311. X
  312. X#include <stdio.h>
  313. X#include "const.h"
  314. X#include "vars.h"
  315. X#include "dbgvars.h"
  316. X
  317. Xextern POINT plot_char();
  318. X
  319. Xlabel(s)
  320. Xchar *s;
  321. X{
  322. X    char *sp;
  323. X    POINT   l_point;
  324. X    sp=s;
  325. X#ifdef TESTVER
  326. X    int     was_on,
  327. X            xwas_on;        /* for debugging */
  328. X
  329. X    /* turn debug2/2x off, if necessary, for the duration of labeling */
  330. X    if (debug2) {
  331. X    was_on = TRUE;
  332. X    debug2 = FALSE;
  333. X    } else {
  334. X    was_on = FALSE;
  335. X    }
  336. X    if (debug2x) {
  337. X    xwas_on = TRUE;
  338. X    debug2x = FALSE;
  339. X    } else {
  340. X    xwas_on = FALSE;
  341. X    }
  342. X#endif
  343. X
  344. X    l_point = current;
  345. X    if (stand_set_sel)
  346. X    while ((c = *sp++) != NULL) {
  347. X        l_point = plot_char(l_point, c, set_standard);
  348. X    }
  349. X    else
  350. X    while ((c = *sp++) != NULL) {
  351. X        l_point = plot_char(l_point, c, set_alternate);
  352. X    }
  353. X    pen_up = TRUE;
  354. X
  355. X#ifdef TESTVER
  356. X    if (was_on) {
  357. X    debug2 = TRUE;
  358. X    }
  359. X    if (xwas_on) {
  360. X    debug2x = TRUE;
  361. X    }
  362. X#endif
  363. X}
  364. X
  365. SHAR_EOF
  366. $TOUCH -am 1010115088 libplot/lp/label.c &&
  367. chmod 0644 libplot/lp/label.c ||
  368. echo "restore of libplot/lp/label.c failed"
  369. set `wc -c libplot/lp/label.c`;Wc_c=$1
  370. if test "$Wc_c" != "939"; then
  371.     echo original size 939, current size $Wc_c
  372. fi
  373. # ============= libplot/lp/liblj.c ==============
  374. echo "x - extracting libplot/lp/liblj.c (Text)"
  375. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/liblj.c &&
  376. X/*
  377. X * main.c
  378. X *
  379. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  380. X *
  381. X * hpglplot v2.1
  382. X *
  383. X * Filter to read HPGL commands (Hewlett-Packard Graphics Language,
  384. X * used by HP7475A 6-pen plotter, among others) and produce bit map
  385. X * graphics commands for various printers.
  386. X *
  387. X * Usage: tplotlp -eismh
  388. X * Options: for the lpdriver.c program  
  389. X * -e    produce output for Epson LQ-1500
  390. X * -i    produce output for IBM Proprinter
  391. X * -s    produce output for HP LaserJet+ small
  392. X * -m   produce output for HP LaserJet+ enlarged
  393. X * -h   produce output for HP LaserJet+ extra large
  394. X *
  395. X *
  396. X * Authors:
  397. X *  Mel Brooks
  398. X *    Initial program design, command interpreter, Epson bit-map.
  399. X *  Al Chase
  400. X *    Fill routines, LaserJet and Proprinter bit-maps.
  401. X *  David MacKenzie
  402. X *    Rewrote option parser and makefile, cleaned up.
  403. X */
  404. X/* plot(4) graphics library for a regis terminal for VT240/VT300/GIGI */
  405. Xextern float deltx,delty;
  406. Xfloat pitograd;
  407. X
  408. X#include <math.h>
  409. X#include "plotlp.h"
  410. X
  411. Xclosepl()
  412. X{
  413. Xdump_map(printer);
  414. X}
  415. X
  416. Xspace(x0,y0,x1,y1)
  417. Xint x0,y0,x1,y1;
  418. X{
  419. Xint x,y;
  420. Xpitograd=(180.0/M_PI);
  421. X
  422. Xif (x1>0 && y1>0 && y0<y1 && x0<x1) {
  423. X    x=x1-x0;y=y1-y0;
  424. X    gxscrunch=(7850/(float) x);gyscrunch=(7850/(float) y);
  425. X    offx = -(x0*gxscrunch);offy= -(y0*gyscrunch);
  426. X}
  427. X
  428. X}
  429. X
  430. Xerase()
  431. X{
  432. X/*    printf("\014");*/
  433. X}
  434. X
  435. X
  436. Xarc(x,y,x0,y0,x1,y1)
  437. Xint x,y,x0,y0,x1,y1;
  438. X{
  439. X/*
  440. Xfloat a1,a2,r1,r2;
  441. Xint xo,yo,c1,c2,c;
  442. X    move(x0,y0);
  443. X    if ((x-x0) > 0) {
  444. X        r1=(y-y0)/(x-x0);
  445. X        a1=atan(r1);
  446. X        c1=(a1*pitograd);
  447. X    }
  448. X    else {
  449. X        c1=180;
  450. X    }
  451. X    if ((x-x1) > 0) {
  452. X        r2=(y-y1)/(x-x1);
  453. X        a2=atan(r2);
  454. X        c2=(a2*pitograd);
  455. X    }
  456. X    else {
  457. X        c2=180;
  458. X    }
  459. X        c=c1-c2;
  460. X    xo=(x*gxscrunch);yo=(y*gyscrunch);
  461. X    yo += offy ;xo +=  offx ;
  462. X    printf("\033PpC(A%dC) [%d,%d]\033\\",c,xo,yo);
  463. X
  464. X*/
  465. X}
  466. X/*
  467. X * do_ew.c
  468. X *
  469. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  470. X
  471. X#include <stdio.h>
  472. X#include <math.h>
  473. X#include "const.h"
  474. X#include "vars.h"
  475. X#ifdef TESTVER
  476. X#  include "dbgvars.h"
  477. X#endif
  478. X
  479. X#define DEGREES_TO_RADIANS 3.1415926535898 / 180.0
  480. X
  481. Xdo_EW()
  482. X{
  483. X    POINT   t,
  484. X            t1;
  485. X    float   radius;
  486. X    int     i_radius,
  487. X            start_angle,
  488. X            sweep_angle,
  489. X            chordangle;
  490. X    int     i;
  491. X
  492. X#ifdef TESTVER
  493. X    int     xwas_on;        /* for debugging 
  494. X
  495. X    /* turn debug2x off, if necessary, for the duration of do_EW() 
  496. X    if (debug2x) {
  497. X    xwas_on = TRUE;
  498. X    debug2x = FALSE;
  499. X    } else {
  500. X    xwas_on = FALSE;
  501. X    }
  502. X#endif
  503. X
  504. X    if (scanf("%f,%d,%d", &radius, &start_angle, &sweep_angle) != 3) {
  505. X    fprintf(stderr, "Odd number of coordinate\n");
  506. X    exit(4);
  507. X    }
  508. X    if ((c = getchar()) != ';') {
  509. X    scanf("%d", &chordangle);
  510. X    getchar();
  511. X    } else {
  512. X    chordangle = chord_angle;
  513. X    }
  514. X
  515. X    if (sweep_angle < 0)
  516. X    chordangle = -1 * (abs(chordangle));
  517. X
  518. X    start_angle %= 360;
  519. X    if (sweep_angle > 360)
  520. X    sweep_angle = 360;
  521. X    else if (sweep_angle < -360)
  522. X    sweep_angle = -360;
  523. X
  524. X    if (scaling) {
  525. X    i_radius = (int) (radius * x_scaler);
  526. X    if (i_radius < 0)
  527. X        i_radius -= 1;
  528. X    } else
  529. X    i_radius = (int) radius;
  530. X
  531. X    /* plot starting radius 
  532. X    t.x = (int) ((double) radius * cos((double) start_angle *
  533. X        DEGREES_TO_RADIANS) + 0.5) + current.x;
  534. X    t.y = (int) ((double) radius * sin((double) start_angle *
  535. X        DEGREES_TO_RADIANS) + 0.5) + current.y;
  536. X    put_seg(current, t);
  537. X
  538. X    /* plot chords up to (but not incl) sweep_angle 
  539. X    for (i = chordangle; abs(i) < abs(sweep_angle); i += chordangle) {
  540. X    t1.x = (int) ((double) radius * cos((double) (start_angle + i)
  541. X        * DEGREES_TO_RADIANS) + 0.5) + current.x;
  542. X    t1.y = (int) ((double) radius * sin((double) (start_angle + i)
  543. X        * DEGREES_TO_RADIANS) + 0.5) + current.y;
  544. X    put_seg(t, t1);
  545. X    t = t1;
  546. X    }
  547. X
  548. X    /* plot remaining (partial?) chord needed to make up the full sweep angle 
  549. X    t1.x = (int) ((double) radius * cos((double) (start_angle + sweep_angle)
  550. X        * DEGREES_TO_RADIANS) + 0.5) + current.x;
  551. X    t1.y = (int) ((double) radius * sin((double) (start_angle + sweep_angle)
  552. X        * DEGREES_TO_RADIANS) + 0.5) + current.y;
  553. X    put_seg(t, t1);
  554. X    t = t1;
  555. X
  556. X    /* plot ending radius 
  557. X    put_seg(t1, current);
  558. X
  559. X#ifdef TESTVER            /* reset debug2x if necessary 
  560. X    if (xwas_on) {
  561. X    debug2x = TRUE;
  562. X    }
  563. X#endif
  564. X}
  565. X*/
  566. X
  567. Xdot(xi,yi,dx,n,pat)
  568. Xint xi,yi,dx,n,pat[256];
  569. X{
  570. X}
  571. X
  572. Xpoint(x,y)
  573. Xint x,y;
  574. X{
  575. X      move(x,y);
  576. X      cont(x,y);
  577. X}
  578. X
  579. X
  580. Xline (x1, y1, x2, y2)
  581. Xint x1,y1,x2,y2;
  582. X{
  583. X    move(x1,y1);
  584. X    cont(x2,y2);
  585. X}
  586. X
  587. X
  588. X
  589. X
  590. SHAR_EOF
  591. $TOUCH -am 1011095088 libplot/lp/liblj.c &&
  592. chmod 0644 libplot/lp/liblj.c ||
  593. echo "restore of libplot/lp/liblj.c failed"
  594. set `wc -c libplot/lp/liblj.c`;Wc_c=$1
  595. if test "$Wc_c" != "4267"; then
  596.     echo original size 4267, current size $Wc_c
  597. fi
  598. # ============= libplot/lp/linemod.c ==============
  599. echo "x - extracting libplot/lp/linemod.c (Text)"
  600. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/linemod.c &&
  601. X#include "plotlp.h"
  602. X
  603. Xlinemod(s)
  604. Xchar *s;
  605. X{
  606. X    line_type = SOLID;
  607. X  if (strcmp(s,"dotted")==0) {
  608. X    line_type=DOTS;
  609. X      }
  610. X  else if (strcmp(s,"solid")==0) {
  611. X    line_type = SOLID;
  612. X      }
  613. X      else if (strcmp(s,"longdashed")==0) {
  614. X          line_type=BROKN_2DASH;
  615. X          }
  616. X         else if (strcmp(s,"shortdashed")==0) {
  617. X             line_type=SHORT_DASH;
  618. X             }
  619. X            else if (strcmp(s,"dotdashed")==0) {
  620. X                line_type=BROKN_DASH;
  621. X                }
  622. X}
  623. X
  624. SHAR_EOF
  625. $TOUCH -am 1010110488 libplot/lp/linemod.c &&
  626. chmod 0644 libplot/lp/linemod.c ||
  627. echo "restore of libplot/lp/linemod.c failed"
  628. set `wc -c libplot/lp/linemod.c`;Wc_c=$1
  629. if test "$Wc_c" != "399"; then
  630.     echo original size 399, current size $Wc_c
  631. fi
  632. # ============= libplot/lp/lj_map.c ==============
  633. echo "x - extracting libplot/lp/lj_map.c (Text)"
  634. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/lj_map.c &&
  635. X/*
  636. X * lj_map.c
  637. X *
  638. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  639. X */
  640. X
  641. X#include <stdio.h>
  642. X#include "const.h"
  643. X#include "vars.h"
  644. X#include "fillcnst.h"
  645. X#include "itoa.h"
  646. X
  647. X#ifdef TESTVER
  648. X#include <signal.h>
  649. X#endif
  650. X
  651. X/*
  652. X * Origin is at lower left corner.
  653. X * Bytes of raster data are oriented along the x-axis, hi bit at left:
  654. X *       (0,0) is bit 7 of byte 0;
  655. X *       (7,0) is bit 0 of byte 0;
  656. X *       (16,0) is bit 7 of byte 2;
  657. X *       (16,3) is bit 7 of byte (2 + Xlim*3)
  658. X */
  659. X
  660. X/*
  661. X * Constants
  662. X * Ylim = 1440 dot rows, plus a couple extra for rounding error
  663. X#define Ylim 1442
  664. X#define Xlim  235
  665. X#define scaleX  0.180859
  666. X#define scaleY  0.180859
  667. X
  668. X#define Ylim 1841
  669. X#define Xlim  300
  670. X
  671. X/* scaleX = scaleY = number of dots per plotter unit
  672. X                   = 1440 dot rows in y-direction / 7962 PU's in y-dir 
  673. X#define scaleX  0.231205
  674. X#define scaleY  0.231205
  675. X#define rounder 0.0
  676. X [hot@mh.nl] */
  677. X
  678. Xstatic int Ylim,Xlim,Ylim8;
  679. Xstatic double scaleX,scaleY,rounder;
  680. X
  681. X#define ABS(x) ((x) > 0.0 ? (x) : -(x))
  682. X
  683. X/* move bit map to maps.c for combined printer version --- */
  684. X#if 0
  685. Xchar    map[Xlim * Ylim];
  686. X
  687. X#endif
  688. Xextern char map[];
  689. X
  690. Xstatic char BITS[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  691. X#ifdef TESTVER
  692. X#define PUT_BIT(x, y)  map[(tempindex = (tempx = (x >> 3)) + ((tempy = y) * Xlim))] |= BITS[x & 7];
  693. X#else
  694. X#define P_BIT(x, y)  map[(x >> 3) + (y * Xlim)] |= BITS[x & 7]; 
  695. XPUT_BIT(x, y)
  696. Xint x,y;
  697. X{
  698. Xint saveit;
  699. Xif (printer == LASERHIGH || printer == LASERMED) { 
  700. X    saveit=x;x=y;y=Ylim-saveit;
  701. X}
  702. XP_BIT(x,y);
  703. X}
  704. X
  705. X#endif
  706. X
  707. X
  708. X#ifdef TESTVER
  709. Xstatic int tempindex,
  710. X        tempx,
  711. X        tempy;
  712. Xstatic POINT tempp1,
  713. X        tempp2;
  714. X
  715. Xlj_catch()
  716. X{
  717. X    fprintf(stderr, "Segmentation violation\n");
  718. X    fprintf(stderr, "tempindex = %d x = %d y = %d p1 = %d,%d p2 = %d,%d\n",
  719. X    tempindex, tempx, tempy, tempp1.x, tempp1.y, tempp2.x, tempp2.y);
  720. X    lj_dump_map(FALSE);
  721. X    exit(1);
  722. X}
  723. X
  724. Xljcatchi()
  725. X{
  726. X    lj_dump_map(FALSE);
  727. X    exit(1);
  728. X}
  729. X
  730. X#endif
  731. X
  732. Xlj_put_seg(p1, p2)
  733. X    POINT   p1,
  734. X            p2;
  735. X{
  736. X    double  diffx,
  737. X            diffy,
  738. X            change_ratio;
  739. X    register int x,
  740. X            y;
  741. X    register int inc;
  742. X
  743. X#ifdef TESTVER
  744. X#if 0
  745. X    signal(SIGSEGV, lj_catch);
  746. X    signal(SIGINT, ljcatchi);
  747. X#endif
  748. X    tempp1 = p1;
  749. X    tempp2 = p2;
  750. X#endif
  751. X
  752. X    p1.x = scaleX * (double) p1.x + rounder;
  753. X    p2.x = scaleX * (double) p2.x + rounder;
  754. X    p1.y = scaleY * (double) p1.y + rounder;
  755. X    p2.y = scaleY * (double) p2.y + rounder;
  756. X
  757. X    diffx = p2.x - p1.x;
  758. X    diffy = p2.y - p1.y;
  759. X
  760. X    if (diffx != 0.0 && diffy != 0.0) {
  761. X    if (ABS(diffx) > ABS(diffy)) {
  762. X        inc = (diffx < 0) ? -1 : 1;
  763. X        change_ratio = diffy / diffx;
  764. X        for (x = p1.x; x != p2.x; x += inc) {
  765. X        y = (x - p1.x) * change_ratio + p1.y + rounder;
  766. X        PUT_BIT(x, y);
  767. X        }
  768. X        PUT_BIT(p2.x, p2.y);
  769. X    } else {
  770. X        inc = (diffy < 0) ? -1 : 1;
  771. X        change_ratio = diffx / diffy;
  772. X        for (y = p1.y; y != p2.y; y += inc) {
  773. X        x = (y - p1.y) * change_ratio + p1.x + rounder;
  774. X        PUT_BIT(x, y);
  775. X        }
  776. X        PUT_BIT(p2.x, p2.y);
  777. X    }
  778. X    } else {
  779. X    if (diffx) {        /* horizontal line */
  780. X        y = p1.y;
  781. X        inc = (diffx < 0) ? -1 : 1;
  782. X        for (x = p1.x; x != p2.x; x += inc) {
  783. X        PUT_BIT(x, y);
  784. X        }
  785. X        PUT_BIT(p2.x, y);
  786. X    } else {
  787. X        x = p1.x;
  788. X        inc = (diffy < 0) ? -1 : 1;
  789. X        for (y = p1.y; y != p2.y; y += inc) {
  790. X        PUT_BIT(x, y);
  791. X        }
  792. X        PUT_BIT(x, p2.y);
  793. X    }
  794. X    }
  795. X}
  796. X
  797. X
  798. Xlj_dump_map(to_printer)
  799. X    int     to_printer;
  800. X{
  801. X    register int r;
  802. X    char    ccount[8];/* [hot@mh.nl] */
  803. X    char    hdr[80];/* [hot@mh.nl] */
  804. X    char   *mp = map;
  805. X    char   *p,leeg,
  806. X           *maxp;        /* for LF-char test */
  807. X    short int schrijfspaar,hdr_length;
  808. X    short int county,countx,countsx,countdif;/* [hot@mh.nl] */
  809. X
  810. X    if (to_printer) {
  811. X    hdr[0] = ESC;
  812. X
  813. X    /* reset printer */
  814. X    hdr_length = 1 + n_strcpy(&hdr[1], "E");
  815. X    write(1, hdr, hdr_length);
  816. X
  817. X    /* set printer to interpret a '\n' char to a '\r\n' pair */
  818. X    hdr_length = 1 + n_strcpy(&hdr[1], "&k2G");
  819. X    write(1, hdr, hdr_length);
  820. X
  821. X    /* raster graphics resolution: 300 dots/in */
  822. X    hdr_length = 1 + n_strcpy(&hdr[1], "*t300R");
  823. X    write(1, hdr, hdr_length);
  824. X
  825. X    if (printer == LASERLOW) {
  826. X        /* set cursor to col 11  */
  827. X        hdr_length = 1 + n_strcpy(&hdr[1], "&a11C");
  828. X        write(1, hdr, hdr_length);
  829. X
  830. X            /* set cursor to row 10 */
  831. X        hdr_length = 1 + n_strcpy(&hdr[1], "&a10R");
  832. X        write(1, hdr, hdr_length);
  833. X        /* [hot@mh.nl] */
  834. X    }
  835. X
  836. X    /* start graphics at current cursor posn */
  837. X    hdr_length = 1 + n_strcpy(&hdr[1], "*r1A");
  838. X    write(1, hdr, hdr_length);
  839. X
  840. X    if (printer==LASERLOW) {
  841. X        /* transfer-line-of-graphics escape sequence -- 235 is Xlim */
  842. X        hdr_length = 1 + n_strcpy(&hdr[1], "*b");
  843. X        itoa(Xlim,ccount);
  844. X        hdr_length += n_strcpy(&hdr[hdr_length], ccount);
  845. X        hdr_length += n_strcpy(&hdr[hdr_length], "W");
  846. X    }
  847. X
  848. X    /*
  849. X     * write Ylim rows, each row is Xlim bytes starting at offset r from
  850. X     * map[0] 
  851. X     */
  852. X    for (r = (Ylim - 1) * Xlim,county=1; r >= 0; r -= Xlim,county++) {
  853. X        /* check this row for LF-chars; replace with byte value of 8 */
  854. X        p = mp + r;
  855. X        maxp = p + Xlim;
  856. X        leeg=0;    /* [hot@mh.nl] */
  857. X        countx=0;
  858. X        schrijfspaar=FALSE;
  859. X        while (p < maxp) {
  860. X        if (*p == '\n') *p = '\010';
  861. X        if (printer != LASERLOW){
  862. X        if (*p == '\000') {
  863. X            if (schrijfspaar==TRUE) {
  864. X            /* transfer-line-of-graphics escape sequence -- 235 is Xlim */
  865. X                hdr_length += n_strcpy(&hdr[hdr_length], "\033*b");
  866. X                itoa(countdif,ccount);
  867. X                hdr_length += n_strcpy(&hdr[hdr_length], ccount);
  868. X                hdr_length += n_strcpy(&hdr[hdr_length], "W");
  869. X                write(1, hdr, hdr_length);
  870. X                write(1, mp + r + countsx, countdif);
  871. X            /* end raster graphics */
  872. X                hdr_length = 1 + n_strcpy(&hdr[1], "*rB");
  873. X                write(1, hdr, hdr_length);
  874. X                schrijfspaar=FALSE;
  875. X                fflush(stdout);
  876. X                }
  877. X            }
  878. X         else { /* *p != 0 */
  879. X             if (schrijfspaar==FALSE) {
  880. X                /* make cursorposition header */
  881. X            /* set cursor to current col  */
  882. X                hdr_length = 1 + n_strcpy(&hdr[1], "*p");
  883. X                itoa((countx*8),ccount);
  884. X                hdr_length += n_strcpy(&hdr[hdr_length], ccount);
  885. X                hdr_length += n_strcpy(&hdr[hdr_length], "X");
  886. X            /* set cursor to current row */
  887. X                hdr_length += n_strcpy(&hdr[hdr_length], "\033*p");
  888. X                itoa(county,ccount);
  889. X                hdr_length += n_strcpy(&hdr[hdr_length], ccount);
  890. X                hdr_length += n_strcpy(&hdr[hdr_length], "Y");
  891. X            /* start graphics at current cursor posn */
  892. X                hdr_length += n_strcpy(&hdr[hdr_length], "\033*r1A");
  893. X                countdif=1;countsx=countx;
  894. X                schrijfspaar=TRUE;
  895. X                     }
  896. X                      else /* schrijfspaar==TRUE */
  897. X              {
  898. X                  countdif++;
  899. X              }
  900. X
  901. X             }        /* end of if (*p == 0) */
  902. X                    /* [hot@mh.nl] */
  903. X          }         /* end of if (printer != LASERLOW) */
  904. X        p++;countx++;
  905. X        }             /* end of while (p < maxp) */
  906. X        if (printer == LASERLOW) { 
  907. X            write(1, hdr, hdr_length);
  908. X            write(1, mp + r, Xlim);
  909. X        }
  910. X        else {
  911. X            if (schrijfspaar==TRUE) {
  912. X            /* transfer-line-of-graphics escape sequence -- 235 is Xlim */
  913. X                hdr_length += n_strcpy(&hdr[hdr_length], "\033*b");
  914. X                itoa(countdif,ccount);
  915. X                hdr_length += n_strcpy(&hdr[hdr_length], ccount);
  916. X                hdr_length += n_strcpy(&hdr[hdr_length], "W");
  917. X                write(1, hdr, hdr_length);
  918. X                write(1, mp + r + countsx, countdif);
  919. X            /* end raster graphics */
  920. X                hdr_length = 1 + n_strcpy(&hdr[1], "*rB");
  921. X                write(1, hdr, hdr_length);
  922. X                schrijfspaar=FALSE;
  923. X                }
  924. X        }         /* end else van if (printer==LASERLOW) */
  925. X        fflush(stdout);
  926. X    }        /* end van de grote for loop voor iedere regel */
  927. X    if (printer==LASERLOW) {
  928. X        /* end raster graphics */
  929. X        hdr_length = 1 + n_strcpy(&hdr[1], "*rB");
  930. X        write(1, hdr, hdr_length);
  931. X    }
  932. X
  933. X    /* reset printer and eject the page 
  934. X    hdr_length = 1 + n_strcpy(&hdr[1], "E");
  935. X    write(1, hdr, hdr_length);
  936. X*/
  937. X    /*
  938. X     * set printer to interpret a '\n' char to a '\r\n' pair. this works
  939. X     * in combo with the plot script, which also controls interpretation
  940. X     * of \n's at the port 
  941. X     */
  942. X    hdr_length = 1 + n_strcpy(&hdr[1], "&k2G");
  943. X    write(1, hdr, hdr_length);
  944. X
  945. X    fflush(stdout);
  946. X    }
  947. X}
  948. X
  949. X
  950. X/*
  951. X * copy string from src to dst, including terminating \0.
  952. X * return number of chars copied, excluding terminating \0
  953. X */
  954. Xint
  955. Xn_strcpy(dst, src)
  956. X    char   *dst,
  957. X           *src;
  958. X{
  959. X    char   *p;
  960. X
  961. X    p = src;
  962. X    while (*dst++ = *src++);
  963. X    return ((--src) - p);
  964. X}
  965. X
  966. X
  967. Xlj_init_map()
  968. X{
  969. X    register int k;
  970. X    register char *mp;
  971. X    int     map_max ;
  972. X#ifdef TRUESOLID
  973. X    extern double PUs_per_dot;    /* declared in file filltype.c */
  974. X#endif
  975. X
  976. X    switch(printer) {
  977. X        case LASERLOW:
  978. X            Ylim=1442;
  979. X            Xlim=235;
  980. X            scaleX=0.180859;
  981. X            scaleY=0.180859;
  982. X            rounder=0.0;
  983. X            break;
  984. X        case LASERMED:
  985. X            Ylim=1841;
  986. X            Xlim=300;
  987. X            scaleX=0.231205;
  988. X            scaleY=0.231205;
  989. X            rounder=0.0;
  990. X            break;
  991. X
  992. X/* scaleX = scaleY = number of dots per plotter unit
  993. X                   = 1440 dot rows in y-direction / 7962 PU's in y-dir */
  994. X        case LASERHIGH:
  995. X            Ylim=3000;
  996. X            Ylim8=375;
  997. X            Xlim=298;
  998. X            scaleX=0.2995369;
  999. X            scaleY=0.2995369;
  1000. X            rounder=0.0;
  1001. X            break;
  1002. X    }
  1003. X    map_max = Ylim * Xlim;
  1004. X
  1005. X#ifdef TRUESOLID
  1006. X    PUs_per_dot = 1.0 / scaleX;    /* used by fix_fill() in file filltype.c */
  1007. X#endif
  1008. X
  1009. X    mp = map;
  1010. X    for (k = 0; k < map_max; k++) {
  1011. X    *mp++ = 0;
  1012. X    }
  1013. X}
  1014. SHAR_EOF
  1015. $TOUCH -am 0216085089 libplot/lp/lj_map.c &&
  1016. chmod 0644 libplot/lp/lj_map.c ||
  1017. echo "restore of libplot/lp/lj_map.c failed"
  1018. set `wc -c libplot/lp/lj_map.c`;Wc_c=$1
  1019. if test "$Wc_c" != "9092"; then
  1020.     echo original size 9092, current size $Wc_c
  1021. fi
  1022. # ============= libplot/lp/maps.c ==============
  1023. echo "x - extracting libplot/lp/maps.c (Text)"
  1024. sed 's/^X//' << 'SHAR_EOF' > libplot/lp/maps.c &&
  1025. X/*
  1026. X * maps.c
  1027. X *
  1028. X * Copyright (c) 1988 Environmental Defense Fund, Inc.
  1029. X *
  1030. X * Uses the value of printer to dispatch map-related function
  1031. X * calls to either ep_map.c or lj_map.c
  1032. X */
  1033. X
  1034. X#include "const.h"
  1035. X#include "vars.h"
  1036. X
  1037. X/*
  1038. X * This is a single bit map, accessed by either the epson or laserjet
  1039. X * map-related function calls, depending on which printer is being used.
  1040. X * It has been declared to be somewhat larger than necessary.
  1041. X */
  1042. X
  1043. Xchar    map[BITMAPSIZE];
  1044. X
  1045. Xinit_map()
  1046. X{
  1047. X    switch (printer) {
  1048. X    case EPSON:
  1049. X    ep_init_map();
  1050. X    break;
  1051. X    case LASERLOW:
  1052. X    case LASERMED:
  1053. X    case LASERHIGH:
  1054. X    lj_init_map();
  1055. X    break;
  1056. X    case IBM_PRO:
  1057. X    ib_init_map();
  1058. X    break;
  1059. X    }
  1060. X}
  1061. X
  1062. Xdump_map(to_printer)
  1063. X    int     to_printer;
  1064. X{
  1065. X    switch (printer) {
  1066. X    case EPSON:
  1067. X    ep_dump_map(to_printer);
  1068. X    break;
  1069. X    case LASERLOW:
  1070. X    case LASERMED:
  1071. X    case LASERHIGH:
  1072. X    lj_dump_map(to_printer);
  1073. X    break;
  1074. X    case IBM_PRO:
  1075. X    ib_dump_map(to_printer);
  1076. X    break;
  1077. X    }
  1078. X}
  1079. X
  1080. Xput_seg(p1, p2)
  1081. X    POINT   p1,
  1082. X            p2;
  1083. X{
  1084. X    switch (printer) {
  1085. X    case EPSON:
  1086. X    ep_put_seg(p1, p2);
  1087. X    break;
  1088. X    case LASERLOW:
  1089. X    case LASERMED:
  1090. X    case LASERHIGH:
  1091. X    lj_put_seg(p1, p2);
  1092. X    break;
  1093. X    case IBM_PRO:
  1094. X    ib_put_seg(p1, p2);
  1095. X    break;
  1096. X    }
  1097. X}
  1098. SHAR_EOF
  1099. $TOUCH -am 1007125888 libplot/lp/maps.c &&
  1100. chmod 0644 libplot/lp/maps.c ||
  1101. echo "restore of libplot/lp/maps.c failed"
  1102. set `wc -c libplot/lp/maps.c`;Wc_c=$1
  1103. if test "$Wc_c" != "1200"; then
  1104.     echo original size 1200, current size $Wc_c
  1105. fi
  1106. echo "End of part 4, continue with part 5"
  1107. exit 0
  1108.  
  1109.  
  1110.  
  1111. -- 
  1112. UUCP: ..!uunet!mcsun!hp4nl!integow!hot    or  hot@integow.UUCP or hot@hot.mug
  1113. Roland van Hout, Sr. software engineer, Integrity software consultants, 
  1114.          Pelmolenlaan 16, 3447 GW Woerden, Netherlands,
  1115.             tel +31 3480-30131, fax +31 3480-30182
  1116.