home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d306 / rexxplplot.lha / RexxPlPlot / src / src.zoo / laserjetii.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-06  |  3.2 KB  |  150 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. #ifdef AZTEC_C
  9. #define memset(ptr,val,len)    setmem(ptr,len,val)
  10. extern char *calloc();
  11. #else
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #endif
  15. #include <math.h>
  16.  
  17. #define DPI      150            /* Resolution Dots per Inch */
  18. #define CURX     51
  19. #define CURY     61
  20. #define ESC      0x1b
  21. #define FF       0x0c
  22. #define XDOTS    1104           /* # dots across */
  23. #define YDOTS    1410           /* # dots down   */
  24. #define BPROW    XDOTS/8        /* # bytes across */
  25. #define NBYTES   BPROW*YDOTS    /* total number of bytes */
  26.  
  27. static FILE *OutFile;
  28.  
  29. /* bitmap contains a pointer to an area of memory NBYTES in size */
  30. static char *bitmap;
  31. static int FirstClear=1;
  32.  
  33. /* Opens the file for binary mode. */
  34.  
  35. void jetini()
  36. {
  37.   char FileName[80];
  38.  
  39.   printf("Enter file name for LaserJet II graphics commands. ");
  40.   scanf("%s",FileName);
  41.  
  42.   if((OutFile = fopen(FileName,"w")) == NULL) {
  43.    printf("Error opening %s \n",FileName);
  44.    exit(1);
  45.   }
  46.  
  47.   /* Allocate storage for bit map matrix */
  48.   if((bitmap = (char *)calloc(NBYTES,sizeof(char))) == NULL)
  49.    printf("Out of memory in call to calloc \n");
  50.  
  51.   /* Reset Printer */
  52.   fprintf(OutFile,"%cE",ESC);
  53. }
  54.  
  55. /* Set JET to test mode */
  56. void jettex()
  57. {
  58.   /* do nothing here */
  59. }
  60.  
  61. /* Set JET to graphics mode */
  62. void jetgra()
  63. {
  64.   /* Do nothing here */
  65. }
  66.  
  67. /* Print out page */
  68. void jetclr()
  69. {
  70.   int i,j;
  71.  
  72.   if(FirstClear)
  73.     FirstClear=0;
  74.   else {
  75.     /* First move cursor to origin */
  76.     fprintf(OutFile,"%c*p%dX",ESC,CURX);
  77.     fprintf(OutFile,"%c*p%dY",ESC,CURY);
  78.  
  79.     /* Then put Laser Printer in 150 dpi mode */
  80.     fprintf(OutFile,"%c*t%dR",ESC,DPI);
  81.     fprintf(OutFile,"%c*r1A",ESC);
  82.  
  83.     /* Write out raster data */
  84.     for(j=0;j<YDOTS;j++){
  85.       fprintf(OutFile,"%c*b%dW",ESC,BPROW);
  86.       for(i=0;i<BPROW;i++)
  87.         putc(*(bitmap+i+j*BPROW),OutFile);
  88.     }
  89.  
  90.     /* End raster graphics and send Form Feed */
  91.     fprintf(OutFile,"%c*rB",ESC);
  92.     fprintf(OutFile,"%c",FF);
  93.  
  94.     /* Finally, clear out bitmap storage area */
  95.     memset(bitmap,'\0',NBYTES);
  96.   }
  97. }
  98.  
  99. /* Change color */
  100. void jetcol(colour)
  101. int colour;
  102. {
  103. }
  104.  
  105. /* Function to draw the line in the bitmap */
  106. void jetlin(x1,y1,x2,y2)
  107. int x1,y1,x2,y2;
  108. {
  109.  int i;
  110.  float length,fx,fy,dx,dy;
  111.  void setpoint();
  112.  
  113.  length = (float)sqrt((double)((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
  114.  if(length == 0.)
  115.    length = 1.;
  116.  dx = (x2 - x1)/length;
  117.  dy = (y2 - y1)/length;
  118.  
  119.  fx = x1;
  120.  fy = y1;
  121.  setpoint(x1,y1);
  122.  setpoint(x2,y2);
  123.  
  124.  for(i=1;i<=(int)length;i++)
  125.   setpoint((int)(fx+=dx),(int)(fy+=dy));
  126. }
  127.  
  128. static char mask[8] = {'\200','\100','\040','\020','\010','\004','\002','\001'};
  129.  
  130. /* Function to set a bit in the bitmap */
  131. static void setpoint(x,y)
  132. int x,y;
  133. {
  134.  int index;
  135.  index = x/8 + y*BPROW;
  136.  *(bitmap+index) = *(bitmap+index) | mask[x%8];
  137. }
  138.  
  139. /* Reset printer and close file */
  140. void jettid()
  141. {
  142.   jetclr();
  143.   /* Reset Printer */
  144.   fprintf(OutFile,"%cE",ESC);
  145.   fclose(OutFile);
  146.   free((void *)bitmap);
  147. }
  148.  
  149.  
  150.