home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_01 / epson.trm < prev    next >
Text File  |  1991-02-05  |  12KB  |  482 lines

  1. /* GNUPLOT - epson.trm */
  2. /*
  3.  * Copyright (C) 1990   
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  epson_lx800, nec_cp6c, nec_cp6d, nec_cp6b, starc,
  21.  *  epson_60dpi, tandy_60dpi
  22.  *
  23.  * AUTHORS
  24.  *  Russell Lang
  25.  *  William Wilson
  26.  *
  27.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  28.  * 
  29.  */
  30.  
  31. /* The following epson lx800 driver uses generic bit mapped graphics
  32.    routines to build up a bit map in memory. */
  33. /* by Russell Lang, rjl@monu1.cc.monash.edu.au */
  34. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  35. /* EPSON_init changes outfile to binary mode on PC's */
  36.  
  37. #ifdef EPSON
  38.  
  39. #define EPSONXMAX    512 
  40. #define EPSONYMAX    384
  41.  
  42. #define EPSONXLAST (EPSONXMAX - 1)
  43. #define EPSONYLAST (EPSONYMAX - 1)
  44.  
  45. #define EPSONVCHAR        FNT5X9_VCHAR      
  46. #define EPSONHCHAR        FNT5X9_HCHAR        
  47. #define EPSONVTIC        6
  48. #define EPSONHTIC        6
  49.  
  50. EPSONinit()
  51. {
  52. #ifdef PC
  53.     reopen_binary();
  54. #endif
  55. #ifdef vms
  56.     reopen_binary();
  57. #endif
  58. }
  59.  
  60.  
  61. EPSONgraphics()
  62. {
  63.     b_charsize(FNT5X9);
  64.     b_makebitmap((unsigned int)(EPSONXMAX*xsize),
  65.                  (unsigned int)(EPSONYMAX*ysize),1);
  66. }
  67.  
  68.  
  69. EPSONtext()
  70. {
  71.     epson_dump();
  72.     b_freebitmap();
  73. }
  74.  
  75.  
  76. #define EPSONlinetype b_setlinetype
  77. #define EPSONmove b_move
  78. #define EPSONvector b_vector
  79. #define EPSONput_text b_put_text
  80. #define EPSON_text_angle b_text_angle
  81.  
  82. EPSONreset()
  83. {
  84. #ifdef vms
  85.     fflush_binary();
  86. #endif
  87. }
  88.  
  89.  
  90. /* output file must be binary mode for epson_dump */
  91. epson_dump()
  92. {
  93.   register unsigned int x;
  94.   int j;
  95.     for (j=(b_ysize/8)-1; j>=0; j--) {
  96.         /* select plotter graphics mode (square pixels) */
  97.         fprintf(outfile,"\033J\030");    /* line feed 8/72" = 8 dots */
  98.         fprintf(outfile,"\r\033*\005");
  99.         (void) fputc((char)(b_xsize%256),outfile);
  100.         (void) fputc((char)(b_xsize/256),outfile);
  101.         for (x=0; x<b_xsize; x++) {
  102.             (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  103.         }
  104.     }
  105. #ifdef PC
  106.     fprintf(stderr,"Print using: COPY /B\n");
  107. #endif
  108. }
  109.  
  110. #endif /* EPSON */
  111.  
  112.  
  113. /* The following NEC CP6 Pinwriter driver uses generic bit mapped graphics
  114.    routines to build up a bit map in memory. */
  115. /* by Russell Lang, rjl@monu1.cc.monash.edu.au */
  116. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  117. /* NECinit changes outfile to binary mode for PC's */
  118.  
  119. /* Add a Monochrome NEC printer (for faster speed and line types) jdc */
  120.  
  121. #ifdef NEC
  122.  
  123. #define NECXMAX    400 
  124. #define NECYMAX    320
  125.  
  126. #define NECXLAST (NECXMAX - 1)
  127. #define NECYLAST (NECYMAX - 1)
  128.  
  129. #define NECVCHAR        FNT5X9_VCHAR      
  130. #define NECHCHAR        FNT5X9_HCHAR        
  131. #define NECVTIC        6
  132. #define NECHTIC        6
  133.  
  134. /* plane 0=black, 1=cyan(blue), 2=magenta(red), 3=yellow */
  135. static unsigned int neccolor[] = {1,8,4,2,10,12,6,14};
  136. static unsigned int necpcolor[]= {0,2,1,4};
  137.  
  138. NECinit()
  139. {
  140. #ifdef PC
  141.     reopen_binary();
  142. #endif
  143. #ifdef vms
  144.     reopen_binary();
  145. #endif
  146. }
  147.  
  148.  
  149. /* Monochrome only NEC CP6 printer (set term nec_cp6m or nec_cp6d). */
  150. /* will probably work with NEC P6 printer */
  151. NECMgraphics()
  152. {
  153.     b_charsize(FNT5X9);
  154.     b_makebitmap((unsigned int)(NECXMAX*xsize),
  155.                  (unsigned int)(NECYMAX*ysize),1);
  156. }
  157.  
  158. /* Color ribbon in NEC CP6 printer (set term nec_cp6c) */
  159. NECCgraphics()
  160. {
  161.     b_charsize(FNT5X9);
  162.     b_makebitmap((unsigned int)(NECXMAX*xsize),
  163.                  (unsigned int)(NECYMAX*ysize),4);
  164. }
  165.  
  166.  
  167. NECdraft_text()
  168. {
  169.     nec_draft_dump();
  170.     b_freebitmap();
  171. }
  172.  
  173. NECtext()
  174. {
  175.     nec_dump();
  176.     b_freebitmap();
  177. }
  178.  
  179. NECClinetype(linetype)
  180. int linetype;
  181. {
  182.     if (linetype>=6)
  183.         linetype %= 6;
  184.     b_setvalue(neccolor[linetype+2]);
  185. }
  186.  
  187. #define NECMlinetype b_setlinetype
  188. #define NECmove b_move
  189. #define NECvector b_vector
  190. #define NECput_text b_put_text
  191. #define NEC_text_angle b_text_angle
  192.  
  193.     
  194. NECreset()
  195. {
  196. #ifdef vms
  197.     fflush_binary();
  198. #endif
  199. }
  200.  
  201.  
  202. /* output file must be binary mode for nec_dump */
  203. nec_dump()
  204. {
  205. unsigned int x;
  206. unsigned int plane,offset;
  207. int j;
  208. unsigned int column8;
  209. unsigned long column24;
  210. char column3, column2, column1;
  211.     fprintf(outfile,"\033P\033l\005");  /* 10cpi, left margin 5 char */
  212.     for (j=(b_ysize/8)-1;j>=0;j--) {
  213.             fprintf(outfile,"\033J\030");  /* 24/180" line feed */
  214.             for (plane=0; plane<b_planes; plane++) {
  215.                 offset=plane*b_psize;
  216.                 if (b_planes>1) {
  217.                     /* select colour for plane */
  218.                     fprintf(outfile,"\033r");
  219.                     (void) fputc((char)necpcolor[plane],outfile);
  220.                 }
  221.                 /* select plotter graphics mode (square pixels) */
  222.                 fprintf(outfile,"\r\033*\047");
  223.                 (void) fputc((char)((b_xsize*3)%256),outfile);
  224.                 (void) fputc((char)((b_xsize*3)/256),outfile);
  225.                 for (x=0; x<b_xsize; x++) {
  226.                     column8= (unsigned int)(*((*b_p)[j+offset]+x));
  227.                     column24=0;
  228.                     if (column8&0x01) column24|=(long)0x000007;
  229.                     if (column8&0x02) column24|=(long)0x000038;
  230.                     if (column8&0x04) column24|=(long)0x0001c0;
  231.                     if (column8&0x08) column24|=(long)0x000e00;
  232.                     if (column8&0x10) column24|=(long)0x007000;
  233.                     if (column8&0x20) column24|=(long)0x038000;
  234.                     if (column8&0x40) column24|=(long)0x1c0000;
  235.                     if (column8&0x80) column24|=(long)0xe00000;
  236.                     column1 = (char) ( column24      & (long)0xff);
  237.                     column2 = (char) ((column24>>8)  & (long)0xff);
  238.                     column3 = (char) ((column24>>16) & (long)0xff);
  239.                     (void) fputc(column3,outfile);
  240.                     (void) fputc(column2,outfile);
  241.                     (void) fputc(column1,outfile);
  242.                     (void) fputc(column3,outfile);
  243.                     (void) fputc(column2,outfile);
  244.                     (void) fputc(column1,outfile);
  245.                     (void) fputc(column3,outfile);
  246.                     (void) fputc(column2,outfile);
  247.                     (void) fputc(column1,outfile);
  248.                 }
  249.             }
  250.     }
  251.     fprintf(outfile,"\r\033l");
  252.     (void) fputc('\0',outfile);                /* set left margin to 0 */
  253.     if (b_planes > 1) {
  254.         fprintf(outfile,"\033r");
  255.         (void) fputc('\0',outfile);                /* set color to black */
  256.     }
  257. #ifdef PC
  258.     fprintf(stderr,"Print using: COPY /B\n");
  259. #endif
  260. #ifdef vms
  261.     fflush_binary();
  262. #endif
  263. }
  264.  
  265. /* output file must be binary mode for nec_dump */
  266. nec_draft_dump()
  267. {
  268. unsigned int x;
  269. unsigned int plane,offset;
  270. int j;
  271.     fprintf(outfile,"\033P\033l\005\r");  /* 10cpi, left margin 5 char */
  272.     for (j=(b_ysize/8)-1;j>=0;j--) {
  273.             fprintf(outfile,"\033J\030");  /* 24/180" line feed */
  274.             for (plane=0; plane<b_planes; plane++) {
  275.                 offset=plane*b_psize;
  276.                 if (b_planes>1) {
  277.                     /* select colour for plane */
  278.                     fprintf(outfile,"\033r");
  279.                     (void) fputc((char)necpcolor[plane],outfile);
  280.                 }
  281.                 /* select plotter graphics mode (square pixels) */
  282.                 fprintf(outfile,"\r\033*");
  283.                 (void) fputc('\0',outfile);
  284.                 (void) fputc((char)(b_xsize%256),outfile);
  285.                 (void) fputc((char)(b_xsize/256),outfile);
  286.                 for (x=0; x<b_xsize; x++) {
  287.                     (void) fputc( (char)(*((*b_p)[j+offset]+x)), outfile );
  288.                 }
  289.             }
  290.     }
  291.     fprintf(outfile,"\r\033l");
  292.     (void) fputc('\0',outfile);                /* set left margin to 0 */
  293.     if (b_planes > 1) {
  294.         fprintf(outfile,"\033r");
  295.         (void) fputc('\0',outfile);                /* set color to black */
  296.     }
  297. #ifdef PC
  298.     fprintf(stderr,"Print using: COPY /B\n");
  299. #endif
  300. }
  301.  
  302. #endif /* NEC */
  303.  
  304. #ifdef STARC
  305. /* The following Star color driver uses generic bit mapped graphics
  306.    routines to build up a bit map in memory. */
  307. /* Star Color changes made by William Wilson, wew@naucse.cse.nau.edu */
  308. /* On PC, print using 'copy file /b lpt1:', do NOT use 'print' */
  309. /* STARC_init changes outfile to binary mode on PC's */
  310.  
  311. #define STARCXMAX    512 
  312. #define STARCYMAX    384
  313.  
  314. #define STARCXLAST (STARCXMAX - 1)
  315. #define STARCYLAST (STARCYMAX - 1)
  316.  
  317. #define STARCVCHAR        FNT5X9_VCHAR      
  318. #define STARCHCHAR        FNT5X9_HCHAR        
  319. #define STARCVTIC        6
  320. #define STARCHTIC        6
  321.  
  322. /* plane 0=black, 1=cyan(blue), 2=magenta(red), 3=yellow */
  323. static unsigned int STARCcolor[] = {1,8,4,2,10,12,6,14};
  324. static unsigned int STARCpcolor[]= {0,2,1,4};
  325.  
  326. STARCinit()
  327. {
  328. #ifdef PC
  329.     reopen_binary();
  330. #endif
  331. #ifdef vms
  332.     reopen_binary();
  333. #endif
  334. }
  335.  
  336.  
  337. STARCgraphics()
  338. {
  339.     b_charsize(FNT5X9);
  340.     b_makebitmap((unsigned int)(STARCXMAX*xsize),
  341.                  (unsigned int)(STARCYMAX*ysize),4);
  342. }
  343.  
  344.  
  345. STARCtext()
  346. {
  347.     STARC_dump();
  348.     b_freebitmap();
  349. }
  350.  
  351. STARClinetype(linetype)
  352. int linetype;
  353. {
  354.     if (linetype>=6)
  355.         linetype %= 6;
  356.     b_setvalue(STARCcolor[linetype+2]);
  357. }
  358.  
  359.  
  360. #define STARCmove b_move
  361. #define STARCvector b_vector
  362. #define STARCput_text b_put_text
  363. #define STARC_text_angle b_text_angle
  364.  
  365. STARCreset()
  366. {
  367. #ifdef vms
  368.     fflush_binary();
  369. #endif
  370. }
  371.  
  372.  
  373. /* output file must be binary mode for STARC_dump */
  374. STARC_dump()
  375. {
  376. unsigned int x;
  377. unsigned int plane,offset;
  378. int j;
  379.     for (j=(b_ysize/8)-1;j>=0;j--) {
  380.         fprintf(outfile,"\033J\030");    /* line feed 8/72" = 8 dots */
  381.         for (plane=0; plane<b_planes; plane++) {
  382.             offset=plane*b_psize;
  383.             if (b_planes>1) {
  384.                 /* select colour for plane */
  385.                 fprintf(outfile,"\033r");
  386.                 (void) fputc((char)STARCpcolor[plane],outfile);
  387.             }
  388.             /* select plotter graphics mode (square pixels) */
  389.             fprintf(outfile,"\r\033*\005");
  390.             (void) fputc((char)(b_xsize%256),outfile);
  391.             (void) fputc((char)(b_xsize/256),outfile);
  392.             for (x=0; x<b_xsize; x++) {
  393.                 (void) fputc( (char)(*((*b_p)[j+offset]+x)), outfile );
  394.             }
  395.         }
  396.     }
  397.     if (b_planes > 1) {
  398.         fprintf(outfile,"\033r");
  399.         (void) fputc('\0',outfile);                /* set color to black */
  400.     }
  401. #ifdef PC
  402.     fprintf(stderr,"Print using: COPY /B\n");
  403. #endif
  404. }
  405.  
  406. #endif /* STARC */
  407.  
  408.  
  409. #ifdef EPS60
  410.  
  411. /* make the total dimensions 8 inches by 5 inches */
  412. #define EPS60XMAX    480
  413. #define EPS60YMAX    360
  414.  
  415. #define EPS60XLAST (EPS60XMAX - 1)
  416. #define EPS60YLAST (EPS60YMAX - 1)
  417.  
  418. EPS60graphics()
  419. {
  420.     b_charsize(FNT5X9);
  421.     b_makebitmap((unsigned int)(EPS60XMAX*xsize),
  422.                  (unsigned int)(EPS60YMAX*ysize),1);
  423. }
  424.  
  425.  
  426. EPS60text()
  427. {
  428.     eps60_dump();
  429.     b_freebitmap();
  430. }
  431.  
  432.  
  433.  
  434. /* output file must be binary mode for eps60_dump */
  435. eps60_dump()
  436. {
  437.   register unsigned int x;
  438.   int j;
  439.     fprintf(outfile,"\033%c\030",'3'); /* set line spacing 24/216" = 8 dots */
  440.     for (j=(b_ysize/8)-1; j>=0; j--) {
  441.         /* select printer graphics mode 'K' */
  442.         fprintf(outfile,"\r\n\033K");
  443.         (void) fputc((char)(b_xsize%256),outfile);
  444.         (void) fputc((char)(b_xsize/256),outfile);
  445.         for (x=0; x<b_xsize; x++) {
  446.             (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  447.         }
  448.     }
  449.     fprintf(outfile,"\033%c\044\r\n",'3'); /* set line spacing 36/216" = 1/6" */
  450. #ifdef PC
  451.     fprintf(stderr,"Print using: COPY /B\n");
  452. #endif
  453. }
  454.  
  455. #endif /* EPS60 */
  456.  
  457. #ifdef TANDY60
  458.  
  459. /* The only difference between TANDY60 and EPS60 is the inclusion
  460.    of codes to swap the Tandy printer into IBM mode and back
  461.    into Tandy mode.  For a Tandy already in IBM mode, use EPS60. */
  462.  
  463.  
  464. TANDY60text()
  465. {
  466. #ifdef PC
  467.     fprintf(stderr, "Inserting Tandy/IBM mode conversion codes\n");
  468. #endif
  469.     /* Switch to IBM mode, and leave 3 inches above the plot so as
  470.        to get rough vertical centring on the page.  Perform the
  471.        centring by setting 1" line feeds and issuing 3 of them. */
  472.     fprintf(outfile, "\033!\033%c%c\n\n\n", '3',216);
  473.     eps60_dump();
  474.     b_freebitmap();
  475.     /* A form feed must be sent before switching back to Tandy mode,
  476.        or else the form setting will be messed up. */
  477.     fprintf(outfile, "\f\033!");
  478. }
  479.  
  480.  
  481. #endif  /* TANDY60 */
  482.