This is laserjetii.c in view mode; [Download] [Up]
/* 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=NULL; static int porient=0; static int fileopen=0; /* bitmap contains a pointer to an area of memory NBYTES in size */ static char *bitmap; void jetsetup(xdpi, ydpi, xwid, ywid) int xwid, ywid; double xdpi, ydpi; { } /* Opens the file for binary mode. */ void jetinit() { char response[80]; smod(0); /* not an interactive terminal */ scol(1); swid(1); setpxl(5.905,5.905); if(!porient) setphy(0,JETX,0,JETY); else setphy(0,JETY,0,JETX); while(!OutFile) { printf("Enter graphics command storage file name. "); fgets(response,sizeof(response),stdin); response[strlen(response)-1] = '\0'; if ((OutFile = fopen(response,"w")) == NULL) fprintf(stdout,"Can't open %s.\n",response); else fileopen = 1; } /* 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 jetorient(ori) int ori; { porient = ori; } void jetselect(file) FILE *file; { OutFile = file; fileopen = 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() { } void jeteop() { } /* Change color */ void jetcolor(colour) int colour; { } void jetwidth(width) int width; { } /* Function to draw the line in the bitmap */ void jetline(x1a,y1a,x2a,y2a) int 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); if(fileopen) fclose(OutFile); free((char *)bitmap); } void jetcwin() { } void jetgwin() { }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.