home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff552.lzh / GNUPlot / gnuplot3.lzh / gnuplot / term / fig.trm < prev    next >
Text File  |  1991-08-25  |  7KB  |  274 lines

  1. /* GNUPLOT - fig.trm */
  2. /*
  3.  * Copyright (C) 1990
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted,
  7.  * provided that the above copyright notice appear in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed
  13.  * as patches to released version.
  14.  *
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  *
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  Fig graphics language
  21.  *
  22.  * AUTHORS
  23.  *  Micah Beck, David Kotz
  24.  *
  25.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  26.  *
  27.  */
  28.  
  29. #ifdef MSDOS
  30. #define long int
  31. #endif /* MSDOS */
  32.  
  33. /*
  34.  * Original for Fig code output by Micah Beck, 1989
  35.  * Department of Computer Science, Cornell University
  36.  * Updated by David Kotz for gnuplot 2.0
  37.  * More efficient output Ian by Dall
  38.  */
  39. #include "object.h"                     /* from the TransFig distribution */
  40. #define FIG_DEFAULT (-1)
  41. #define FIG_ROMAN_FONT (0)
  42.  
  43. #ifndef FIG_RES
  44. /* Must be 80 for the Fig editor, but may be increased if used
  45.  * only by TransFig filters.
  46.  * Represents resolution per inch.
  47.  */
  48. #define FIG_RES         80
  49. #endif
  50.  
  51. #define FIG_COORD_SYS   2
  52.  
  53. #define FIG_MAGIC       "#FIG 1.4-TFX"
  54. #define FIG_HTIC        (5*FIG_RES/80)
  55. #define FIG_VTIC        (5*FIG_RES/80)
  56. #define FIG_FONT_S      FIG_DEFAULT
  57. #define FIG_HCHAR       (6*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  58. #define FIG_VCHAR       (12*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  59. #define FIG_ARROW_WIDTH FIG_HTIC
  60. #define FIG_ARROW_HEIGHT FIG_HTIC
  61.  
  62. static long FIG_xbase = FIG_RES/2;
  63. static long FIG_ybase = FIG_RES/2;
  64.  
  65. static long FIG_posx;
  66. static long FIG_posy;
  67. static int FIG_poly_vec_cnt;
  68. enum FIG_poly_stat {FIG_poly_new, FIG_poly_part};
  69. static enum FIG_poly_stat FIG_polyvec_stat;
  70. /* 5 inches wide by 3 inches high */
  71. #define FIG_XMAX (5 * FIG_RES)
  72. #define FIG_YMAX (3 * FIG_RES)
  73.  
  74. #define FIG_XOFF (FIG_RES/4)
  75. #define FIG_YOFF (FIG_RES/4)
  76.  
  77. static int FIG_type;            /* negative types use real lines */
  78. static float FIG_spacing;       /* length of dash or dot spacing */
  79. static int FIG_justify;         /* Fig justification T_*_JUSTIFIED */
  80. static float FIG_angle;         /* Fig text angle 0=horiz, Pi/2=vert */
  81.  
  82. #define FIG_POINT_TYPES POINT_TYPES /* we use the same points */
  83.  
  84. static
  85.   FIG_poly_clean(stat)
  86. enum FIG_poly_stat stat;
  87. {
  88.   if(stat == FIG_poly_part)
  89.         fprintf(outfile, " 9999 9999\n");
  90.   FIG_polyvec_stat = FIG_poly_new;
  91. }
  92.  
  93. FIG_init()
  94. {
  95.     FIG_posx = FIG_posy = 0;
  96.     FIG_polyvec_stat = FIG_poly_new;
  97.     FIG_linetype(-1);
  98.     FIG_justify_text(LEFT);
  99.     FIG_text_angle(0);
  100.  
  101.     fprintf(outfile, "%s\n", FIG_MAGIC);
  102.     fprintf(outfile, "%d %d\n", FIG_RES, FIG_COORD_SYS);
  103. }
  104.  
  105.  
  106. FIG_graphics()
  107. {
  108.     FIG_posx = FIG_posy = 0;
  109.     FIG_polyvec_stat = FIG_poly_new;
  110.     /* there is no way to have separate pictures in a FIG file */
  111. }
  112.  
  113.  
  114. FIG_text()
  115. {
  116.     /* there is no way to have separate pictures in a FIG file */
  117.     FIG_poly_clean(FIG_polyvec_stat);
  118.     FIG_posx = FIG_posy = 0;
  119.     fflush(outfile);
  120. }
  121.  
  122.  
  123. /* Line types for FIG work like this:
  124.  *  -2 : solid (border)
  125.  *  -1 : dashed 4 (axes)
  126.  *   0 : solid (first curve)
  127.  *   1 : dotted 3
  128.  *   2 : dashed 3
  129.  *   3 : dotted 6
  130.  *   4 : dashed 6
  131.  *   ... ...
  132.  */
  133.  
  134. FIG_linetype(linetype)
  135.         int linetype;                   /* expect linetype >= -2 */
  136. {
  137.     int last_FIG_type = FIG_type;
  138.     int last_FIG_spacing = FIG_spacing;
  139.     switch (linetype) {
  140.            case 0:
  141.            case -2: {
  142.                   FIG_type = 0; /* solid line */
  143.                   FIG_spacing = 0.0;
  144.                   break;
  145.            }
  146.            case -1: {
  147.                   FIG_type = 1; /* dashed */
  148.                   FIG_spacing = 4.0; /* dash length */
  149.                   break;
  150.            }
  151.            default: {
  152.                   linetype = abs(linetype); /* shouldn't be negative anyway */
  153.                   /* now linetype >= 1 */
  154.                   FIG_type = linetype % 2 + 1; /* dotted, dashed, ... */
  155.                   FIG_spacing = (linetype+1) / 2 * 3;
  156.                   break;
  157.            }
  158.     }
  159.     if (FIG_type != last_FIG_type || FIG_spacing != last_FIG_spacing)
  160.       FIG_poly_clean(FIG_polyvec_stat);
  161. }
  162.  
  163. FIG_move(x,y)
  164.         unsigned int x,y;
  165. {
  166.     int last_FIG_posx = FIG_posx;
  167.     int last_FIG_posy = FIG_posy;
  168.     FIG_posx = x;
  169.     FIG_posy = y;
  170.     if (FIG_posx != last_FIG_posx || FIG_posy != last_FIG_posy)
  171.           FIG_poly_clean(FIG_polyvec_stat);
  172. }
  173.  
  174.  
  175. FIG_vector(ux,uy)
  176.      unsigned int ux,uy;
  177. {
  178.   int x=ux, y=uy;
  179.  
  180.   if (FIG_polyvec_stat != FIG_poly_part)
  181.     {
  182.       fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  183.               O_POLYLINE, T_POLYLINE,
  184.               FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  185.               0, 0);
  186.       fprintf(outfile, "%d %d",
  187.               FIG_XOFF + FIG_posx, FIG_YMAX + FIG_YOFF - FIG_posy);
  188.       FIG_poly_vec_cnt = 1;
  189.       FIG_polyvec_stat = FIG_poly_part;
  190.     }
  191.   fprintf(outfile, " %d %d",
  192.           FIG_XOFF +  x, FIG_YMAX + FIG_YOFF-y);
  193.   FIG_poly_vec_cnt++;
  194.   if (FIG_poly_vec_cnt > 50)
  195.     FIG_poly_clean(FIG_polyvec_stat);
  196.  
  197.   FIG_posx = x;
  198.   FIG_posy = y;
  199. }
  200.  
  201.  
  202. FIG_arrow(sx, sy, ex, ey, head)
  203.         int sx, sy;     /* start coord */
  204.         int ex, ey;     /* end coord */
  205.     BOOLEAN head;
  206. {
  207.     FIG_poly_clean(FIG_polyvec_stat);
  208.         fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  209.                 O_POLYLINE, T_POLYLINE,
  210.                 FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  211.                 head ? 1 : 0, 0);
  212.         /* arrow line */
  213.     if ( head )
  214.             fprintf(outfile, "%d %d %.3f %.3f %.3f\n",
  215.                     0, 0, 1.0,
  216.             (double)FIG_ARROW_WIDTH, (double)FIG_ARROW_HEIGHT);
  217.         fprintf(outfile, "%d %d %d %d 9999 9999\n",
  218.                 FIG_XOFF + sx, FIG_YOFF + FIG_YMAX - sy,
  219.         FIG_XOFF + ex, FIG_YOFF + FIG_YMAX - ey);
  220.  
  221.         FIG_posx = ex;
  222.         FIG_posy = ey;
  223. }
  224.  
  225.  
  226. FIG_put_text(x, y, str)
  227.         int x, y;
  228.         char *str;
  229. {
  230.   if (strlen(str) == 0) return;
  231.   FIG_poly_clean(FIG_polyvec_stat);
  232.     y = y - FIG_VCHAR/2;                /* assuming vertical center justified */
  233.  
  234.     fprintf(outfile, "%d %d %d %d %d %d %d %6.3f %d %d %d %d %d %s\01\n",
  235.                   O_TEXT, FIG_justify,
  236.                   FIG_ROMAN_FONT, FIG_FONT_S, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_angle,
  237.                   FIG_DEFAULT, FIG_VCHAR, FIG_HCHAR*strlen(str), FIG_XOFF + x,
  238.         FIG_YMAX + FIG_YOFF-y, str);
  239. }
  240.  
  241. int FIG_justify_text(mode)
  242.         enum JUSTIFY mode;
  243. {
  244.     switch(mode) {
  245.            case LEFT: FIG_justify = T_LEFT_JUSTIFIED; break;
  246.            case CENTRE: FIG_justify = T_CENTER_JUSTIFIED; break;
  247.            case RIGHT: FIG_justify = T_RIGHT_JUSTIFIED; break;
  248.            /* shouldn't happen */
  249.            default: FIG_justify = T_LEFT_JUSTIFIED; break;
  250.     }
  251.     return (TRUE);
  252. }
  253.  
  254. int FIG_text_angle(angle)
  255.         int angle;
  256. {
  257.     if (angle)
  258.          FIG_angle = Pi / 2.0;  /* vertical is pi/2 radians */
  259.     else
  260.          FIG_angle = 0.0;               /* horizontal */
  261.     return (TRUE);
  262. }
  263.  
  264. FIG_reset()
  265. {
  266.     FIG_poly_clean(FIG_polyvec_stat);
  267.     FIG_posx = FIG_posy = 0;
  268.     fflush(outfile);
  269. }
  270.  
  271. #ifdef MSDOS
  272. #undef long
  273. #endif /* MSDOS */
  274.