home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / maths / plplot / plplot_2 / drivers / ljii.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  8.1 KB  |  326 lines

  1. /* $Id: ljii.c,v 1.18 1994/07/19 22:30:20 mjl Exp $
  2.  * $Log: ljii.c,v $
  3.  * Revision 1.18  1994/07/19  22:30:20  mjl
  4.  * All device drivers: enabling macro renamed to PLD_<driver>, where <driver>
  5.  * is xwin, ps, etc.  See plDevs.h for more detail.
  6.  *
  7.  * Revision 1.17  1994/04/30  16:14:43  mjl
  8.  * Fixed format field (%ld instead of %d) or introduced casts where
  9.  * appropriate to eliminate warnings given by gcc -Wall.
  10.  *
  11.  * Revision 1.16  1994/04/08  11:34:38  mjl
  12.  * Fix for DOS machines running DJGPP.
  13.  *
  14.  * Revision 1.15  1994/03/23  06:34:28  mjl
  15.  * All drivers: cleaned up by eliminating extraneous includes (stdio.h and
  16.  * stdlib.h now included automatically by plplotP.h), extraneous clears
  17.  * of pls->fileset, pls->page, and pls->OutFile = NULL (now handled in
  18.  * driver interface or driver initialization as appropriate).  Special
  19.  * handling for malloc includes eliminated (no longer needed) and malloc
  20.  * prototypes fixed as necessary.
  21.  *
  22.  * Revision 1.14  1993/08/09  22:12:32  mjl
  23.  * Changed call syntax to plRotPhy to allow easier usage.
  24.  *
  25.  * Revision 1.13  1993/07/31  07:56:34  mjl
  26.  * Several driver functions consolidated, for all drivers.  The width and color
  27.  * commands are now part of a more general "state" command.  The text and
  28.  * graph commands used for switching between modes is now handled by the
  29.  * escape function (very few drivers require it).  The device-specific PLDev
  30.  * structure is now malloc'ed for each driver that requires it, and freed when
  31.  * the stream is terminated.
  32. */
  33.  
  34. /*    ljii.c
  35.  
  36.     PLPLOT Laser Jet II device driver.
  37.     Note only the 150 dpi mode is supported.  The others (75,100,300)
  38.     should work by just changing the value of DPI and changing the
  39.     values passed to plP_setphy().
  40. */
  41. #include "plDevs.h"
  42.  
  43. #ifdef PLD_ljii
  44.  
  45. #include "plplotP.h"
  46. #include "drivers.h"
  47. #include <math.h>
  48. #include <string.h>
  49.  
  50. #ifdef __GO32__            /* dos386/djgpp */
  51. #ifdef MSDOS
  52. #undef MSDOS
  53. #endif
  54. #endif
  55.  
  56. /* Function prototypes */
  57.  
  58. static void setpoint(PLINT, PLINT);
  59.  
  60. /* top level declarations */
  61.  
  62. #define JETX     1103
  63. #define JETY     1409
  64.  
  65. #define DPI      150        /* Resolution Dots per Inch */
  66. #define CURX     51
  67. #define CURY     61
  68. #define XDOTS     1104L        /* # dots across */
  69. #define YDOTS     1410L        /* # dots down     */
  70. #define BPROW     XDOTS/8L    /* # bytes across */
  71. #define NBYTES     BPROW*YDOTS    /* total number of bytes */
  72.  
  73. /* Graphics control characters. */
  74.  
  75. #define ESC      0x1b
  76. #define FF       0x0c
  77.  
  78. static char mask[8] =
  79. {'\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001'};
  80.  
  81. #ifndef MSDOS
  82. #define _HUGE
  83. #else
  84. #define _HUGE _huge
  85. #endif
  86.  
  87. static char _HUGE *bitmap;    /* points to memory area NBYTES in size */
  88.  
  89. /*----------------------------------------------------------------------*\
  90. * plD_init_ljii()
  91. *
  92. * Initialize device.
  93. \*----------------------------------------------------------------------*/
  94.  
  95. void
  96. plD_init_ljii(PLStream *pls)
  97. {
  98.     PLDev *dev;
  99.  
  100.     pls->termin = 0;        /* not an interactive terminal */
  101.     pls->icol0 = 1;
  102.     pls->color = 0;
  103.     pls->width = 1;
  104.     pls->bytecnt = 0;
  105.     pls->page = 0;
  106.  
  107. /* Initialize family file info */
  108.  
  109.     plFamInit(pls);
  110.  
  111. /* Prompt for a file name if not already set */
  112.  
  113.     plOpenFile(pls);
  114.  
  115. /* Allocate and initialize device-specific data */
  116.  
  117.     dev = plAllocDev(pls);
  118.  
  119.     dev->xold = UNDEFINED;
  120.     dev->yold = UNDEFINED;
  121.     dev->xmin = 0;
  122.     dev->ymin = 0;
  123.  
  124.     plP_setpxl((PLFLT) 5.905, (PLFLT) 5.905);
  125.  
  126. /* Rotate by 90 degrees since portrait mode addressing is used */
  127.  
  128.     dev->xmin = 0;
  129.     dev->ymin = 0;
  130.     dev->xmax = JETY;
  131.     dev->ymax = JETX;
  132.     dev->xlen = dev->xmax - dev->xmin;
  133.     dev->ylen = dev->ymax - dev->ymin;
  134.  
  135.     plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
  136.  
  137. /* Allocate storage for bit map matrix */
  138.  
  139. #ifdef MSDOS
  140.     if ((bitmap = (char _HUGE *) halloc((long) NBYTES, sizeof(char))) == NULL)
  141.     plexit("Out of memory in call to calloc");
  142. #else
  143.     if ((bitmap = (void *) calloc(NBYTES, sizeof(char))) == NULL)
  144.     plexit("Out of memory in call to calloc");
  145. #endif
  146.  
  147. /* Reset Printer */
  148.  
  149.     fprintf(pls->OutFile, "%cE", ESC);
  150. }
  151.  
  152. /*----------------------------------------------------------------------*\
  153. * plD_line_ljii()
  154. *
  155. * Draw a line in the current color from (x1,y1) to (x2,y2).
  156. \*----------------------------------------------------------------------*/
  157.  
  158. void
  159. plD_line_ljii(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  160. {
  161.     PLDev *dev = (PLDev *) pls->dev;
  162.     int i;
  163.     int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
  164.     PLINT x1b, y1b, x2b, y2b;
  165.     float length, fx, fy, dx, dy;
  166.  
  167. /* Take mirror image, since PCL expects (0,0) to be at top left */
  168.  
  169.     y1 = dev->ymax - (y1 - dev->ymin);
  170.     y2 = dev->ymax - (y2 - dev->ymin);
  171.  
  172. /* Rotate by 90 degrees */
  173.  
  174.     plRotPhy(1, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x1, &y1);
  175.     plRotPhy(1, dev->xmin, dev->ymin, dev->xmax, dev->ymax, &x2, &y2);
  176.  
  177.     x1b = x1, x2b = x2, y1b = y1, y2b = y2;
  178.     length = (float) sqrt((double)
  179.              ((x2b - x1b) * (x2b - x1b) + (y2b - y1b) * (y2b - y1b)));
  180.  
  181.     if (length == 0.)
  182.     length = 1.;
  183.     dx = (x2 - x1) / length;
  184.     dy = (y2 - y1) / length;
  185.  
  186.     fx = x1;
  187.     fy = y1;
  188.     setpoint((PLINT) x1, (PLINT) y1);
  189.     setpoint((PLINT) x2, (PLINT) y2);
  190.  
  191.     for (i = 1; i <= (int) length; i++)
  192.     setpoint((PLINT) (fx += dx), (PLINT) (fy += dy));
  193. }
  194.  
  195. /*----------------------------------------------------------------------*\
  196. * plD_polyline_ljii()
  197. *
  198. * Draw a polyline in the current color.
  199. \*----------------------------------------------------------------------*/
  200.  
  201. void
  202. plD_polyline_ljii(PLStream *pls, short *xa, short *ya, PLINT npts)
  203. {
  204.     PLINT i;
  205.  
  206.     for (i = 0; i < npts - 1; i++)
  207.     plD_line_ljii(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]);
  208. }
  209.  
  210. /*----------------------------------------------------------------------*\
  211. * plD_eop_ljii()
  212. *
  213. * End of page.(prints it here).
  214. \*----------------------------------------------------------------------*/
  215.  
  216. void
  217. plD_eop_ljii(PLStream *pls)
  218. {
  219.     PLINT i, j;
  220.  
  221.     /* First move cursor to origin */
  222.  
  223.     fprintf(pls->OutFile, "%c*p%dX", ESC, CURX);
  224.     fprintf(pls->OutFile, "%c*p%dY", ESC, CURY);
  225.  
  226.     /* Then put Laser Printer in 150 dpi mode */
  227.  
  228.     fprintf(pls->OutFile, "%c*t%dR", ESC, DPI);
  229.     fprintf(pls->OutFile, "%c*r1A", ESC);
  230.  
  231.     /* Write out raster data */
  232.  
  233.     for (j = 0; j < YDOTS; j++) {
  234.     fprintf(pls->OutFile, "%c*b%ldW", ESC, BPROW);
  235.     for (i = 0; i < BPROW; i++)
  236.         putc(*(bitmap + i + j * BPROW), pls->OutFile);
  237.     }
  238.     pls->bytecnt += NBYTES;
  239.  
  240.     /* End raster graphics and send Form Feed */
  241.  
  242.     fprintf(pls->OutFile, "%c*rB", ESC);
  243.     fprintf(pls->OutFile, "%c", FF);
  244.  
  245.     /* Finally, clear out bitmap storage area */
  246.  
  247.     memset(bitmap, '\0', NBYTES);
  248. }
  249.  
  250. /*----------------------------------------------------------------------*\
  251. * plD_bop_ljii()
  252. *
  253. * Set up for the next page.
  254. * Advance to next family file if necessary (file output).
  255. \*----------------------------------------------------------------------*/
  256.  
  257. void
  258. plD_bop_ljii(PLStream *pls)
  259. {
  260.     if (!pls->termin)
  261.     plGetFam(pls);
  262.  
  263.     pls->page++;
  264. }
  265.  
  266. /*----------------------------------------------------------------------*\
  267. * plD_tidy_ljii()
  268. *
  269. * Close graphics file or otherwise clean up.
  270. \*----------------------------------------------------------------------*/
  271.  
  272. void
  273. plD_tidy_ljii(PLStream *pls)
  274. {
  275. /* Reset Printer */
  276.  
  277.     fprintf(pls->OutFile, "%cE", ESC);
  278.     fclose(pls->OutFile);
  279.     free((void *) bitmap);
  280. }
  281.  
  282. /*----------------------------------------------------------------------*\
  283. * plD_state_ljii()
  284. *
  285. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  286. \*----------------------------------------------------------------------*/
  287.  
  288. void 
  289. plD_state_ljii(PLStream *pls, PLINT op)
  290. {
  291. }
  292.  
  293. /*----------------------------------------------------------------------*\
  294. * plD_esc_ljii()
  295. *
  296. * Escape function.
  297. \*----------------------------------------------------------------------*/
  298.  
  299. void
  300. plD_esc_ljii(PLStream *pls, PLINT op, void *ptr)
  301. {
  302. }
  303.  
  304. /*----------------------------------------------------------------------*\
  305. * setpoint()
  306. *
  307. * Sets a bit in the bitmap.
  308. \*----------------------------------------------------------------------*/
  309.  
  310. static void
  311. setpoint(PLINT x, PLINT y)
  312. {
  313.     PLINT index;
  314.     index = x / 8 + y * BPROW;
  315.     *(bitmap + index) = *(bitmap + index) | mask[x % 8];
  316. }
  317.  
  318. #else
  319. int 
  320. pldummy_ljii()
  321. {
  322.     return 0;
  323. }
  324.  
  325. #endif                /* PLD_ljii */
  326.