home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / HippoDraw / hippo / hippoplotPS.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-28  |  17.1 KB  |  649 lines

  1. /*
  2.  * hippoplotPS.c - Postscript routines for displaying hippo ntuples.
  3.  *
  4.  * Copyright (C)  1991  The Board of Trustees of The Leland Stanford
  5.  * Junior University.  All Rights Reserved.
  6.  *
  7.  * $ID$
  8.  *
  9.  * by Paul Rensing, Apr. 8, 1992
  10.  */
  11.  
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include "hippo.h"
  16. #include "hippoplotPS.h"
  17. #include "hippoutil.h"
  18.  
  19. /* various globals */
  20.  
  21. GLOB_QUAL const char hippoplotPS_c_rcsid[] = 
  22.      "$Id: hippoplotPS.c,v 1.2 1992/04/10 01:37:29 rensing Rel $";
  23.  
  24. GLOB_QUAL const char hippoplotPS_h_rcsid[] = _HIPPOPLOTPS_H_RCSID_;
  25.  
  26. #define MAXNPTS_PRINT 500
  27.  
  28. static struct {
  29.      float xScale;
  30.      float yScale;
  31.      float xMarg;
  32.      float yMarg;
  33.      float xOrig;
  34.      float yOrig;
  35.      float xMax;
  36.      float yMax;
  37. } data;
  38. static float bbox[4];        /* bounding box required by DPSDoUserPath */
  39.  
  40. static FILE *outfile = stdout;
  41. static int inPage = 0;
  42. static int nPages = 0;
  43.  
  44. int initDrvr_PS( FILE *fl )
  45. {
  46.      outfile = fl;
  47.      fprintf(outfile,"%%!PS-Adobe-2.0\n");
  48.      fprintf(outfile,"%%%%Creator: hippoplotamus\n");
  49.      fprintf(outfile,"%%%%Pages: (atend) 1\n");
  50.      fprintf(outfile,"%%%%BoundingBox: (atend)\n");
  51.      fprintf(outfile,"%%%%EndComments\n");
  52.      fprintf(outfile,"\n\n");
  53.      
  54.      /* NeXT's magic number for fast drawing */
  55.      fprintf(outfile,"0.15 setlinewidth\n");    
  56.      
  57.      return 0;
  58. }
  59.  
  60. int endDrvr_PS( void )
  61. {
  62.      endPage_PS();
  63.      fprintf(outfile,"%%%%Pages: %d %d\n",nPages,nPages);
  64.      return 0;
  65. }
  66.  
  67.  
  68. int initPlot_PS( rectangle *draw, rectangle *margin, rectangle *user )
  69. {
  70.      data.xScale = margin->size.width/user->size.width;
  71.      data.yScale = margin->size.height/user->size.height;
  72.      data.xMarg = margin->origin.x;
  73.      data.yMarg = margin->origin.y;
  74.      data.xOrig = user->origin.x;
  75.      data.yOrig = user->origin.y;
  76.      data.xMax = user->origin.x + user->size.width;
  77.      data.yMax = user->origin.y + user->size.height;
  78.      
  79.      /* specify bounding box  (add a small margin for safety) */    
  80.      bbox[0] = data.xOrig -
  81.       (data.xMarg - draw->origin.x)/data.xScale;
  82.      bbox[1] = data.yOrig - 
  83.       (data.yMarg - draw->origin.y)/data.yScale;
  84.      bbox[2] = data.xOrig + user->size.width +
  85.       (draw->size.width + draw->origin.x - 
  86.        (data.xMarg+margin->size.width))/data.xScale;
  87.      bbox[3] = data.yOrig + user->size.height +
  88.       (draw->size.height + draw->origin.y - 
  89.        (data.yMarg + margin->size.height))/data.yScale;
  90.      
  91.      inPage = 1;
  92.  
  93.      fprintf(outfile,"%%\n%%\n");
  94.  
  95.      return 0;
  96. }
  97.  
  98. int endPage_PS( void )
  99. {
  100.      if (inPage)
  101.      {
  102.       fprintf(outfile,"showpage\n");
  103.       fprintf(outfile,"%%\n%%\n");
  104.       
  105.       /* NeXT's magic number for fast drawing */
  106.       fprintf(outfile,"0.15 setlinewidth\n");    
  107.      }
  108.      inPage = 0;
  109.      
  110.      return 0;
  111. }
  112.  
  113. int drawLine_PS(float *coords, int nCoords, linestyle_t linest)
  114. {
  115.      int i;
  116.      
  117.      int repeatCount;        /* this number + 32 must be < 255 */
  118.      /* to display and < 127 for printing */
  119.      /* to fit in 1 char */
  120.      float *co;
  121.      int count;
  122.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 
  123.                  1.0/data.yScale, 0.0, 0.0 };
  124.      
  125.      fprintf(outfile,"%% drawLine_PS\n");
  126.  
  127.      repeatCount = 92;    /* work around apparent bug */
  128.      fprintf(outfile,"gsave  ");
  129.  
  130.      /* get into user coords */
  131.      fprintf(outfile,"%f %f translate  ",data.xMarg, data.yMarg);
  132.      fprintf(outfile,"%f %f scale  ",data.xScale, data.yScale);
  133.      fprintf(outfile,"%f %f translate\n", -data.xOrig, -data.yOrig);
  134.      
  135.      co = coords;
  136.      do
  137.      {
  138.       if (nCoords > repeatCount) count = repeatCount;
  139.       else count = nCoords;
  140.       
  141.       fprintf(outfile,"gsave\nnewpath systemdict begin\n");
  142.       fprintf(outfile,"%f %f moveto\n",*co++,*co++);
  143.       for (i=1; i<count; i++)
  144.            fprintf(outfile,"%f %f lineto\n",*co++, *co++);
  145.       fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  146.           ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  147.           ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  148.       fprintf(outfile,"stroke grestore\n");
  149.       co += 2*(count - 1);
  150.       nCoords -= (count - 1);
  151.      }
  152.      while (nCoords > 1);    /* 1 because we always back up 1 point */
  153.      /*  to connect the segments */
  154.      
  155.      fprintf(outfile,"grestore\n");
  156.      return 0;
  157. }
  158.  
  159.  
  160.  
  161. int drawPoints_PS(float *coords, int nCoords, plotsymbol_t symbol,
  162.            float symbolSize)
  163. {
  164.      
  165.      int i;
  166.      int filled=0;
  167.      int count;
  168.      int maxnpts;
  169.      float xPointSide, yPointSide;
  170.      float xHalfPointSide, yHalfPointSide;
  171.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 1.0/data.yScale, 0.0, 0.0 };
  172.      
  173.      fprintf(outfile,"%% drawPoints_PS\n");
  174.      
  175.      maxnpts = MAXNPTS_PRINT;
  176.      
  177.      if (symbol == SOLIDSQUARE)
  178.       filled = 1;
  179.      
  180.      if (filled) maxnpts /= 5;
  181.      
  182.      xPointSide = symbolSize / data.xScale;
  183.      yPointSide = symbolSize / data.yScale;
  184.      xHalfPointSide = xPointSide / 2.0;
  185.      yHalfPointSide = yPointSide / 2.0;
  186.      
  187.      fprintf(outfile,"gsave\n");
  188.      
  189.      /* get into user coords */
  190.      fprintf(outfile,"%f %f translate  ", data.xMarg, data.yMarg);
  191.      fprintf(outfile,"%f %f scale  ", data.xScale, data.yScale);
  192.      fprintf(outfile,"%f %f translate\n", -data.xOrig, -data.yOrig);
  193.      
  194.      if (nCoords > maxnpts) i = maxnpts;
  195.      else i = nCoords;
  196.      do
  197.      {
  198.       if (nCoords > maxnpts) count = maxnpts;
  199.       else count = nCoords;
  200.       
  201.       fprintf(outfile,"gsave\nnewpath systemdict begin\n");
  202.  
  203.       switch (symbol)
  204.       {
  205.       case SQUARE:
  206.       case SOLIDSQUARE:
  207.            for (i = 0; i < count; i++)
  208.            {
  209.             fprintf(outfile,"%f %f moveto\n", 
  210.                 *coords++ - xHalfPointSide,
  211.                 *coords++ - yHalfPointSide);
  212.             fprintf(outfile,"%f %f rlineto\n", +xPointSide, 0.0);
  213.             fprintf(outfile,"%f %f rlineto\n", +0.0, +yPointSide);
  214.             fprintf(outfile,"%f %f rlineto\n", -xPointSide, +0.0);
  215.             fprintf(outfile,"closepath\n");
  216.            }
  217.            break;
  218.            
  219.       case PLUS:
  220.            for (i = 0; i < count; i++)
  221.            {
  222.             fprintf(outfile,"%f %f moveto\n", 
  223.                 *coords++ - xHalfPointSide,
  224.                 *coords++);
  225.             fprintf(outfile,"%f %f rlineto\n", xPointSide, 0.0);
  226.             fprintf(outfile,"%f %f moveto\n", -xHalfPointSide, 
  227.                 yHalfPointSide);
  228.             fprintf(outfile,"%f %f rlineto\n", 0.0,    -yPointSide);
  229.            }
  230.            break;
  231.            
  232.       case TIMES:
  233.            for (i = 0; i < count; i++)
  234.            {
  235.             fprintf(outfile,"%f %f moveto\n", 
  236.                 *coords++ - xHalfPointSide,
  237.                 *coords++ - yHalfPointSide);
  238.             fprintf(outfile,"%f %f rlineto\n", xPointSide, yPointSide);
  239.             fprintf(outfile,"%f %f moveto\n", 0.0, yPointSide);
  240.             fprintf(outfile,"%f %f rlineto\n", xPointSide, 
  241.                 -yPointSide);
  242.            }
  243.            break;
  244.            
  245.       default:
  246.            break;
  247.       }
  248.       if (filled)
  249.       {
  250.            fprintf(outfile,"end\n");
  251.            fprintf(outfile,"fill grestore\n");
  252.       }
  253.       else
  254.       {
  255.            fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  256.                ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  257.                ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  258.            fprintf(outfile,"stroke grestore\n");
  259.       }
  260.       
  261.       nCoords -= count;
  262.      }
  263.      while (nCoords > 0);
  264.      
  265.      fprintf(outfile,"grestore\n");
  266.      
  267.      return 0;
  268. }
  269.  
  270.  
  271. int drawYError_PS(float *coords, float *errorYs, int nCoords)
  272. {
  273. #define ERRORCAPSIZE 2.0
  274.      
  275.      int i;
  276.      int count;
  277.      int maxnpts;
  278.      float x, yhi, ylo;
  279.      float halfErrorCap = ERRORCAPSIZE/data.xScale * 0.5;
  280.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 1.0/data.yScale, 0.0, 0.0 };
  281.      
  282.      fprintf(outfile,"%% drawYError_PS\n");
  283.      
  284.      maxnpts = MAXNPTS_PRINT;
  285.      
  286.      if (nCoords > maxnpts) i = maxnpts;
  287.      else i = nCoords;
  288.      
  289.      fprintf(outfile,"gsave\n");
  290.      
  291.      /* get into user coords */
  292.      fprintf(outfile,"%f %f translate  ", data.xMarg, data.yMarg);
  293.      fprintf(outfile,"%f %f scale  ", data.xScale, data.yScale);
  294.      fprintf(outfile,"%f %f translate\n", -data.xOrig, -data.yOrig);
  295.      
  296.      do 
  297.      {
  298.       if (nCoords > maxnpts) count = maxnpts;
  299.       else count = nCoords;
  300.       
  301.       fprintf(outfile,"gsave\nnewpath systemdict begin\n");
  302. /*      fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  303.           bbox[2],bbox[3]);
  304. */      
  305.       for (i = 0; i < count; i++)
  306.       {
  307.            x = *coords++;    /* x coord */
  308.            coords++;    /* skip over this y coord - not needed */
  309.            yhi = *errorYs++; /* y of high end of error bar */
  310.            ylo = *errorYs++; /* y of low end of error bar */
  311.            
  312.            fprintf(outfile,"%f %f moveto\n",x,ylo);
  313.            fprintf(outfile,"%f %f lineto\n",x,yhi);
  314.            fprintf(outfile,"%f %f moveto\n", x - halfErrorCap, yhi);
  315.            fprintf(outfile,"%f %f lineto\n", x + halfErrorCap, yhi);
  316.            fprintf(outfile,"%f %f moveto\n", x - halfErrorCap, ylo);
  317.            fprintf(outfile,"%f %f lineto\n", x + halfErrorCap, ylo);
  318.       }
  319.       
  320.       fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  321.           ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  322.           ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  323.       fprintf(outfile,"stroke grestore\n");
  324.       nCoords -= count;
  325.      }
  326.      while (nCoords > 0);
  327.      
  328.      fprintf(outfile,"grestore\n");
  329.      
  330.      return 0;
  331. }
  332.  
  333.  
  334. int drawXError_PS(float *coords, float *errorXs, int nCoords)
  335. {
  336.      int i;
  337.      int count;
  338.      int maxnpts;
  339.      float halfErrorCap = ERRORCAPSIZE/data.yScale * 0.5;
  340.      float y, xlo, xhi; 
  341.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 1.0/data.yScale, 0.0, 0.0 };
  342.      
  343.      fprintf(outfile,"%% drawXError_PS\n");
  344.      
  345.      maxnpts = MAXNPTS_PRINT;
  346.      
  347.      if (nCoords > maxnpts) i = maxnpts;
  348.      else i = nCoords;
  349.      
  350.      fprintf(outfile,"gsave\n");
  351.       
  352.      /* get into user coords */
  353.      fprintf(outfile,"%f %f translate  ", data.xMarg, data.yMarg);
  354.      fprintf(outfile,"%f %f scale  ", data.xScale, data.yScale);
  355.      fprintf(outfile,"%f %f translate\n", -data.xOrig, -data.yOrig);
  356.      
  357.      do 
  358.      {
  359.       if (nCoords > maxnpts) count = maxnpts;
  360.       else count = nCoords;
  361.       
  362.         fprintf(outfile,"gsave\nnewpath systemdict begin\n");
  363. /*        fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  364.                 bbox[2],bbox[3]);
  365. */          
  366.       for (i = 0; i < count; i++)
  367.       {
  368.            coords++;    /* skip over this x coord - not needed */
  369.            y = *coords++;    /* y coord */
  370.            xhi = *errorXs++; /* x of high end of error bar */
  371.            xlo = *errorXs++; /* x of low end of error bar */
  372.            
  373.         fprintf(outfile,"%f %f moveto\n",xlo,y);
  374.         fprintf(outfile,"%f %f lineto\n",xhi,y);
  375.         fprintf(outfile,"%f %f moveto\n", xlo, y - halfErrorCap);
  376.         fprintf(outfile,"%f %f lineto\n", xlo, y + halfErrorCap);
  377.         fprintf(outfile,"%f %f moveto\n", xhi, y - halfErrorCap);
  378.         fprintf(outfile,"%f %f lineto\n", xhi, y + halfErrorCap);
  379.       }
  380.       
  381.         fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  382.                 ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  383.                 ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  384.         fprintf(outfile,"stroke grestore\n");
  385.       nCoords -= count;
  386.      }
  387.      while (nCoords > 0);
  388.  
  389.      fprintf(outfile,"grestore\n");
  390.      
  391.      return 0;
  392. }
  393.  
  394. int drawYTicks_PS( float *y, int nt, float tickwidth, int side )
  395. {
  396.      int i;
  397.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 1.0/data.yScale, 0.0, 0.0 };
  398.      float start;
  399.      
  400.      tickwidth /= data.xScale;
  401.      
  402.      fprintf(outfile,"%% drawYTicks_PS\n");
  403.  
  404.      if (side == 0)
  405.       start = data.xOrig;
  406.      else
  407.       start = data.xMax - tickwidth;
  408.  
  409.      fprintf(outfile,"gsave\n");
  410.      
  411.      /* get into user coords */
  412.      fprintf(outfile,"%f %f translate  ", data.xMarg, data.yMarg);
  413.      fprintf(outfile,"%f %f scale  ", data.xScale, data.yScale);
  414.      fprintf(outfile,"%f %f translate\n",-data.xOrig, -data.yOrig);
  415.      
  416.      fprintf(outfile,"newpath systemdict begin\n");
  417. /*     fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  418.          bbox[2],bbox[3]);
  419. */     
  420.      for (i = 0; i < nt; i++)
  421.      {
  422.       fprintf(outfile,"%f %f moveto  ", start, y[i] );
  423.       fprintf(outfile,"%f %f rlineto\n", tickwidth, 0.0 );
  424.      }
  425.      fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  426.          ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  427.          ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  428.      fprintf(outfile,"stroke\n");
  429.      
  430.      fprintf(outfile,"grestore\n");
  431.      
  432.      return 0;
  433. }
  434.  
  435. int drawXTicks_PS( float *y, int nt, float tickwidth, int side )
  436. {
  437.      int i;
  438.      float ctm_matrix[6] = {1.0/data.xScale, 0.0, 0.0, 1.0/data.yScale, 0.0, 0.0 };
  439.      float start;
  440.      
  441.      tickwidth /= data.yScale;
  442.      
  443.      fprintf(outfile,"%% drawXTicks_PS\n");
  444.      
  445.      if (side == 0)
  446.       start = data.yOrig;
  447.      else
  448.       start = data.yMax - tickwidth;
  449.  
  450.      fprintf(outfile,"gsave\n");
  451.      
  452.      /* get into user coords */
  453.      fprintf(outfile,"%f %f translate  ", data.xMarg, data.yMarg);
  454.      fprintf(outfile,"%f %f scale  ", data.xScale, data.yScale);
  455.      fprintf(outfile,"%f %f translate\n", -data.xOrig, -data.yOrig);
  456.      
  457.      fprintf(outfile,"newpath systemdict begin\n");
  458. /*     fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  459.          bbox[2],bbox[3]);
  460. */     
  461.      for (i = 0; i < nt; i++)
  462.      {
  463.       fprintf(outfile,"%f %f moveto  ", y[i], start );
  464.       fprintf(outfile,"%f %f rlineto\n", 0.0, tickwidth );
  465.      }
  466.      fprintf(outfile,"end\n[%f %f %f %f %f %f] concat\n",
  467.          ctm_matrix[0],ctm_matrix[1],ctm_matrix[2],
  468.          ctm_matrix[3],ctm_matrix[4],ctm_matrix[5]);
  469.      fprintf(outfile,"stroke\n");
  470.      
  471.      
  472.      fprintf(outfile,"grestore\n");
  473.      
  474.      return 0;
  475. }
  476.  
  477. int drawMag_PS(float x, float y, int mag, float fontSize)
  478. {
  479.      char str[10];
  480.      
  481.      fprintf(outfile,"%% drawMag_PS\n");
  482.      
  483.      fprintf(outfile,"(Helvetica) %f selectfont\n",fontSize);
  484.      fprintf(outfile,"%f %f moveto\n", x, y );
  485.      fprintf(outfile,"(x10) show");
  486.      fprintf(outfile,"%f %f rmoveto\n", 0.0, 0.5*fontSize );
  487.      sprintf(str,"%d",mag);
  488.      fprintf(outfile,"(%s) show\n", str);
  489.      
  490.      return 0;
  491. }
  492.  
  493.  
  494. int drawText_PS(char *string, float x, float y, float fontSize, 
  495.          float rotation, char xAlign, char yAlign)
  496. {
  497.      float xStep = 0.0, yStep = 0.0;
  498.      
  499.      fprintf(outfile,"%% drawText_PS\n");
  500.      
  501.      switch (yAlign)
  502.      {
  503.      case 'C':
  504.      case 'c':
  505.       yStep = 0.4;
  506.       break;
  507.       
  508.      case 'T':
  509.      case 't':
  510.       yStep = 0.8;
  511.       break;
  512.      }
  513.      
  514.      switch (xAlign)
  515.      {
  516.      case 'C':
  517.      case 'c':
  518.       xStep = 0.5;
  519.       break;
  520.      case 'R':
  521.      case 'r':
  522.       xStep = 1.0;
  523.       break;
  524.      }
  525.      
  526.      fprintf(outfile,"gsave\n");
  527.      fprintf(outfile,"(Helvetica) %f selectfont\n", fontSize);
  528.      fprintf(outfile,"%f %f translate %f rotate\n",x,y,rotation);
  529.      
  530.      fprintf(outfile,"(%s) stringwidth pop\n", string);
  531.      fprintf(outfile,"%f neg mul %f moveto\n",xStep,-fontSize*yStep);
  532.      fprintf(outfile,"(%s) show\n",string);
  533.      fprintf(outfile,"grestore\n");
  534.      
  535.      return 0;
  536. }
  537.  
  538.  
  539.  
  540. int drawColor2D_PS(int nXBins, int nYBins, rectangle *marginRect,
  541.             float *data, float binMin, float binMax, int useColor )
  542. {
  543.      int  iYBin;
  544.      int totBins = nXBins * nYBins;
  545.      float deltaX = marginRect->size.width / nXBins;
  546.      float deltaY = marginRect->size.height / nYBins;
  547.      float grayScale, nearWhite = 0.9;
  548.      float  xCoord, yCoord;
  549.      int i, count;
  550.      int maxnpts = 30;
  551.      
  552.      fprintf(outfile,"%% drawColor2D_PS\n");
  553.      
  554.      /* 
  555.       * this routine leaves color in unpredictable state, 
  556.       * so we need a gsave/grestore
  557.       */ 
  558.      fprintf(outfile,"gsave\n");    
  559.      
  560.      if (binMin == binMax)
  561.       grayScale = 1.0;
  562.      else 
  563.       grayScale = nearWhite / (binMax - binMin);
  564.      xCoord = marginRect->origin.x;
  565.      yCoord = marginRect->origin.y;
  566.      iYBin = 0;
  567.      
  568.      do 
  569.      {
  570.       if (totBins > maxnpts) count = maxnpts;
  571.       else count = totBins;
  572.       
  573.       fprintf(outfile,"gsave\nnewpath systemdict begin\n");
  574. /*      fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  575.           bbox[2],bbox[3]);
  576. */      
  577.       for (i = 0; i < count; i++)
  578.       {
  579.            /* bins are arranged as bins[x][y] with y changing fastest */
  580.            if (*data != 0)
  581.            {
  582.             fprintf(outfile,"%f setgray\n", (binMax- *data)*grayScale);
  583.             fprintf(outfile,"%f %f moveto %f %f rlineto\n",
  584.                 xCoord, yCoord, deltaX, 0.0 );
  585.             fprintf(outfile,"%f %f rlineto %f %f rlineto closepath\n",
  586.                 0.0, deltaY, -deltaX, 0.0 );
  587.            }
  588.            data++;
  589.            yCoord += deltaY;
  590.            iYBin++;
  591.            if ( iYBin == nYBins) 
  592.            {
  593.             iYBin = 0;
  594.             yCoord = marginRect->origin.y;
  595.             xCoord += deltaX;
  596.             
  597.            }
  598.       }
  599.       fprintf(outfile,"end\n");
  600.       fprintf(outfile,"fill grestore\n");
  601.       totBins -= count;
  602.       
  603.      }
  604.      while (totBins > 0);
  605.      
  606.      
  607.      fprintf(outfile,"grestore\n");
  608.      return 0;
  609. }
  610.  
  611.  
  612. int drawLego2D_PS(rectangle *marginRect)
  613. {
  614.      float fontHeight = 0.2 * data.yMarg;
  615.      
  616.      fprintf(outfile,"%% drawLego2D_PS\n");
  617.      
  618.      if (fontHeight > 24.0) fontHeight = 24.0;
  619.      
  620.      drawText_PS("Not implemented yet.", 
  621.           marginRect->origin.x + marginRect->size.width*0.5,
  622.           marginRect->origin.y + marginRect->size.height*0.5,
  623.           fontHeight,0.0,'c','c');
  624.      return 0;
  625. }
  626.  
  627. int shade_PS(float xlow, float xhigh, float ylow, float yhigh )
  628. {
  629.      fprintf(outfile,"%% shade_PS\n");
  630.      
  631.      fprintf(outfile,"gsave\n");
  632.      /*     PSsetalpha(0.0);*/
  633.      fprintf(outfile,"%f setgray\n", 0.6);    
  634.      fprintf(outfile,"newpath systemdict begin\n");
  635. /*     fprintf(outfile,"%f %f %f %f setbbox\n",bbox[0],bbox[1],
  636.          bbox[2],bbox[3]);
  637. */     
  638.      fprintf(outfile,"%f %f moveto %f %f rlineto\n",
  639.          xlow, ylow, xhigh-xlow, 0.0 );
  640.      fprintf(outfile,"%f %f rlineto %f %f rlineto closepath\n",
  641.          0.0, yhigh-ylow, xlow-xhigh, 0.0 );
  642.      fprintf(outfile,"end\n");
  643.      fprintf(outfile,"fill grestore\n");
  644.      
  645.      return 0;
  646. }
  647.  
  648.  
  649.