home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / DRAWPS.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  20KB  |  685 lines

  1. /*
  2.  *                      D R A W P S . C 
  3.  *
  4.  *  Changed to take magnification into account, 27 August 1990.
  5.  *
  6.  * (minor mods by don on 5 Jan 90 to accommodate highres PostScript)
  7.  *
  8.  * $Revision: 1.1 $
  9.  *
  10.  * $Log:    drawPS.c,v $
  11.  * Revision 1.1  90/03/10  20:32:48  grunwald
  12.  * Initial revision
  13.  * 
  14.  *
  15.  * 89/04/24: decouty@irisa.fr, priol@irisa.fr
  16.  *              added three shading levels for fig,
  17.  *              removed '\n' in cmdout() calls
  18.  *
  19.  * Revision 1.4  87/05/07  15:06:24  dorab
  20.  * relinked back hh to h and vv to v undoing a previous change.
  21.  * this was causing subtle quantization problems. the main change
  22.  * is in the definition of hconvPS and vconvPS.
  23.  * 
  24.  * changed the handling of the UC seal. the PS file should now be
  25.  * sent via the -i option.
  26.  * 
  27.  * Revision 1.3  86/04/29  23:20:55  dorab
  28.  * first general release
  29.  * 
  30.  * Revision 1.3  86/04/29  22:59:21  dorab
  31.  * first general release
  32.  * 
  33.  * Revision 1.2  86/04/29  13:23:40  dorab
  34.  * Added distinctive RCS header
  35.  * 
  36.  */
  37. #ifndef lint
  38. static char RCSid[] = 
  39.   "@(#)$Header: /usr/local/src/TeX/Dvips-5.0.2/RCS/drawPS.c,v 1.1 90/03/10 20:32:48 grunwald Exp $ (UCLA)";
  40. #endif
  41.  
  42. /*
  43.  the driver for handling the \special commands put out by
  44.  the tpic program as modified by Tim Morgan <morgan@uci.edu>
  45.  the co-ordinate system is with the origin at the top left
  46.  and the x-axis is to the right, and the y-axis is to the bottom.
  47.  when these routines are called, the origin is set at the last dvi position,
  48.  which has to be gotten from the dvi-driver (in this case, dvips) and will
  49.  have to be converted to device co-ordinates (in this case, by [hv]convPS).
  50.  all dimensions are given in milli-inches and must be converted to what
  51.  dvips has set up (i.e. there are convRESOLUTION units per inch).
  52.  
  53.  it handles the following \special commands
  54.     pn n                        set pen size to n
  55.     pa x y                      add path segment to (x,y)
  56.     fp                          flush path
  57.     ip                          flush invisible path, i.e. do shading only
  58.     da l                        flush dashed - each dash is l (inches)
  59.     dt l                        flush dotted - one dot per l (inches)
  60.     sp [l]                      flush spline - optional l is dot/dash length
  61.     ar x y xr yr sa ea          arc centered at (x,y) with x-radius xr
  62.                                 and y-radius yr, start angle sa (in rads),
  63.                                 end angle ea (in rads)
  64.     ia x y xr yr sa ea          invisible arc with same parameters as above
  65.     sh [s]                      shade last path (box, circle, ellipse)
  66.                 s = gray level (0 = white, 1 = black)
  67.     wh                          whiten last path (box, circle, ellipse)
  68.     bk                          blacken last path (box,circle, ellipse)
  69.     tx                          texture command - Added by T. Priol
  70.                 (priol@irisa.fr), enhanced by M. Jourdan:
  71.                 textures are translated into uniform gray levels
  72.  
  73.   this code is in the public domain
  74.  
  75.   written by dorab patel <dorab@cs.ucla.edu>
  76.   december 1985
  77.   released feb 1986
  78.   changes for dvips july 1987
  79.  
  80.   */
  81.  
  82. #ifdef TPIC                     /* rest of the file !! */
  83.  
  84. #include "structures.h"
  85. #include <math.h>        /* used in function "arc" */
  86.  
  87. #ifdef DEBUG
  88. extern integer debug_flag;
  89. #endif  /* DEBUG */
  90.  
  91.  
  92. /*
  93.  * external functions used here
  94.  */
  95. extern void cmdout();
  96. extern void floatout();
  97. extern void numout();
  98. extern void error();
  99.  
  100. /*
  101.  * external variables used here
  102.  */
  103. extern integer hh,vv;           /* the current x,y position in pixel units */
  104. extern int actualdpi ;
  105. extern int vactualdpi ;
  106. extern integer mag ;
  107.  
  108. #define convRESOLUTION DPI
  109. #define convVRESOLUTION VDPI
  110. #define TRUE 1
  111. #define FALSE 0
  112. #define tpicRESOLUTION 1000     /* number of tpic units per inch */
  113.  
  114. /* convert from tpic units to PS units */
  115. #define PixRound(a,b) zPixRound((integer)(a),(integer)(b))
  116. #define convPS(x) PixRound((x),convRESOLUTION)
  117. #define convVPS(x) PixRound((x),convVRESOLUTION)
  118.  
  119. /* convert from tpic locn to abs horiz PS locn */
  120. #define hconvPS(x) (integer)(hh + convPS(x))
  121. /* convert from tpic locn to abs vert PS locn */
  122. #define vconvPS(x) (integer)(vv + convVPS(x))
  123. /* convert to degrees */
  124. #define convDeg(x) (360*(x)/(2*3.14159265358))
  125.  
  126. /* if PostScript had splines, i wouldnt need to store the path */
  127. #define MAXPATHS 300            /* maximum number of path segments */
  128. #define NONE 0                  /* for shading */
  129. #define BLACK           1       /* for shading */
  130. #define GRAY        2       /* MJ; for shading */
  131. #define WHITE           3       /* for shading */
  132.  
  133. /* the following defines are used to make the PostScript shorter;
  134.   the corresponding defines are in the PostScript prolog special.lpro */
  135. #define MOVETO "a"
  136. #define LINETO "li"
  137. #define RCURVETO "rc"
  138. #define RLINETO "rl"
  139. #define STROKE "st"
  140. #define FILL "fil"
  141. #define NEWPATH "np"
  142. #define CLOSEPATH "closepath"
  143. /*
  144.  * STROKE and FILL must restore the current point to that
  145.  * saved by NEWPATH
  146.  */
  147.  
  148. static integer xx[MAXPATHS], yy[MAXPATHS]; /* the current path in milli-inches */
  149. static integer pathLen = 0;             /* the current path length */
  150. static integer shading = NONE;  /* what to shade the last figure */
  151. static integer penSize = 2;             /* pen size in PS units */
  152.  
  153. /* forward declarations */
  154. /* static void doShading(); */
  155. static integer zPixRound();             /* (int)(x/y)PixRound((int)x,(int)y) */
  156. static double  shadetp = 0.5;
  157.              /* shading level, initialized as requested by tpic 2.0 -- MJ */
  158.  
  159. void
  160. setPenSize(cp)
  161.      char *cp;
  162. {
  163.   long ps;
  164.  
  165.   if (sscanf(cp, " %ld ", &ps) != 1) 
  166.     {
  167.       error("Illegal .ps command format");
  168.       return;
  169.     }
  170.  
  171.   penSize = convPS(ps);
  172.   numout((integer)penSize);
  173.   cmdout("setlinewidth");
  174. }                               /* end setPenSize */
  175.  
  176. void
  177. addPath(cp)
  178.      char *cp;
  179. {
  180.   long x,y;
  181.  
  182.   if (++pathLen >= MAXPATHS) error("! Too many points");
  183.   if (sscanf(cp, " %ld %ld ", &x, &y) != 2)
  184.     error("! Malformed path expression");
  185.   xx[pathLen] = x;
  186.   yy[pathLen] = y;
  187. }                               /* end of addPath */
  188.  
  189. void
  190. arc(cp, invis)
  191.      char *cp;
  192.     int invis;
  193. {
  194.   long xc, yc, xrad, yrad;
  195.   float startAngle, endAngle;
  196.  
  197.   if (sscanf(cp, " %ld %ld %ld %ld %f %f ", &xc, &yc, &xrad, &yrad,
  198.              &startAngle, &endAngle) != 6)
  199.     {
  200.       error("Illegal arc specification");
  201.       return;
  202.     }
  203.  
  204. /* To have filled ellipses/circles also have borders, we duplicate the object
  205.    specification; first time we emit a FILL command, second time we emit a
  206.    STROKE command.
  207.    There certainly exists a better way to do that in PostScript, by
  208.    remembering the object specification (path) across the fill command.
  209.    However I (MJ) am completely unproficient at PostScript...
  210. */
  211.  
  212. /* we need the newpath since STROKE doesnt do a newpath */
  213.  
  214.   if (shading) {
  215.       /* first time for shading */
  216.       cmdout(NEWPATH);
  217.       numout((integer)hconvPS(xc));
  218.       numout((integer)vconvPS(yc));
  219.       numout((integer)convPS(xrad));
  220.       if (xrad != yrad && VDPI == DPI)
  221.     numout((integer)convPS(yrad));
  222.       floatout(convDeg(startAngle));
  223.       floatout(convDeg(endAngle));
  224.  
  225.       if (xrad == yrad && VDPI == DPI)        /* for arcs and circles */
  226.     cmdout("arc");
  227.       else
  228.     cmdout("ellipse");
  229.  
  230.       cmdout(FILL);
  231.       shading = NONE;
  232.       cmdout("0 setgray");    /* default of black */
  233.   }
  234.  
  235.   if (!invis) {
  236.       /* There is a problem with tpic 2.0's handling of dotted ellipses.
  237.      In most (all?) cases, after conversion to degrees and rounding
  238.      to integers, startAngle and endAngle become the same, so nothing,
  239.      not even a dot (as requested), is printed in the output (at least
  240.      on my Apple LaserWriter).
  241.      So I (MJ) singled out this case.
  242.        */
  243.       float degStAng = convDeg(startAngle),
  244.             degEnAng = convDeg(endAngle);
  245.  
  246.       cmdout(NEWPATH);        /* save current point */
  247.  
  248.       if (degStAng != degEnAng) { /* normal case */
  249.       numout((integer)hconvPS(xc));
  250.       numout((integer)vconvPS(yc));
  251.       numout((integer)convPS(xrad));
  252.       if (xrad != yrad)
  253.           numout((integer)convPS(yrad));
  254.       floatout(degStAng);
  255.       floatout(degEnAng);
  256.  
  257.       if (xrad == yrad)    /* for arcs and circles */
  258.           cmdout("arc");
  259.       else
  260.           cmdout("ellipse");
  261.       }
  262.       else {            /* draw a single dot */
  263.       long xdot, ydot;
  264.       xdot = (long) ((double)xc + (double)xrad * cos ((startAngle + endAngle) / 2.0));
  265.       ydot = (long) ((double)yc + (double)yrad * sin ((startAngle + endAngle) / 2.0));
  266.       numout((integer)hconvPS(xdot));
  267.       numout((integer)vconvPS(ydot));
  268.       cmdout(MOVETO);
  269.       /* +1 to make sure the dot is printed */
  270.       numout((integer)hconvPS(xdot)+1);
  271.       numout((integer)vconvPS(ydot)+1);
  272.       cmdout(LINETO);
  273.       }
  274.  
  275.       cmdout(STROKE);
  276.   }
  277. }                               /* end of arc */
  278.  
  279. /*
  280.  * In pic dashed lines are created in a manner which makes boths ends
  281.  * of a line solid.
  282.  * This means that the corner of a dotted box is a dot and the corner
  283.  * of a dashed box is solid.
  284.  * The number of inches/dash must be adjusted accordingly.
  285.  */
  286. void
  287. flushDashedPath(dotted, inchesPerDash)
  288.     int dotted;
  289.     float inchesPerDash;
  290. {
  291.   register int i;
  292.   int nipd = (integer) convPS((int) inchesPerDash);
  293.  
  294.   if (nipd == 0)
  295.     nipd = 1 ;
  296.   if (pathLen < 2) 
  297.     {
  298.       error("Path less than 2 points - ignored");
  299.       return;
  300.     }
  301.  
  302.   cmdout(NEWPATH);        /* to save the current point */
  303.   for (i=2; i <= pathLen; i++) {
  304.       integer dx = hconvPS(xx[i-1]) - hconvPS(xx[i]);
  305.       integer dy = vconvPS(yy[i-1]) - vconvPS(yy[i]);
  306.       float delta = sqrt((double) (dx * dx + dy * dy));
  307.       float ipd;
  308.       int ndashes;
  309.  
  310.       /*
  311.        * If a line is dashed there must be an odd number of dashes.
  312.        * This makes the first and last dash of the line solid.
  313.        * If a line is dotted the length of a dot + space sequence must be
  314.        * chosen such that (n+1) * dotlength + n space length = linelength
  315.        * => (dot + space) = (line - dot) / n
  316.        */
  317.       if (dotted)
  318.       delta -= penSize;
  319.       ndashes = (integer) (delta / nipd + 0.5); /* number of dashes on line */
  320.       /* only odd when dashed, choose odd number with smallest deviation */
  321.       if (ndashes > 1 && (ndashes & 0x1) == 0 && !dotted) {
  322.     if (fabs(nipd - delta/(ndashes - 1)) <
  323.         (fabs(nipd - delta/(ndashes + 1))))
  324.         ndashes -= 1;
  325.     else
  326.         ndashes += 1;
  327.       }
  328.       ipd = delta / ndashes;
  329.       if (ipd <= 0)
  330.          ipd = 1 ;
  331.       cmdout("[");
  332.       if (dotted) {
  333.     numout((integer)penSize);
  334.     floatout(ipd - penSize);
  335.       } else                               /* if dashed */
  336.     floatout(ipd);
  337.  
  338.       cmdout("]");
  339.       numout((integer)0);
  340.       cmdout("setdash");
  341.       numout((integer)hconvPS(xx[i-1]));
  342.       numout((integer)vconvPS(yy[i-1]));
  343.       cmdout(MOVETO);
  344.       numout((integer)hconvPS(xx[i]));
  345.       numout((integer)vconvPS(yy[i]));
  346.       cmdout(LINETO);
  347.       cmdout(STROKE);
  348.   }
  349.   cmdout("[] 0 setdash");
  350.   pathLen = 0;
  351. }
  352.  
  353. void
  354. flushPath(invis)
  355.     int invis;
  356. {
  357.   register int i;
  358.  
  359.   if (pathLen < 2) 
  360.     {
  361.       error("Path less than 2 points - ignored");
  362.       return;
  363.     }
  364.   
  365. /* To have filled boxes also have borders, we duplicate the object
  366.    specification; first time we emit a FILL command, second time we emit a
  367.    STROKE command.
  368.    There certainly exists a better way to do that in PostScript, by
  369.    remembering the object specification (path) across the fill command.
  370.    However I (MJ) am completely unproficient at PostScript...
  371. */
  372.  
  373. #ifdef DEBUG
  374.     if (dd(D_SPECIAL))
  375.         (void)fprintf(stderr,
  376. #ifdef SHORTINT
  377.             "flushpath(1): hh=%ld, vv=%ld, x=%ld, y=%ld, xPS=%ld, yPS=%ld\n",
  378. #else   /* ~SHORTINT */
  379.             "flushpath(1): hh=%d, vv=%d, x=%d, y=%d, xPS=%d, yPS=%d\n",
  380. #endif  /* ~SHORTINT */
  381.                     hh, vv, xx[1], yy[1], hconvPS(xx[1]), vconvPS(yy[1]));
  382. #endif /* DEBUG */
  383.   if (shading) {
  384.       /* first time for shading */
  385.       cmdout(NEWPATH); /* to save the current point */
  386.       numout((integer)hconvPS(xx[1]));
  387.       numout((integer)vconvPS(yy[1]));
  388.       cmdout(MOVETO);
  389.       for (i=2; i < pathLen; i++) {
  390. #ifdef DEBUG
  391.     if (dd(D_SPECIAL))
  392.         (void)fprintf(stderr,
  393. #ifdef SHORTINT
  394.         "flushpath(%ld): hh=%ld, vv=%ld, x=%ld, y=%ld, xPS=%ld, yPS=%ld\n",
  395. #else   /* ~SHORTINT */
  396.         "flushpath(%d): hh=%d, vv=%d, x=%d, y=%d, xPS=%d, yPS=%d\n",
  397. #endif  /* ~SHORTINT */
  398.             i, hh, vv, xx[i], yy[i], hconvPS(xx[i]), vconvPS(yy[i]));
  399. #endif /* DEBUG */
  400.     numout((integer)hconvPS(xx[i]));
  401.     numout((integer)vconvPS(yy[i]));
  402.     cmdout(LINETO);
  403.     }
  404.       /* Shading should always apply to a closed path
  405.      force it and complain if necessary */
  406.       if (xx[1] == xx[pathLen] && yy[1] == yy[pathLen])
  407.     cmdout(CLOSEPATH);
  408.       else {
  409.     numout((integer)hconvPS(xx[pathLen]));
  410.     numout((integer)vconvPS(yy[pathLen]));
  411.     cmdout(LINETO);
  412.     cmdout(CLOSEPATH);
  413.     error("Attempt to fill a non-closed path");
  414.     fprintf(stderr,
  415. #ifdef SHORTINT
  416.         "\tfirst point: x=%ld, y=%ld; last point: x=%ld, y=%ld\n",
  417. #else   /* ~SHORTINT */
  418.         "\tfirst point: x=%d, y=%d; last point: x=%d, y=%d\n",
  419. #endif  /* ~SHORTINT */
  420.             xx[1], yy[1], xx[pathLen], yy[pathLen]);
  421.  
  422.       }
  423.       cmdout(FILL);
  424.       shading = NONE;
  425.       cmdout("0 setgray");    /* default of black */
  426.   }
  427.  
  428.   if (!invis) {
  429.       cmdout(NEWPATH);        /* to save the current point */
  430.       numout((integer)hconvPS(xx[1]));
  431.       numout((integer)vconvPS(yy[1]));
  432.       cmdout(MOVETO);
  433.       for (i=2; i < pathLen; i++) {
  434.       numout((integer)hconvPS(xx[i]));
  435.       numout((integer)vconvPS(yy[i]));
  436.       cmdout(LINETO);
  437.       }
  438.       if (xx[1] == xx[pathLen] && yy[1] == yy[pathLen])
  439.       cmdout(CLOSEPATH);
  440.       else {
  441.       numout((integer)hconvPS(xx[pathLen]));
  442.       numout((integer)vconvPS(yy[pathLen]));
  443.       cmdout(LINETO);
  444.       }
  445.       cmdout(STROKE);
  446.   }
  447.  
  448.   pathLen = 0;
  449. }                               /* end of flushPath */
  450.  
  451. void
  452. flushDashed(cp, dotted)
  453.      char *cp;
  454.      int dotted;
  455. {
  456.   float inchesPerDash;
  457.   int savelen = pathLen;
  458.  
  459.   if (sscanf(cp, " %f ", &inchesPerDash) != 1) 
  460.     {
  461.       error ("Illegal format for dotted/dashed line");
  462.       return;
  463.     }
  464.   
  465.   if (inchesPerDash <= 0.0)
  466.     {
  467.       error ("Length of dash/dot cannot be negative");
  468.       return;
  469.     }
  470.  
  471.   inchesPerDash = 1000 * inchesPerDash; /* to get milli-inches */
  472.   flushPath(1);/* print filled, always invisible bounds */
  473.   pathLen = savelen;
  474.   flushDashedPath(dotted,inchesPerDash);
  475.  
  476.   cmdout("[] 0 setdash");
  477. }                               /* end of flushDashed */
  478.  
  479. void
  480. flushSpline(cp)
  481.     char *cp;
  482. {                               /* as exact as psdit!!! */
  483.   register long i, dxi, dyi, dxi1, dyi1;
  484.  
  485.   if (*cp) {
  486.       float inchesPerDash;
  487.       int ipd ;
  488.  
  489.       if (sscanf(cp, "%f ", &inchesPerDash) != 1) {
  490.       error ("Illegal format for dotted/dashed spline");
  491.       return;
  492.       }
  493.   
  494.       ipd = 1000 * inchesPerDash; /* to get milli-inches */
  495.   
  496.       if (ipd != 0) {
  497.       cmdout("[");
  498.       if (inchesPerDash < 0.0) /* dotted */ {
  499.           numout((integer)penSize);
  500.           numout((integer)convPS((int)-ipd) - penSize);
  501.       } else        /* dashed */
  502.           numout((integer)convPS((int)ipd));
  503.  
  504.       cmdout("]");
  505.       numout((integer)0);
  506.       cmdout("setdash");
  507.       }
  508.   }
  509.  
  510.   if (pathLen < 2)
  511.     {
  512.       error("Spline less than two points - ignored");
  513.       return;
  514.     }
  515.   
  516.   cmdout(NEWPATH);      /* to save the current point */
  517.   numout((integer)hconvPS(xx[1]));
  518.   numout((integer)vconvPS(yy[1]));
  519.   cmdout(MOVETO);
  520.   numout((integer)convPS((xx[2]-xx[1])/2));
  521.   numout((integer)convPS((yy[2]-yy[1])/2));
  522.   cmdout(RLINETO);
  523.  
  524.   for (i=2; i < pathLen; i++)
  525.     {
  526.       dxi = convPS(xx[i] - xx[i-1]);
  527.       dyi = convVPS(yy[i] - yy[i-1]);
  528.       dxi1 = convPS(xx[i+1] - xx[i]);
  529.       dyi1 = convVPS(yy[i+1] - yy[i]);
  530.  
  531.       numout((integer)dxi/3);
  532.       numout((integer)dyi/3);
  533.       numout((integer)(3*dxi+dxi1)/6);
  534.       numout((integer)(3*dyi+dyi1)/6);
  535.       numout((integer)(dxi+dxi1)/2);
  536.       numout((integer)(dyi+dyi1)/2);
  537.       cmdout(RCURVETO);
  538.     }
  539.  
  540.   numout((integer)hconvPS(xx[pathLen]));
  541.   numout((integer)vconvPS(yy[pathLen]));
  542.   cmdout(LINETO);
  543.  
  544. /*  doShading(); */
  545.   cmdout(STROKE);        /* assume no shaded splines */
  546.   pathLen = 0;
  547.  
  548.   if (*cp)
  549.       cmdout("[] 0 setdash");
  550.          
  551. }                               /* end of flushSpline */
  552.  
  553. /* set shading level (used with  Fig 1.4-TFX). priol@irisa.fr, 89/04 */
  554. /* A better trial at setting shading level -- jourdan@minos.inria.fr */
  555. /* Count number of black bits in the pattern together with total number, */
  556. /* compute the average and use this as the PostScript gray level */
  557. void
  558. SetShade(cp)
  559. register char *cp;
  560. {
  561.     int blackbits = 0, totalbits = 0;
  562.  
  563.     while (*cp) {
  564.     switch (*cp) {
  565.     case '0':
  566.         totalbits += 4;
  567.         break;
  568.     case '1':
  569.     case '2':
  570.     case '4':
  571.     case '8':
  572.         blackbits += 1;
  573.         totalbits += 4;
  574.         break;
  575.     case '3':
  576.     case '5':
  577.     case '6':
  578.     case '9':
  579.     case 'a':
  580.     case 'A':
  581.     case 'c':
  582.     case 'C':
  583.         blackbits += 2;
  584.         totalbits += 4;
  585.         break;
  586.     case '7':
  587.     case 'b':
  588.     case 'B':
  589.     case 'd':
  590.     case 'D':
  591.     case 'e':
  592.     case 'E':
  593.         blackbits += 3;
  594.         totalbits += 4;
  595.         break;
  596.     case 'f':
  597.     case 'F':
  598.         blackbits += 4;
  599.         totalbits += 4;
  600.         break;
  601.     case ' ':
  602.         break;
  603.     default:
  604.         error("Invalid character in .tx pattern");
  605.         break;
  606.     }
  607.     cp++;
  608.     }
  609.     shadetp = 1.0 - ((double) blackbits / (double) totalbits);
  610.     shading = GRAY;
  611. }                               /* end of SetShade       */
  612.  
  613. void
  614. shadeLast(cp)
  615.     char *cp;
  616. {
  617.   char tpout[20];
  618.  
  619.   if (*cp) {
  620.       float tempShadetp;
  621.  
  622.       if (sscanf(cp, "%f ", &tempShadetp) != 1)
  623.       error ("Illegal format for shade level");
  624.       else if (tempShadetp < 0.0 || tempShadetp > 1.0)
  625.       error ("Invalid shade level");
  626.       else
  627.       /* if "sh" has an argument we can safely assume that tpic 2.0 is used
  628.          so that all subsequent "sh" commands will come with an explicit
  629.          argument.  Hence we may overwrite shadetp's old value */
  630.       /* Also note the inversion of gray levels for tpic 2.0 (0 = white,
  631.          1 = black) w.r.t. PostScript (0 = black, 1 = white) */
  632.       shadetp = 1.0 - tempShadetp;
  633.   }
  634.  
  635.   shading = GRAY;
  636.   sprintf(tpout,"%1.3f setgray",shadetp); /* priol@irisa.fr, MJ */
  637.   cmdout(tpout);
  638. }                               /* end of shadeLast */
  639.  
  640. void
  641. whitenLast()
  642. {
  643.   shading = WHITE;
  644.   cmdout("1 setgray");
  645. }                               /* end of whitenLast */
  646.  
  647. void
  648. blackenLast()
  649. {
  650.   shading = BLACK;
  651.   cmdout("0 setgray");          /* actually this aint needed */
  652. }                               /* end of whitenLast */
  653.  
  654. /*
  655. static void
  656. doShading()
  657. {
  658.   if (shading) 
  659.     {
  660.       cmdout(FILL);
  661.       shading = NONE;
  662.       cmdout("0 setgray");      !* default of black *!
  663.     }
  664.   else
  665.     cmdout(STROKE);
  666. }                               !* end of doShading *!
  667. */
  668.  
  669. /*
  670.  *   We need to calculate (x * convDPI * mag) / (tpicResolution * 1000)
  671.  *   So we use floating point.  (This should have a very small impact
  672.  *   on the speed of the program.)
  673.  */
  674. static integer
  675. zPixRound(x, convDPI)      /* return rounded number of pixels */
  676.         register integer x;             /* in DVI units */
  677.         register integer convDPI;       /* dots per inch */
  678. {
  679.    return ((integer)(x * (float)mag * (float)convDPI /
  680.                     (1000.0 * tpicRESOLUTION))) ;
  681. }
  682.  
  683. #endif /* TPIC */
  684.  
  685.