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

  1. /* This file contains drivers for the HP7475A plotter */
  2.  
  3. #include "plplot.h"
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #define PLTX       10299
  8. #define PLTY        7649
  9.  
  10. static FILE *OutDev;
  11. static PLINT orient;
  12. static PLINT select=0;
  13. static char FileName[80];
  14.  
  15. void hp7475setup(xdpi, ydpi, xwid, ywid)
  16. PLINT xwid, ywid;
  17. PLFLT xdpi, ydpi;
  18. {
  19. }
  20.  
  21. void hp7475select(ori, name)
  22. PLINT ori;
  23. char *name;
  24. {
  25.    orient = ori;
  26.    strncpy(FileName,name,sizeof(FileName)-1);
  27.    FileName[sizeof(FileName)-1] = '\0';
  28.    select = 1;
  29. }
  30.  
  31. /* Set up device specific stuff and initialize the device */
  32. /* If orient is 0 set up for landscape, otherwise portrait. */
  33. void hp7475init()
  34. {
  35.    char line[80];
  36.  
  37.    if(!select) {
  38.       printf("Landscape or portrait orientation? (0 or 1) ");
  39.       fgets(line,sizeof(line),stdin);
  40.       if(sscanf(line,"%d",&orient) != 1)
  41.          orient = 0;
  42.    }
  43.  
  44.    /* setpxl() sets the dots/mm in the x and y directions */
  45.    setpxl(40.,40.);         /* 40 dots/mm or 1016 dots/inch */
  46.  
  47.    /* setphy() sets the device coordinates. These are integer */
  48.    /* values. Set up for landscape orientation (long axis of page in the */
  49.    /* x direction). Origin is in the lower left hand corner. */
  50.    if(!orient)
  51.       setphy(0,PLTX,0,PLTY);
  52.    else
  53.       setphy(0,PLTY,0,PLTX);
  54.  
  55.    /* Set default pen color using scol(color). */
  56.    /* Any default pen color can be used but a black pen is probably best. */
  57.    scol(1);
  58.  
  59.    /* Set default pen width using swid(width) */
  60.    swid(1);
  61.  
  62.    /* Set device interaction mode using smod(mode). Set mode to 0 for */
  63.    /* a noninteractive device, Unless you are writing your */
  64.    /* own Amiga screen driver mode should be 0. */
  65.    smod(0);
  66.  
  67.    /* Well that's all the information plplot needs. Let's prompt for a */
  68.    /* graphics file name. */
  69.    for(;;) {
  70.       if(!select) {
  71.          printf("Enter graphics file name. ");
  72.          fgets(line,sizeof(line),stdin);
  73.          if(sscanf(line,"%s",FileName)!=1)
  74.             continue;
  75.       }
  76.  
  77.       if (!(OutDev = fopen(FileName,"w"))) {
  78.          fprintf(stderr,"Can't open %s.\n",FileName);
  79.          select = 0;
  80.       }
  81.       else
  82.          break;
  83.    }
  84.    select = 0;
  85.    fprintf(OutDev,"IN; ");
  86. }
  87.  
  88. /* Sets to text mode */
  89. void hp7475text()
  90. {
  91.    /* None of the built in fonts are supported yet. */
  92. }
  93.  
  94. /* Sets to graphics mode */
  95. void hp7475graph()
  96. {
  97.    /* We're always in graphics mode with this device. */
  98. }
  99.  
  100. /* Clears the page */
  101. void hp7475clear()
  102. {
  103.    /* On the HP plotter eject the page. */
  104.    fprintf(OutDev,"PG; ");
  105. }
  106.  
  107. static PLINT xlast, ylast;
  108.  
  109. void hp7475page()
  110. {
  111.    xlast = -100000; ylast = -100000;
  112. }
  113.  
  114. void hp7475width(width)
  115. PLINT width;
  116. {
  117. }
  118.  
  119. /* Change the pen color */
  120. void hp7475color(color)
  121. PLINT color;
  122. {
  123.    if(color<1 || color>8)
  124.       fprintf(stderr,"Invalid pen selection.\n");
  125.    else
  126.       fprintf(OutDev,"SP %d;",color);
  127. }
  128.  
  129.  
  130. /* Draws a line from (x1,y1) to (x2,y2) */
  131. void hp7475line(x1,y1,x2,y2)
  132. PLINT x1,y1,x2,y2;
  133. {
  134.  
  135.    /* If starting point of this line is the same as the ending point of */
  136.    /* the previous line then don't raise the pen. (This really speeds up */
  137.    /* plotting and reduces the size of the file. */
  138.    if(!orient) {
  139.       if(x1 == xlast && y1 == ylast)
  140.          fprintf(OutDev," %d %d",x2,y2);
  141.       else
  142.          fprintf(OutDev,"\nPU %d %d PD %d %d",x1,y1,x2,y2);
  143.    }
  144.    else {
  145.       if(x1 == xlast && y1 == ylast)
  146.          fprintf(OutDev," %d %d",PLTX-y2,x2);
  147.       else
  148.          fprintf(OutDev,"\nPU %d %d PD %d %d",PLTX-y1,x1,PLTX-y2,x2);
  149.    }
  150.  
  151.    xlast = x2;
  152.    ylast = y2;
  153. }
  154.  
  155. /* Cleanup and close file. */
  156. void hp7475tidy()
  157. {
  158.    fprintf(OutDev,"\nSP0");
  159.    fclose(OutDev);
  160. }
  161.  
  162.  
  163.  
  164.