home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / unix / laserjetii.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  4.2 KB  |  206 lines

  1. /* This file contains the Laser Jet II device dependent subroutines for */
  2. /* use with plplot. Only the 150 dpi mode is supported.  The others     */
  3. /* (75,100,300) should work by just changing the value of DPI and       */
  4. /* changing the values passed to setphy in DEVICE.f77                   */
  5.  
  6. #include "plplot.h"
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <math.h>
  10.  
  11. #define DPI      150            /* Resolution Dots per Inch */
  12. #define CURX     51
  13. #define CURY     61
  14. #define ESC      0x1b
  15. #define FF       0x0c
  16. #define XDOTS    1104           /* # dots across */
  17. #define YDOTS    1410           /* # dots down   */
  18. #define BPROW    XDOTS/8        /* # bytes across */
  19. #define NBYTES   BPROW*YDOTS    /* total number of bytes */
  20.  
  21. #define JETX     1409
  22. #define JETY     1103
  23.  
  24. static FILE *OutFile;
  25. static int porient;
  26. static int select=0;
  27. char FileName[80];
  28.  
  29. /* bitmap contains a pointer to an area of memory NBYTES in size */
  30. static char *bitmap;
  31.  
  32. void jetsetup(xdpi, ydpi, xwid, ywid)
  33. PLINT xwid, ywid;
  34. PLFLT xdpi, ydpi;
  35. {
  36. }
  37.  
  38. /* Opens the file for binary mode. */
  39. void jetinit()
  40. {
  41.   char response[80];
  42.   int ori;
  43.  
  44.   smod(0);  /* not an interactive terminal */
  45.   scol(1);
  46.   swid(1);
  47.   setpxl(5.905,5.905);
  48.   
  49.   if(!select) {
  50.      printf("Landscape or portrait orientation? (0 or 1): ");
  51.      fgets(response,sizeof(response),stdin);
  52.      if(sscanf(response,"%d",&ori) != 1)
  53.         ori = 0;   /* carriage return defaults to landscape */
  54.   }
  55.   
  56.   porient = ori;
  57.   if(!porient)
  58.      setphy(0,JETX,0,JETY);
  59.   else
  60.      setphy(0,JETY,0,JETX);
  61.  
  62.   OutFile = NULL;
  63.   while(!OutFile) {
  64.      if(!select) {
  65.         printf("Enter graphics command storage file name. ");
  66.         fgets(response,sizeof(response),stdin);
  67.         if(sscanf(response,"%s",FileName) != 1) {
  68.             printf("Invalid entry.n");
  69.             continue;
  70.         }
  71.      }
  72.      if ((OutFile = fopen(FileName,"w")) == NULL) 
  73.          printf("Can't open %s.\n",FileName);
  74.      select = 0;
  75.   }
  76.  
  77.   /* Allocate storage for bit map matrix */
  78.   if((bitmap = (char *)calloc(NBYTES,sizeof(char))) == NULL)
  79.    printf("Out of memory in call to calloc \n");
  80.  
  81.   /* Reset Printer */
  82.   fprintf(OutFile,"%cE",ESC);
  83. }
  84.  
  85. void jetselect(ori,file)
  86. PLINT ori;
  87. char *file;
  88. {
  89.    porient = ori;
  90.    strncpy(FileName,file,sizeof(FileName)-1);
  91.    FileName[sizeof(FileName)-1] = '\0';
  92.    select = 1;
  93. }
  94.  
  95. /* Set JET to test mode */
  96. void jettext()
  97. {
  98.   /* do nothing here */
  99. }
  100.  
  101. /* Set JET to graphics mode */
  102. void jetgraph()
  103. {
  104.   /* Do nothing here */
  105. }
  106.  
  107. /* Print out page */
  108. void jetclear()
  109. {
  110.   int i,j;
  111.  
  112.   /* First move cursor to origin */
  113.   fprintf(OutFile,"%c*p%dX",ESC,CURX);
  114.   fprintf(OutFile,"%c*p%dY",ESC,CURY);
  115.  
  116.   /* Then put Laser Printer in 150 dpi mode */
  117.   fprintf(OutFile,"%c*t%dR",ESC,DPI);
  118.   fprintf(OutFile,"%c*r1A",ESC);
  119.  
  120.   /* Write out raster data */
  121.   for(j=0;j<YDOTS;j++){
  122.     fprintf(OutFile,"%c*b%dW",ESC,BPROW);
  123.     for(i=0;i<BPROW;i++)
  124.       putc(*(bitmap+i+j*BPROW),OutFile);
  125.   }
  126.  
  127.   /* End raster graphics and send Form Feed */
  128.   fprintf(OutFile,"%c*rB",ESC);
  129.   fprintf(OutFile,"%c",FF);
  130.  
  131.   /* Finally, clear out bitmap storage area */
  132.   memset(bitmap,'\0',NBYTES);
  133. }
  134.  
  135. void jetpage()
  136. {
  137. }
  138.  
  139. /* Change color */
  140. void jetcolor(colour)
  141. PLINT colour;
  142. {
  143. }
  144.  
  145. void jetwidth(width)
  146. PLINT width;
  147. {
  148. }
  149.  
  150. /* Function to draw the line in the bitmap */
  151. void jetline(x1a,y1a,x2a,y2a)
  152. PLINT x1a,y1a,x2a,y2a;
  153. {
  154.  int i,x1,y1,x2,y2;
  155.  float length,fx,fy,dx,dy;
  156.  void setpoint();
  157.  
  158.  if(!porient) {
  159.    x1 = x1a;
  160.    y1 = y1a;
  161.    x2 = x2a;
  162.    y2 = y2a;
  163.  }
  164.  else {
  165.    x1 = JETX - y1a;
  166.    y1 = x1a;
  167.    x2 = JETX - y2a;
  168.    y2 = x2a;
  169.  }
  170.  
  171.  length = (float)sqrt((double)((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
  172.  if(length == 0.)
  173.    length = 1.;
  174.  dx = (x2 - x1)/length;
  175.  dy = (y2 - y1)/length;
  176.  
  177.  fx = x1;
  178.  fy = y1;
  179.  setpoint(x1,y1);
  180.  setpoint(x2,y2);
  181.  
  182.  for(i=1;i<=(int)length;i++)
  183.   setpoint((int)(fx+=dx),(int)(fy+=dy));
  184. }
  185.  
  186. static char mask[8] = {'\200','\100','\040','\020','\010','\004','\002','\001'};
  187.  
  188. /* Function to set a bit in the bitmap */
  189. static void setpoint(x,y)
  190. int x,y;
  191. {
  192.  int index;
  193.  index = x/8 + y*BPROW;
  194.  *(bitmap+index) = *(bitmap+index) | mask[x%8];
  195. }
  196.  
  197. /* Reset printer and close file */
  198. void jettidy()
  199. {
  200.   jetclear();
  201.   /* Reset Printer */
  202.   fprintf(OutFile,"%cE",ESC);
  203.   fclose(OutFile);
  204.   free((char *)bitmap);
  205. }
  206.