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

  1. /* This file contains the IMPRESS device dependent subroutines for */
  2. /* use with plplot. */
  3.  
  4. #include "plplot.h"
  5. #include <stdio.h>
  6. #include <limits.h>
  7.  
  8. #define SET_HV_SYSTEM   0315
  9. #define OPBYTE1         031
  10. #define OPBYTE2         0140
  11. #define SET_ABS_H       0207
  12. #define SET_ABS_V       0211
  13. #define OPWORDH1        0
  14. #define OPWORDH2        150
  15. #define OPWORDV1        0
  16. #define OPWORDV2        150
  17. #define ENDPAGE         0333
  18.  
  19. #define BUFFPTS         50
  20. #define BUFFLENG        2*BUFFPTS
  21.  
  22. #define IMPX            2999
  23. #define IMPY            2249
  24.  
  25. static FILE *OutFile;
  26. static int porient;
  27. static short *LineBuff;
  28. static int select=0;
  29. char FileName[80];
  30.  
  31. void flushline(void);
  32.  
  33. void impsetup(xdpi,ydpi,xwid,ywid)
  34. PLINT xwid, ywid;
  35. PLFLT xdpi, ydpi;
  36. {
  37. }
  38.  
  39. /* Open file.  Set up for graphics. */
  40. void impinit()
  41. {
  42.       char response[80];
  43.       int ori;
  44.  
  45.       smod(0);  /* not an interactive terminal */
  46.       scol(1);
  47.       swid(1);
  48.       setpxl(11.81,11.81);
  49.       
  50.       if(!select) {
  51.          printf("Landscape or portrait orientation? (0 or 1): ");
  52.          fgets(response,sizeof(response),stdin);
  53.          if(sscanf(response,"%d",&ori) != 1)
  54.             ori = 0;   /* carriage return defaults to landscape */
  55.       }
  56.       
  57.       porient = ori;
  58.       if(!porient)
  59.          setphy(0,IMPX,0,IMPY);
  60.       else
  61.          setphy(0,IMPY,0,IMPX);
  62.  
  63.       OutFile = NULL;
  64.       while(!OutFile) {
  65.          if(!select) {
  66.             printf("Enter graphics command storage file name. ");
  67.             fgets(response,sizeof(response),stdin);
  68.             if(sscanf(response,"%s",FileName) != 1) {
  69.                 printf("Invalid entry.n");
  70.                 continue;
  71.             }
  72.          }
  73.          select = 0;
  74.          if ((OutFile = fopen(FileName,"w")) == NULL) 
  75.              printf("Can't open %s.\n",FileName);
  76.       }
  77.  
  78.       LineBuff = (short *)malloc(BUFFLENG*sizeof(short));
  79.       if(LineBuff == NULL) {
  80.         printf("\nError in memory alloc in impini().\n");
  81.         exit(1);
  82.       }
  83.       fprintf(OutFile,"@Document(Language ImPress, jobheader off)");
  84.       fprintf(OutFile,"%c%c",SET_HV_SYSTEM,OPBYTE1);
  85.       fprintf(OutFile,"%c%c%c",SET_ABS_H,OPWORDH1,OPWORDH2);
  86.       fprintf(OutFile,"%c%c%c",SET_ABS_V,OPWORDV1,OPWORDV2);
  87.       fprintf(OutFile,"%c%c",SET_HV_SYSTEM,OPBYTE2);
  88. }
  89.  
  90. void impselect(ori,file)
  91. PLINT ori;
  92. char *file;
  93. {
  94.    porient = ori;
  95.    strncpy(FileName,file,sizeof(FileName)-1);
  96.    FileName[sizeof(FileName)-1] = '\0';
  97.    select = 1;
  98. }
  99.  
  100. /* Sets the IMPRESS to text mode */
  101. void imptext()
  102. {
  103. }
  104.  
  105. /* Sets the IMPRESS to graphics mode */
  106. void impgraph()
  107. {
  108. }
  109.  
  110. /* Form feed */
  111. void impclear()
  112. {
  113.      flushline();
  114.      fprintf(OutFile,"%c",ENDPAGE);
  115. }
  116.  
  117. static short FirstLine;
  118.  
  119. void imppage()
  120. {
  121.    FirstLine = 1;
  122. }
  123.  
  124. /* May put something here someday */
  125. void impcolor(colour)
  126. PLINT colour;
  127. {
  128. }
  129.  
  130. #define SET_PEN       0350
  131.  
  132. static int penchange=0, penwidth;
  133.  
  134. void impwidth(width)
  135. PLINT width;
  136. {
  137.       if(width>0 && width <= 20) {
  138.         penwidth = width;
  139.         penchange = 1;
  140.       }
  141. }
  142.  
  143. #define CREATE_PATH   0346
  144. #define DRAW_PATH     0352
  145. #define OPTYPE        017
  146.  
  147. static short count;
  148.  
  149. void impline(x1a,y1a,x2a,y2a)
  150. PLINT x1a,y1a,x2a,y2a;
  151. {
  152.       static int xold, yold;
  153.       int x1, y1, x2, y2;
  154.  
  155.       if(!porient) {
  156.          x1 = x1a;
  157.          y1 = y1a;
  158.          x2 = x2a;
  159.          y2 = y2a;
  160.       }
  161.       else {
  162.          x1 = IMPX - y1a;
  163.          y1 = x1a;
  164.          x2 = IMPX - y2a;
  165.          y2 = x2a;
  166.       }
  167.  
  168.       if(FirstLine) {
  169.         if(penchange) {
  170.           fprintf(OutFile,"%c%c",SET_PEN,(char)penwidth);
  171.           penchange = 0;
  172.         }
  173.         /* Add both points to path */
  174.         count = 0;
  175.         FirstLine = 0;
  176.         *(LineBuff+count++) = (short)x1;
  177.         *(LineBuff+count++) = (short)y1;
  178.         *(LineBuff+count++) = (short)x2;
  179.         *(LineBuff+count++) = (short)y2;
  180.       }
  181.       else if((count+2) < BUFFLENG && x1 == xold && y1 == yold) {
  182.         /* Add new point to path */
  183.         *(LineBuff+count++) = (short)x2;
  184.         *(LineBuff+count++) = (short)y2;
  185.       }
  186.       else {
  187.         /* Write out old path */
  188.         count /= 2;
  189.         fprintf(OutFile,"%c%c%c",CREATE_PATH,(char)count/256,(char)count%256);
  190.         fwrite((char *)LineBuff,sizeof(short),2*count,OutFile);
  191.         fprintf(OutFile,"%c%c",DRAW_PATH,OPTYPE);
  192.         
  193.         /* And start a new path */
  194.         if(penchange) {
  195.           fprintf(OutFile,"%c%c",SET_PEN,(char)penwidth);
  196.           penchange = 0;
  197.         }
  198.         count = 0;
  199.         *(LineBuff+count++) = (short)x1;
  200.         *(LineBuff+count++) = (short)y1;
  201.         *(LineBuff+count++) = (short)x2;
  202.         *(LineBuff+count++) = (short)y2;
  203.       }
  204.  
  205.       xold = x2;
  206.       yold = y2;
  207. }
  208.       
  209. void flushline()
  210. {
  211.    count /= 2;
  212.    fprintf(OutFile,"%c%c%c",CREATE_PATH,(char)count/256,(char)count%256);
  213.    fwrite((char *)LineBuff,sizeof(short),2*count,OutFile);
  214.    fprintf(OutFile,"%c%c",DRAW_PATH,OPTYPE);
  215.    FirstLine = 1;
  216. }
  217. /* Close graphics file */
  218. void imptidy()
  219. {
  220.       flushline();
  221.       fprintf(OutFile,"%c",ENDPAGE);
  222.       free((char *)LineBuff);
  223.       fclose(OutFile);
  224.       select = 0;
  225. }
  226.