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

  1. /* ///////////////////////////////////////////////////////////////////
  2. // $Id: hpgl.c,v 1.4 1994/07/25 06:03:13 mjl Exp $
  3. // $Log: hpgl.c,v $
  4.  * Revision 1.4  1994/07/25  06:03:13  mjl
  5.  * Added new driver -- HP Laserjet III in HPGL emulation mode (lj_hpgl).
  6.  * Produces fairly small output files (compared to the LJIIP compressed
  7.  * rasters, MUCH smaller than the LJII full rasters).  Contributed by Conrad
  8.  * Steenberg.
  9.  *
  10.  * Revision 1.3  1994/07/19  22:30:17  mjl
  11.  * All device drivers: enabling macro renamed to PLD_<driver>, where <driver>
  12.  * is xwin, ps, etc.  See plDevs.h for more detail.
  13.  *
  14.  * Revision 1.2  1994/05/26  19:21:45  mjl
  15.  * Minor changes to bring up to spec with the other drivers.
  16.  *
  17.  * Revision 1.1  1994/05/25  09:34:14  mjl
  18.  * Consolidated HP pen plotter driver, contributed by Mark Olesen
  19.  * (olesen@weber.me.queensu.ca).
  20.  *
  21. //
  22. //  File:       hpgl.c
  23. //
  24. //  Descript:   hp7470, hp7580, and lj_hpgl drivers
  25. //
  26. //  Library:    ---
  27. //
  28. //  Requires:   ---
  29. //
  30. //  Public:     plD_init_hp7470()
  31. //              plD_init_hp7580()
  32. //              plD_init_lj_hpgl()
  33. //              plD_line_hpgl()
  34. //              plD_polyline_hpgl()
  35. //              plD_eop_hpgl()
  36. //              plD_bop_hpgl()
  37. //              plD_tidy_hpgl()
  38. //              plD_state_hpgl()
  39. //              plD_esc_hpgl()
  40. //
  41. //              pldummy_hpgl()
  42. //
  43. //  Private:    initialize_hpgl_pls()
  44. //
  45. //  Notes:      ---
  46. //
  47. //  Revisions:
  48. //  13 Apr 94   mjo     documented, amalgamated hp7470 and hp7580 drivers
  49. //                      hpgl commands changed to uppercase: makes HPGL
  50. //                      interpreters happier and the plotters don't care
  51. //
  52. /////////////////////////////////////////////////////////////////// */
  53.  
  54. #include "plDevs.h"
  55.  
  56. #if defined(PLD_hp7470) || defined(PLD_hp7580) || defined(PLD_lj_hpgl)
  57.  
  58. #include "plplotP.h"
  59. #include <stdio.h>
  60. #include <string.h>
  61. #include "drivers.h"
  62.  
  63. /* top level declarations */
  64.  
  65. /* Plotter sizes */
  66.  
  67. #define HP7470_XMIN       0
  68. #define HP7470_XMAX   10299
  69. #define HP7470_YMIN       0
  70. #define HP7470_YMAX    7649
  71.  
  72. #define HP7580_XMIN  -4500
  73. #define HP7580_XMAX   4500
  74. #define HP7580_YMIN  -2790
  75. #define HP7580_YMAX   2790
  76.  
  77. #define LJIII_XMIN  0
  78. #define LJIII_XMAX  11000
  79. #define LJIII_YMIN  500
  80. #define LJIII_YMAX  7700
  81.  
  82. /*----------------------------------------------------------------------*\
  83.  * initialize_hpgl_pls()
  84.  *
  85.  * Initialize plot stream
  86. \*----------------------------------------------------------------------*/
  87.  
  88. static void
  89. initialize_hpgl_pls(PLStream *pls)
  90. {
  91.     PLDev *dev = (PLDev *) pls->dev;
  92.  
  93.     pls->termin = 0;            /* not an interactive terminal */
  94.     pls->icol0 = 1;
  95.     pls->width = 1;
  96.     pls->bytecnt = 0;
  97.     pls->page = 0;
  98.  
  99.     plFamInit(pls);             /* Initialize family file info */
  100.     plOpenFile(pls);            /* get file name if not already set */
  101.  
  102.     dev->xold = UNDEFINED;
  103.     dev->yold = UNDEFINED;
  104.     dev->xlen = dev->xmax - dev->xmin;
  105.     dev->ylen = dev->ymax - dev->ymin;
  106.  
  107.     plP_setpxl((PLFLT) 40., (PLFLT) 40.);
  108.     plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
  109. }
  110.  
  111. /*----------------------------------------------------------------------*\
  112.  * plD_init_hp7470()
  113.  *
  114.  * Initialize device.
  115. \*----------------------------------------------------------------------*/
  116.  
  117. #ifdef PLD_hp7470
  118. void
  119. plD_init_hp7470(PLStream *pls)
  120. {
  121.     PLDev *dev;
  122.  
  123.     pls->color = 1;
  124.     dev = plAllocDev(pls);      /* Allocate device-specific data */
  125.     dev->xmin = HP7470_XMIN;
  126.     dev->xmax = HP7470_XMAX;
  127.     dev->ymin = HP7470_YMIN;
  128.     dev->ymax = HP7470_YMAX;
  129.  
  130.     initialize_hpgl_pls(pls);   /* initialize plot stream */
  131.  
  132.     fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", pls->OutFile );
  133. }
  134. #endif          /* PLD_hp7470 */
  135.  
  136. /*----------------------------------------------------------------------*\
  137.  * plD_init_hp7580()
  138.  *
  139.  * Initialize device.
  140. \*----------------------------------------------------------------------*/
  141.  
  142. #ifdef PLD_hp7580
  143. void
  144. plD_init_hp7580(PLStream *pls)
  145. {
  146.     PLDev *dev;
  147.  
  148.     pls->color = 1;
  149.     dev = plAllocDev(pls);      /* Allocate device-specific data */
  150.     dev->xmin = HP7580_XMIN;
  151.     dev->xmax = HP7580_XMAX;
  152.     dev->ymin = HP7580_YMIN;
  153.     dev->ymax = HP7580_YMAX;
  154.  
  155.     initialize_hpgl_pls(pls);   /* initialize plot stream */
  156.  
  157.     fputs( "\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n", pls->OutFile );
  158.     fputs( "RO90;IP;SP4;PA;\n", pls->OutFile );
  159. }
  160. #endif  /* PLD_hp7580 */
  161.  
  162. /*----------------------------------------------------------------------*\
  163.  * plD_init_lj_hpgl()
  164.  *
  165.  * Initialize device.
  166. \*----------------------------------------------------------------------*/
  167.  
  168. #ifdef PLD_lj_hpgl
  169. void
  170. plD_init_lj_hpgl(PLStream *pls)
  171. {
  172.     PLDev *dev;
  173.  
  174.     dev = plAllocDev(pls);      /* Allocate device-specific data */
  175.     dev->xmin = LJIII_XMIN;
  176.     dev->xmax = LJIII_XMAX;
  177.     dev->ymin = LJIII_YMIN;
  178.     dev->ymax = LJIII_YMAX;
  179.  
  180.     initialize_hpgl_pls(pls);   /* initialize plot stream */
  181.  
  182. /* HP III changes here up to .I200 puts printer in HPGL/2 emulation
  183.    with 300DPI printing.
  184.    Next line : added pw 0.2 for pen width 0.2 (of an inch ?)
  185. */
  186.     fputs("\x1b*T300R\x1b%1B;\x1b.I200;;17:\x1b.N;19:\x1b.M;;;10:IN;\n",
  187.       pls->OutFile);
  188.  
  189.     fputs("RO90;IP;PW 0.2;SP 1;PA;", pls->OutFile);
  190. }
  191. #endif  /* PLD_lj_hpgl */
  192.  
  193. /*----------------------------------------------------------------------*\
  194.  * plD_line_hpgl()
  195.  *
  196.  * Draw a line in the current color from (x1,y1) to (x2,y2).
  197. \*----------------------------------------------------------------------*/
  198.  
  199. void
  200. plD_line_hpgl(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  201. {
  202.     PLDev *dev = (PLDev *) pls->dev;
  203.     int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
  204.  
  205.     /* Write out old path */
  206.     if (x1 != dev->xold || y1 != dev->yold)    /* Write out old path */
  207.       pls->bytecnt += fprintf( pls->OutFile, "PU%d %d;", x1, y1 );
  208.  
  209.     /* Add new point to path */
  210.     pls->bytecnt += fprintf( pls->OutFile, "PD%d %d\n", x2, y2);
  211.  
  212.     dev->xold = x2;
  213.     dev->yold = y2;
  214. }
  215.  
  216. /*----------------------------------------------------------------------*\
  217.  * plD_polyline_hpgl()
  218.  *
  219.  * Draw a polyline in the current color.
  220. \*----------------------------------------------------------------------*/
  221.  
  222. void
  223. plD_polyline_hpgl(PLStream *pls, short *xa, short *ya, PLINT npts)
  224. {
  225.   register PLINT i;
  226.   PLDev *dev = (PLDev *) pls->dev;
  227.  
  228.   /* Write out old path */
  229.   if (xa[0] != dev->xold || ya[0] != dev->yold)
  230.     pls->bytecnt += fprintf( pls->OutFile, "PU%d %d;", xa[0], ya[0] );
  231.  
  232.   for (i = 1; i < npts; i++)        /* Add new point to path */
  233.     pls->bytecnt += fprintf( pls->OutFile, "PD%d %d\n", xa[i], ya[i] );
  234.  
  235.   dev->xold = xa[ npts - 1 ];
  236.   dev->yold = ya[ npts - 1 ];
  237. }
  238.  
  239. /*----------------------------------------------------------------------*\
  240.  * plD_eop_hpgl()
  241.  *
  242.  * End of page.
  243. \*----------------------------------------------------------------------*/
  244.  
  245. void
  246. plD_eop_hpgl(PLStream *pls)
  247. {
  248. }
  249.  
  250. /*----------------------------------------------------------------------*\
  251.  * plD_bop_hpgl()
  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_hpgl(PLStream *pls)
  259. {
  260.     PLDev *dev = (PLDev *) pls->dev;
  261.  
  262.     dev->xold = UNDEFINED;
  263.     dev->yold = UNDEFINED;
  264.  
  265.     fputs( "PG;\n", pls->OutFile );
  266.     if (!pls->termin)
  267.         plGetFam(pls);
  268.  
  269.     pls->page++;
  270. }
  271.  
  272. /*----------------------------------------------------------------------*\
  273.  * plD_tidy_hpgl()
  274.  *
  275.  * Close graphics file or otherwise clean up.
  276. \*----------------------------------------------------------------------*/
  277.  
  278. void
  279. plD_tidy_hpgl(PLStream *pls)
  280. {
  281.     fputs( "SP0\n", pls->OutFile );
  282.     fclose(pls->OutFile);
  283. }
  284.  
  285. /*----------------------------------------------------------------------*\
  286.  * plD_state_hpgl()
  287.  *
  288.  * Handle change in PLStream state (color, pen width, fill attribute, etc).
  289. \*----------------------------------------------------------------------*/
  290.  
  291. void
  292. plD_state_hpgl(PLStream *pls, PLINT op)
  293. {
  294.     switch (op) {
  295.  
  296.     case PLSTATE_WIDTH:
  297.         break;
  298.  
  299.     case PLSTATE_COLOR0:
  300.         if ( pls->icol0 < 1 || pls->icol0 > 8)
  301.           fputs( "\nInvalid pen selection.", stderr );
  302.         else
  303.           fprintf( pls->OutFile, "SP%d %d\n", pls->icol0, pls->width );
  304.         break;
  305.  
  306.     case PLSTATE_COLOR1:
  307.         break;
  308.     }
  309. }
  310.  
  311. /*----------------------------------------------------------------------*\
  312.  * plD_esc_hpgl()
  313.  *
  314.  * Escape function.
  315. \*----------------------------------------------------------------------*/
  316.  
  317. void
  318. plD_esc_hpgl(PLStream *pls, PLINT op, void *ptr)
  319. {
  320. }
  321.  
  322. #else
  323. int
  324. pldummy_hpgl(void)
  325. {
  326.     return 0;
  327. }
  328.  
  329. #endif        /* PLD_hp7470 || PLD_hp7580 || PLD_lj_hpgl */
  330.