home *** CD-ROM | disk | FTP | other *** search
- /* This file contains the Laser Jet II device dependent subroutines for */
- /* use with plplot. Only the 150 dpi mode is supported. The others */
- /* (75,100,300) should work by just changing the value of DPI and */
- /* changing the values passed to setphy in DEVICE.f77 */
-
- #include "plplot.h"
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
-
- #define DPI 150 /* Resolution Dots per Inch */
- #define CURX 51
- #define CURY 61
- #define ESC 0x1b
- #define FF 0x0c
- #define XDOTS 1104 /* # dots across */
- #define YDOTS 1410 /* # dots down */
- #define BPROW XDOTS/8 /* # bytes across */
- #define NBYTES BPROW*YDOTS /* total number of bytes */
-
- #define JETX 1409
- #define JETY 1103
-
- static FILE *OutFile;
- static int porient;
- static int select=0;
- char FileName[80];
-
- /* bitmap contains a pointer to an area of memory NBYTES in size */
- static char *bitmap;
-
- void jetsetup(xdpi, ydpi, xwid, ywid)
- PLINT xwid, ywid;
- PLFLT xdpi, ydpi;
- {
- }
-
- /* Opens the file for binary mode. */
- void jetinit()
- {
- char response[80];
- int ori;
-
- smod(0); /* not an interactive terminal */
- scol(1);
- swid(1);
- setpxl(5.905,5.905);
-
- if(!select) {
- printf("Landscape or portrait orientation? (0 or 1): ");
- fgets(response,sizeof(response),stdin);
- if(sscanf(response,"%d",&ori) != 1)
- ori = 0; /* carriage return defaults to landscape */
- }
-
- porient = ori;
- if(!porient)
- setphy(0,JETX,0,JETY);
- else
- setphy(0,JETY,0,JETX);
-
- OutFile = NULL;
- while(!OutFile) {
- if(!select) {
- printf("Enter graphics command storage file name. ");
- fgets(response,sizeof(response),stdin);
- if(sscanf(response,"%s",FileName) != 1) {
- printf("Invalid entry.n");
- continue;
- }
- }
- if ((OutFile = fopen(FileName,"w")) == NULL)
- printf("Can't open %s.\n",FileName);
- select = 0;
- }
-
- /* Allocate storage for bit map matrix */
- if((bitmap = (char *)calloc(NBYTES,sizeof(char))) == NULL)
- printf("Out of memory in call to calloc \n");
-
- /* Reset Printer */
- fprintf(OutFile,"%cE",ESC);
- }
-
- void jetselect(ori,file)
- PLINT ori;
- char *file;
- {
- porient = ori;
- strncpy(FileName,file,sizeof(FileName)-1);
- FileName[sizeof(FileName)-1] = '\0';
- select = 1;
- }
-
- /* Set JET to test mode */
- void jettext()
- {
- /* do nothing here */
- }
-
- /* Set JET to graphics mode */
- void jetgraph()
- {
- /* Do nothing here */
- }
-
- /* Print out page */
- void jetclear()
- {
- int i,j;
-
- /* First move cursor to origin */
- fprintf(OutFile,"%c*p%dX",ESC,CURX);
- fprintf(OutFile,"%c*p%dY",ESC,CURY);
-
- /* Then put Laser Printer in 150 dpi mode */
- fprintf(OutFile,"%c*t%dR",ESC,DPI);
- fprintf(OutFile,"%c*r1A",ESC);
-
- /* Write out raster data */
- for(j=0;j<YDOTS;j++){
- fprintf(OutFile,"%c*b%dW",ESC,BPROW);
- for(i=0;i<BPROW;i++)
- putc(*(bitmap+i+j*BPROW),OutFile);
- }
-
- /* End raster graphics and send Form Feed */
- fprintf(OutFile,"%c*rB",ESC);
- fprintf(OutFile,"%c",FF);
-
- /* Finally, clear out bitmap storage area */
- memset(bitmap,'\0',NBYTES);
- }
-
- void jetpage()
- {
- }
-
- /* Change color */
- void jetcolor(colour)
- PLINT colour;
- {
- }
-
- void jetwidth(width)
- PLINT width;
- {
- }
-
- /* Function to draw the line in the bitmap */
- void jetline(x1a,y1a,x2a,y2a)
- PLINT x1a,y1a,x2a,y2a;
- {
- int i,x1,y1,x2,y2;
- float length,fx,fy,dx,dy;
- void setpoint();
-
- if(!porient) {
- x1 = x1a;
- y1 = y1a;
- x2 = x2a;
- y2 = y2a;
- }
- else {
- x1 = JETX - y1a;
- y1 = x1a;
- x2 = JETX - y2a;
- y2 = x2a;
- }
-
- length = (float)sqrt((double)((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
- if(length == 0.)
- length = 1.;
- dx = (x2 - x1)/length;
- dy = (y2 - y1)/length;
-
- fx = x1;
- fy = y1;
- setpoint(x1,y1);
- setpoint(x2,y2);
-
- for(i=1;i<=(int)length;i++)
- setpoint((int)(fx+=dx),(int)(fy+=dy));
- }
-
- static char mask[8] = {'\200','\100','\040','\020','\010','\004','\002','\001'};
-
- /* Function to set a bit in the bitmap */
- static void setpoint(x,y)
- int x,y;
- {
- int index;
- index = x/8 + y*BPROW;
- *(bitmap+index) = *(bitmap+index) | mask[x%8];
- }
-
- /* Reset printer and close file */
- void jettidy()
- {
- jetclear();
- /* Reset Printer */
- fprintf(OutFile,"%cE",ESC);
- fclose(OutFile);
- free((char *)bitmap);
- }
-