ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/drivers/xfig.c

This is xfig.c in view mode; [Download] [Up]

/* This file contains drivers for the HP7475A plotter */

#include <stdio.h>
#include <string.h>

#define FIGX        599
#define FIGY        599
#define DPI          80

static FILE *OutDev=NULL;
static int fileopen=0;
static short *buffptr, bufflen;
#define BSIZE  25

void xfigsetup(xdpi, ydpi, xwid, ywid)
int xwid, ywid;
double xdpi, ydpi;
{
}

void xfigorient(ori)
int ori;
{
}

void xfigselect(file)
FILE *file;
{
   OutDev=file;
   fileopen=0;
}

/* Set up device specific stuff and initialize the device */
void xfiginit()
{
   char line[80];
   /* setpxl() sets the dots/mm in the x and y directions */
   setpxl(3.1496,3.1496); /* 80 DPI */

   /* setphy() sets the device coordinates. These are integer */
   /* values. Set up for landscape orientation (long axis of page in the */
   /* x direction). Origin is in the lower left hand corner. */
   setphy(0,FIGX,0,FIGY);

   /* Set default pen color using scol(color). */
   /* Any default pen color can be used but a black pen is probably best. */
   scol(1);

   /* Set default pen width using swid(width) */
   swid(1);

   /* Set device interaction mode using smod(mode). Set mode to 0 for */
   /* a noninteractive device, Unless you are writing your */
   /* own Amiga screen driver mode should be 0. */
   smod(0);

   while(!OutDev) {

      printf("Enter graphics file name. ");
      fgets(line,sizeof(line),stdin);
      line[strlen(line)-1] = '\0';
      if (!(OutDev = fopen(line,"w"))) 
         fprintf(stderr,"Can't open %s.\n",line);
      else
         fileopen=1;
   }

   /* Write out header */
   fprintf(OutDev,"#FIG 1.4X\n");
   fprintf(OutDev,"%d 2\n",DPI);

   bufflen = 2*BSIZE;
   buffptr = (short *)malloc(sizeof(short)*bufflen);
   if(buffptr == NULL)
      plexit("Out of memory!");

}

/* Sets to text mode */
void xfigtext()
{
}

/* Sets to graphics mode */
void xfiggraph()
{
}

static int firstline=1;
/* Clears the page */
void xfigclear()
{
   void flushbuffer();

   if(!firstline) 
      flushbuffer();
}

static short xlast, ylast;

void xfigpage()
{
   firstline = 1;
   xlast = -10000; ylast = -10000;
}

void xfigeop()
{
}

static int curwid;
void xfigwidth(width)
int width;
{
   void flushbuffer();

   flushbuffer();
   firstline = 1;

   if(width <= 1)
      curwid = 1;
   else if(width >= 4)
      curwid = 3;
   else
      curwid = width;
}

/* Change the pen color */
void xfigcolor(color)
int color;
{
}

static short count;

/* Draws a line from (x1,y1) to (x2,y2) */
void xfigline(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
   short *tempptr;
   void flushbuffer();

   /* If starting point of this line is the same as the ending point of */
   /* the previous line then don't raise the pen. (This really speeds up */
   /* plotting and reduces the size of the file. */
   if(firstline) {
      count = 0;
      *(buffptr+count++) = x1;
      *(buffptr+count++) = y1;
      *(buffptr+count++) = x2;
      *(buffptr+count++) = y2;
      firstline = 0;
   }
   else if(x1 == xlast && y1 == ylast) {
      if(count+2 >= bufflen) {
         bufflen += 2*BSIZE;
         tempptr = (short *)realloc((char *)buffptr,bufflen*sizeof(short));
         if(tempptr == NULL){
            free((char *)buffptr);
            plexit("Out of memory!");
         }
         buffptr = tempptr;
      }
      *(buffptr+count++) = x2;
      *(buffptr+count++) = y2;
   }
   else {
      flushbuffer();
      *(buffptr+count++) = x1;
      *(buffptr+count++) = y1;
      *(buffptr+count++) = x2;
      *(buffptr+count++) = y2;
   }

   xlast = x2;
   ylast = y2;
}

static void flushbuffer()
{
   short i=0;

   if(count==0)
     return;
   fprintf(OutDev,"2 1 0 %d 0 0 0 0 0.000 0 0\n",curwid);
   while(i<count) {
     fprintf(OutDev,"%d %d ",*(buffptr+i),FIGY-*(buffptr+i+1));
     i += 2;
   }
   fprintf(OutDev,"9999 9999\n");
   count = 0;
}

/* Cleanup and close file. */
void xfigtidy()
{
   flushbuffer();
   free((char *)buffptr);
   if(fileopen)
      fclose(OutDev);
}

void xfigcwin()
{
}

void xfiggwin()
{
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.