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

  1. /* $Id: impress.c,v 1.15 1994/07/19 22:30:18 mjl Exp $
  2.  * $Log: impress.c,v $
  3.  * Revision 1.15  1994/07/19  22:30:18  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.14  1994/03/23  06:34:26  mjl
  8.  * All drivers: cleaned up by eliminating extraneous includes (stdio.h and
  9.  * stdlib.h now included automatically by plplotP.h), extraneous clears
  10.  * of pls->fileset, pls->page, and pls->OutFile = NULL (now handled in
  11.  * driver interface or driver initialization as appropriate).  Special
  12.  * handling for malloc includes eliminated (no longer needed) and malloc
  13.  * prototypes fixed as necessary.
  14. */
  15.  
  16. /*    impress.c
  17.  
  18.     PLPLOT ImPress device driver.
  19. */
  20. #include "plDevs.h"
  21.  
  22. #ifdef PLD_imp
  23.  
  24. #include "plplotP.h"
  25. #include "drivers.h"
  26.  
  27. /* Function prototypes */
  28.  
  29. static void flushline(PLStream *);
  30.  
  31. /* top level declarations */
  32.  
  33. #define IMPX        2999
  34. #define IMPY        2249
  35.  
  36. #define BUFFPTS        50
  37. #define BUFFLENG    2*BUFFPTS
  38.  
  39. /* Graphics control characters. */
  40.  
  41. #define SET_HV_SYSTEM    0315
  42. #define OPBYTE1        031
  43. #define OPBYTE2        0140
  44. #define SET_ABS_H    0207
  45. #define SET_ABS_V    0211
  46. #define OPWORDH1    0
  47. #define OPWORDH2    150
  48. #define OPWORDV1    0
  49. #define OPWORDV2    150
  50. #define ENDPAGE        0333
  51.  
  52. #define SET_PEN        0350
  53. #define CREATE_PATH    0346
  54. #define DRAW_PATH    0352
  55. #define OPTYPE        017
  56.  
  57. static short *LineBuff;
  58. static short FirstLine;
  59. static int penchange = 0, penwidth;
  60. static short count;
  61.  
  62. /*----------------------------------------------------------------------*\
  63. * plD_init_imp()
  64. *
  65. * Initialize device (terminal).
  66. \*----------------------------------------------------------------------*/
  67.  
  68. void
  69. plD_init_imp(PLStream *pls)
  70. {
  71.     PLDev *dev;
  72.  
  73.     pls->termin = 0;        /* not an interactive terminal */
  74.     pls->icol0 = 1;
  75.     pls->color = 0;
  76.     pls->width = 1;
  77.     pls->bytecnt = 0;
  78.     pls->page = 0;
  79.  
  80. /* Initialize family file info */
  81.  
  82.     plFamInit(pls);
  83.  
  84. /* Prompt for a file name if not already set */
  85.  
  86.     plOpenFile(pls);
  87.  
  88. /* Allocate and initialize device-specific data */
  89.  
  90.     dev = plAllocDev(pls);
  91.  
  92.     dev->xold = UNDEFINED;
  93.     dev->yold = UNDEFINED;
  94.     dev->xmin = 0;
  95.     dev->ymin = 0;
  96.     dev->xmax = IMPX;
  97.     dev->ymax = IMPY;
  98.     dev->xlen = dev->xmax - dev->xmin;
  99.     dev->ylen = dev->ymax - dev->ymin;
  100.  
  101.     plP_setpxl((PLFLT) 11.81, (PLFLT) 11.81);
  102.     plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
  103.  
  104.     LineBuff = (short *) malloc(BUFFLENG * sizeof(short));
  105.     if (LineBuff == NULL) {
  106.     plexit("Error in memory alloc in plD_init_imp().");
  107.     }
  108.     fprintf(pls->OutFile, "@Document(Language ImPress, jobheader off)");
  109.     fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE1);
  110.     fprintf(pls->OutFile, "%c%c%c", SET_ABS_H, OPWORDH1, OPWORDH2);
  111.     fprintf(pls->OutFile, "%c%c%c", SET_ABS_V, OPWORDV1, OPWORDV2);
  112.     fprintf(pls->OutFile, "%c%c", SET_HV_SYSTEM, OPBYTE2);
  113. }
  114.  
  115. /*----------------------------------------------------------------------*\
  116. * plD_line_imp()
  117. *
  118. * Draw a line in the current color from (x1,y1) to (x2,y2).
  119. \*----------------------------------------------------------------------*/
  120.  
  121. void
  122. plD_line_imp(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  123. {
  124.     PLDev *dev = (PLDev *) pls->dev;
  125.     int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
  126.  
  127.     if (FirstLine) {
  128.     if (penchange) {
  129.         fprintf(pls->OutFile, "%c%c", SET_PEN, (char) penwidth);
  130.         penchange = 0;
  131.     }
  132.     /* Add both points to path */
  133.     count = 0;
  134.     FirstLine = 0;
  135.     *(LineBuff + count++) = (short) x1;
  136.     *(LineBuff + count++) = (short) y1;
  137.     *(LineBuff + count++) = (short) x2;
  138.     *(LineBuff + count++) = (short) y2;
  139.     }
  140.     else if ((count + 2) < BUFFLENG && x1 == dev->xold && y1 == dev->yold) {
  141.     /* Add new point to path */
  142.     *(LineBuff + count++) = (short) x2;
  143.     *(LineBuff + count++) = (short) y2;
  144.     }
  145.     else {
  146.     /* Write out old path */
  147.     count /= 2;
  148.     fprintf(pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256);
  149.     fwrite((char *) LineBuff, sizeof(short), 2 * count, pls->OutFile);
  150.     fprintf(pls->OutFile, "%c%c", DRAW_PATH, OPTYPE);
  151.  
  152.     /* And start a new path */
  153.     if (penchange) {
  154.         fprintf(pls->OutFile, "%c%c", SET_PEN, (char) penwidth);
  155.         penchange = 0;
  156.     }
  157.     count = 0;
  158.     *(LineBuff + count++) = (short) x1;
  159.     *(LineBuff + count++) = (short) y1;
  160.     *(LineBuff + count++) = (short) x2;
  161.     *(LineBuff + count++) = (short) y2;
  162.     }
  163.     dev->xold = x2;
  164.     dev->yold = y2;
  165. }
  166.  
  167. /*----------------------------------------------------------------------*\
  168. * plD_polyline_imp()
  169. *
  170. * Draw a polyline in the current color.
  171. \*----------------------------------------------------------------------*/
  172.  
  173. void
  174. plD_polyline_imp(PLStream *pls, short *xa, short *ya, PLINT npts)
  175. {
  176.     PLINT i;
  177.  
  178.     for (i = 0; i < npts - 1; i++)
  179.     plD_line_imp(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]);
  180. }
  181.  
  182. /*----------------------------------------------------------------------*\
  183. * plD_eop_imp()
  184. *
  185. * End of page.
  186. \*----------------------------------------------------------------------*/
  187.  
  188. void
  189. plD_eop_imp(PLStream *pls)
  190. {
  191.     flushline(pls);
  192.     fprintf(pls->OutFile, "%c", ENDPAGE);
  193. }
  194.  
  195. /*----------------------------------------------------------------------*\
  196. * plD_bop_imp()
  197. *
  198. * Set up for the next page.
  199. * Advance to next family file if necessary (file output).
  200. \*----------------------------------------------------------------------*/
  201.  
  202. void
  203. plD_bop_imp(PLStream *pls)
  204. {
  205.     PLDev *dev = (PLDev *) pls->dev;
  206.  
  207.     FirstLine = 1;
  208.     dev->xold = UNDEFINED;
  209.     dev->yold = UNDEFINED;
  210.  
  211.     if (!pls->termin)
  212.     plGetFam(pls);
  213.  
  214.     pls->page++;
  215. }
  216.  
  217. /*----------------------------------------------------------------------*\
  218. * plD_tidy_imp()
  219. *
  220. * Close graphics file or otherwise clean up.
  221. \*----------------------------------------------------------------------*/
  222.  
  223. void
  224. plD_tidy_imp(PLStream *pls)
  225. {
  226.     free((void *) LineBuff);
  227.     fclose(pls->OutFile);
  228. }
  229.  
  230. /*----------------------------------------------------------------------*\
  231. * plD_state_imp()
  232. *
  233. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  234. \*----------------------------------------------------------------------*/
  235.  
  236. void 
  237. plD_state_imp(PLStream *pls, PLINT op)
  238. {
  239.     switch (op) {
  240.  
  241.     case PLSTATE_WIDTH:
  242.     if (pls->width > 0 && pls->width <= 20) {
  243.         penwidth = pls->width;
  244.         penchange = 1;
  245.     }
  246.     break;
  247.  
  248.     case PLSTATE_COLOR0:
  249.     break;
  250.  
  251.     case PLSTATE_COLOR1:
  252.     break;
  253.     }
  254. }
  255.  
  256. /*----------------------------------------------------------------------*\
  257. * plD_esc_imp()
  258. *
  259. * Escape function.
  260. \*----------------------------------------------------------------------*/
  261.  
  262. void
  263. plD_esc_imp(PLStream *pls, PLINT op, void *ptr)
  264. {
  265. }
  266.  
  267. /*----------------------------------------------------------------------*\
  268. * flushline()
  269. *
  270. * Spits out the line buffer.
  271. \*----------------------------------------------------------------------*/
  272.  
  273. static void
  274. flushline(PLStream *pls)
  275. {
  276.     count /= 2;
  277.     fprintf(pls->OutFile, "%c%c%c", CREATE_PATH, (char) count / 256, (char) count % 256);
  278.     fwrite((char *) LineBuff, sizeof(short), 2 * count, pls->OutFile);
  279.     fprintf(pls->OutFile, "%c%c", DRAW_PATH, OPTYPE);
  280.     FirstLine = 1;
  281. }
  282.  
  283. #else
  284. int 
  285. pldummy_impress()
  286. {
  287.     return 0;
  288. }
  289.  
  290. #endif                /* PLD_imp */
  291.