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

  1. /* Prints out a "string" at reference position with physical         */
  2. /* coordinates (refx,refy). The coordinates of the vectors defining  */
  3. /* the string are passed through the linear mapping defined by the   */
  4. /* 2 x 2 matrix xform() before being plotted.                        */
  5. /* The reference position is at the left-hand edge of the string. If */
  6. /* base = 1, it is aligned with the baseline of the string. If       */
  7. /* base = 0, it is aligned with the centre of the character box.     */
  8.  
  9. /* Note, all calculations are done in terms of millimetres. These */
  10. /* are scaled as necessary before plotting the string on the page */
  11.  
  12. #include "plplot.h"
  13. #include <math.h>
  14.  
  15. void plstr(base,xform,refx,refy,string)
  16. PLINT base, refx, refy;
  17. char *string;
  18. PLFLT *xform;
  19. {
  20.    short int *symbol;
  21.    SCHAR *xygrid;
  22.    PLINT ch, cx, cy, i, k, length, level, penup;
  23.    PLINT xbase, ybase, ydisp, lx, ly, style;
  24.    PLINT oline, uline;
  25.    PLFLT width, xorg, yorg, x, y, def, ht, dscale, scale;
  26.    PLFLT xscl, xoff, yscl, yoff;
  27.  
  28.    width = 0.0;
  29.    oline = 0;
  30.    uline = 0;
  31.  
  32.    gchr(&def,&ht);
  33.    dscale = 0.05*ht;
  34.    scale = dscale;
  35.    gmp(&xscl,&xoff,&yscl,&yoff);
  36.  
  37.    /* Line style must be continuous */
  38.  
  39.    gnms(&style);
  40.    snms(0);
  41.  
  42.    pldeco(&symbol,&length,string);
  43.    xorg = 0.0;
  44.    yorg = 0.0;
  45.    level = 0;
  46.  
  47.    for (i=0; i<length; i++)  {
  48.      ch = symbol[i];
  49.      if (ch == -1) {
  50.        level = level + 1;
  51.        yorg = yorg + 16.0 * scale;
  52.        scale = dscale * pow(0.75,(double)abs(level));
  53.      }
  54.      else if (ch == -2) {
  55.        level = level - 1;
  56.        scale = dscale * pow(0.75,(double)abs(level));
  57.        yorg = yorg - 16.0 * scale;
  58.      }
  59.      else if (ch == -3)
  60.        xorg = xorg - width * scale;
  61.      else if (ch == -4)
  62.        oline = !oline;
  63.      else if (ch == -5)
  64.        uline = !uline;
  65.      else  {
  66.        if (plcvec(ch,&xygrid)) {
  67.          xbase = xygrid[2];
  68.          width = xygrid[3] - xbase;
  69.          if (base == 0) {
  70.            ybase = 0;
  71.            ydisp = xygrid[0];
  72.          }
  73.          else  {
  74.            ybase = xygrid[0];
  75.            ydisp = 0;
  76.          }
  77.          k = 4;
  78.          penup = 1;
  79.          while(1) {
  80.            cx = xygrid[k++];
  81.            cy = xygrid[k++];
  82.            if(cx == 64 && cy == 64)
  83.               break;
  84.            if (cx == 64 && cy == 0)
  85.              penup = 1;
  86.            else {
  87.              x = xorg + (cx - xbase) * scale;
  88.              y = yorg + (cy - ybase) * scale;
  89.              lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  90.              ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  91.              if (penup != 0) {
  92.                movphy(lx,ly);
  93.                penup = 0;
  94.              }
  95.              else
  96.                draphy(lx,ly);
  97.            }
  98.          }
  99.  
  100.          if (oline) {
  101.            x = xorg;
  102.            y = yorg + (30+ydisp)*scale;
  103.            lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  104.            ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  105.            movphy(lx,ly);
  106.            x = xorg + width*scale;
  107.            lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  108.            ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  109.            draphy(lx,ly);
  110.          }
  111.          if (uline) {
  112.            x = xorg;
  113.            y = yorg + (-5+ydisp)*scale;
  114.            lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  115.            ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  116.            movphy(lx,ly);
  117.            x = xorg + width*scale;
  118.            lx = refx + round(xscl*(xform[0]*x + xform[1]*y));
  119.            ly = refy + round(yscl*(xform[2]*x + xform[3]*y));
  120.            draphy(lx,ly);
  121.          }
  122.          xorg = xorg + width*scale;
  123.        }
  124.      }
  125.    }
  126.    snms(style);
  127. }
  128.