home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_01 / fig.trm < prev    next >
Text File  |  1991-02-05  |  5KB  |  212 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. /*
  30.  * Original for Fig code output by Micah Beck, 1989
  31.  * Department of Computer Science, Cornell University
  32.  * Updated by David Kotz for gnuplot 2.0
  33.  */
  34. #include "object.h"            /* from the TransFig distribution */
  35.  
  36. #ifndef FIG_RES
  37. /* Must be 80 for the Fig editor, but may be increased if used 
  38.  * only by TransFig filters.
  39.  * Represents resolution per inch.
  40.  */
  41. #define FIG_RES        80
  42. #endif
  43.  
  44. #define FIG_COORD_SYS    2
  45.  
  46. #define FIG_MAGIC    "#FIG 1.4-TFX"
  47. #define FIG_HTIC    (5*FIG_RES/80)
  48. #define FIG_VTIC    (5*FIG_RES/80)
  49. #define FIG_HCHAR    (6*FIG_RES/80)
  50. #define FIG_VCHAR    (12*FIG_RES/80)
  51.  
  52. #define FIG_ARROW_WIDTH FIG_HTIC
  53. #define FIG_ARROW_HEIGHT FIG_HTIC
  54.  
  55. static long FIG_xbase = FIG_RES/2;
  56. static long FIG_ybase = FIG_RES/2;
  57.  
  58. static long FIG_posx;
  59. static long FIG_posy;
  60. /* 5 inches wide by 3 inches high */
  61. #define FIG_XMAX (5 * FIG_RES)
  62. #define FIG_YMAX (3 * FIG_RES)
  63.  
  64. static int FIG_type;        /* negative types use real lines */
  65. static float FIG_spacing;    /* length of dash or dot spacing */
  66. static int FIG_justify;        /* Fig justification T_*_JUSTIFIED */
  67. static float FIG_angle;        /* Fig text angle 0=horiz, Pi/2=vert */
  68.  
  69. #define FIG_POINT_TYPES POINT_TYPES /* we use the same points */
  70.  
  71. FIG_init()
  72. {
  73.     FIG_posx = FIG_posy = 0;
  74.     FIG_linetype(-1);
  75.     FIG_justify_text(LEFT);
  76.     FIG_text_angle(0);
  77.  
  78.     fprintf(outfile, "%s\n", FIG_MAGIC);
  79.     fprintf(outfile, "%d %d\n", FIG_RES, FIG_COORD_SYS);
  80. }
  81.  
  82.  
  83. FIG_graphics()
  84. {
  85.     FIG_posx = FIG_posy = 0;
  86.     /* there is no way to have separate pictures in a FIG file */
  87. }
  88.  
  89.  
  90. FIG_text()
  91. {
  92.     /* there is no way to have separate pictures in a FIG file */
  93. }
  94.  
  95.  
  96. /* Line types for FIG work like this:
  97.  *  -2 : solid (border)
  98.  *  -1 : dashed 4 (axes)
  99.  *   0 : solid (first curve)
  100.  *   1 : dotted 3
  101.  *   2 : dashed 3
  102.  *   3 : dotted 6
  103.  *   4 : dashed 6
  104.  *   ... ...
  105.  */
  106.  
  107. FIG_linetype(linetype)
  108.     int linetype;            /* expect linetype >= -2 */
  109. {
  110.     switch (linetype) {
  111.        case 0:
  112.        case -2: {
  113.           FIG_type = 0;    /* solid line */
  114.           FIG_spacing = 0.0;
  115.           break;
  116.        } 
  117.        case -1: {
  118.           FIG_type = 1;    /* dashed */
  119.           FIG_spacing = 4.0; /* dash length */
  120.           break;
  121.        }
  122.        default: {
  123.           linetype = abs(linetype); /* shouldn't be negative anyway */
  124.           /* now linetype >= 1 */
  125.           FIG_type = linetype % 2 + 1; /* dotted, dashed, ... */
  126.           FIG_spacing = (linetype+1) / 2 * 3;
  127.           break;          
  128.        }
  129.     }
  130. }
  131.  
  132. FIG_move(x,y)
  133.     unsigned int x,y;
  134. {
  135.     FIG_posx = x;
  136.     FIG_posy = y;
  137. }
  138.  
  139. FIG_vector(ux,uy)
  140.     unsigned int ux,uy;
  141. {
  142.         int x=ux, y=uy;
  143.  
  144.       fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  145.          O_POLYLINE, T_POLYLINE,
  146.          FIG_type, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_spacing,
  147.          0, 0);
  148.       fprintf(outfile, "%d %d %d %d 9999 9999\n",
  149.          FIG_posx, FIG_YMAX-FIG_posy, x, FIG_YMAX-y);
  150.  
  151.     FIG_posx = x;
  152.         FIG_posy = y;
  153. }
  154.  
  155. FIG_arrow(sx, sy, ex, ey)
  156.     int sx, sy;    /* start coord */
  157.     int ex, ey;    /* end coord */
  158. {
  159.       fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  160.          O_POLYLINE, T_POLYLINE,
  161.          FIG_type, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_spacing,
  162.          1, 0);
  163.     /* arrow line */
  164.       fprintf(outfile, "%d %d %.3f %.3f %.3f\n",
  165.          0, 0, 1.0, (float)FIG_ARROW_WIDTH, (float)FIG_ARROW_HEIGHT);
  166.       fprintf(outfile, "%d %d %d %d 9999 9999\n",
  167.          sx, FIG_YMAX-sy, ex, FIG_YMAX-ey);
  168.  
  169.     FIG_posx = ex;
  170.         FIG_posy = ey;
  171. }
  172.  
  173. FIG_put_text(x, y, str)
  174.     int x, y;
  175.     char *str;
  176. {
  177.     y = y - FIG_VCHAR/2;        /* assuming vertical center justified */
  178.  
  179.     fprintf(outfile, "%d %d %d %d %d %d %d %6.3f %d %d %d %d %d %s\01\n",
  180.           O_TEXT, FIG_justify,
  181.           ROMAN_FONT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, FIG_angle,
  182.           DEFAULT, 16, 8*strlen(str), x, FIG_YMAX-y, str);
  183. }
  184.  
  185. int FIG_justify_text(mode)
  186.     enum JUSTIFY mode;
  187. {
  188.     switch(mode) {
  189.        case LEFT: FIG_justify = T_LEFT_JUSTIFIED; break;
  190.        case CENTRE: FIG_justify = T_CENTER_JUSTIFIED; break;
  191.        case RIGHT: FIG_justify = T_RIGHT_JUSTIFIED; break;
  192.        /* shouldn't happen */
  193.        default: FIG_justify = T_LEFT_JUSTIFIED; break;
  194.     }
  195.     return (TRUE);
  196. }
  197.  
  198. int FIG_text_angle(angle)
  199.     int angle;
  200. {
  201.     if (angle)
  202.      FIG_angle = Pi / 2.0;    /* vertical is pi/2 radians */
  203.     else
  204.      FIG_angle = 0.0;        /* horizontal */
  205.     return (TRUE);
  206. }
  207.  
  208. FIG_reset()
  209. {
  210.     FIG_posx = FIG_posy = 0;
  211. }
  212.