home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume18 / treepar / part01 / plotSIZE.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-12  |  1.6 KB  |  87 lines

  1. /* plotSIZE.c - plot driver for finding the size of a plot
  2.  *
  3.  * 22.Dec.87  jimmc  Initial definition
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "plot.h"
  8.  
  9. static FILE *PSZfile;
  10. static minx, maxx, miny, maxy;
  11. static int textxsize, textysize;
  12.  
  13. #define SIZELEFT 0
  14. #define SIZERIGHT 1000
  15. #define SIZEBOTTOM 0
  16. #define SIZETOP 1000
  17.  
  18. int        /* 1 if OK */
  19. PSZInit(filename,lxp,lyp,hxp,hyp)
  20. char *filename;
  21. int *lxp,*lyp,*hxp,*hyp;    /* returns bounding box of window */
  22. {
  23.     if (strcmp(filename,"stdout")==0) PSZfile=stdout;
  24.     else if (strcmp(filename,"stderr")==0) PSZfile=stderr;
  25.     else PSZfile = fopen(filename,"w");
  26.     if (!PSZfile) {
  27.         printf("can't open file %s",filename);
  28.         return 0;
  29.     }
  30.     *lxp = maxx = SIZELEFT;
  31.     *lyp = maxy = SIZEBOTTOM;
  32.     *hxp = minx = SIZERIGHT;
  33.     *hyp = miny = SIZETOP;
  34.     textxsize = textysize = 0;
  35.     return 1;
  36. }
  37.  
  38. #define CHECKX(x) { if ((x)<minx) minx=(x); if ((x)>maxx) maxx=(x); }
  39. #define CHECKY(y) { if ((y)<miny) miny=(y); if ((y)>maxy) maxy=(y); }
  40. #define CHECKXY(x,y) CHECKX(x) CHECKY(y)
  41.  
  42. PSZDone()
  43. {
  44.     fprintf(PSZfile,"On a scale of 0 to 1000, x=%d and y=%d\n",
  45.         maxx-minx, maxy-miny);
  46.     if (PSZfile!=stdout && PSZfile!=stderr)
  47.         fclose(PSZfile);
  48. }
  49.  
  50. PSZTextSize(x,y)
  51. int x,y;
  52. {
  53.     fprintf(PSZfile,"TextSize (%d %d)\n",x,y);
  54.     textxsize = x;
  55.     textysize = y;
  56. }
  57.  
  58. PSZLine(lx,ly,hx,hy)
  59. int lx,ly,hx,hy;
  60. {
  61.     CHECKXY(lx,ly)
  62.     CHECKXY(hx,hy)
  63. }
  64.  
  65. PSZText(x,y,text)
  66. int x,y;
  67. char *text;
  68. {
  69.     CHECKXY(x,y)
  70.     CHECKXY(x+strlen(text)*textxsize,y+textysize);
  71. }
  72.  
  73. PSZSetup()
  74. {
  75. PDevInfo *p;
  76.  
  77.     p = Pnew();
  78.     p->name = "SIZE";
  79.     p->init = PSZInit;
  80.     p->done = PSZDone;
  81.     p->line = PSZLine;
  82.     p->text = PSZText;
  83.     p->textsize = PSZTextSize;
  84. }
  85.  
  86. /* end */
  87.